| | |
| | | /*********************************************************************** |
| | | * Project: CoreCms |
| | | * ProjectName: 核心内容管理系统 |
| | | * Web: https://www.corecms.net |
| | | * Author: 大灰灰 |
| | | * Email: jianweie@163.com |
| | | * CreateTime: 2021/1/31 21:45:10 |
| | | * Project: baifenBinfa |
| | | * ProjectName: 百分兵法管理系统 |
| | | * Web: http://chuanyin.com |
| | | * Author: |
| | | * Email: |
| | | * CreateTime: 202403/02 |
| | | * Description: 暂无 |
| | | ***********************************************************************/ |
| | | |
| | |
| | | using CoreCms.Net.Utility.Extensions; |
| | | using CoreCms.Net.Utility.Helper; |
| | | using CoreCms.Net.WeChat.Service.HttpClients; |
| | | using Essensoft.Paylink.Alipay.Domain; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | |
| | | using SKIT.FlurlHttpClient.Wechat.Api.Models; |
| | | using SqlSugar; |
| | | using Yitter.IdGenerator; |
| | | using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinUserInfoBatchGetRequest.Types; |
| | | using static SKIT.FlurlHttpClient.Wechat.Api.Models.ChannelsECLeagueHeadSupplierOrderGetResponse.Types.CommssionOrder.Types.OrderDetail.Types; |
| | | |
| | | |
| | | namespace CoreCms.Net.Services |
| | |
| | | private readonly IRedisOperationRepository _redisOperationRepository; |
| | | private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices; |
| | | private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory; |
| | | private readonly ICoreCmsPlanOrderServices _planOrderServices; |
| | | |
| | | |
| | | private IUnitOfWork _unitOfWork; |
| | | |
| | |
| | | , ICoreCmsPaymentsServices paymentsServices |
| | | , ICoreCmsBillRefundServices billRefundServices |
| | | , ICoreCmsBillLadingServices billLadingServices |
| | | , ICoreCmsBillReshipServices billReshipServices, ICoreCmsMessageCenterServices messageCenterServices, ICoreCmsGoodsCommentServices goodsCommentServices, ISysTaskLogServices taskLogServices, ICoreCmsPromotionRecordServices promotionRecordServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IUnitOfWork unitOfWork) |
| | | , ICoreCmsBillReshipServices billReshipServices, ICoreCmsMessageCenterServices messageCenterServices, ICoreCmsGoodsCommentServices goodsCommentServices, ISysTaskLogServices taskLogServices, ICoreCmsPromotionRecordServices promotionRecordServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IUnitOfWork unitOfWork |
| | | , ICoreCmsPlanOrderServices planOrderServices) |
| | | { |
| | | this._dal = dal; |
| | | base.BaseDal = dal; |
| | |
| | | _userWeChatInfoServices = userWeChatInfoServices; |
| | | _weChatApiHttpClientFactory = weChatApiHttpClientFactory; |
| | | _unitOfWork = unitOfWork; |
| | | _planOrderServices = planOrderServices; |
| | | } |
| | | |
| | | #region 查询团购秒杀下单数量(获取货品的秒杀团购数据) |
| | |
| | | /// <param name="requireOrder">微信自定义组件(是否需要推单,1:需要,0:不需要)</param> |
| | | /// <param name="requiredFundType">微信自定义组件(requireOrder = 1时生效,0,非二级商户号订单,1,二级商户号订单,2,两种方式皆可(后续只会存在1))</param> |
| | | /// <param name="traceId">微信自定义组件(跟踪ID,有效期十分钟,会影响主播归因、分享员归因等,需创建订单前调用,调用生成订单 api 时需传入该参数)</param> |
| | | /// <param name="planorderId">计划订单id</param> |
| | | /// <returns></returns> |
| | | public async Task<WebApiCallBack> ToAdd(int userId, int orderType, string cartIds, int receiptType, int ushipId, int storeId, string ladingName, string ladingMobile, string memo, int point, string couponCode, int source, int scene, int taxType, string taxName, string taxCode, int objectId, int teamId, int requireOrder, int requiredFundType, string traceId) |
| | | public async Task<WebApiCallBack> ToAdd(int userId, int orderType, string cartIds, int receiptType, int ushipId, int storeId, string ladingName, string ladingMobile, string memo, int point, string couponCode, int source, int scene, int taxType, string taxName, string taxCode, int objectId, int teamId, int requireOrder, int requiredFundType, string traceId, string planorderId) |
| | | { |
| | | var jm = new WebApiCallBack() { methodDescription = "创建订单" }; |
| | | try |
| | |
| | | order.confirmStatus = (int)GlobalEnumVars.OrderConfirmStatus.ReceiptNotConfirmed; |
| | | order.createTime = DateTime.Now; |
| | | order.scene = scene; |
| | | order.planorderId = planorderId; |
| | | |
| | | //上面保存好订单表,下面保存订单的其他信息 |
| | | if (orderItems == null) |
| | |
| | | }; |
| | | await _orderLogServices.InsertAsync(orderLog); |
| | | |
| | | |
| | | //拆单 |
| | | var jms = await Chaidan(order.orderId); |
| | | var orderchai = await _dal.QueryByClauseAsync(p => p.orderId == order.orderId); |
| | | orderchai.Orderitems = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); |
| | | |
| | | |
| | | //如果是门店自提,应该自动跳过发货,生成提货单信息,使用提货单核销。 |
| | | if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery) |
| | | { |
| | |
| | | if (storeOrderAutomaticDelivery == 1) |
| | | { |
| | | //订单自动发货 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(orderchai)); |
| | | } |
| | | } |
| | | |
| | | //用户升级处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(orderchai)); |
| | | //发送支付成功信息,增加发送内容 |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString(), JObject.FromObject(order)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString(), JObject.FromObject(order)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString(), JObject.FromObject(orderchai)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString(), JObject.FromObject(orderchai)); |
| | | //易联云打印机打印 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(orderchai)); |
| | | } |
| | | else |
| | | { |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.CreateOrder.ToString(), JObject.FromObject(order)); |
| | | if (!string.IsNullOrEmpty(planorderId)) |
| | | { |
| | | //查询计划订单 |
| | | var planOrder = await _planOrderServices.QueryByIdAsync(planorderId); |
| | | //上面保存好订单表,下面保存订单的其他信息 |
| | | if (planOrder == null || planOrder.isdelete == true) |
| | | { |
| | | _unitOfWork.RollbackTran(); |
| | | jm.msg = "计划订单获取失败"; |
| | | return jm; |
| | | } |
| | | //if (planOrder.status != 2) |
| | | //{ |
| | | // _unitOfWork.RollbackTran(); |
| | | // jm.msg = "计划订单没有锁单"; |
| | | // return jm; |
| | | //} |
| | | |
| | | if ((planOrder.keYongAmount - planOrder.huaFeiAmount - order.orderAmount)<0) |
| | | { |
| | | _unitOfWork.RollbackTran(); |
| | | jm.msg = "计划订单可用余额不足"; |
| | | return jm; |
| | | } |
| | | planOrder.huaFeiAmount = planOrder.huaFeiAmount + order.orderAmount; |
| | | //修改计划订单的已花费金额 |
| | | var crr = await _planOrderServices.UpdateAsync(planOrder); |
| | | |
| | | |
| | | |
| | | //创建支付单 |
| | | var billPayments = new CoreCmsBillPayments(); |
| | | billPayments.paymentId = CommonHelper.GetSerialNumberType((int)GlobalEnumVars.SerialNumberType.支付单编号); |
| | | billPayments.sourceId = order.orderId; |
| | | billPayments.money = order.orderAmount; |
| | | billPayments.userId = userId; |
| | | billPayments.type = order.orderType; |
| | | billPayments.status = (int)GlobalEnumVars.BillPaymentsStatus.Payed; |
| | | billPayments.paymentCode = GlobalEnumVars.PaymentsTypes.planorderpay.ToString(); |
| | | billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; |
| | | billPayments.payedMsg = "计划订单直接支付成功"; |
| | | billPayments.parameters = ""; |
| | | billPayments.createTime = DateTime.Now; |
| | | billPayments.updateTime = DateTime.Now; |
| | | |
| | | |
| | | await _billPaymentsServices.InsertAsync(billPayments); |
| | | |
| | | //调整直接支付成功 |
| | | await _dal.UpdateAsync(p => new CoreCmsOrder() |
| | | { |
| | | payedAmount = order.orderAmount, |
| | | paymentTime = DateTime.Now, |
| | | updateTime = DateTime.Now, |
| | | paymentCode = GlobalEnumVars.PaymentsTypes.planorderpay.ToString(), |
| | | payStatus = (int)GlobalEnumVars.OrderPayStatus.Yes, |
| | | orderAmount = order.orderAmount |
| | | }, p => p.orderId == order.orderId); |
| | | |
| | | //记录订单日志 |
| | | orderLog = new CoreCmsOrderLog |
| | | { |
| | | userId = userId, |
| | | orderId = order.orderId, |
| | | type = (int)GlobalEnumVars.OrderLogTypes.LOG_TYPE_PAY, |
| | | msg = "计划订单直接支付成功", |
| | | data = JsonConvert.SerializeObject(order), |
| | | createTime = DateTime.Now |
| | | }; |
| | | await _orderLogServices.InsertAsync(orderLog); |
| | | |
| | | |
| | | //拆单 |
| | | var jms = await Chaidan(order.orderId); |
| | | var orderchai = await _dal.QueryByClauseAsync(p => p.orderId == order.orderId); |
| | | orderchai.Orderitems = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); |
| | | |
| | | //如果是门店自提,应该自动跳过发货,生成提货单信息,使用提货单核销。 |
| | | if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery) |
| | | { |
| | | var allConfigs = await _settingServices.GetConfigDictionaries(); |
| | | var storeOrderAutomaticDelivery = CommonHelper |
| | | .GetConfigDictionary(allConfigs, SystemSettingConstVars.StoreOrderAutomaticDelivery) |
| | | .ObjectToInt(1); |
| | | if (storeOrderAutomaticDelivery == 1) |
| | | { |
| | | //订单自动发货 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(orderchai)); |
| | | } |
| | | } |
| | | |
| | | //结佣处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAgentOrDistribution, JsonConvert.SerializeObject(orderchai)); |
| | | |
| | | //用户升级处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(orderchai)); |
| | | //发送支付成功信息,增加发送内容 |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString(), JObject.FromObject(orderchai)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString(), JObject.FromObject(orderchai)); |
| | | //易联云打印机打印 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(orderchai)); |
| | | |
| | | } |
| | | else |
| | | { |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.CreateOrder.ToString(), JObject.FromObject(order)); |
| | | } |
| | | |
| | | } |
| | | |
| | | _unitOfWork.CommitTran(); |
| | |
| | | order.shipAddress = userShipInfo.street + " " + userShipInfo.address; |
| | | order.shipName = userShipInfo.name; |
| | | order.shipMobile = userShipInfo.mobile; |
| | | order.shipCoordinate = userShipInfo.latitude + "," + userShipInfo.longitude; |
| | | |
| | | var ship = await _shipServices.GetShip(userShipInfo.areaId); |
| | | if (ship != null) |
| | |
| | | weight = Math.Round(item.weight * item.nums, 2), |
| | | sendNums = 0, |
| | | addon = item.products.spesDesc, |
| | | createTime = DateTime.Now |
| | | createTime = DateTime.Now, |
| | | CustomizableMoney= item.CustomizableMoney, |
| | | IsCustomizable = item.isCustomizable, |
| | | |
| | | }; |
| | | if (item.products.promotionList.Count > 0) |
| | | { |
| | |
| | | order.aftersalesItem = await _billAftersalesServices.QueryListByClauseAsync(p => p.orderId == order.orderId); |
| | | //发货单 |
| | | order.delivery = await _billDeliveryServices.QueryListByClauseAsync(p => p.orderId == order.orderId); |
| | | |
| | | if (order.delivery != null && order.delivery.Any()) |
| | | { |
| | | foreach (var item in order.delivery) |
| | | { |
| | | var outFirstAsync = await _logisticsServices.QueryByClauseAsync(p => p.logiCode == item.logiCode); |
| | | item.logiName = outFirstAsync != null ? outFirstAsync.logiName : item.logiCode; |
| | | if (item.logiCode == "Distributor") |
| | | { |
| | | //是供应商送货 |
| | | var ds= await _unitOfWork.GetDbClient().Queryable<CoreCmsDistribution>().Where(x => x.id == item.sendDistributionID).FirstAsync(); |
| | | if(ds==null) |
| | | { |
| | | item.logiName = "经销商配送,但是经销商已经退出或者不存在"; |
| | | } |
| | | else |
| | | { |
| | | item.logiName = $"经销商配送({ds.schoolName}--{ds.name})"; |
| | | } |
| | | item.distributionAcceptStr = item.sendDistributionAccept?.GetDescription() ?? "经销商未确认接受配送"; |
| | | |
| | | } |
| | | else |
| | | { |
| | | var outFirstAsync = await _logisticsServices.QueryByClauseAsync(p => p.logiCode == item.logiCode); |
| | | item.logiName = outFirstAsync != null ? outFirstAsync.logiName : item.logiCode; |
| | | } |
| | | } |
| | | } |
| | | //获取提货门店 |
| | |
| | | await _invoiceServices.InsertAsync(taxInfo); |
| | | } |
| | | |
| | | //拆单 |
| | | var jms = await Chaidan(order.orderId); |
| | | var orderchai = await _dal.QueryByClauseAsync(p => p.orderId == order.orderId); |
| | | orderchai.Orderitems = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); |
| | | |
| | | |
| | | |
| | | //如果是门店自提,应该自动跳过发货,生成提货单信息,使用提货单核销。 |
| | | if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery) |
| | | { |
| | |
| | | if (storeOrderAutomaticDelivery == 1) |
| | | { |
| | | //订单自动发货 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(orderchai)); |
| | | } |
| | | } |
| | | |
| | |
| | | //} |
| | | |
| | | //结佣处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAgentOrDistribution, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAgentOrDistribution, JsonConvert.SerializeObject(orderchai)); |
| | | //易联云打印机打印 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(orderchai)); |
| | | |
| | | //发送支付成功信息,增加发送内容 |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString(), JObject.FromObject(order)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString(), JObject.FromObject(order)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString(), JObject.FromObject(orderchai)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString(), JObject.FromObject(orderchai)); |
| | | |
| | | //用户升级处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(order)); |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(orderchai)); |
| | | |
| | | } |
| | | } |
| | |
| | | { |
| | | if (payStatus == (int)GlobalEnumVars.OrderPayStatus.No) |
| | | { |
| | | html.Append("<a class='layui-btn layui-btn-xs pay-order' lay-active='payOrder' data-id='" + orderId + "'>支付</a><br>"); |
| | | //html.Append("<a class='layui-btn layui-btn-xs pay-order' lay-active='payOrder' data-id='" + orderId + "'>支付</a><br>"); |
| | | html.Append("<a class='layui-btn layui-btn-xs edit-order' lay-active='editOrder' data-id='" + orderId + "'>编辑</a><br>"); |
| | | html.Append("<a class='layui-btn layui-btn-xs cancel-order' lay-active='cancelOrder' data-id='" + orderId + "'>取消</a><br>"); |
| | | } |
| | |
| | | shipMobile = orderInfo[0].shipMobile, |
| | | logisticsId = orderInfo[0].logisticsId, |
| | | logisticsName = orderInfo[0].logisticsName, |
| | | Coordinate= orderInfo[0].shipCoordinate, |
| | | items = new List<CoreCmsOrderItem>(), |
| | | orders = orderInfo //把订单信息冗余上去 |
| | | }; |
| | |
| | | //是否有警告 |
| | | if (string.IsNullOrEmpty(jm.msg)) |
| | | { |
| | | jm.msg = "请注意!合并发货订单中存在:" + jm.msg + "。确定发货吗?"; |
| | | //多地址多用户禁止 合并发货 20240605 |
| | | |
| | | jm.msg = jm.msg + "。不可合并发货"; |
| | | jm.status = false; |
| | | return jm; |
| | | // jm.msg = "请注意!合并发货订单中存在:" + jm.msg + "。确定发货吗?"; |
| | | } |
| | | jm.status = true; |
| | | jm.data = newOrder; |
| | |
| | | /// <param name="deliveryCompanyId">第三方对接物流编码</param> |
| | | /// <returns></returns> |
| | | public async Task<WebApiCallBack> BatchShip(string[] ids, string logiCode, string logiNo, |
| | | Dictionary<int, int> items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "") |
| | | Dictionary<int, int> items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "", int? sendDistributionID = null) |
| | | { |
| | | |
| | | var result = await _billDeliveryServices.BatchShip(ids, logiCode, logiNo, items, storeId, shipName, shipMobile, shipAreaId, shipAddress, memo, deliveryCompanyId); |
| | | var result = await _billDeliveryServices.BatchShip(ids, logiCode, logiNo, items, storeId, shipName, shipMobile, shipAreaId, shipAddress, memo, deliveryCompanyId,sendDistributionID); |
| | | return result; |
| | | |
| | | } |
| | |
| | | /// <param name="deliveryCompanyId">第三方对接物流编码</param> |
| | | /// <returns></returns> |
| | | public async Task<WebApiCallBack> Ship(string orderId, string logiCode, string logiNo, |
| | | Dictionary<int, int> items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "") |
| | | Dictionary<int, int> items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "", int? sendDistributionID = null) |
| | | { |
| | | var result = await _billDeliveryServices.Ship(orderId, logiCode, logiNo, items, storeId, shipName, shipMobile, shipAreaId, shipAddress, memo, deliveryCompanyId); |
| | | var result = await _billDeliveryServices.Ship(orderId, logiCode, logiNo, items, storeId, shipName, shipMobile, shipAreaId, shipAddress, memo, deliveryCompanyId,sendDistributionID); |
| | | return result; |
| | | |
| | | } |
| | |
| | | createTime = DateTime.Now |
| | | }; |
| | | await _orderLogServices.InsertAsync(orderLog); |
| | | //百分兵法特殊奖励 |
| | | var allConfigs = await _settingServices.GetConfigDictionaries(); |
| | | var pointExchangeModel = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DictionaryAchievementOnOff).ObjectToInt(); |
| | | if (pointExchangeModel == 1) |
| | | { |
| | | //开启业绩奖励模式 |
| | | var user = await _userServices.QueryByIdAsync(orderInfo.userId, isDataCache: true, cacheTimes: 1); |
| | | if (user.parentId != 0) |
| | | { |
| | | //如果是 |
| | | CreateDAOrderInParam data = new CreateDAOrderInParam |
| | | { |
| | | Money = money, |
| | | OderId = orderInfo.orderId, |
| | | SourceTypes = GlobalEnumVars.UserBalanceSourceTypes.GoodsOder, |
| | | UserID = user.parentId, |
| | | |
| | | |
| | | }; |
| | | //经销商业务订单结算 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.DistributionAchievementOder, JsonConvert.SerializeObject(data)); |
| | | } |
| | | } |
| | | //订单完成结算订单 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderFinishCommand, orderInfo.orderId); |
| | | |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region 订单拆单 |
| | | |
| | | /// <summary> |
| | | /// 订单拆单(根据商品所属对订单进行拆单) |
| | | /// </summary> |
| | | /// <param name="orderId">订单编号</param> |
| | | /// <returns></returns> |
| | | public async Task<WebApiCallBack> Chaidan(string orderId) |
| | | { |
| | | var jm = new WebApiCallBack() { msg = "订单拆单失败" }; |
| | | |
| | | //获取订单 |
| | | var order = await _dal.QueryByClauseAsync(p => p.orderId == orderId); |
| | | if (order == null) |
| | | { |
| | | return jm; |
| | | } |
| | | //查询订单明细 |
| | | //订单详情(子货品数据) |
| | | var orderItems = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); |
| | | var goodsids = orderItems.Select(x => x.goodsId).ToArray(); |
| | | //查询订单包含的货品 |
| | | var coreCmsGoods = await _goodsServices.QueryListByClauseAsync(p => goodsids.Contains(p.id)); |
| | | coreCmsGoods = coreCmsGoods.OrderBy(x => x.publisherId).ToList(); |
| | | //判断订单是否属于多个供应商,如果属于多个供应商,则拆单发货 |
| | | int publisherIdcount = 1 ; |
| | | int publisherId = coreCmsGoods[0].publisherId.HasValue? coreCmsGoods[0].publisherId.Value : 0; |
| | | |
| | | for (int i = 1; i < coreCmsGoods.Count; i++) |
| | | { |
| | | int publisherIdnow = coreCmsGoods[i].publisherId.HasValue ? coreCmsGoods[i].publisherId.Value : 0; |
| | | |
| | | if ( publisherId == publisherIdnow) |
| | | { |
| | | continue; |
| | | }else |
| | | { |
| | | publisherIdcount += 1; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (publisherIdcount <= 1) |
| | | { |
| | | //修改订单的货权人 |
| | | if (coreCmsGoods[0].publisherId.HasValue) |
| | | { |
| | | order.publisherId = coreCmsGoods[0].publisherId; |
| | | await _dal.UpdateAsync(order); |
| | | } |
| | | jm.status = true; |
| | | jm.msg = "订单不需要拆单"; |
| | | return jm; |
| | | } |
| | | |
| | | foreach (var orderItem in orderItems) |
| | | { |
| | | var coreCmsGoods1 = coreCmsGoods.Where(x => x.id == orderItem.goodsId).FirstOrDefault(); |
| | | if (coreCmsGoods1 != null) |
| | | { |
| | | orderItem.publisherId = coreCmsGoods1.publisherId; |
| | | } |
| | | } |
| | | orderItems = orderItems.OrderBy(x => x.publisherId).ToList() ; |
| | | //订单商品总价 |
| | | var amount = orderItems.Sum(x => x.amount); |
| | | //开始拆单 |
| | | int orderItemscount = 1; |
| | | while(orderItemscount < orderItems.Count) |
| | | { |
| | | if (orderItems[orderItemscount].publisherId != orderItems[orderItemscount - 1].publisherId) |
| | | { |
| | | //当前供应商的所有商品 |
| | | var coreCmsOrderItems = orderItems.Where(x=>x.publisherId == orderItems[orderItemscount].publisherId).ToList(); |
| | | var coreCmsamount = coreCmsOrderItems.Sum(x => x.amount); |
| | | //当前供应商所占商品价格比值 |
| | | var bizhi = coreCmsamount / amount; |
| | | |
| | | //生成新的订单 |
| | | var coreCmsOrder = new CoreCmsOrder(); |
| | | coreCmsOrder.orderId = CommonHelper.GetSerialNumberType((int)GlobalEnumVars.SerialNumberType.订单编号); |
| | | if (order.goodsAmount > 0) |
| | | { |
| | | coreCmsOrder.goodsAmount = Math.Round(order.goodsAmount * bizhi,2); |
| | | order.goodsAmount = order.goodsAmount - coreCmsOrder.goodsAmount; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.goodsAmount = 0; |
| | | } |
| | | |
| | | if (order.payedAmount > 0) |
| | | { |
| | | coreCmsOrder.payedAmount = Math.Round(order.payedAmount * bizhi, 2); |
| | | order.payedAmount = order.payedAmount - coreCmsOrder.payedAmount; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.payedAmount = 0; |
| | | } |
| | | |
| | | if (order.orderAmount > 0) |
| | | { |
| | | coreCmsOrder.orderAmount = Math.Round(order.orderAmount * bizhi, 2); |
| | | order.orderAmount = order.orderAmount - coreCmsOrder.orderAmount; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.orderAmount = 0; |
| | | } |
| | | |
| | | coreCmsOrder.payStatus = order.payStatus; |
| | | coreCmsOrder.shipStatus = order.shipStatus; |
| | | coreCmsOrder.status = order.status; |
| | | coreCmsOrder.orderType = order.orderType; |
| | | coreCmsOrder.receiptType = order.receiptType; |
| | | coreCmsOrder.paymentCode = order.paymentCode; |
| | | coreCmsOrder.paymentTime = order.paymentTime; |
| | | coreCmsOrder.logisticsId = order.logisticsId; |
| | | coreCmsOrder.logisticsName = order.logisticsName; |
| | | |
| | | if (order.costFreight > 0) |
| | | { |
| | | coreCmsOrder.costFreight = Math.Round(order.costFreight * bizhi, 2); |
| | | order.costFreight = order.costFreight - coreCmsOrder.costFreight; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.costFreight = 0; |
| | | } |
| | | |
| | | coreCmsOrder.userId = order.userId; |
| | | coreCmsOrder.sellerId = order.sellerId; |
| | | coreCmsOrder.confirmStatus = order.confirmStatus; |
| | | coreCmsOrder.confirmTime = order.confirmTime; |
| | | coreCmsOrder.storeId = order.storeId; |
| | | coreCmsOrder.shipAreaId = order.shipAreaId; |
| | | coreCmsOrder.shipAddress = order.shipAddress; |
| | | coreCmsOrder.shipCoordinate = order.shipCoordinate; |
| | | coreCmsOrder.shipName = order.shipName; |
| | | coreCmsOrder.shipMobile = order.shipMobile; |
| | | |
| | | coreCmsOrder.weight = coreCmsOrderItems.Sum(x=>x.weight); |
| | | order.weight = order.weight - coreCmsOrder.weight; |
| | | |
| | | coreCmsOrder.taxType = order.taxType; |
| | | coreCmsOrder.taxCode = order.taxCode; |
| | | coreCmsOrder.taxTitle = order.taxTitle; |
| | | |
| | | if (order.point > 0) |
| | | { |
| | | coreCmsOrder.point = Convert.ToInt32(order.point * bizhi); |
| | | order.point = order.point - coreCmsOrder.point; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.point = 0; |
| | | } |
| | | |
| | | if (order.pointMoney > 0) |
| | | { |
| | | coreCmsOrder.pointMoney = Math.Round(order.pointMoney * bizhi, 2); |
| | | order.pointMoney = order.pointMoney - coreCmsOrder.pointMoney; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.pointMoney = 0; |
| | | } |
| | | |
| | | if (order.orderDiscountAmount > 0) |
| | | { |
| | | coreCmsOrder.orderDiscountAmount = Math.Round(order.orderDiscountAmount * bizhi, 2); |
| | | order.orderDiscountAmount = order.orderDiscountAmount - coreCmsOrder.orderDiscountAmount; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.orderDiscountAmount = 0; |
| | | } |
| | | |
| | | |
| | | if (order.goodsDiscountAmount > 0) |
| | | { |
| | | coreCmsOrder.goodsDiscountAmount = Math.Round(order.goodsDiscountAmount * bizhi, 2); |
| | | order.goodsDiscountAmount = order.goodsDiscountAmount - coreCmsOrder.goodsDiscountAmount; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.goodsDiscountAmount = 0; |
| | | } |
| | | |
| | | if (order.couponDiscountAmount > 0) |
| | | { |
| | | coreCmsOrder.couponDiscountAmount = Math.Round(order.couponDiscountAmount * bizhi, 2); |
| | | order.couponDiscountAmount = order.couponDiscountAmount - coreCmsOrder.couponDiscountAmount; |
| | | } |
| | | else |
| | | { |
| | | coreCmsOrder.couponDiscountAmount = 0; |
| | | } |
| | | |
| | | coreCmsOrder.coupon = order.coupon; |
| | | coreCmsOrder.promotionList = order.promotionList; |
| | | coreCmsOrder.memo = order.memo; |
| | | coreCmsOrder.ip = order.ip; |
| | | coreCmsOrder.mark = order.mark; |
| | | coreCmsOrder.source = order.source; |
| | | coreCmsOrder.scene = order.scene; |
| | | coreCmsOrder.isComment = order.isComment; |
| | | coreCmsOrder.isdel = order.isdel; |
| | | coreCmsOrder.objectId = order.objectId; |
| | | coreCmsOrder.createTime = order.createTime; |
| | | coreCmsOrder.updateTime = order.updateTime; |
| | | coreCmsOrder.planorderId = order.planorderId; |
| | | coreCmsOrder.publisherId = order.publisherId; |
| | | coreCmsOrder.oldOderId = order.oldOderId; |
| | | |
| | | |
| | | var res = await _dal.InsertAsync(coreCmsOrder); |
| | | |
| | | //修改订单的所有明细 |
| | | foreach (var coreCmsOrderItem in coreCmsOrderItems) |
| | | { |
| | | coreCmsOrderItem.orderId = coreCmsOrder.orderId; |
| | | var sss = await _orderItemServices.UpdateAsync(coreCmsOrderItem); |
| | | } |
| | | |
| | | coreCmsOrder.Orderitems = coreCmsOrderItems; |
| | | |
| | | |
| | | |
| | | //生成支付信息 |
| | | |
| | | //创建支付单 |
| | | var billPayments = new CoreCmsBillPayments(); |
| | | billPayments.paymentId = CommonHelper.GetSerialNumberType((int)GlobalEnumVars.SerialNumberType.支付单编号); |
| | | billPayments.sourceId = coreCmsOrder.orderId; |
| | | billPayments.money = coreCmsOrder.orderAmount; |
| | | billPayments.userId = coreCmsOrder.userId; |
| | | billPayments.type = coreCmsOrder.orderType; |
| | | billPayments.status = (int)GlobalEnumVars.BillPaymentsStatus.Payed; |
| | | billPayments.paymentCode = coreCmsOrder.paymentCode; |
| | | billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; |
| | | billPayments.payedMsg = "订单拆单支付成功"; |
| | | billPayments.parameters = ""; |
| | | billPayments.createTime = DateTime.Now; |
| | | billPayments.updateTime = DateTime.Now; |
| | | |
| | | |
| | | await _billPaymentsServices.InsertAsync(billPayments); |
| | | |
| | | //各种处理 |
| | | //如果是门店自提,应该自动跳过发货,生成提货单信息,使用提货单核销。 |
| | | if (coreCmsOrder.receiptType == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery) |
| | | { |
| | | var allConfigs = await _settingServices.GetConfigDictionaries(); |
| | | var storeOrderAutomaticDelivery = CommonHelper |
| | | .GetConfigDictionary(allConfigs, SystemSettingConstVars.StoreOrderAutomaticDelivery) |
| | | .ObjectToInt(1); |
| | | if (storeOrderAutomaticDelivery == 1) |
| | | { |
| | | //订单自动发货 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(coreCmsOrder)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //结佣处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAgentOrDistribution, JsonConvert.SerializeObject(coreCmsOrder)); |
| | | //易联云打印机打印 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(coreCmsOrder)); |
| | | |
| | | //发送支付成功信息,增加发送内容 |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString(), JObject.FromObject(coreCmsOrder)); |
| | | await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString(), JObject.FromObject(coreCmsOrder)); |
| | | |
| | | //用户升级处理 |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(coreCmsOrder)); |
| | | |
| | | |
| | | //跳转到下一个订单 |
| | | orderItemscount += coreCmsOrderItems.Count; |
| | | } |
| | | else |
| | | { |
| | | orderItemscount += 1; |
| | | } |
| | | } |
| | | |
| | | //修改订单的货权人 |
| | | if (coreCmsGoods[0].publisherId.HasValue) |
| | | { |
| | | order.publisherId = coreCmsGoods[0].publisherId; |
| | | |
| | | } |
| | | var ssssss = await _dal.UpdateAsync(order); |
| | | |
| | | jm.status = true; |
| | | jm.msg = "订单拆单成功"; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //订单记录 |
| | | var orderLog = new CoreCmsOrderLog |
| | | { |
| | | orderId = order.orderId, |
| | | userId = order.userId, |
| | | type = (int)GlobalEnumVars.OrderLogTypes.LOG_TYPE_PAY, |
| | | msg = jm.msg, |
| | | data = JsonConvert.SerializeObject(jm), |
| | | createTime = DateTime.Now |
| | | }; |
| | | await _orderLogServices.InsertAsync(orderLog); |
| | | |
| | | return jm; |
| | | } |
| | | #endregion |
| | | |
| | | } |
| | | } |