mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 10:29:50 +08:00
添加项目文件。
This commit is contained in:
112
CoreCms.Net.Web.WebApi/Controllers/AdvertController.cs
Normal file
112
CoreCms.Net.Web.WebApi/Controllers/AdvertController.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 广告api控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AdvertController : ControllerBase
|
||||
{
|
||||
|
||||
private IHttpContextUser _user;
|
||||
private readonly ICoreCmsArticleServices _articleServices;
|
||||
private readonly ICoreCmsAdvertPositionServices _advertPositionServices;
|
||||
private readonly ICoreCmsAdvertisementServices _advertisementServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="articleServices"></param>
|
||||
/// <param name="advertPositionServices"></param>
|
||||
/// <param name="advertisementServices"></param>
|
||||
public AdvertController(IHttpContextUser user
|
||||
, ICoreCmsArticleServices articleServices
|
||||
, ICoreCmsAdvertPositionServices advertPositionServices
|
||||
, ICoreCmsAdvertisementServices advertisementServices
|
||||
)
|
||||
{
|
||||
_user = user;
|
||||
_articleServices = articleServices;
|
||||
_advertPositionServices = advertPositionServices;
|
||||
_advertisementServices = advertisementServices;
|
||||
}
|
||||
|
||||
#region 获取广告列表=============================================================================
|
||||
/// <summary>
|
||||
/// 获取广告列表
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetAdvertList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _advertisementServices.QueryPageAsync(p => p.code == entity.where, p => p.createTime, OrderByType.Desc,
|
||||
entity.page, entity.limit);
|
||||
jm.status = true;
|
||||
jm.data = list;
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取广告位置信息=============================================================================
|
||||
/// <summary>
|
||||
/// 获取广告位置信息
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetPositionList([FromBody] WxAdvert entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var position = await _advertPositionServices.QueryListByClauseAsync(p => p.isEnable && p.code == entity.codes);
|
||||
if (!position.Any())
|
||||
{
|
||||
return jm;
|
||||
}
|
||||
var ids = position.Select(p => p.id).ToList();
|
||||
var isement = await _advertisementServices.QueryListByClauseAsync(p => ids.Contains(p.positionId));
|
||||
|
||||
Dictionary<string, List<CoreCmsAdvertisement>> list = new Dictionary<string, List<CoreCmsAdvertisement>>();
|
||||
list.Add(entity.codes, isement);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = list;
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
441
CoreCms.Net.Web.WebApi/Controllers/AgentController.cs
Normal file
441
CoreCms.Net.Web.WebApi/Controllers/AgentController.cs
Normal file
@@ -0,0 +1,441 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代理请求接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AgentController : ControllerBase
|
||||
{
|
||||
private IHttpContextUser _user;
|
||||
private readonly ICoreCmsAgentServices _agentServices;
|
||||
private readonly ICoreCmsAgentOrderServices _agentOrderServices;
|
||||
private readonly ICoreCmsAgentGoodsServices _agentGoodsServices;
|
||||
private readonly ICoreCmsSettingServices _settingServices;
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="agentServices"></param>
|
||||
/// <param name="settingServices"></param>
|
||||
/// <param name="agentOrderServices"></param>
|
||||
/// <param name="userServices"></param>
|
||||
/// <param name="goodsServices"></param>
|
||||
/// <param name="agentGoodsServices"></param>
|
||||
public AgentController(IHttpContextUser user, ICoreCmsAgentServices agentServices, ICoreCmsSettingServices settingServices, ICoreCmsAgentOrderServices agentOrderServices, ICoreCmsUserServices userServices, ICoreCmsGoodsServices goodsServices, ICoreCmsAgentGoodsServices agentGoodsServices)
|
||||
{
|
||||
_user = user;
|
||||
_agentServices = agentServices;
|
||||
_settingServices = settingServices;
|
||||
_agentOrderServices = agentOrderServices;
|
||||
_userServices = userServices;
|
||||
_goodsServices = goodsServices;
|
||||
_agentGoodsServices = agentGoodsServices;
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取店铺信息
|
||||
/// <summary>
|
||||
/// 获取店铺信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetStoreInfo([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.id == 0)
|
||||
{
|
||||
jm.msg = "店铺信息丢失";
|
||||
return jm;
|
||||
}
|
||||
var store = UserHelper.GetUserIdByShareCode(entity.id);
|
||||
if (store <= 0)
|
||||
{
|
||||
jm.msg = "店铺信息丢失";
|
||||
return jm;
|
||||
}
|
||||
jm = await _agentServices.GetStore(store);
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 根据查询条件获取分页数据============================================================
|
||||
/// <summary>
|
||||
/// 根据查询条件获取分页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsPageList([FromBody] FMPageByWhereOrder entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var where = PredicateBuilder.True<CoreCmsGoods>();
|
||||
where = where.And(p => p.isDel == false);
|
||||
where = where.And(p => p.isMarketable == true);
|
||||
|
||||
var className = string.Empty;
|
||||
if (!string.IsNullOrEmpty(entity.where))
|
||||
{
|
||||
var obj = JsonConvert.DeserializeAnonymousType(entity.where, new
|
||||
{
|
||||
priceFrom = "",
|
||||
priceTo = "",
|
||||
catId = "",
|
||||
brandId = "",
|
||||
labelId = "",
|
||||
searchName = "",
|
||||
});
|
||||
|
||||
if (!string.IsNullOrEmpty(obj.priceFrom))
|
||||
{
|
||||
var priceF = obj.priceFrom.ObjectToDouble(0);
|
||||
if (priceF >= 0)
|
||||
{
|
||||
var f = Convert.ToDecimal(priceF);
|
||||
where = where.And(p => p.price >= f);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(obj.priceTo))
|
||||
{
|
||||
var priceT = obj.priceTo.ObjectToDouble(0);
|
||||
if (priceT >= 0)
|
||||
{
|
||||
var f = Convert.ToDecimal(priceT);
|
||||
where = where.And(p => p.price <= f);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(obj.brandId))
|
||||
{
|
||||
var brandId = obj.brandId.ObjectToInt(0);
|
||||
if (brandId >= 0)
|
||||
{
|
||||
where = where.And(p => p.brandId == brandId);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(obj.labelId))
|
||||
{
|
||||
var brandId = obj.brandId.ObjectToInt(0);
|
||||
if (brandId >= 0)
|
||||
{
|
||||
where = where.And(p => p.brandId == brandId);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(obj.searchName))
|
||||
{
|
||||
where = where.And(p => p.name.Contains(obj.searchName));
|
||||
}
|
||||
}
|
||||
|
||||
var orderBy = " isRecommend desc,isHot desc";
|
||||
if (!string.IsNullOrEmpty(entity.order))
|
||||
{
|
||||
orderBy += "," + entity.order;
|
||||
}
|
||||
|
||||
var list = await _goodsServices.QueryAgentGoodsPageAsync(where, orderBy, entity.page, entity.limit, false);
|
||||
if (list.Any())
|
||||
{
|
||||
foreach (var goods in list)
|
||||
{
|
||||
goods.images = !string.IsNullOrEmpty(goods.images) ? goods.images.Split(",")[0] : "/static/images/common/empty.png";
|
||||
}
|
||||
}
|
||||
|
||||
//返回数据
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
list,
|
||||
className,
|
||||
entity.page,
|
||||
list.TotalCount,
|
||||
list.TotalPages,
|
||||
entity.limit,
|
||||
entity.where,
|
||||
entity.order,
|
||||
};
|
||||
jm.msg = "数据调用成功!";
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 查询用户是否可以成为代理商
|
||||
/// <summary>
|
||||
/// 查询用户是否可以成为代理商
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> Info()
|
||||
{
|
||||
var jm = await _agentServices.GetInfo(_user.ID);
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 申请成为代理商接口
|
||||
/// <summary>
|
||||
/// 申请成为代理商接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> ApplyAgent([FromBody] FMAgentApply entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.agreement != "on")
|
||||
{
|
||||
jm.msg = "请勾选代理商协议";
|
||||
return jm;
|
||||
}
|
||||
var iData = new CoreCmsAgent();
|
||||
iData.mobile = entity.mobile;
|
||||
iData.name = entity.name;
|
||||
iData.weixin = entity.weixin;
|
||||
iData.qq = entity.qq;
|
||||
jm = await _agentServices.AddData(iData, _user.ID);
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取我的下级用户数量
|
||||
/// <summary>
|
||||
/// 获取我的下级用户数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetTeamSum()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//发展人数
|
||||
var first = await _userServices.QueryChildCountAsync(_user.ID, 1);
|
||||
//订单数
|
||||
var second = await _agentOrderServices.GetCountAsync(p => p.userId == _user.ID);
|
||||
|
||||
//当月发展人数
|
||||
var monthFirst = await _userServices.QueryChildCountAsync(_user.ID, 1, true);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
//本月第一天时间
|
||||
DateTime dtFirst = dt.AddDays(1 - (dt.Day));
|
||||
dtFirst = new DateTime(dtFirst.Year, dtFirst.Month, dtFirst.Day, 0, 0, 0);
|
||||
//获得某年某月的天数
|
||||
int year = dt.Date.Year;
|
||||
int month = dt.Date.Month;
|
||||
int dayCount = DateTime.DaysInMonth(year, month);
|
||||
//本月最后一天时间
|
||||
DateTime dtLast = dtFirst.AddDays(dayCount - 1);
|
||||
|
||||
var monthSecond = await _agentOrderServices.GetCountAsync(p => p.userId == _user.ID && p.createTime > dtFirst && p.createTime < dtLast, true);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
count = first + second,
|
||||
first,
|
||||
second,
|
||||
monthCount = monthFirst + monthSecond,
|
||||
monthFirst,
|
||||
monthSecond
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取我的订单统计
|
||||
/// <summary>
|
||||
/// 获取我的订单统计
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetOrderSum()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
//本月第一天时间
|
||||
DateTime dtFirst = dt.AddDays(1 - (dt.Day));
|
||||
dtFirst = new DateTime(dtFirst.Year, dtFirst.Month, dtFirst.Day, 0, 0, 0);
|
||||
//获得某年某月的天数
|
||||
int dayCount = DateTime.DaysInMonth(dt.Date.Year, dt.Date.Month);
|
||||
//本月最后一天时间
|
||||
DateTime dtLast = dtFirst.AddDays(dayCount - 1);
|
||||
|
||||
|
||||
//全部订单
|
||||
var allOrder = await _agentOrderServices.GetCountAsync(p => p.userId == _user.ID, true);
|
||||
//代购订单
|
||||
var procurementServiceOrder = await _agentOrderServices.GetCountAsync(p => p.userId == _user.ID && p.buyUserId == _user.ID, true);
|
||||
//推广订单
|
||||
var customerOrder = await _agentOrderServices.GetCountAsync(p => p.userId == _user.ID && p.buyUserId != _user.ID, true);
|
||||
//本月订单
|
||||
var monthOrder = await _agentOrderServices.GetCountAsync(p => p.userId == _user.ID && p.createTime > dtFirst && p.createTime < dtLast, true);
|
||||
|
||||
|
||||
//全部订单金额
|
||||
var allOrderMoney = await _agentOrderServices.GetSumAsync(p => p.userId == _user.ID, p => p.amount, true);
|
||||
//代购订单金额
|
||||
var procurementServiceOrderMoney = await _agentOrderServices.GetSumAsync(p => p.userId == _user.ID && p.buyUserId == _user.ID, p => p.amount, true);
|
||||
//推广订单金额
|
||||
var customerOrderMoney = await _agentOrderServices.GetSumAsync(p => p.userId == _user.ID && p.buyUserId != _user.ID, p => p.amount, true);
|
||||
//本月订单金额
|
||||
var monthOrderMoney = await _agentOrderServices.GetSumAsync(p => p.userId == _user.ID && p.createTime > dtFirst && p.createTime < dtLast, p => p.amount, true);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
allOrder,
|
||||
procurementServiceOrder,
|
||||
customerOrder,
|
||||
monthOrder,
|
||||
allOrderMoney,
|
||||
procurementServiceOrderMoney,
|
||||
customerOrderMoney,
|
||||
monthOrderMoney
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 我推广的订单
|
||||
/// <summary>
|
||||
/// 我推广的订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> MyOrder([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = await _agentServices.GetMyOrderList(_user.ID, entity.page, entity.limit, entity.id);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 店铺设置
|
||||
/// <summary>
|
||||
/// 店铺设置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> SetStore([FromBody] FMSetAgentStorePost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.storeName))
|
||||
{
|
||||
jm.msg = "请填写店铺名称";
|
||||
return jm;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.storeLogo))
|
||||
{
|
||||
jm.msg = "请上传店铺logo";
|
||||
return jm;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.storeBanner))
|
||||
{
|
||||
jm.msg = "请上传店铺banner";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var info = await _agentServices.QueryByClauseAsync(p => p.userId == _user.ID);
|
||||
if (info != null)
|
||||
{
|
||||
info.storeLogo = entity.storeLogo;
|
||||
info.storeBanner = entity.storeBanner;
|
||||
info.storeDesc = entity.storeDesc;
|
||||
info.storeName = entity.storeName;
|
||||
await _agentServices.UpdateAsync(info);
|
||||
}
|
||||
jm.status = true;
|
||||
jm.msg = "保存成功";
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取代理商排行
|
||||
/// <summary>
|
||||
/// 获取代理商排行
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetAgentRanking([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _agentServices.QueryRankingPageAsync(entity.page, entity.limit);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
data = list,
|
||||
list.HasNextPage,
|
||||
list.HasPreviousPage,
|
||||
list.PageIndex,
|
||||
list.PageSize,
|
||||
list.TotalPages,
|
||||
list.TotalCount,
|
||||
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
127
CoreCms.Net.Web.WebApi/Controllers/ArticleController.cs
Normal file
127
CoreCms.Net.Web.WebApi/Controllers/ArticleController.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章api控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ArticleController : ControllerBase
|
||||
{
|
||||
|
||||
private IHttpContextUser _user;
|
||||
private readonly ICoreCmsArticleServices _articleServices;
|
||||
private readonly ICoreCmsArticleTypeServices _articleTypeServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="articleServices"></param>
|
||||
/// <param name="articleTypeServices"></param>
|
||||
public ArticleController(IHttpContextUser user, ICoreCmsArticleServices articleServices, ICoreCmsArticleTypeServices articleTypeServices)
|
||||
{
|
||||
_user = user;
|
||||
_articleServices = articleServices;
|
||||
_articleTypeServices = articleTypeServices;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 获取通知列表
|
||||
/// <summary>
|
||||
/// 获取通知列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> NoticeList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _articleServices.QueryPageAsync(p => p.isDel == false, p => p.createTime, OrderByType.Desc,
|
||||
entity.page, entity.limit);
|
||||
jm.status = true;
|
||||
jm.data = list;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取文章列表
|
||||
/// <summary>
|
||||
/// 获取文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetArticleList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _articleServices.QueryPageAsync(p => p.isDel == false && p.typeId == entity.id, p => p.createTime, OrderByType.Desc,
|
||||
entity.page, entity.limit);
|
||||
|
||||
var articleType = await _articleTypeServices.QueryAsync();
|
||||
var typeName = string.Empty;
|
||||
if (articleType.Any())
|
||||
{
|
||||
var type = articleType.Find(p => p.id == entity.id);
|
||||
typeName = type != null ? type.name : "";
|
||||
}
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
list,
|
||||
articleType,
|
||||
type_name = typeName,
|
||||
count = list.TotalCount
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个文章内容
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetArticleDetail([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var model = await _articleServices.ArticleDetail(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "数据获取失败";
|
||||
return jm;
|
||||
}
|
||||
jm.status = true;
|
||||
jm.data = model;
|
||||
return jm;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
142
CoreCms.Net.Web.WebApi/Controllers/CartController.cs
Normal file
142
CoreCms.Net.Web.WebApi/Controllers/CartController.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车操作
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class CartController : ControllerBase
|
||||
{
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsCartServices _cartServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CartController(IHttpContextUser user, ICoreCmsCartServices cartServices)
|
||||
{
|
||||
_user = user;
|
||||
_cartServices = cartServices;
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 添加单个货品到购物车
|
||||
|
||||
/// <summary>
|
||||
/// 添加单个货品到购物车
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> AddCart([FromBody] FMCartAdd entity)
|
||||
{
|
||||
var jm = await _cartServices.Add(_user.ID, entity.ProductId, entity.Nums, entity.type, entity.cartType, entity.objectId);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion 添加单个货品到购物车
|
||||
|
||||
#region 获取购物车列表======================================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取购物车列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetList([FromBody] FMCartGetList entity)
|
||||
{
|
||||
var ids = CommonHelper.StringToIntArray(entity.ids);
|
||||
//判断免费运费
|
||||
var freeFreight = entity.receiptType != 1;
|
||||
//获取数据
|
||||
var jm = await _cartServices.GetCartInfos(_user.ID, ids, entity.type, entity.areaId, entity.point, entity.couponCode, freeFreight, entity.receiptType, entity.objectId);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion 获取购物车列表======================================================================
|
||||
|
||||
#region 删除购物车信息
|
||||
|
||||
/// <summary>
|
||||
/// 获取购物车列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> DoDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.id <= 0)
|
||||
{
|
||||
jm.msg = "请提交要删除的货品";
|
||||
return jm;
|
||||
}
|
||||
jm = await _cartServices.DeleteByIdsAsync(entity.id, _user.ID);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion 删除购物车信息
|
||||
|
||||
#region 设置购物车商品数量
|
||||
|
||||
/// <summary>
|
||||
/// 设置购物车商品数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> SetCartNum([FromBody] FMSetCartNum entity)
|
||||
{
|
||||
var jm = await _cartServices.SetCartNum(entity.id, entity.nums, _user.ID, 2, 1);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion 设置购物车商品数量
|
||||
|
||||
#region 根据提交的数据判断哪些购物券可以使用==================================================
|
||||
|
||||
/// <summary>
|
||||
/// 根据提交的数据判断哪些购物券可以使用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetCartAvailableCoupon([FromBody] FMCouponForUserCouponPost entity)
|
||||
{
|
||||
var ids = CommonHelper.StringToIntArray(entity.ids);
|
||||
var jm = await _cartServices.GetCartAvailableCoupon(_user.ID, ids);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion 根据提交的数据判断哪些购物券可以使用==================================================
|
||||
}
|
||||
}
|
||||
327
CoreCms.Net.Web.WebApi/Controllers/CommonController.cs
Normal file
327
CoreCms.Net.Web.WebApi/Controllers/CommonController.cs
Normal file
@@ -0,0 +1,327 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Aliyun.OSS;
|
||||
using Aliyun.OSS.Util;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.Options;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using COSXML;
|
||||
using COSXML.Auth;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用调用接口数据
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class CommonController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly ICoreCmsSettingServices _settingServices;
|
||||
private readonly ICoreCmsAreaServices _areaServices;
|
||||
private readonly ICoreCmsServiceDescriptionServices _serviceDescriptionServices;
|
||||
|
||||
private readonly ICoreCmsSettingServices _coreCmsSettingServices;
|
||||
private readonly IToolsServices _toolsServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CommonController(ICoreCmsSettingServices settingServices
|
||||
, ICoreCmsAreaServices areaServices
|
||||
, IWebHostEnvironment webHostEnvironment, ICoreCmsServiceDescriptionServices serviceDescriptionServices, ICoreCmsSettingServices coreCmsSettingServices, IToolsServices toolsServices)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_serviceDescriptionServices = serviceDescriptionServices;
|
||||
_coreCmsSettingServices = coreCmsSettingServices;
|
||||
_toolsServices = toolsServices;
|
||||
_settingServices = settingServices;
|
||||
_areaServices = areaServices;
|
||||
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 接口测试反馈=============================================================
|
||||
/// <summary>
|
||||
/// 接口测试反馈
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public WebApiCallBack InterFaceTest()
|
||||
{
|
||||
var jm = new WebApiCallBack { status = true, msg = "接口访问正常", data = DateTime.Now };
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 返回配置数据文件V2.0===============================================================
|
||||
/// <summary>
|
||||
/// 返回配置数据文件V2.0
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetConfigV2()
|
||||
{
|
||||
var jm = new WebApiCallBack { status = true, msg = "接口访问正常", data = DateTime.Now };
|
||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
||||
|
||||
var shopLogo = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopLogo); //店铺logo
|
||||
var shopName = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopName); //店铺名称
|
||||
var shopBeiAn = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopBeiAn); //店铺备案
|
||||
var shopDesc = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopDesc); //店铺描述
|
||||
var showStoresSwitch = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowStoresSwitch).ObjectToInt(2); //显示门店列表
|
||||
var showStoreBalanceRechargeSwitch = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowStoreBalanceRechargeSwitch).ObjectToInt(2); //显示充值功能
|
||||
|
||||
var imageMax = 5; //前端上传图片最多几张
|
||||
var storeSwitch = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.StoreSwitch).ObjectToInt(); //开启门店自提状态
|
||||
var cateStyle = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.CateStyle).ObjectToInt(); //分类样式
|
||||
var cateType = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.CateType).ObjectToInt(); //H5分类类型
|
||||
var toCashMoneyLow = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.TocashMoneyLow); //最低提现
|
||||
var toCashMoneyRate = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.TocashMoneyRate); //服务费
|
||||
var pointSwitch = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.PointSwitch).ObjectToInt(); //是否开启积分功能
|
||||
var statistics = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.StatisticsCode); //获取统计代码
|
||||
var recommendKeysStr = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.RecommendKeys);
|
||||
var recommendKeys = !string.IsNullOrEmpty(recommendKeysStr) ? recommendKeysStr.Split("|") : new string[] { }; //搜索推荐关键字
|
||||
var invoiceSwitch = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.InvoiceSwitch).ObjectToInt(); //发票功能开关
|
||||
var goodsStocksWarn = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.GoodsStocksWarn).ObjectToInt(); //库存报警数量
|
||||
var shopDefaultImage = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopDefaultImage); //获取默认图片
|
||||
var shopMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopMobile); //店铺联系电话
|
||||
var openDistribution = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.OpenDistribution).ObjectToInt(); //是否开启分销
|
||||
var distributionNotes = string.Empty;
|
||||
var distributionAgreement = string.Empty;
|
||||
var distributionStore = 2;
|
||||
if (openDistribution == 1)
|
||||
{
|
||||
distributionNotes = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DistributionNotes); //用户须知
|
||||
distributionAgreement = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DistributionAgreement); //分销协议
|
||||
distributionStore = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DistributionStore).ObjectToInt(2); //是否开启店铺
|
||||
}
|
||||
var showInviter = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowInviterInfo).ObjectToInt(); //是否显示邀请人信息
|
||||
var shareTitle = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShareTitle); //分享标题
|
||||
var shareDesc = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShareDesc); //分享描述
|
||||
var shareImage = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShareImage); //分享图片
|
||||
var aboutArticleId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.AboutArticleId).ObjectToInt(2); //关于我们文章
|
||||
var entId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.EntId); //客服ID
|
||||
var userAgreementId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.UserAgreementId).ObjectToInt(3); //用户协议
|
||||
var privacyPolicyId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.PrivacyPolicyId).ObjectToInt(4); //隐私政策
|
||||
|
||||
var reshipName = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipName); //退货联系人
|
||||
var reshipMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipMobile); //退货联系方式
|
||||
var reshipAreaId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAreaId); //退货区域
|
||||
var reshipAddress = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAddress); //退货联系方式
|
||||
var reshipCoordinate = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipCoordinate); //退货坐标
|
||||
|
||||
var orderCancelTime = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.OrderCancelTime).ObjectToInt(60); //订单取消时间
|
||||
|
||||
//代理
|
||||
var isOpenAgent = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IsOpenAgent).ObjectToInt(); //是否开启代理模块
|
||||
var isShowAgentPortal = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IsShowAgentPortal).ObjectToInt(); //是否显示代理模块入口
|
||||
|
||||
var agentNotes = string.Empty;
|
||||
var agentAgreement = string.Empty;
|
||||
if (isOpenAgent == 1 && isShowAgentPortal == 1)
|
||||
{
|
||||
agentNotes = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.AgentNotes); //用户须知
|
||||
agentAgreement = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.AgentAgreement); //分销协议
|
||||
}
|
||||
|
||||
|
||||
var model = new
|
||||
{
|
||||
shopLogo,
|
||||
shopName,
|
||||
shopBeiAn = shopBeiAn,
|
||||
shopDesc,
|
||||
imageMax,
|
||||
storeSwitch,
|
||||
showStoresSwitch,
|
||||
showStoreBalanceRechargeSwitch,
|
||||
cateStyle,
|
||||
cateType,
|
||||
toCashMoneyLow,
|
||||
toCashMoneyRate,
|
||||
pointSwitch,
|
||||
statistics,
|
||||
recommendKeys,
|
||||
invoiceSwitch,
|
||||
goodsStocksWarn,
|
||||
shopDefaultImage,
|
||||
shopMobile,
|
||||
openDistribution,
|
||||
distributionNotes,
|
||||
distributionAgreement,
|
||||
distributionStore,
|
||||
showInviter,
|
||||
shareTitle,
|
||||
shareDesc,
|
||||
shareImage,
|
||||
aboutArticleId,
|
||||
entId,
|
||||
userAgreementId,
|
||||
privacyPolicyId,
|
||||
reshipName,
|
||||
reshipMobile,
|
||||
reshipAreaId,
|
||||
reshipAddress,
|
||||
reshipCoordinate,
|
||||
orderCancelTime,
|
||||
isOpenAgent,
|
||||
isShowAgentPortal,
|
||||
agentNotes,
|
||||
agentAgreement
|
||||
};
|
||||
jm.data = model;
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取区域配置=============================================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取层级分配后的区域信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetAreas()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var areas = await _areaServices.GetCaChe();
|
||||
jm.status = true;
|
||||
jm.data = AreaHelper.GetList(areas);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取商城关键词说明列表
|
||||
|
||||
/// <summary>
|
||||
/// 获取商城关键词说明列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetServiceDescription()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var caCheList = await _serviceDescriptionServices.GetCaChe();
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
commonQuestion = caCheList.Where(p => p.type == (int)GlobalEnumVars.ShopServiceNoteType.CommonQuestion && p.isShow == true).OrderBy(p => p.sortId).ToList(),
|
||||
service = caCheList.Where(p => p.type == (int)GlobalEnumVars.ShopServiceNoteType.Service && p.isShow == true).OrderBy(p => p.sortId).ToList(),
|
||||
delivery = caCheList.Where(p => p.type == (int)GlobalEnumVars.ShopServiceNoteType.Delivery && p.isShow == true).OrderBy(p => p.sortId).ToList()
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 上传附件通用接口====================================================
|
||||
|
||||
/// <summary>
|
||||
/// 上传附件通用接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> UploadImages()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
|
||||
|
||||
//初始化上传参数
|
||||
var maxSize = 1024 * 1024 * filesStorageOptions.MaxSize; //上传大小5M
|
||||
|
||||
var file = Request.Form.Files["file"];
|
||||
if (file == null)
|
||||
{
|
||||
jm.msg = "请选择文件";
|
||||
return jm;
|
||||
}
|
||||
string fileName = file.FileName;
|
||||
string fileExt = Path.GetExtension(fileName).ToLowerInvariant();
|
||||
|
||||
//检查大小
|
||||
if (file.Length > maxSize)
|
||||
{
|
||||
jm.msg = "上传文件大小超过限制,最大允许上传" + filesStorageOptions.MaxSize + "M";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//检查文件扩展名
|
||||
if (string.IsNullOrEmpty(fileExt) ||
|
||||
Array.IndexOf(filesStorageOptions.FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
|
||||
{
|
||||
jm.msg = "上传文件扩展名是不允许的扩展名,请上传后缀名为:" + filesStorageOptions.FileTypes;
|
||||
return jm;
|
||||
}
|
||||
|
||||
string url = string.Empty;
|
||||
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForLocalStorage(filesStorageOptions, fileExt, file, (int)GlobalEnumVars.FilesStorageLocation.API);
|
||||
}
|
||||
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForAliYunOSS(filesStorageOptions, fileExt, file);
|
||||
}
|
||||
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForQCloudOSS(filesStorageOptions, fileExt, file);
|
||||
}
|
||||
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForQiNiuKoDo(filesStorageOptions, fileExt, file);
|
||||
}
|
||||
|
||||
var bl = !string.IsNullOrEmpty(url);
|
||||
jm.status = bl;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? "上传成功!" : "上传失败";
|
||||
jm.data = new
|
||||
{
|
||||
fileUrl = url,
|
||||
src = url,
|
||||
imageId = url
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
226
CoreCms.Net.Web.WebApi/Controllers/CouponController.cs
Normal file
226
CoreCms.Net.Web.WebApi/Controllers/CouponController.cs
Normal file
@@ -0,0 +1,226 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class CouponController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsCouponServices _couponServices;
|
||||
private readonly ICoreCmsPromotionServices _promotionServices;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="couponServices"></param>
|
||||
/// <param name="promotionServices"></param>
|
||||
public CouponController(IHttpContextUser user
|
||||
, ICoreCmsCouponServices couponServices, ICoreCmsPromotionServices promotionServices)
|
||||
{
|
||||
_user = user;
|
||||
_couponServices = couponServices;
|
||||
_promotionServices = promotionServices;
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取 可领取的优惠券==================================================
|
||||
/// <summary>
|
||||
/// 获取 可领取的优惠券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
//[Authorize]
|
||||
public async Task<WebApiCallBack> CouponList([FromBody] FMCouponForUserCouponPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack() { msg = "获取失败" };
|
||||
|
||||
var list = await _promotionServices.GetReceiveCouponList(entity.page, entity.limit);
|
||||
jm.status = true;
|
||||
jm.data = list;
|
||||
jm.msg = "获取成功";
|
||||
jm.otherData = new
|
||||
{
|
||||
totalCount = 0,
|
||||
totalPages = 0,
|
||||
};
|
||||
if (list != null && list.Any())
|
||||
{
|
||||
jm.data = list;
|
||||
jm.otherData = new
|
||||
{
|
||||
list.TotalCount,
|
||||
list.TotalPages
|
||||
};
|
||||
}
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 获取优惠券 详情==================================================
|
||||
/// <summary>
|
||||
/// 获取优惠券 详情
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> CouponDetail([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack() { msg = "获取失败" };
|
||||
|
||||
if (entity.id == 0)
|
||||
{
|
||||
jm.status = false;
|
||||
jm.msg = GlobalErrorCodeVars.Code15006;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var promotionModel = await _promotionServices.QueryByClauseAsync(p => p.id == entity.id);
|
||||
if (promotionModel != null)
|
||||
{
|
||||
jm.status = true;
|
||||
jm.data = promotionModel;
|
||||
jm.msg = "获取成功";
|
||||
}
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取用户已领取的优惠券==================================================
|
||||
/// <summary>
|
||||
/// 获取用户已领取的优惠券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> UserCoupon([FromBody] FMCouponForUserCouponPost entity)
|
||||
{
|
||||
var jm = await _couponServices.GetMyCoupon(_user.ID, 0, entity.display, entity.page, entity.limit);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 用户领取优惠券==================================================
|
||||
/// <summary>
|
||||
/// 用户领取优惠券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetCoupon([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.id == 0)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15006;
|
||||
return jm;
|
||||
}
|
||||
//判断优惠券是否可以领取?
|
||||
var promotionModel = await _promotionServices.ReceiveCoupon(entity.id);
|
||||
if (promotionModel.status == false)
|
||||
{
|
||||
return promotionModel;
|
||||
}
|
||||
|
||||
var promotion = (CoreCmsPromotion)promotionModel.data;
|
||||
if (promotion == null)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15019;
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (promotion.maxNums > 0)
|
||||
{
|
||||
//判断用户是否已领取?领取次数
|
||||
var couponResult = await _couponServices.GetMyCoupon(_user.ID, entity.id, "all", 1, 9999);
|
||||
if (couponResult.status && couponResult.code >= promotion.maxNums)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15018;
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
jm = await _couponServices.AddData(_user.ID, entity.id, promotion);
|
||||
jm.otherData = promotionModel;
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 用户输入code领取优惠券==================================================
|
||||
/// <summary>
|
||||
/// 用户输入code领取优惠券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetCouponKey([FromBody] FMCouponForGetCouponKeyPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.key))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15006;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var coupon = await _couponServices.QueryByClauseAsync(p => p.couponCode == entity.key);
|
||||
if (coupon == null || coupon.promotionId <= 0)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15009;
|
||||
return jm;
|
||||
}
|
||||
|
||||
//判断优惠券是否可以领取?
|
||||
var promotionModel = await _promotionServices.ReceiveCoupon(coupon.promotionId);
|
||||
if (promotionModel.status == false)
|
||||
{
|
||||
return promotionModel;
|
||||
}
|
||||
//判断用户是否已领取?
|
||||
if (promotionModel.data is CoreCmsPromotion { maxNums: > 0 } info)
|
||||
{
|
||||
//判断用户是否已领取?领取次数
|
||||
var couponResult = await _couponServices.GetMyCoupon(_user.ID, coupon.promotionId, "all", 1, 9999);
|
||||
if (couponResult.status && couponResult.code > info.maxNums)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15018;
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
//
|
||||
jm = await _couponServices.ReceiveCoupon(_user.ID, entity.key);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
29
CoreCms.Net.Web.WebApi/Controllers/DemoController.cs
Normal file
29
CoreCms.Net.Web.WebApi/Controllers/DemoController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认接口示例
|
||||
/// </summary>
|
||||
public class DemoController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认首页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Content("已结束");
|
||||
}
|
||||
}
|
||||
}
|
||||
313
CoreCms.Net.Web.WebApi/Controllers/DistributionController.cs
Normal file
313
CoreCms.Net.Web.WebApi/Controllers/DistributionController.cs
Normal file
@@ -0,0 +1,313 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 分销请求接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class DistributionController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsDistributionOrderServices _distributionOrderServices;
|
||||
private readonly ICoreCmsDistributionServices _distributionServices;
|
||||
private readonly ICoreCmsSettingServices _settingServices;
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
private readonly IHttpContextUser _user;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public DistributionController(IHttpContextUser user, ICoreCmsDistributionServices distributionServices,
|
||||
ICoreCmsSettingServices settingServices, ICoreCmsUserServices userServices,
|
||||
ICoreCmsDistributionOrderServices distributionOrderServices)
|
||||
{
|
||||
_user = user;
|
||||
_distributionServices = distributionServices;
|
||||
_settingServices = settingServices;
|
||||
_userServices = userServices;
|
||||
_distributionOrderServices = distributionOrderServices;
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取店铺信息
|
||||
|
||||
/// <summary>
|
||||
/// 获取店铺信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetStoreInfo([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.id == 0)
|
||||
{
|
||||
jm.msg = "店铺信息丢失";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var store = UserHelper.GetUserIdByShareCode(entity.id);
|
||||
if (store <= 0)
|
||||
{
|
||||
jm.msg = "店铺信息丢失";
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm = await _distributionServices.GetStore(store);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 查询用户是否可以成为分销商
|
||||
|
||||
/// <summary>
|
||||
/// 查询用户是否可以成为分销商
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> Info()
|
||||
{
|
||||
var jm = await _distributionServices.GetInfo(_user.ID, true);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 申请成为分销商接口
|
||||
|
||||
/// <summary>
|
||||
/// 申请成为分销商接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> ApplyDistribution([FromBody] FMDistributionApply entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.agreement != "on")
|
||||
{
|
||||
jm.msg = "请勾选分销协议";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var iData = new CoreCmsDistribution();
|
||||
iData.mobile = entity.mobile;
|
||||
iData.name = entity.name;
|
||||
iData.weixin = entity.weixin;
|
||||
iData.qq = entity.qq;
|
||||
jm = await _distributionServices.AddData(iData, _user.ID);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 我推广的订单
|
||||
|
||||
/// <summary>
|
||||
/// 我推广的订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> MyOrder([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = await _distributionServices.GetMyOrderList(_user.ID, entity.page, entity.limit, entity.id);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 店铺设置
|
||||
|
||||
/// <summary>
|
||||
/// 店铺设置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> SetStore([FromBody] FMSetDistributionStorePost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.storeName))
|
||||
{
|
||||
jm.msg = "请填写店铺名称";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(entity.storeLogo))
|
||||
{
|
||||
jm.msg = "请上传店铺logo";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(entity.storeBanner))
|
||||
{
|
||||
jm.msg = "请上传店铺banner";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var info = await _distributionServices.QueryByClauseAsync(p => p.userId == _user.ID);
|
||||
if (info != null)
|
||||
{
|
||||
info.storeLogo = entity.storeLogo;
|
||||
info.storeBanner = entity.storeBanner;
|
||||
info.storeDesc = entity.storeDesc;
|
||||
info.storeName = entity.storeName;
|
||||
await _distributionServices.UpdateAsync(info);
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "保存成功";
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取我的订单统计
|
||||
|
||||
/// <summary>
|
||||
/// 获取我的订单统计
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetOrderSum()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//全部订单
|
||||
var allOrder = await _distributionOrderServices.QueryChildOrderCountAsync(_user.ID, 0);
|
||||
//一级订单
|
||||
var firstOrder = await _distributionOrderServices.QueryChildOrderCountAsync(_user.ID);
|
||||
//二级订单
|
||||
var secondOrder = await _distributionOrderServices.QueryChildOrderCountAsync(_user.ID, 2);
|
||||
//本月订单
|
||||
var monthOrder = await _distributionOrderServices.QueryChildOrderCountAsync(_user.ID, 0, true);
|
||||
|
||||
//全部订单金额
|
||||
var allOrderMoney = await _distributionOrderServices.QueryChildOrderMoneySumAsync(_user.ID, 0);
|
||||
//代购订单金额
|
||||
var firstOrderMoney = await _distributionOrderServices.QueryChildOrderMoneySumAsync(_user.ID);
|
||||
//推广订单金额
|
||||
var secondOrderMoney = await _distributionOrderServices.QueryChildOrderMoneySumAsync(_user.ID, 2);
|
||||
//本月订单金额
|
||||
var monthOrderMoney = await _distributionOrderServices.QueryChildOrderMoneySumAsync(_user.ID, 0, true);
|
||||
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
allOrder,
|
||||
firstOrder,
|
||||
secondOrder,
|
||||
monthOrder,
|
||||
allOrderMoney,
|
||||
firstOrderMoney,
|
||||
secondOrderMoney,
|
||||
monthOrderMoney
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取我的下级用户数量
|
||||
|
||||
/// <summary>
|
||||
/// 获取我的下级用户数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetTeamSum()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//一级统计人数
|
||||
var first = await _userServices.QueryChildCountAsync(_user.ID);
|
||||
//二级发展人数
|
||||
var second = await _userServices.QueryChildCountAsync(_user.ID, 2);
|
||||
|
||||
//当月发展一级人数
|
||||
var monthFirst = await _userServices.QueryChildCountAsync(_user.ID, 1, true);
|
||||
//当月发展二级分数
|
||||
var monthSecond = await _userServices.QueryChildCountAsync(_user.ID, 2, true);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
count = first + second,
|
||||
first,
|
||||
second,
|
||||
monthCount = monthFirst + monthSecond,
|
||||
monthFirst,
|
||||
monthSecond
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取分销商排行
|
||||
|
||||
/// <summary>
|
||||
/// 获取分销商排行
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetDistributionRanking([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _distributionServices.QueryRankingPageAsync(entity.page, entity.limit);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
data = list,
|
||||
list.HasNextPage,
|
||||
list.HasPreviousPage,
|
||||
list.PageIndex,
|
||||
list.PageSize,
|
||||
list.TotalPages,
|
||||
list.TotalCount
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
79
CoreCms.Net.Web.WebApi/Controllers/FormController.cs
Normal file
79
CoreCms.Net.Web.WebApi/Controllers/FormController.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FormController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsFormServices _formServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="formServices"></param>
|
||||
public FormController(ICoreCmsFormServices formServices)
|
||||
{
|
||||
_formServices = formServices;
|
||||
}
|
||||
|
||||
|
||||
#region 万能表单/获取活动商品详情=============================================================================
|
||||
/// <summary>
|
||||
/// 万能表单/获取活动商品详情
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetFormDetial([FromBody] FmGetForm entity)
|
||||
{
|
||||
var jm = await _formServices.GetFormInfo(entity.id, entity.token);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 万能表单/提交表单=============================================================================
|
||||
/// <summary>
|
||||
/// 万能表单/提交表单
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> AddSubmit([FromBody] FmAddSubmit entity)
|
||||
{
|
||||
var jm = await _formServices.AddSubmit(entity);
|
||||
|
||||
jm.otherData = entity;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
495
CoreCms.Net.Web.WebApi/Controllers/GoodController.cs
Normal file
495
CoreCms.Net.Web.WebApi/Controllers/GoodController.cs
Normal file
@@ -0,0 +1,495 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品相关接口处理
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class GoodController : ControllerBase
|
||||
{
|
||||
private IMapper _mapper;
|
||||
private readonly IHttpContextUser _user;
|
||||
|
||||
private ICoreCmsSettingServices _settingServices;
|
||||
private ICoreCmsGoodsCategoryServices _goodsCategoryServices;
|
||||
private ICoreCmsGoodsServices _goodsServices;
|
||||
private ICoreCmsProductsServices _productsServices;
|
||||
private ICoreCmsBrandServices _brandServices;
|
||||
private ICoreCmsOrderItemServices _orderItemServices;
|
||||
private ICoreCmsGoodsCommentServices _goodsCommentServices;
|
||||
private ICoreCmsGoodsParamsServices _goodsParamsServices;
|
||||
private ICoreCmsGoodsCollectionServices _goodsCollectionServices;
|
||||
private ICoreCmsUserServices _userServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public GoodController(IMapper mapper
|
||||
, IHttpContextUser user
|
||||
, ICoreCmsSettingServices settingServices
|
||||
, ICoreCmsGoodsCategoryServices goodsCategoryServices
|
||||
, ICoreCmsGoodsServices goodsServices
|
||||
, ICoreCmsProductsServices productsServices
|
||||
, ICoreCmsBrandServices brandServices
|
||||
, ICoreCmsOrderItemServices orderItemServices
|
||||
, ICoreCmsGoodsCommentServices goodsCommentServices
|
||||
, ICoreCmsGoodsParamsServices goodsParamsServices
|
||||
, ICoreCmsGoodsCollectionServices goodsCollectionServices
|
||||
, ICoreCmsUserServices userServices
|
||||
)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_user = user;
|
||||
_settingServices = settingServices;
|
||||
_goodsCategoryServices = goodsCategoryServices;
|
||||
_goodsServices = goodsServices;
|
||||
_productsServices = productsServices;
|
||||
_brandServices = brandServices;
|
||||
_orderItemServices = orderItemServices;
|
||||
_goodsCommentServices = goodsCommentServices;
|
||||
_goodsParamsServices = goodsParamsServices;
|
||||
_goodsCollectionServices = goodsCollectionServices;
|
||||
_userServices = userServices;
|
||||
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取所有商品分类栏目数据
|
||||
/// <summary>
|
||||
/// 获取所有商品分类栏目数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetAllCategories()
|
||||
{
|
||||
var jm = new WebApiCallBack() { status = true };
|
||||
|
||||
var data = await _goodsCategoryServices.QueryListByClauseAsync(p => p.isShow == true, p => p.sort,
|
||||
OrderByType.Asc);
|
||||
var wxGoodCategoryDto = new List<WxGoodCategoryDto>();
|
||||
|
||||
var parents = data.Where(p => p.parentId == 0).ToList();
|
||||
if (parents.Any())
|
||||
{
|
||||
parents.ForEach(p =>
|
||||
{
|
||||
var model = new WxGoodCategoryDto();
|
||||
model.id = p.id;
|
||||
model.name = p.name;
|
||||
model.imageUrl = !string.IsNullOrEmpty(p.imageUrl) ? p.imageUrl : "/static/images/common/empty.png";
|
||||
model.sort = p.sort;
|
||||
|
||||
var childs = data.Where(p => p.parentId == model.id).ToList();
|
||||
if (childs.Any())
|
||||
{
|
||||
var childsList = new List<WxGoodCategoryChild>();
|
||||
childs.ForEach(o =>
|
||||
{
|
||||
childsList.Add(new WxGoodCategoryChild()
|
||||
{
|
||||
id = o.id,
|
||||
imageUrl = !string.IsNullOrEmpty(o.imageUrl) ? o.imageUrl : "/static/images/common/empty.png",
|
||||
name = o.name,
|
||||
sort = o.sort
|
||||
});
|
||||
});
|
||||
model.child = childsList;
|
||||
}
|
||||
wxGoodCategoryDto.Add(model);
|
||||
});
|
||||
}
|
||||
jm.status = true;
|
||||
jm.data = wxGoodCategoryDto;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 根据查询条件获取分页数据============================================================
|
||||
/// <summary>
|
||||
/// 根据查询条件获取分页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsPageList([FromBody] FMPageByWhereOrder entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var where = PredicateBuilder.True<CoreCmsGoods>();
|
||||
where = where.And(p => p.isDel == false);
|
||||
where = where.And(p => p.isMarketable == true);
|
||||
|
||||
var className = string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(entity.where))
|
||||
{
|
||||
var obj = JsonConvert.DeserializeAnonymousType(entity.where, new
|
||||
{
|
||||
priceFrom = "",
|
||||
priceTo = "",
|
||||
catId = "",
|
||||
brandId = "",
|
||||
labelId = "",
|
||||
searchName = "",
|
||||
});
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(obj.priceFrom))
|
||||
{
|
||||
var priceF = obj.priceFrom.ObjectToDouble(0);
|
||||
if (priceF >= 0)
|
||||
{
|
||||
var f = Convert.ToDecimal(priceF);
|
||||
where = where.And(p => p.price >= f);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.priceTo))
|
||||
{
|
||||
var priceT = obj.priceTo.ObjectToDouble(0);
|
||||
if (priceT > 0)
|
||||
{
|
||||
var f = Convert.ToDecimal(priceT);
|
||||
where = where.And(p => p.price <= f);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.catId))
|
||||
{
|
||||
var catId = obj.catId.ObjectToInt(0);
|
||||
if (catId > 0)
|
||||
{
|
||||
var category = await _goodsCategoryServices.QueryByIdAsync(catId);
|
||||
if (category != null)
|
||||
{
|
||||
className = category.name;
|
||||
}
|
||||
|
||||
var childs = await _goodsCategoryServices.QueryListByClauseAsync(p => p.parentId == catId);
|
||||
if (childs.Any())
|
||||
{
|
||||
var ids = childs.Select(p => p.id).ToList();
|
||||
where = where.And(p => ids.Contains(p.goodsCategoryId) || p.goodsCategoryId == catId);
|
||||
}
|
||||
else
|
||||
{
|
||||
where = where.And(p => p.goodsCategoryId == catId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.brandId))
|
||||
{
|
||||
var brandId = obj.brandId.ObjectToInt(0);
|
||||
if (brandId > 0)
|
||||
{
|
||||
where = where.And(p => p.brandId == brandId);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.labelId))
|
||||
{
|
||||
where = where.And(p => (',' + p.labelIds.Trim(',') + ',').Contains(',' + obj.labelId.Trim(',') + ','));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.searchName))
|
||||
{
|
||||
where = where.And(p => p.name.Contains(obj.searchName));
|
||||
}
|
||||
}
|
||||
|
||||
var orderBy = " isRecommend desc,isHot desc";
|
||||
if (!string.IsNullOrWhiteSpace(entity.order))
|
||||
{
|
||||
orderBy += "," + entity.order;
|
||||
}
|
||||
|
||||
|
||||
//获取数据
|
||||
var list = await _goodsServices.QueryPageAsync(where, orderBy, entity.page, entity.limit, false);
|
||||
if (list.Any())
|
||||
{
|
||||
foreach (var goods in list)
|
||||
{
|
||||
goods.images = !string.IsNullOrEmpty(goods.images) ? goods.images.Split(",")[0] : "/static/images/common/empty.png";
|
||||
}
|
||||
}
|
||||
|
||||
//获取品牌
|
||||
var brands = await _brandServices.QueryListByClauseAsync(p => p.isShow == true, p => p.sort, OrderByType.Desc);
|
||||
|
||||
|
||||
//返回数据
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
list,
|
||||
className,
|
||||
entity.page,
|
||||
list.TotalCount,
|
||||
list.TotalPages,
|
||||
entity.limit,
|
||||
entity.where,
|
||||
entity.order,
|
||||
brands
|
||||
};
|
||||
jm.msg = "数据调用成功!";
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取商品详情======================================================================
|
||||
/// <summary>
|
||||
/// 获取商品详情
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetDetial([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var userId = 0;
|
||||
if (_user != null)
|
||||
{
|
||||
userId = _user.ID;
|
||||
}
|
||||
|
||||
var model = await _goodsServices.GetGoodsDetial(entity.id, userId, false);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "商品获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "获取商品详情成功";
|
||||
jm.data = model;
|
||||
jm.methodDescription = JsonConvert.SerializeObject(_user);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取单个货品信息======================================================================
|
||||
/// <summary>
|
||||
/// 获取单个货品信息
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetProductInfo([FromBody] FMGetProductInfo entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var userId = 0;
|
||||
if (_user != null)
|
||||
{
|
||||
userId = _user.ID;
|
||||
}
|
||||
|
||||
bool bl = entity.type == "pinTuan" || entity.type == "group";
|
||||
|
||||
var getProductInfo = await _productsServices.GetProductInfo(entity.id, bl, userId, entity.type, entity.groupId);
|
||||
if (getProductInfo == null)
|
||||
{
|
||||
jm.msg = "获取单个货品失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "获取单个货品成功";
|
||||
jm.data = getProductInfo;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取商品评价列表分页数据======================================================================
|
||||
/// <summary>
|
||||
/// 获取商品评价列表分页数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsComment([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//获取数据
|
||||
var list = await _goodsCommentServices.QueryPageAsync(p => p.goodsId == entity.id && p.isDisplay == true, p => p.createTime, OrderByType.Desc, entity.page, entity.limit);
|
||||
|
||||
if (list.Any())
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.imagesArr = !string.IsNullOrEmpty(item.images) ? item.images.Split(",") : null;
|
||||
}
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "获取评论成功";
|
||||
jm.data = new
|
||||
{
|
||||
list,
|
||||
commentsCount = list.TotalCount,
|
||||
totalPages = list.TotalPages
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取商品参数======================================================================
|
||||
/// <summary>
|
||||
/// 获取单个商品参数
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsParams([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//获取数据
|
||||
var goods = await _goodsServices.QueryByIdAsync(entity.id);
|
||||
if (goods == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
var list = new List<WxNameValueDto>();
|
||||
var goodsParams = await _goodsParamsServices.QueryAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(goods.parameters))
|
||||
{
|
||||
var arrItem = goods.parameters.Split("|");
|
||||
foreach (var item in arrItem)
|
||||
{
|
||||
if (!item.Contains(":")) continue;
|
||||
|
||||
var childArr = item.Split(":");
|
||||
if (childArr.Length == 2)
|
||||
{
|
||||
var paramsId = Convert.ToInt32(childArr[0]);
|
||||
var paramsModel = goodsParams.First(p => p.id == paramsId);
|
||||
if (paramsModel != null)
|
||||
{
|
||||
list.Add(new WxNameValueDto()
|
||||
{
|
||||
name = paramsModel.name,
|
||||
value = childArr[1]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
jm.status = true;
|
||||
jm.msg = "获取商品参数成功";
|
||||
jm.data = list;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取随机推荐商品==================================================
|
||||
/// <summary>
|
||||
/// 获取随机推荐商品
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsRecommendList([FromBody] FMIntId entity)
|
||||
{
|
||||
if (entity.id <= 0)
|
||||
{
|
||||
entity.id = 10;
|
||||
}
|
||||
|
||||
var bl = entity.data.ObjectToBool();
|
||||
|
||||
var jm = new WebApiCallBack()
|
||||
{
|
||||
status = true,
|
||||
code = 0,
|
||||
msg = "获取成功",
|
||||
data = await _goodsServices.GetGoodsRecommendList(entity.id, bl)
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
|
||||
#region 根据Token获取商品详情======================================================================
|
||||
/// <summary>
|
||||
/// 根据Token获取商品详情
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetDetialByToken([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var userId = 0;
|
||||
if (_user != null)
|
||||
{
|
||||
userId = _user.ID;
|
||||
}
|
||||
|
||||
var model = await _goodsServices.GetGoodsDetial(entity.id, userId, false);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "商品获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
await _goodsServices.UpdateAsync(p => new CoreCmsGoods() { viewCount = p.viewCount + 1 },
|
||||
p => p.id == entity.id);
|
||||
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "获取商品详情成功";
|
||||
jm.data = model;
|
||||
jm.methodDescription = JsonConvert.SerializeObject(_user);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
84
CoreCms.Net.Web.WebApi/Controllers/GroupController.cs
Normal file
84
CoreCms.Net.Web.WebApi/Controllers/GroupController.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 团购调用接口数据
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class GroupController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsPromotionServices _coreCmsPromotionServices;
|
||||
private ICoreCmsGoodsServices _goodsServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public GroupController(IHttpContextUser user, ICoreCmsPromotionServices coreCmsPromotionServices, ICoreCmsGoodsServices goodsServices)
|
||||
{
|
||||
_user = user;
|
||||
_coreCmsPromotionServices = coreCmsPromotionServices;
|
||||
_goodsServices = goodsServices;
|
||||
}
|
||||
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取秒杀团购列表===========================================================
|
||||
/// <summary>
|
||||
/// 获取秒杀团购列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetList([FromBody] FMGroupGetListPost entity)
|
||||
{
|
||||
var jm = await _coreCmsPromotionServices.GetGroupList(entity.type, _user.ID, entity.status, entity.page, entity.limit);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取秒杀团购详情===========================================================
|
||||
/// <summary>
|
||||
/// 获取秒杀团购详情
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsDetial([FromBody] FMGetGoodsDetial entity)
|
||||
{
|
||||
var jm = await _coreCmsPromotionServices.GetGroupDetail(entity.id, 0, "group", entity.groupId);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
95
CoreCms.Net.Web.WebApi/Controllers/NoticeController.cs
Normal file
95
CoreCms.Net.Web.WebApi/Controllers/NoticeController.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 公告控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class NoticeController : ControllerBase
|
||||
{
|
||||
private IHttpContextUser _user;
|
||||
private ICoreCmsNoticeServices _noticeServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="noticeServices"></param>
|
||||
public NoticeController(IHttpContextUser user, ICoreCmsNoticeServices noticeServices)
|
||||
{
|
||||
_user = user;
|
||||
_noticeServices = noticeServices;
|
||||
}
|
||||
|
||||
|
||||
#region 列表
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> NoticeList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _noticeServices.QueryPageAsync(p => p.isDel == false, p => p.createTime, OrderByType.Desc,
|
||||
entity.page, entity.limit);
|
||||
jm.status = true;
|
||||
jm.data = list;
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个公告内容
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> NoticeInfo([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var model = await _noticeServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "数据获取失败";
|
||||
return jm;
|
||||
}
|
||||
jm.status = true;
|
||||
jm.data = model;
|
||||
return jm;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
528
CoreCms.Net.Web.WebApi/Controllers/OrderController.cs
Normal file
528
CoreCms.Net.Web.WebApi/Controllers/OrderController.cs
Normal file
@@ -0,0 +1,528 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单调用接口数据
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class OrderController : ControllerBase
|
||||
{
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsOrderServices _orderServices;
|
||||
private readonly ICoreCmsBillAftersalesServices _aftersalesServices;
|
||||
private readonly ICoreCmsSettingServices _settingServices;
|
||||
private readonly ICoreCmsAreaServices _areaServices;
|
||||
private readonly ICoreCmsBillReshipServices _reshipServices;
|
||||
private readonly ICoreCmsShipServices _shipServices;
|
||||
private readonly ICoreCmsBillDeliveryServices _billDeliveryServices;
|
||||
private readonly ICoreCmsLogisticsServices _logisticsServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
private readonly ICoreCmsStoreServices _storeServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public OrderController(IHttpContextUser user
|
||||
, ICoreCmsOrderServices orderServices
|
||||
, ICoreCmsBillAftersalesServices aftersalesServices
|
||||
, ICoreCmsSettingServices settingServices
|
||||
, ICoreCmsAreaServices areaServices
|
||||
, ICoreCmsBillReshipServices reshipServices, ICoreCmsShipServices shipServices
|
||||
, ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsLogisticsServices logisticsServices, ICoreCmsGoodsServices goodsServices, ICoreCmsStoreServices storeServices)
|
||||
{
|
||||
_user = user;
|
||||
_orderServices = orderServices;
|
||||
_aftersalesServices = aftersalesServices;
|
||||
_settingServices = settingServices;
|
||||
_areaServices = areaServices;
|
||||
_reshipServices = reshipServices;
|
||||
_shipServices = shipServices;
|
||||
_billDeliveryServices = billDeliveryServices;
|
||||
_logisticsServices = logisticsServices;
|
||||
_goodsServices = goodsServices;
|
||||
_storeServices = storeServices;
|
||||
}
|
||||
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 发票模糊查询==================================================
|
||||
/// <summary>
|
||||
/// 发票模糊查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetTaxCode([FromBody] GetTaxCodePost entity)
|
||||
{
|
||||
var jm = await _orderServices.GetTaxCode(entity.name);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建订单==================================================
|
||||
/// <summary>
|
||||
/// 创建订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> CreateOrder([FromBody] CreateOrder entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var type = entity.receiptType;
|
||||
if (type == (int)GlobalEnumVars.OrderReceiptType.Logistics || type == (int)GlobalEnumVars.OrderReceiptType.IntraCityService)
|
||||
{
|
||||
//收货地址id
|
||||
if (entity.ushipId == 0)
|
||||
{
|
||||
jm.data = 13001;
|
||||
jm.msg = GlobalErrorCodeVars.Code13001;
|
||||
}
|
||||
}
|
||||
else if (type == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery)
|
||||
{
|
||||
//提货门店
|
||||
if (entity.storeId == 0)
|
||||
{
|
||||
jm.data = 13001;
|
||||
jm.msg = GlobalErrorCodeVars.Code13001;
|
||||
}
|
||||
//提货人姓名 提货人电话
|
||||
if (string.IsNullOrEmpty(entity.ladingName))
|
||||
{
|
||||
jm.data = 13001;
|
||||
jm.msg = "请输入姓名";
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.ladingMobile))
|
||||
{
|
||||
jm.data = 13001;
|
||||
jm.msg = "请输入电话";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.data = 13001;
|
||||
jm.msg = "未查询到配送方式";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(entity.cartIds))
|
||||
{
|
||||
jm.data = 10000;
|
||||
jm.msg = GlobalErrorCodeVars.Code10000;
|
||||
}
|
||||
jm = await _orderServices.ToAdd(_user.ID, entity.orderType, entity.cartIds, entity.receiptType,
|
||||
entity.ushipId, entity.storeId, entity.ladingName, entity.ladingMobile, entity.memo,
|
||||
entity.point, entity.couponCode, entity.source, entity.scene, entity.taxType, entity.taxName,
|
||||
entity.taxCode, entity.objectId, entity.teamId);
|
||||
jm.otherData = entity;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 订单预览==================================================
|
||||
/// <summary>
|
||||
/// 订单预览
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> OrderDetails([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var userId = _user.ID;
|
||||
if ((string)entity.data == "merchant")
|
||||
{
|
||||
var store = await _storeServices.GetStoreByUserId(_user.ID);
|
||||
if (store == null)
|
||||
{
|
||||
jm.status = false;
|
||||
jm.msg = "你不是店员";
|
||||
return jm;
|
||||
}
|
||||
else
|
||||
{
|
||||
userId = 0;
|
||||
}
|
||||
}
|
||||
jm = await _orderServices.GetOrderInfoByOrderId(entity.id, userId);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取订单不同状态的数量==================================================
|
||||
/// <summary>
|
||||
/// 获取订单不同状态的数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetOrderStatusNum([FromBody] GetOrderStatusNumPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.ids))
|
||||
{
|
||||
jm.msg = "请提交要查询的订单统计类型";
|
||||
}
|
||||
var ids = CommonHelper.StringToIntArray(entity.ids);
|
||||
jm = await _orderServices.GetOrderStatusNum(_user.ID, ids, entity.isAfterSale);
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取个人订单列表=======================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人订单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetOrderList([FromBody] GetOrderListPost entity)
|
||||
{
|
||||
var jm = await _orderServices.GetOrderList(entity.status, _user.ID, entity.page, entity.limit);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 取消订单====================================================
|
||||
|
||||
/// <summary>
|
||||
/// 取消订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> CancelOrder([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交要取消的订单号";
|
||||
return jm;
|
||||
}
|
||||
var ids = entity.id.Split(",");
|
||||
jm = await _orderServices.CancelOrder(ids, _user.ID);
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除订单====================================================
|
||||
|
||||
/// <summary>
|
||||
/// 删除订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> DeleteOrder([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交要取消的订单号";
|
||||
return jm;
|
||||
}
|
||||
var ids = entity.id.Split(",");
|
||||
jm.status = await _orderServices.DeleteAsync(p => ids.Contains(p.orderId) && p.userId == _user.ID);
|
||||
jm.msg = jm.status ? "删除成功" : "删除失败";
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 确认签收订单====================================================
|
||||
/// <summary>
|
||||
/// 确认签收订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> OrderConfirm([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交要确认签收的订单号";
|
||||
return jm;
|
||||
}
|
||||
jm = await _orderServices.ConfirmOrder(entity.id, Convert.ToInt32(entity.data));
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 添加售后单=======================================================
|
||||
|
||||
/// <summary>
|
||||
/// 添加售后单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> AddAftersales([FromBody] ToAddBillAfterSalesPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
jm.otherData = entity;
|
||||
if (string.IsNullOrEmpty(entity.orderId))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code13100;
|
||||
jm.code = 13100;
|
||||
return jm;
|
||||
}
|
||||
if (entity.type == 0)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code10051;
|
||||
jm.code = 10051;
|
||||
return jm;
|
||||
}
|
||||
jm = await _aftersalesServices.ToAdd(_user.ID, entity.orderId, entity.type, entity.items, entity.images,
|
||||
entity.reason, entity.refund);
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取售后单列表=======================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取售后单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> AftersalesList([FromBody] FMPageByStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "数据获取成功";
|
||||
|
||||
var where = PredicateBuilder.True<CoreCmsBillAftersales>();
|
||||
where = where.And(p => p.userId == _user.ID);
|
||||
if (!string.IsNullOrEmpty(entity.order))
|
||||
{
|
||||
where = where.And(p => p.orderId == entity.id);
|
||||
}
|
||||
var data = await _aftersalesServices.QueryPageAsync(where, p => p.createTime, OrderByType.Desc, entity.page, entity.limit);
|
||||
|
||||
jm.data = new
|
||||
{
|
||||
list = data,
|
||||
page = data.PageIndex,
|
||||
totalPage = data.TotalPages,
|
||||
hasNextPage = data.HasNextPage
|
||||
};
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取单个售后单详情
|
||||
|
||||
/// <summary>
|
||||
/// 获取售后单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> Aftersalesinfo([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack { status = true, msg = "数据获取成功" };
|
||||
|
||||
var info = await _aftersalesServices.GetInfo(entity.id, _user.ID);
|
||||
|
||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
||||
|
||||
var reshipAddress = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAddress);
|
||||
var reshipArea = string.Empty;
|
||||
var reshipId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAreaId).ObjectToInt(0);
|
||||
if (reshipId > 0)
|
||||
{
|
||||
var result = await _areaServices.GetAreaFullName(reshipId);
|
||||
if (result.status)
|
||||
{
|
||||
reshipArea = result.data.ToString();
|
||||
}
|
||||
}
|
||||
var reshipMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipMobile);
|
||||
var reshipName = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipName);
|
||||
var reship = new
|
||||
{
|
||||
reshipAddress,
|
||||
reshipArea,
|
||||
reshipMobile,
|
||||
reshipName
|
||||
};
|
||||
|
||||
jm.data = new
|
||||
{
|
||||
info,
|
||||
reship
|
||||
};
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 提交售后发货快递信息
|
||||
|
||||
/// <summary>
|
||||
/// 提交售后发货快递信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> SendReship([FromBody] FMBillReshipForSendReshipPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.reshipId))
|
||||
{
|
||||
jm.data = jm.msg = GlobalErrorCodeVars.Code13212;
|
||||
return jm;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(entity.logiCode))
|
||||
{
|
||||
jm.data = jm.msg = GlobalErrorCodeVars.Code13213;
|
||||
return jm;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(entity.logiNo))
|
||||
{
|
||||
jm.data = jm.msg = GlobalErrorCodeVars.Code13214;
|
||||
return jm;
|
||||
}
|
||||
|
||||
|
||||
var model = await _reshipServices.QueryByIdAsync(entity.reshipId);
|
||||
if (model == null)
|
||||
{
|
||||
jm.data = jm.msg = GlobalErrorCodeVars.Code13211;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var up = await _reshipServices.UpdateAsync(
|
||||
p => new CoreCmsBillReship()
|
||||
{
|
||||
logiCode = entity.logiCode,
|
||||
logiNo = entity.logiNo,
|
||||
status = (int)GlobalEnumVars.BillReshipStatus.运输中
|
||||
}, p => p.reshipId == entity.reshipId);
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "数据保存成功";
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取配送方式列表=======================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取配送方式列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public WebApiCallBack GetShip([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
jm.msg = "暂未设置配送方式";
|
||||
|
||||
var ship = _shipServices.GetShip(entity.id);
|
||||
if (ship != null)
|
||||
{
|
||||
jm.status = true;
|
||||
jm.data = ship;
|
||||
jm.msg = "获取成功";
|
||||
}
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 前台物流查询接口=======================================================
|
||||
|
||||
/// <summary>
|
||||
/// 前台物流查询接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> LogisticsByApi([FromBody] FMApiLogisticsByApiPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.code) || string.IsNullOrEmpty(entity.no))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code13225;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var systemLogistics = SystemSettingDictionary.GetSystemLogistics();
|
||||
foreach (var p in systemLogistics)
|
||||
{
|
||||
if (entity.code == p.sKey)
|
||||
{
|
||||
jm.msg = p.sDescription + "不支持轨迹查询";
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
|
||||
jm = await _logisticsServices.ExpressPoll(entity.code, entity.no, entity.mobile);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
162
CoreCms.Net.Web.WebApi/Controllers/PageController.cs
Normal file
162
CoreCms.Net.Web.WebApi/Controllers/PageController.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 页面接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class PageController : ControllerBase
|
||||
{
|
||||
private IMapper _mapper;
|
||||
private readonly ICoreCmsSettingServices _settingServices;
|
||||
private readonly ICoreCmsPagesServices _pagesServices;
|
||||
private readonly ICoreCmsOrderServices _orderServices;
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public PageController(IMapper mapper
|
||||
, ICoreCmsSettingServices settingServices
|
||||
, ICoreCmsPagesServices pagesServices
|
||||
, ICoreCmsOrderServices orderServices
|
||||
, ICoreCmsUserServices userServices)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_settingServices = settingServices;
|
||||
_pagesServices = pagesServices;
|
||||
_orderServices = orderServices;
|
||||
_userServices = userServices;
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取页面布局数据=============================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取页面布局数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取页面布局数据")]
|
||||
public async Task<WebApiCallBack> GetPageConfig([FromBody] FMWxPost entity)
|
||||
{
|
||||
var jm = await _pagesServices.GetPageConfig(entity.code);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取用户购买记录=============================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户购买记录
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Description("获取用户购买记录")]
|
||||
public async Task<WebApiCallBack> GetRecod([FromBody] FMGetRecodPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack() { status = true, msg = "获取成功", otherData = entity };
|
||||
|
||||
/***
|
||||
* 随机数
|
||||
* 其它随机数据,需要自己补充
|
||||
*/
|
||||
//logo作为头像
|
||||
Random rand = new Random();
|
||||
|
||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
||||
|
||||
var avatar = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopLogo);
|
||||
var names = new string[] { "无人像你", "啭裑①羣豞", "朕射妳无罪", "骑着蜗牛狂奔", "残孤星", "上网可以,别开QVOD", "请把QQ留下!", "蹭网可以,一小时两块钱", "I~在。哭泣", "不倾国倾城只倾他一人", "你再发光我就拔你插头", "家,世间最温暖的地方", "挥着鸡翅膀的女孩", "难不难过都是一个人过", "原谅我盛装出席只为错过你", "残孤星", "只适合被遗忘", "爱情,算个屁丶", "执子辶掱", "朕今晚翻你牌子", "①苆兜媞命", "中华一样的高傲", "始于心动止于枯骨", "我们幸福呢", "表白失败,勿扰", "髮型吥能亂", "陽咣丅啲憂喐", "你棺材是翻盖的还是滑盖的", "孤枕", "泪颜葬相思", "喵星人", "超拽霸气的微博名字", "晚安晚安晚晚难安", "却输给了秒", "为什么我吃德芙没有黑丝飘", "请输入我大" };
|
||||
var listUsers = new List<RandUser>();
|
||||
|
||||
foreach (var itemName in names)
|
||||
{
|
||||
var min = rand.Next(100, 1000);
|
||||
var createTime = DateTime.Now.AddMinutes(-min);
|
||||
listUsers.Add(new RandUser()
|
||||
{
|
||||
avatar = avatar,
|
||||
createTime = CommonHelper.TimeAgo(createTime),
|
||||
nickname = itemName,
|
||||
desc = "下单成功",
|
||||
dt = createTime
|
||||
});
|
||||
}
|
||||
|
||||
if (entity.type == "home")
|
||||
{
|
||||
//数据库里面随机取出来几条数据
|
||||
var orders = await _orderServices.QueryListByClauseAsync(p => p.isdel == false, 20, p => p.createTime,
|
||||
OrderByType.Desc);
|
||||
if (orders != null && orders.Any())
|
||||
{
|
||||
Random rd = new Random();
|
||||
var index = rd.Next(orders.Count);
|
||||
var orderItem = orders[index];
|
||||
if (orderItem != null)
|
||||
{
|
||||
var user = await _userServices.QueryByIdAsync(orderItem.userId);
|
||||
if (user != null && !string.IsNullOrEmpty(user.nickName))
|
||||
{
|
||||
jm.data = new RandUser()
|
||||
{
|
||||
avatar = !string.IsNullOrEmpty(user.avatarImage) ? user.avatarImage : avatar,
|
||||
createTime = CommonHelper.TimeAgo(orderItem.createTime),
|
||||
nickname = user.nickName,
|
||||
desc = "下单成功",
|
||||
dt = orderItem.createTime
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Random rd = new Random();
|
||||
var listI = rd.Next(listUsers.Count);
|
||||
jm.data = listUsers[listI];
|
||||
}
|
||||
}
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
283
CoreCms.Net.Web.WebApi/Controllers/PayNotify/AliPayController.cs
Normal file
283
CoreCms.Net.Web.WebApi/Controllers/PayNotify/AliPayController.cs
Normal file
@@ -0,0 +1,283 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Essensoft.Paylink.Alipay;
|
||||
using Essensoft.Paylink.Alipay.Notify;
|
||||
using Essensoft.Paylink.Alipay.Utility;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付宝异步通知
|
||||
/// </summary>
|
||||
[Route("Notify/[controller]/[action]")]
|
||||
public class AliPayController : ControllerBase
|
||||
{
|
||||
private readonly IAlipayNotifyClient _client;
|
||||
private readonly IOptions<AlipayOptions> _optionsAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="optionsAccessor"></param>
|
||||
public AliPayController(IAlipayNotifyClient client, IOptions<AlipayOptions> optionsAccessor)
|
||||
{
|
||||
_client = client;
|
||||
_optionsAccessor = optionsAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用网关
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Gateway()
|
||||
{
|
||||
try
|
||||
{
|
||||
var service = Request.Form["service"].ToString();
|
||||
switch (service)
|
||||
{
|
||||
// 激活开发者模式
|
||||
case "alipay.service.check":
|
||||
{
|
||||
var options = _optionsAccessor.Value;
|
||||
|
||||
// 获取参数
|
||||
var parameters =await _client.GetParametersAsync(Request);
|
||||
var sign = parameters["sign"];
|
||||
parameters.Remove("sign");
|
||||
|
||||
var signContent = AlipaySignature.GetSignContent(parameters);
|
||||
|
||||
// 验签
|
||||
//var isSuccess = AlipaySignature.RSACheckContent(signContent, sign, options.AlipayPublicKey, options.SignType);
|
||||
// 验签
|
||||
var isSuccess = AlipaySignature.RSACheckContent(signContent, sign, options.AlipayPublicKey, options.SignType);
|
||||
|
||||
// 组XML响应内容
|
||||
//var response = MakeVerifyGWResponse(isSuccess, options.AlipayPublicKey, options.AppPrivateKey, options.SignType);
|
||||
var response = MakeVerifyGwResponse(isSuccess, options.AlipayPublicKey, options.AppPrivateKey, options.SignType);
|
||||
|
||||
|
||||
return Content(response, "text/xml");
|
||||
}
|
||||
}
|
||||
|
||||
var msg_method = Request.Form["msg_method"].ToString();
|
||||
switch (msg_method)
|
||||
{
|
||||
// 资金单据状态变更通知
|
||||
case "alipay.fund.trans.order.changed":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayFundTransOrderChangedNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 第三方应用授权取消消息
|
||||
case "alipay.open.auth.appauth.cancelled":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayOpenAuthAppauthCancelledNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 用户授权取消消息
|
||||
case "alipay.open.auth.userauth.cancelled":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayOpenAuthUserauthCancelledNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 小程序审核通过通知
|
||||
case "alipay.open.mini.version.audit.passed":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayOpenMiniVersionAuditPassedNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 用户授权取消消息
|
||||
case "alipay.open.mini.version.audit.rejected":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayOpenMiniVersionAuditRejectedNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 收单资金结算到银行账户,结算退票的异步通知
|
||||
case "alipay.trade.settle.dishonoured":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradeSettleDishonouredNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 收单资金结算到银行账户,结算失败的异步通知
|
||||
case "alipay.trade.settle.fail":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradeSettleFailNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
// 收单资金结算到银行账户,结算成功的异步通知
|
||||
case "alipay.trade.settle.success":
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradeSettleSuccessNotify>(Request, _optionsAccessor.Value);
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫码支付异步通知
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Precreate()
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradePrecreateNotify>(Request, _optionsAccessor.Value);
|
||||
if (notify.TradeStatus == AlipayTradeStatus.Success)
|
||||
{
|
||||
Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
|
||||
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// APP支付异步通知
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AppPay()
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradeAppPayNotify>(Request, _optionsAccessor.Value);
|
||||
if (notify.TradeStatus == AlipayTradeStatus.Success)
|
||||
{
|
||||
Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
|
||||
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 电脑网站支付异步通知
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PagePay()
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradePagePayNotify>(Request, _optionsAccessor.Value);
|
||||
if (notify.TradeStatus == AlipayTradeStatus.Success)
|
||||
{
|
||||
Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
|
||||
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手机网站支付异步通知
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> WapPay()
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradeWapPayNotify>(Request, _optionsAccessor.Value);
|
||||
if (notify.TradeStatus == AlipayTradeStatus.Success)
|
||||
{
|
||||
Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
|
||||
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
private static string MakeVerifyGwResponse(bool isSuccess, string certPublicKey, string appPrivateKey, string signType)
|
||||
{
|
||||
var xmlDoc = new XmlDocument(); //创建实例
|
||||
var xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "GBK", null);
|
||||
xmlDoc.AppendChild(xmldecl);
|
||||
|
||||
var xmlElem = xmlDoc.CreateElement("alipay"); //新建元素
|
||||
xmlDoc.AppendChild(xmlElem); //添加元素
|
||||
|
||||
var alipay = xmlDoc.SelectSingleNode("alipay");
|
||||
|
||||
var response = xmlDoc.CreateElement("response");
|
||||
var success = xmlDoc.CreateElement("success");
|
||||
if (isSuccess)
|
||||
{
|
||||
success.InnerText = "true";//设置文本节点
|
||||
response.AppendChild(success);//添加到<Node>节点中
|
||||
}
|
||||
else
|
||||
{
|
||||
success.InnerText = "false";//设置文本节点
|
||||
response.AppendChild(success);//添加到<Node>节点中
|
||||
var err = xmlDoc.CreateElement("error_code");
|
||||
err.InnerText = "VERIFY_FAILED";
|
||||
response.AppendChild(err);
|
||||
}
|
||||
|
||||
var bizContent = xmlDoc.CreateElement("biz_content");
|
||||
bizContent.InnerText = certPublicKey;
|
||||
response.AppendChild(bizContent);
|
||||
|
||||
alipay.AppendChild(response);
|
||||
|
||||
var sign = xmlDoc.CreateElement("sign");
|
||||
//sign.InnerText = AlipaySignature.RSASignContent(response.InnerXml, appPrivateKey, signType);
|
||||
sign.InnerText = AlipaySignature.RSASignContent(response.InnerXml, appPrivateKey, signType);
|
||||
|
||||
alipay.AppendChild(sign);
|
||||
|
||||
var sign_type = xmlDoc.CreateElement("sign_type");
|
||||
sign_type.InnerText = signType;
|
||||
alipay.AppendChild(sign_type);
|
||||
|
||||
return xmlDoc.InnerXml;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
||||
using Essensoft.Paylink.WeChatPay;
|
||||
using Essensoft.Paylink.WeChatPay.V2;
|
||||
using Essensoft.Paylink.WeChatPay.V2.Notify;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信支付异步通知
|
||||
/// </summary>
|
||||
[Route("Notify/[controller]/[action]")]
|
||||
public class WeChatPayController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsBillPaymentsServices _billPaymentsServices;
|
||||
private readonly ICoreCmsBillRefundServices _billRefundServices;
|
||||
private readonly IWeChatPayNotifyClient _client;
|
||||
private readonly IOptions<WeChatPayOptions> _optionsAccessor;
|
||||
private readonly IRedisOperationRepository _redisOperationRepository;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public WeChatPayController(
|
||||
IWeChatPayNotifyClient client
|
||||
, IOptions<WeChatPayOptions> optionsAccessor
|
||||
, ICoreCmsBillPaymentsServices billPaymentsServices, ICoreCmsBillRefundServices billRefundServices, IRedisOperationRepository redisOperationRepository)
|
||||
{
|
||||
_client = client;
|
||||
_optionsAccessor = optionsAccessor;
|
||||
_billPaymentsServices = billPaymentsServices;
|
||||
_billRefundServices = billRefundServices;
|
||||
_redisOperationRepository = redisOperationRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统一下单支付结果通知
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Unifiedorder()
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);
|
||||
if (notify.ReturnCode == WeChatPayCode.Success)
|
||||
{
|
||||
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.WeChatPayNotice, JsonConvert.SerializeObject(notify));
|
||||
return WeChatPayNotifyResult.Success;
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Refund, "微信支付成功回调", "统一下单支付结果通知", ex);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退款结果通知
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Refund()
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request, _optionsAccessor.Value);
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Refund, "微信退款结果通知", JsonConvert.SerializeObject(notify));
|
||||
|
||||
if (notify.ReturnCode == WeChatPayCode.Success)
|
||||
if (notify.RefundStatus == WeChatPayCode.Success)
|
||||
{
|
||||
//Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
|
||||
var memo = JsonConvert.SerializeObject(notify);
|
||||
await _billRefundServices.UpdateAsync(p => new CoreCmsBillRefund { memo = memo }, p => p.refundId == notify.OutTradeNo);
|
||||
return WeChatPayNotifyResult.Success;
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Refund, "微信退款结果通知", "退款结果通知", ex);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
128
CoreCms.Net.Web.WebApi/Controllers/PaymentsController.cs
Normal file
128
CoreCms.Net.Web.WebApi/Controllers/PaymentsController.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付调用接口数据
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class PaymentsController : ControllerBase
|
||||
{
|
||||
|
||||
private IHttpContextUser _user;
|
||||
private ICoreCmsBillPaymentsServices _billPaymentsServices;
|
||||
private ICoreCmsPaymentsServices _paymentsServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="billPaymentsServices"></param>
|
||||
/// <param name="paymentsServices"></param>
|
||||
public PaymentsController(IHttpContextUser user
|
||||
, ICoreCmsBillPaymentsServices billPaymentsServices
|
||||
, ICoreCmsPaymentsServices paymentsServices
|
||||
)
|
||||
{
|
||||
_user = user;
|
||||
_billPaymentsServices = billPaymentsServices;
|
||||
_paymentsServices = paymentsServices;
|
||||
}
|
||||
|
||||
//公共接口====================================================================================================
|
||||
|
||||
#region 获取支付方式列表==================================================
|
||||
/// <summary>
|
||||
/// 获取支付方式列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetList()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var list = await _paymentsServices.QueryListByClauseAsync(p => p.isEnable == true, p => p.sort, OrderByType.Asc);
|
||||
jm.status = true;
|
||||
jm.data = list;
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 支付确认页面取信息==================================================
|
||||
/// <summary>
|
||||
/// 支付确认页面取信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> CheckPay([FromBody] CheckPayPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.ids))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code13100;
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm = await _billPaymentsServices.FormatPaymentRel(entity.ids, entity.paymentType, entity.@params);
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取支付单详情==================================================
|
||||
/// <summary>
|
||||
/// 获取支付单详情
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetInfo([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code13100;
|
||||
return jm;
|
||||
}
|
||||
var userId = entity.data.ObjectToInt(0);
|
||||
jm = await _billPaymentsServices.GetInfo(entity.id, userId);
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
175
CoreCms.Net.Web.WebApi/Controllers/PinTuanController.cs
Normal file
175
CoreCms.Net.Web.WebApi/Controllers/PinTuanController.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 拼团接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class PinTuanController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsPinTuanGoodsServices _pinTuanGoodsServices;
|
||||
private readonly ICoreCmsPinTuanRuleServices _pinTuanRuleServices;
|
||||
private readonly ICoreCmsProductsServices _productsServices;
|
||||
private readonly ICoreCmsPinTuanRecordServices _pinTuanRecordServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public PinTuanController(IHttpContextUser user
|
||||
, ICoreCmsPinTuanGoodsServices pinTuanGoodsServices
|
||||
, ICoreCmsPinTuanRuleServices pinTuanRuleServices
|
||||
, ICoreCmsProductsServices productsServices
|
||||
, ICoreCmsPinTuanRecordServices pinTuanRecordServices, ICoreCmsGoodsServices goodsServices)
|
||||
{
|
||||
_user = user;
|
||||
_pinTuanGoodsServices = pinTuanGoodsServices;
|
||||
_pinTuanRuleServices = pinTuanRuleServices;
|
||||
_productsServices = productsServices;
|
||||
_pinTuanRecordServices = pinTuanRecordServices;
|
||||
_goodsServices = goodsServices;
|
||||
}
|
||||
|
||||
|
||||
#region 拼团列表
|
||||
/// <summary>
|
||||
/// 拼团列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetList([FromBody] FMIntId entity)
|
||||
{
|
||||
WebApiCallBack jm;
|
||||
|
||||
var userId = 0;
|
||||
if (_user != null)
|
||||
{
|
||||
userId = _user.ID;
|
||||
}
|
||||
var id = 0;
|
||||
if (entity.id > 0)
|
||||
{
|
||||
id = entity.id;
|
||||
}
|
||||
jm = await _pinTuanRuleServices.GetPinTuanList(id, userId);
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取拼团商品信息
|
||||
/// <summary>
|
||||
/// 获取拼团商品信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetGoodsInfo([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var userId = 0;
|
||||
if (_user != null)
|
||||
{
|
||||
userId = _user.ID;
|
||||
}
|
||||
var pinTuanStatus = entity.data.ObjectToInt(1);
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "获取详情成功";
|
||||
jm.data = await _pinTuanGoodsServices.GetGoodsInfo(entity.id, userId, pinTuanStatus);
|
||||
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取货品信息
|
||||
/// <summary>
|
||||
/// 获取货品信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetProductInfo([FromBody] FMGetProductInfo entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var products = await _productsServices.GetProductInfo(entity.id, false, 0, entity.type);
|
||||
if (products == null)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code10000;
|
||||
return jm;
|
||||
}
|
||||
//把拼团的一些属性等加上
|
||||
var info = await _pinTuanRuleServices.QueryMuchFirstAsync<CoreCmsPinTuanRule, CoreCmsPinTuanGoods, CoreCmsPinTuanRule>(
|
||||
(join1, join2) => new object[] { JoinType.Left, join1.id == join2.ruleId },
|
||||
(join1, join2) => join1, (join1, join2) => join2.goodsId == products.goodsId);
|
||||
|
||||
if (info == null)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code10000;
|
||||
return jm;
|
||||
}
|
||||
products.pinTuanRule = info;
|
||||
jm.status = true;
|
||||
jm.data = products;
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 根据订单id取拼团信息,用在订单详情页
|
||||
/// <summary>
|
||||
/// 根据订单id取拼团信息,用在订单详情页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetPinTuanTeam([FromBody] FMGetPinTuanTeamPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.orderId) && entity.teamId == 0)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15606;
|
||||
return jm;
|
||||
}
|
||||
jm = await _pinTuanRecordServices.GetTeamList(entity.teamId, entity.orderId);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
404
CoreCms.Net.Web.WebApi/Controllers/ServiceController.cs
Normal file
404
CoreCms.Net.Web.WebApi/Controllers/ServiceController.cs
Normal file
@@ -0,0 +1,404 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务卡控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ServiceController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsServicesServices _servicesServices;
|
||||
private readonly ICoreCmsUserServicesOrderServices _userServicesOrderServices;
|
||||
private readonly ICoreCmsUserServicesTicketServices _userServicesTicketServices;
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
private readonly ICoreCmsUserServicesTicketVerificationLogServices _ticketVerificationLogServices;
|
||||
private readonly ICoreCmsClerkServices _clerkServices;
|
||||
private readonly ICoreCmsStoreServices _storeServices;
|
||||
private readonly ICoreCmsUserGradeServices _userGradeServices;
|
||||
|
||||
|
||||
private readonly IHttpContextUser _user;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="servicesServices"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="userServicesOrderServices"></param>
|
||||
/// <param name="userServicesTicketServices"></param>
|
||||
/// <param name="userServices"></param>
|
||||
/// <param name="clerkServices"></param>
|
||||
/// <param name="ticketVerificationLogServices"></param>
|
||||
/// <param name="storeServices"></param>
|
||||
/// <param name="userGradeServices"></param>
|
||||
public ServiceController(ICoreCmsServicesServices servicesServices, IHttpContextUser user, ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsUserServices userServices, ICoreCmsClerkServices clerkServices, ICoreCmsUserServicesTicketVerificationLogServices ticketVerificationLogServices, ICoreCmsStoreServices storeServices, ICoreCmsUserGradeServices userGradeServices)
|
||||
{
|
||||
_servicesServices = servicesServices;
|
||||
_user = user;
|
||||
_userServicesOrderServices = userServicesOrderServices;
|
||||
_userServicesTicketServices = userServicesTicketServices;
|
||||
_userServices = userServices;
|
||||
_clerkServices = clerkServices;
|
||||
_ticketVerificationLogServices = ticketVerificationLogServices;
|
||||
_storeServices = storeServices;
|
||||
_userGradeServices = userGradeServices;
|
||||
}
|
||||
|
||||
|
||||
#region 取得服务卡列表信息
|
||||
/// <summary>
|
||||
/// 取得服务卡列表信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
//[Authorize]
|
||||
public async Task<WebApiCallBack> GetPageList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var dt = DateTime.Now;
|
||||
var where = PredicateBuilder.True<CoreCmsServices>();
|
||||
|
||||
where = where.And(p => p.status == (int)GlobalEnumVars.ServicesStatus.Shelve);
|
||||
where = where.And(p => p.amount > 0);
|
||||
where = where.And(p => p.startTime < dt && p.endTime > dt);
|
||||
|
||||
var list = await _servicesServices.QueryPageAsync(where, p => p.createTime, OrderByType.Desc, entity.page, entity.limit);
|
||||
|
||||
if (list.Any())
|
||||
{
|
||||
var storesAll = await _storeServices.QueryAsync();
|
||||
var userGradesAll = await _userGradeServices.QueryAsync();
|
||||
|
||||
foreach (var data in list)
|
||||
{
|
||||
TimeSpan ts = data.endTime.Subtract(dt);
|
||||
data.timestamp = (int)ts.TotalSeconds;
|
||||
|
||||
if (!string.IsNullOrEmpty(data.consumableStore))
|
||||
{
|
||||
var consumableStoreStr = CommonHelper.GetCaptureInterceptedText(data.consumableStore, ",");
|
||||
var consumableStoreIds = CommonHelper.StringToIntArray(consumableStoreStr);
|
||||
if (consumableStoreIds.Any())
|
||||
{
|
||||
var stores = storesAll.Where(p => consumableStoreIds.Contains(p.id)).ToList();
|
||||
data.consumableStores = stores.Select(p => p.storeName).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(data.allowedMembership))
|
||||
{
|
||||
var allowedMembershipStr = CommonHelper.GetCaptureInterceptedText(data.allowedMembership, ",");
|
||||
var allowedMembershipIds = CommonHelper.StringToIntArray(allowedMembershipStr);
|
||||
if (allowedMembershipIds.Any())
|
||||
{
|
||||
var userGrades = userGradesAll.Where(p => allowedMembershipIds.Contains(p.id)).ToList();
|
||||
data.allowedMemberships = userGrades.Select(p => p.title).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
list = list,
|
||||
count = list.TotalCount,
|
||||
};
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取服务卡详情
|
||||
/// <summary>
|
||||
/// 获取服务卡详情
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
//[Authorize]
|
||||
public async Task<WebApiCallBack> GetDetails([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var data = await _servicesServices.QueryByClauseAsync(p => p.id == entity.id);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
var dt = DateTime.Now;
|
||||
TimeSpan ts = data.endTime.Subtract(dt);
|
||||
data.timestamp = (int)ts.TotalSeconds;
|
||||
|
||||
if (!string.IsNullOrEmpty(data.consumableStore))
|
||||
{
|
||||
var consumableStoreStr = CommonHelper.GetCaptureInterceptedText(data.consumableStore, ",");
|
||||
var consumableStoreIds = CommonHelper.StringToIntArray(consumableStoreStr);
|
||||
if (consumableStoreIds.Any())
|
||||
{
|
||||
var stores = await _storeServices.QueryListByClauseAsync(p => consumableStoreIds.Contains(p.id));
|
||||
data.consumableStores = stores.Select(p => p.storeName).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(data.allowedMembership))
|
||||
{
|
||||
var allowedMembershipStr = CommonHelper.GetCaptureInterceptedText(data.allowedMembership, ",");
|
||||
var allowedMembershipIds = CommonHelper.StringToIntArray(allowedMembershipStr);
|
||||
if (allowedMembershipIds.Any())
|
||||
{
|
||||
var userGrades = await _userGradeServices.QueryListByClauseAsync(p => allowedMembershipIds.Contains(p.id));
|
||||
data.allowedMemberships = userGrades.Select(p => p.title).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.data = data;
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//验证接口====================================================================================================
|
||||
|
||||
#region 添加服务订单
|
||||
/// <summary>
|
||||
/// 取得服务卡列表信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> AddServiceOrder([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var data = await _servicesServices.QueryByClauseAsync(p => p.id == entity.id);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
jm.msg = "服务数据获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var user = await _userServices.QueryByIdAsync(_user.ID);
|
||||
if (user == null)
|
||||
{
|
||||
jm.msg = "用户数据获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (!data.allowedMembership.Contains("," + user.grade + ","))
|
||||
{
|
||||
jm.msg = "您所在的用户级别不支持购买";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var order = new CoreCmsUserServicesOrder();
|
||||
order.serviceOrderId = CommonHelper.GetSerialNumberType((int)GlobalEnumVars.SerialNumberType.服务订单编号);
|
||||
order.userId = _user.ID;
|
||||
order.servicesId = entity.id;
|
||||
order.isPay = false;
|
||||
order.status = (int)GlobalEnumVars.ServicesOrderStatus.正常;
|
||||
order.createTime = DateTime.Now;
|
||||
|
||||
var bl = await _userServicesOrderServices.InsertAsync(order) > 0;
|
||||
|
||||
jm.status = bl;
|
||||
jm.data = order.serviceOrderId;
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 店铺核销的服务券列表
|
||||
/// <summary>
|
||||
/// 店铺核销的服务券列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> VerificationPageList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = await _ticketVerificationLogServices.GetVerificationLogs(_user.ID, entity.page, entity.limit);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 软删除服务券核销单数据
|
||||
/// <summary>
|
||||
/// 软删除服务券核销单数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> LogDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = await _ticketVerificationLogServices.LogDelete(entity.id, _user.ID);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取单个提货单详情
|
||||
/// <summary>
|
||||
/// 获取单个提货单详情
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetTicketInfo([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交查询数据关键词";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var ticket = await _userServicesTicketServices.QueryByClauseAsync(p => p.redeemCode == entity.id);
|
||||
if (ticket == null)
|
||||
{
|
||||
jm.msg = "未查询到服务券";
|
||||
return jm;
|
||||
}
|
||||
|
||||
ticket.statusStr = EnumHelper.GetEnumDescriptionByValue<GlobalEnumVars.ServicesTicketStatus>(ticket.status);
|
||||
|
||||
var service = await _servicesServices.QueryByClauseAsync(p => p.id == ticket.serviceId);
|
||||
var serviceOrder =
|
||||
await _userServicesOrderServices.QueryByClauseAsync(p => p.serviceOrderId == ticket.serviceOrderId);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
ticket,
|
||||
service,
|
||||
serviceOrder
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 核销服务券
|
||||
/// <summary>
|
||||
/// 核销服务券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> VerificationTicket([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交查询数据关键词";
|
||||
return jm;
|
||||
}
|
||||
var ticket = await _userServicesTicketServices.QueryByClauseAsync(p => p.redeemCode == entity.id);
|
||||
if (ticket == null)
|
||||
{
|
||||
jm.msg = "未查询到服务券";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (ticket.status != (int)GlobalEnumVars.ServicesTicketStatus.Normal)
|
||||
{
|
||||
jm.msg = "服务券状态不支持核销";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var service = await _servicesServices.QueryByIdAsync(ticket.serviceId);
|
||||
if (service == null)
|
||||
{
|
||||
jm.msg = "服务项目获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var user = await _userServices.QueryByIdAsync(_user.ID);
|
||||
if (user == null)
|
||||
{
|
||||
jm.msg = "未获取到审核权限";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var clerk = await _clerkServices.QueryByClauseAsync(p => p.userId == user.id);
|
||||
if (clerk == null)
|
||||
{
|
||||
jm.msg = "非门店店员无权限核验";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (!service.consumableStore.Contains("," + clerk.storeId + ","))
|
||||
{
|
||||
jm.msg = "您所在的门店无权核销此券";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//开始更新数据
|
||||
var log = new CoreCmsUserServicesTicketVerificationLog
|
||||
{
|
||||
storeId = clerk.storeId,
|
||||
verificationUserId = _user.ID,
|
||||
ticketId = ticket.id,
|
||||
ticketRedeemCode = ticket.redeemCode,
|
||||
verificationTime = DateTime.Now,
|
||||
serviceId = ticket.serviceId,
|
||||
isDel = false
|
||||
};
|
||||
|
||||
ticket.status = (int)GlobalEnumVars.ServicesTicketStatus.Verification;
|
||||
ticket.verificationTime = DateTime.Now;
|
||||
ticket.isVerification = true;
|
||||
var up = await _userServicesTicketServices.UpdateAsync(ticket);
|
||||
var bl = false;
|
||||
if (up)
|
||||
{
|
||||
bl = await _ticketVerificationLogServices.InsertAsync(log) > 0;
|
||||
}
|
||||
jm.status = up && bl;
|
||||
jm.msg = jm.status ? "核销成功" : "核销失败";
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
365
CoreCms.Net.Web.WebApi/Controllers/StoreController.cs
Normal file
365
CoreCms.Net.Web.WebApi/Controllers/StoreController.cs
Normal file
@@ -0,0 +1,365 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店调用接口数据
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class StoreController : ControllerBase
|
||||
{
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsStoreServices _storeServices;
|
||||
private readonly ICoreCmsClerkServices _clerkServices;
|
||||
private readonly ICoreCmsSettingServices _settingServices;
|
||||
private readonly ICoreCmsBillLadingServices _billLadingServices;
|
||||
private readonly ICoreCmsOrderServices _orderServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public StoreController(IHttpContextUser user
|
||||
, ICoreCmsStoreServices storeServices
|
||||
, ICoreCmsClerkServices clerkServices
|
||||
, ICoreCmsSettingServices settingServices
|
||||
, ICoreCmsBillLadingServices billLadingServices, ICoreCmsOrderServices orderServices)
|
||||
{
|
||||
_user = user;
|
||||
_storeServices = storeServices;
|
||||
_clerkServices = clerkServices;
|
||||
_settingServices = settingServices;
|
||||
_billLadingServices = billLadingServices;
|
||||
_orderServices = orderServices;
|
||||
}
|
||||
|
||||
//公共接口======================================================================================================
|
||||
|
||||
#region 获取默认的门店
|
||||
/// <summary>
|
||||
/// 获取默认的门店
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetDefaultStore()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var ship = await _storeServices.QueryByClauseAsync(p => p.isDefault == true);
|
||||
jm.status = true;
|
||||
jm.data = ship;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取门店列表数据
|
||||
/// <summary>
|
||||
/// 获取门店列表数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetStoreList([FromBody] FMGetStoreQueryPageByCoordinate entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
try
|
||||
{
|
||||
var where = PredicateBuilder.True<CoreCmsStore>();
|
||||
|
||||
if (!string.IsNullOrEmpty(entity.key))
|
||||
{
|
||||
where = where.And(p => p.storeName.Contains(entity.key));
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
|
||||
var data = await _storeServices.QueryPageAsyncByCoordinate(where, p => p.distance, OrderByType.Asc, entity.page, entity.limit, entity.latitude, entity.longitude);
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.distance > 0)
|
||||
{
|
||||
if (item.distance > 1000)
|
||||
{
|
||||
item.distanceStr = Math.Round(item.distance / 1000, 2) + "km";
|
||||
}
|
||||
else
|
||||
{
|
||||
item.distanceStr = Math.Round(item.distance, 2) + "m";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item.distanceStr = "未知";
|
||||
}
|
||||
}
|
||||
jm.data = data;
|
||||
jm.otherData = new
|
||||
{
|
||||
totalCount = data.TotalCount,
|
||||
totalPages = data.TotalPages,
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
jm.msg = GlobalConstVars.DataHandleEx;
|
||||
jm.data = e.ToString();
|
||||
}
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取推荐关键词
|
||||
/// <summary>
|
||||
/// 获取推荐关键词
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetRecommendKeys()
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
||||
var recommendKeysStr = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.RecommendKeys);
|
||||
jm.status = true;
|
||||
jm.msg = "获取成功";
|
||||
jm.data = !string.IsNullOrEmpty(recommendKeysStr) ? recommendKeysStr.Split("|") : new string[] { };
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 判断是否开启门店自提
|
||||
/// <summary>
|
||||
/// 判断是否开启门店自提
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetStoreSwitch()
|
||||
{
|
||||
var jm = new WebApiCallBack { status = true, msg = "获取成功" };
|
||||
|
||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
||||
jm.data = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.StoreSwitch).ObjectToInt(2); ;
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 根据序列获取门店数据
|
||||
/// <summary>
|
||||
/// 根据序列获取门店数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetStoreById([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack
|
||||
{
|
||||
status = true,
|
||||
msg = "获取成功",
|
||||
data = await _storeServices.QueryByClauseAsync(p => p.id == entity.id)
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//验证接口======================================================================================================
|
||||
|
||||
#region 判断访问用户是否是店员
|
||||
/// <summary>
|
||||
/// 判断访问用户是否是店员
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> IsClerk()
|
||||
{
|
||||
var jm = await _clerkServices.IsClerk(_user.ID);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 根据用户序列获取门店数据
|
||||
/// <summary>
|
||||
/// 根据用户序列获取门店数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetStoreByUserId()
|
||||
{
|
||||
var jm = new WebApiCallBack
|
||||
{
|
||||
status = true,
|
||||
msg = "获取成功",
|
||||
data = await _storeServices.GetStoreByUserId(_user.ID)
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取个人订单列表
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人订单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetOrderPageByMerchant([FromBody] GetOrderPageByMerchantPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var store = await _storeServices.GetStoreByUserId(_user.ID);
|
||||
if (store != null)
|
||||
{
|
||||
jm = await _orderServices.GetOrderPageByMerchant(entity.dateType, entity.date, entity.status, entity.storeId, entity.page, entity.limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.status = false;
|
||||
jm.msg = "你不是店员";
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 搜索订单
|
||||
|
||||
/// <summary>
|
||||
/// 搜索订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetOrderPageByMerchantSearch([FromBody] GetOrderPageByMerchantSearcgPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var store = await _storeServices.GetStoreByUserId(_user.ID);
|
||||
if (store != null)
|
||||
{
|
||||
jm = await _orderServices.GetOrderPageByMerchantSearch(entity.keyword, entity.status, entity.receiptType, entity.storeId, entity.page, entity.limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.status = false;
|
||||
jm.msg = "你不是店员";
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 店铺提货单列表
|
||||
/// <summary>
|
||||
/// 店铺提货单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> StoreLadingList([FromBody] FMPageByIntId entity)
|
||||
{
|
||||
var jm = await _billLadingServices.GetStoreLadingList(_user.ID, entity.page, entity.limit);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除提货单数据
|
||||
/// <summary>
|
||||
/// 删除提货单数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> LadingDelete([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = await _billLadingServices.LadingDelete(entity.id, _user.ID);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取单个提货单详情
|
||||
/// <summary>
|
||||
/// 获取单个提货单详情
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> LadingInfo([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交查询数据关键词";
|
||||
return jm;
|
||||
}
|
||||
jm = await _billLadingServices.GetInfo(entity.id, _user.ID);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 核销订单
|
||||
/// <summary>
|
||||
/// 核销订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> Lading([FromBody] FMStringId entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (string.IsNullOrEmpty(entity.id))
|
||||
{
|
||||
jm.msg = "请提交查询数据关键词";
|
||||
return jm;
|
||||
}
|
||||
var array = entity.id.Split(",");
|
||||
var result = await _billLadingServices.LadingOperating(array, _user.ID);
|
||||
jm.status = result.code == 0;
|
||||
jm.msg = result.msg;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
2017
CoreCms.Net.Web.WebApi/Controllers/UserController.cs
Normal file
2017
CoreCms.Net.Web.WebApi/Controllers/UserController.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,110 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信小程序消息订阅接口
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class WeChatAppletsMessageController : ControllerBase
|
||||
{
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly ICoreCmsUserWeChatMsgTemplateServices _userWeChatMsgTemplateServices;
|
||||
private readonly ICoreCmsUserWeChatMsgSubscriptionSwitchServices _userWeChatMsgSubscriptionSwitchServices;
|
||||
private readonly ICoreCmsUserWeChatMsgSubscriptionServices _userWeChatMsgSubscriptionServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public WeChatAppletsMessageController(IHttpContextUser user, ICoreCmsUserWeChatMsgTemplateServices userWeChatMsgTemplateServices, ICoreCmsUserWeChatMsgSubscriptionSwitchServices userWeChatMsgSubscriptionSwitchServices, ICoreCmsUserWeChatMsgSubscriptionServices userWeChatMsgSubscriptionServices)
|
||||
{
|
||||
_user = user;
|
||||
_userWeChatMsgTemplateServices = userWeChatMsgTemplateServices;
|
||||
_userWeChatMsgSubscriptionSwitchServices = userWeChatMsgSubscriptionSwitchServices;
|
||||
_userWeChatMsgSubscriptionServices = userWeChatMsgSubscriptionServices;
|
||||
}
|
||||
|
||||
#region 获取用户是否订阅
|
||||
/// <summary>
|
||||
/// 获取用户是否订阅
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> IsTip()
|
||||
{
|
||||
var jm = await _userWeChatMsgSubscriptionSwitchServices.IsTip(_user.ID);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 用户取消订阅
|
||||
/// <summary>
|
||||
/// 用户取消订阅
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> CloseTip()
|
||||
{
|
||||
var jm = await _userWeChatMsgSubscriptionSwitchServices.CloseTip(_user.ID);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取订阅模板
|
||||
/// <summary>
|
||||
/// 获取订阅模板
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> Tmpl()
|
||||
{
|
||||
var jm = await _userWeChatMsgSubscriptionServices.tmpl(_user.ID);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 设置订阅信息
|
||||
/// <summary>
|
||||
/// 设置订阅信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> SetTip([FromBody] SetWeChatAppletsMessageTip entity)
|
||||
{
|
||||
var jm = await _userWeChatMsgSubscriptionServices.SetTip(_user.ID, entity.templateId, entity.status);
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.WeChat.Service.Configuration;
|
||||
using CoreCms.Net.WeChat.Service.Enums;
|
||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
||||
using CoreCms.Net.WeChat.Service.Mediator;
|
||||
using CoreCms.Net.WeChat.Service.Models;
|
||||
using CoreCms.Net.WeChat.Service.Options;
|
||||
using CoreCms.Net.WeChat.Service.Utilities;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetTaste;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers.WeChatOAuth
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信小程序Controller
|
||||
/// </summary>
|
||||
public class WxOpenController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
private readonly WeChatOptions _weChatOptions;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 原始的加密请求(如果不加密则为null)
|
||||
/// </summary>
|
||||
public XDocument? EcryptRequestDocument { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用加密
|
||||
/// </summary>
|
||||
public bool UsingEncryptMessage = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否取消执行
|
||||
/// </summary>
|
||||
public bool CancelExecute = false;
|
||||
/// <summary>
|
||||
/// 是否使用兼容模式
|
||||
/// </summary>
|
||||
public bool UsingCompatibilityModelEncryptMessage = false;
|
||||
|
||||
/// <summary>
|
||||
/// 微信小程序服务器交互
|
||||
/// </summary>
|
||||
/// <param name="weChatApiHttpClientFactory"></param>
|
||||
/// <param name="weChatOptions"></param>
|
||||
/// <param name="mediator"></param>
|
||||
public WxOpenController(IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IOptions<WeChatOptions> weChatOptions, IMediator mediator)
|
||||
{
|
||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
||||
_mediator = mediator;
|
||||
_weChatOptions = weChatOptions.Value;
|
||||
}
|
||||
|
||||
#region GET请求用于处理微信小程序后台的URL验证
|
||||
/// <summary>
|
||||
/// GET请求用于处理微信小程序后台的URL验证
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ActionName("Index")]
|
||||
public ActionResult Get(PostModel postModel, string echostr)
|
||||
{
|
||||
if (CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, _weChatOptions.WxOpenToken))
|
||||
{
|
||||
return Content(echostr); //返回随机字符串则表示验证通过
|
||||
}
|
||||
else
|
||||
{
|
||||
return Content("failed:" + postModel.Signature + "," + CheckSignature.GetSignature(postModel.Timestamp, postModel.Nonce, _weChatOptions.WxOpenToken) + "。" + "如果你在浏览器中看到这句话,说明此地址可以被作为微信小程序后台的Url,请注意保持Token一致。");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 接收服务器推送
|
||||
/// <summary>
|
||||
/// 接收服务器推送 文档:https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionName("Index")]
|
||||
|
||||
public async Task<IActionResult> Post(PostModel postModel)
|
||||
{
|
||||
if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, _weChatOptions.WxOpenToken))
|
||||
{
|
||||
NLogUtil.WriteFileLog(LogLevel.Error, LogType.WxPost, "接收服务器推送(签名错误)", JsonConvert.SerializeObject(postModel));
|
||||
return Content("fail");
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(签名成功)", JsonConvert.SerializeObject(postModel));
|
||||
}
|
||||
postModel.Token = _weChatOptions.WxOpenToken;//根据自己后台的设置保持一致
|
||||
postModel.EncodingAESKey = _weChatOptions.WxOpenEncodingAESKey;//根据自己后台的设置保持一致
|
||||
postModel.AppId = _weChatOptions.WxOpenAppId;//根据自己后台的设置保持一致(必须提供)
|
||||
|
||||
var body = Request.Body;
|
||||
//获取流数据转xml流
|
||||
XDocument postDataDocument = XmlUtility.Convert(Request.GetRequestStream());
|
||||
|
||||
var msgXml = string.Empty;
|
||||
var callbackXml = Init(postDataDocument, postModel, ref msgXml);
|
||||
|
||||
//怕出现误判,所以将最优结果判断
|
||||
if (callbackXml != null && CancelExecute == false && !string.IsNullOrEmpty(msgXml))
|
||||
{
|
||||
/* 如果是 XML 格式的通知内容 */
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(XML格式的通知内容)", JsonConvert.SerializeObject(callbackXml));
|
||||
var callBack = await ExecuteProcess(callbackXml, msgXml);
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(XML通知微信服务器)", callBack.Data);
|
||||
return Content(callBack.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(解密失败)", JsonConvert.SerializeObject(callbackXml));
|
||||
return Content("fail");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 处理xml内容
|
||||
/// <summary>
|
||||
/// 对解密后的xml数据进行筛选并分发处理结果
|
||||
/// </summary>
|
||||
public async Task<WeChatApiCallBack> ExecuteProcess(XDocument sourceXml, string msgXml)
|
||||
{
|
||||
var requestType = sourceXml.Root?.Element("MsgType")?.Value;
|
||||
|
||||
WeChatApiCallBack callBack = new WeChatApiCallBack();
|
||||
|
||||
if (!string.IsNullOrEmpty(requestType))
|
||||
{
|
||||
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
||||
|
||||
switch (requestType)
|
||||
{
|
||||
|
||||
case RequestMsgType.Text:
|
||||
var textMessageEvent = client.DeserializeEventFromXml<SKIT.FlurlHttpClient.Wechat.Api.Events.TextMessageEvent>(msgXml);
|
||||
callBack = await _mediator.Send(new TextMessageEventCommand() { EventObj = textMessageEvent });
|
||||
break;
|
||||
case RequestMsgType.Location:
|
||||
|
||||
break;
|
||||
case RequestMsgType.Image:
|
||||
var imageMessageEvent = client.DeserializeEventFromXml<SKIT.FlurlHttpClient.Wechat.Api.Events.ImageMessageEvent>(msgXml);
|
||||
callBack = await _mediator.Send(new ImageMessageEventCommand() { EventObj = imageMessageEvent });
|
||||
break;
|
||||
case RequestMsgType.Voice:
|
||||
var voiceMessageEvent = client.DeserializeEventFromXml<SKIT.FlurlHttpClient.Wechat.Api.Events.VoiceMessageEvent>(msgXml);
|
||||
callBack = await _mediator.Send(new VoiceMessageEventCommand() { EventObj = voiceMessageEvent });
|
||||
break;
|
||||
case RequestMsgType.Video:
|
||||
|
||||
break;
|
||||
case RequestMsgType.ShortVideo:
|
||||
|
||||
break;
|
||||
case RequestMsgType.Link:
|
||||
|
||||
break;
|
||||
case RequestMsgType.MessageEvent:
|
||||
var eventType = sourceXml.Root?.Element("Event")?.Value;
|
||||
if (!string.IsNullOrEmpty(eventType))
|
||||
{
|
||||
switch (eventType)
|
||||
{
|
||||
case EventType.Subscribe:
|
||||
|
||||
break;
|
||||
case EventType.Unsubscribe:
|
||||
|
||||
break;
|
||||
case EventType.Localtion:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(处理xml内容/Event无匹配)", JsonConvert.SerializeObject(sourceXml));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(处理xml内容/MsgType无匹配)", JsonConvert.SerializeObject(sourceXml));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WxPost, "接收服务器推送(处理xml内容/获取MsgType失败)", JsonConvert.SerializeObject(sourceXml));
|
||||
}
|
||||
|
||||
return callBack;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 初始化获取xml文本数据
|
||||
|
||||
/// <summary>
|
||||
/// 初始化获取xml文本数据
|
||||
/// </summary>
|
||||
/// <param name="postDataDocument"></param>
|
||||
/// <param name="postModel"></param>
|
||||
/// <param name="msgXml"></param>
|
||||
/// <returns></returns>
|
||||
private XDocument? Init(XDocument postDataDocument, PostModel postModel, ref string msgXml)
|
||||
{
|
||||
//进行加密判断并处理
|
||||
var postDataStr = postDataDocument.ToString();
|
||||
XDocument decryptDoc = postDataDocument;
|
||||
if (postDataDocument.Root?.Element("Encrypt") != null && !string.IsNullOrEmpty(postDataDocument.Root.Element("Encrypt")?.Value))
|
||||
{
|
||||
//使用了加密
|
||||
UsingEncryptMessage = true;
|
||||
EcryptRequestDocument = postDataDocument;
|
||||
|
||||
WXBizMsgCrypt msgCrype = new WXBizMsgCrypt(postModel.Token, postModel.EncodingAESKey, postModel.AppId);
|
||||
|
||||
var result = msgCrype.DecryptMsg(postModel.Msg_Signature, postModel.Timestamp, postModel.Nonce, postDataStr, ref msgXml);
|
||||
//判断result类型
|
||||
if (result != 0)
|
||||
{
|
||||
//验证没有通过,取消执行
|
||||
CancelExecute = true;
|
||||
return null;
|
||||
}
|
||||
if (postDataDocument.Root.Element("FromUserName") != null && !string.IsNullOrEmpty(postDataDocument.Root.Element("FromUserName")?.Value))
|
||||
{
|
||||
//TODO:使用了兼容模式,进行验证即可
|
||||
UsingCompatibilityModelEncryptMessage = true;
|
||||
}
|
||||
decryptDoc = XDocument.Parse(msgXml);//完成解密
|
||||
}
|
||||
return decryptDoc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user