From 5591c18dc3500bd3e0719bb6b28b26f7f9e7cb58 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期三, 15 五月 2024 09:46:19 +0800
Subject: [PATCH] 计划订单

---
 CoreCms.Net.Services/Order/CoreCmsOrderServices.cs |  109 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs
index 6f44512..5a02e7e 100644
--- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs
+++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs
@@ -81,6 +81,7 @@
         private readonly IRedisOperationRepository _redisOperationRepository;
         private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
         private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
+        private readonly ICoreCmsPlanOrderServices _planOrderServices;
 
         private IUnitOfWork _unitOfWork;
 
@@ -108,7 +109,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;
@@ -145,6 +147,7 @@
             _userWeChatInfoServices = userWeChatInfoServices;
             _weChatApiHttpClientFactory = weChatApiHttpClientFactory;
             _unitOfWork = unitOfWork;
+            _planOrderServices = planOrderServices;
         }
 
         #region 鏌ヨ鍥㈣喘绉掓潃涓嬪崟鏁伴噺锛堣幏鍙栬揣鍝佺殑绉掓潃鍥㈣喘鏁版嵁锛�
@@ -226,8 +229,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
@@ -283,6 +287,7 @@
                 order.confirmStatus = (int)GlobalEnumVars.OrderConfirmStatus.ReceiptNotConfirmed;
                 order.createTime = DateTime.Now;
                 order.scene = scene;
+                order.planorderId = planorderId;
 
                 //涓婇潰淇濆瓨濂借鍗曡〃锛屼笅闈繚瀛樿鍗曠殑鍏朵粬淇℃伅
                 if (orderItems == null)
@@ -510,7 +515,105 @@
                 }
                 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);
+
+                        //濡傛灉鏄棬搴楄嚜鎻愶紝搴旇鑷姩璺宠繃鍙戣揣锛岀敓鎴愭彁璐у崟淇℃伅锛屼娇鐢ㄦ彁璐у崟鏍搁攢銆�
+                        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(order));
+                            }
+                        }
+
+                        //鐢ㄦ埛鍗囩骇澶勭悊
+                       // await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.UserUpGrade, JsonConvert.SerializeObject(order));
+                        //鍙戦�佹敮浠樻垚鍔熶俊鎭�,澧炲姞鍙戦�佸唴瀹�
+                        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 _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderPrint, JsonConvert.SerializeObject(order));
+
+                    }
+                    else
+                    {
+                        await _messageCenterServices.SendMessage(order.userId, GlobalEnumVars.PlatformMessageTypes.CreateOrder.ToString(), JObject.FromObject(order));
+                    }
+                      
                 }
 
                 _unitOfWork.CommitTran();

--
Gitblit v1.9.1