/*********************************************************************** * Project: baifenBinfa * ProjectName: 百分兵法管理系统 * Web: http://chuanyin.com * Author: * Email: * CreateTime: 202403/02 * 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 { /// /// 拼团接口 /// [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; /// /// 构造函数 /// 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 拼团列表 /// /// 拼团列表 /// /// [HttpPost] public async Task GetList([FromBody] FMPageByIntId entity) { WebApiCallBack jm; var userId = 0; if (_user != null) { userId = _user.ID; } jm = await _pinTuanRuleServices.GetPinTuanList(userId, entity.page, entity.limit); return jm; } #endregion #region 获取拼团商品信息 /// /// 获取拼团商品信息 /// /// [HttpPost] public async Task GetGoodsInfo([FromBody] FMIntId entity) { var jm = new WebApiCallBack(); var userId = 0; if (_user != null) { userId = _user.ID; } var showSku = entity.data.ObjectToBool(); var pinTuanRule = await _pinTuanRuleServices.QueryByClauseAsync(p => p.id == entity.id, true, true); if (pinTuanRule == null) { jm.msg = "拼团获取失败"; return jm; } var pinTuanGood = await _pinTuanGoodsServices.QueryByClauseAsync(p => p.ruleId == entity.id, true, true); jm.status = true; jm.msg = "获取详情成功"; jm.data = await _pinTuanGoodsServices.GetGoodsInfo(pinTuanRule, pinTuanGood.goodsId, userId, true, true, showSku); return jm; } #endregion #region 获取货品信息 /// /// 获取货品信息 /// /// [HttpPost] public async Task 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( (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取拼团信息,用在订单详情页 /// /// 根据订单id取拼团信息,用在订单详情页 /// /// [HttpPost] public async Task 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 } }