From 626943b5ba84ce44bc19f4c3b8e8e94638bec733 Mon Sep 17 00:00:00 2001 From: username@email.com <yzy2002yzy@163.com> Date: 星期一, 09 九月 2024 14:15:59 +0800 Subject: [PATCH] 查单 --- CoreCms.Net.Services/Order/CoreCmsOrderServices.cs | 572 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 543 insertions(+), 29 deletions(-) diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs index 18a9a99..af659b2 100644 --- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs +++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs @@ -1,10 +1,10 @@ /*********************************************************************** - * 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: 鏆傛棤 ***********************************************************************/ @@ -31,6 +31,7 @@ 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; @@ -38,6 +39,8 @@ 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 @@ -80,6 +83,8 @@ private readonly IRedisOperationRepository _redisOperationRepository; private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices; private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory; + private readonly ICoreCmsPlanOrderServices _planOrderServices; + private IUnitOfWork _unitOfWork; @@ -107,7 +112,8 @@ , 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; @@ -144,6 +150,7 @@ _userWeChatInfoServices = userWeChatInfoServices; _weChatApiHttpClientFactory = weChatApiHttpClientFactory; _unitOfWork = unitOfWork; + _planOrderServices = planOrderServices; } #region 鏌ヨ鍥㈣喘绉掓潃涓嬪崟鏁伴噺锛堣幏鍙栬揣鍝佺殑绉掓潃鍥㈣喘鏁版嵁锛� @@ -225,8 +232,9 @@ /// <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 @@ -282,6 +290,7 @@ order.confirmStatus = (int)GlobalEnumVars.OrderConfirmStatus.ReceiptNotConfirmed; order.createTime = DateTime.Now; order.scene = scene; + order.planorderId = planorderId; //涓婇潰淇濆瓨濂借鍗曡〃锛屼笅闈繚瀛樿鍗曠殑鍏朵粬淇℃伅 if (orderItems == null) @@ -485,6 +494,13 @@ }; 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) { @@ -495,21 +511,128 @@ 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(); @@ -562,6 +685,7 @@ 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) @@ -705,7 +829,10 @@ 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) { @@ -800,12 +927,31 @@ 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; + } } } //鑾峰彇鎻愯揣闂ㄥ簵 @@ -1500,6 +1646,13 @@ 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) { @@ -1510,7 +1663,7 @@ if (storeOrderAutomaticDelivery == 1) { //璁㈠崟鑷姩鍙戣揣 - await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(order)); + await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderAutomaticDelivery, JsonConvert.SerializeObject(orderchai)); } } @@ -1523,16 +1676,16 @@ //} //缁撲剑澶勭悊 - 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)); } } @@ -1650,7 +1803,7 @@ { 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>"); } @@ -1779,6 +1932,7 @@ shipMobile = orderInfo[0].shipMobile, logisticsId = orderInfo[0].logisticsId, logisticsName = orderInfo[0].logisticsName, + Coordinate= orderInfo[0].shipCoordinate, items = new List<CoreCmsOrderItem>(), orders = orderInfo //鎶婅鍗曚俊鎭啑浣欎笂鍘� }; @@ -1850,7 +2004,12 @@ //鏄惁鏈夎鍛� 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; @@ -2017,10 +2176,10 @@ /// <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; } @@ -2044,9 +2203,9 @@ /// <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; } @@ -2121,7 +2280,29 @@ 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); @@ -2553,5 +2734,338 @@ } #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 + } } -- Gitblit v1.9.1