| | |
| | | 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; |
| | |
| | | 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> |
| | |
| | | } |
| | | 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(); |
| | | |
| | | } |
| | |
| | | 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(oder).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; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |