From 1cb49b04ae6709e6054c328f5ed12bff9ca014c8 Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期二, 12 十一月 2024 09:21:57 +0800
Subject: [PATCH] no message

---
 CoreCms.Net.RedisMQ/DistributionSendOderMQ.cs |   51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/CoreCms.Net.RedisMQ/DistributionSendOderMQ.cs b/CoreCms.Net.RedisMQ/DistributionSendOderMQ.cs
index 7863227..bc0b898 100644
--- a/CoreCms.Net.RedisMQ/DistributionSendOderMQ.cs
+++ b/CoreCms.Net.RedisMQ/DistributionSendOderMQ.cs
@@ -4,9 +4,12 @@
 using CoreCms.Net.IServices;
 using CoreCms.Net.Loging;
 using CoreCms.Net.Model.Entities.baifenbingfa.DistributionSendOder;
+using CoreCms.Net.Utility.Extensions;
+using CoreCms.Net.Utility.Helper;
 using InitQ.Abstractions;
 using InitQ.Attributes;
 using Newtonsoft.Json;
+using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -21,10 +24,13 @@
     public class DistributionSendOderMQ: IRedisSubscribe
     {
         private readonly IUnitOfWork _unitOfWork;
-        public DistributionSendOderMQ(IUnitOfWork unitOfWork)
+        private readonly ICoreCmsUserBalanceServices _userBalanceServices;
+        private readonly ICoreCmsSettingServices _coreCmsSettingServices; //娉ㄥ叆鏈嶅姟
+        public DistributionSendOderMQ(IUnitOfWork unitOfWork, ICoreCmsUserBalanceServices userBalanceServices, ICoreCmsSettingServices coreCmsSettingServices)
         {
-            _unitOfWork= unitOfWork;
-
+            _unitOfWork = unitOfWork;
+            _userBalanceServices = userBalanceServices;
+            _coreCmsSettingServices = coreCmsSettingServices;
         }
 
         /// <summary>
@@ -42,7 +48,10 @@
             }
             Param.createTime = DateTime.Now;
             Param.createBy = "绯荤粺闃熷垪";
-           
+            var allConfigs = await _coreCmsSettingServices.GetConfigDictionaries();//鑾峰彇鎵�鏈夐厤缃�
+                                                                            //绛涢�夐厤缃�
+            var DictionaryDeliverFees = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DictionaryDeliverFees).ObjectToDecimal(0);
+            Param.amount = DictionaryDeliverFees;
             await _unitOfWork.GetDbClient().Insertable(Param).ExecuteCommandAsync();
 
         }
@@ -61,14 +70,42 @@
                 NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "ActiveDistributionSendOder 淇敼鐘舵�� 澶勭悊澶辫触", $"杞崲妯″瀷澶辫触===銆� {message}");
                 return;
             }
+            DistributionSendOder oder = null;
+            if (Param.SendOderActive == Model.Entities.sendDistributionAcceptType.OderFreeComplete)
+                 oder=await   _unitOfWork.GetDbClient().Queryable<DistributionSendOder>().Includes(x=>x.delivery).Where(x => x.deliveryID == Param.deliveryID ).FirstAsync();
+            else
 
-          var oder=await   _unitOfWork.GetDbClient().Queryable<DistributionSendOder>().Where(x => x.deliveryID == Param.deliveryID && x.userID == Param.userID).FirstAsync();
+                oder = await _unitOfWork.GetDbClient().Queryable<DistributionSendOder>().Includes(x => x.delivery).Where(x => x.deliveryID == Param.deliveryID && x.userID == Param.userID).FirstAsync();
             oder.upDataTime = DateTime.Now;
             oder.upDataBy = "ActiveDistributionSendOder 闃熷垪";
             oder.description = Param.Dec;
             oder.sendDistributionAccept= Param.SendOderActive;
-         
-            await _unitOfWork.GetDbClient().Updateable(Param).ExecuteCommandAsync();
+            _unitOfWork.BeginTran();
+            try
+            {
+                if (Param.SendOderActive == Model.Entities.sendDistributionAcceptType.OderFreeComplete) {
+                    if (oder.userID != null && oder.delivery?.orderId != null)
+                    {
+                        //閽辨尓鍒颁細鍛樹綑棰濋噷闈�
+                        var result = await _userBalanceServices.Change(oder.userID ?? 0, (int)GlobalEnumVars.UserBalanceSourceTypes.DistributionDelivery,
+                          oder.amount, oder.delivery.orderId);
+                    }
+                    else
+                        NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Order, "缁忛攢鍟嗗彂璐х粨绠楀け璐�", $"DistributionSendOder ID={oder.id}  璇ヨ鍗曠殑鐢ㄦ埛ID鎴栬�呮槸deliveryID鎴栬�呮槸CoreCmsBillDelivery 涓殑 oderId");
+
+
+                }
+                await _unitOfWork.GetDbClient().Updateable(oder).ExecuteCommandAsync();
+
+                _unitOfWork.CommitTran();
+            }
+            catch (Exception  )
+            {
+                _unitOfWork.RollbackTran();
+                throw;
+            }
+           
+          
 
         }
 

--
Gitblit v1.9.1