| | |
| | | using CoreCms.Net.DTO; |
| | | using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinExpressDeliveryOpenMessageGetDeliveryListResponse.Types; |
| | | |
| | | using CoreCms.Net.Loging; |
| | | using CoreCms.Net.Model.Entities.baifenbingfa.DistributionSendOder; |
| | | using StackExchange.Redis; |
| | | using Microsoft.Extensions.Logging; |
| | | |
| | | namespace CoreCms.Net.Services.baifenbingfa |
| | | { |
| | | /// <summary> |
| | |
| | | private readonly IRedisOperationRepository _redisOperationRepository; |
| | | private readonly IHttpContextUser _user; |
| | | |
| | | |
| | | public readonly ICoreCmsDistributionServices _coreCmsDistributionServices; |
| | | private readonly ICoreCmsOrderServices _orderServices; |
| | | |
| | | public DistributorDeliveryServices( |
| | | IUnitOfWork unitOfWork, |
| | |
| | | , ICoreCmsSettingServices settingServices |
| | | , IRedisOperationRepository redisOperationRepository |
| | | , IHttpContextUser user |
| | | ,ICoreCmsDistributionServices coreCmsDistributionServices ) |
| | | ,ICoreCmsDistributionServices coreCmsDistributionServices |
| | | ,ICoreCmsOrderServices orderServices) |
| | | { |
| | | this._dal = dal; |
| | | base.BaseDal = dal; |
| | |
| | | _redisOperationRepository = redisOperationRepository; |
| | | _user = user; |
| | | _coreCmsDistributionServices = coreCmsDistributionServices; |
| | | _orderServices = orderServices; |
| | | } |
| | | |
| | | public async Task<(List< CoreCmsBillDelivery>,int )> GetDeliveryList(GetDeliveryListPost Param) |
| | |
| | | } |
| | | if (Param.distributionAcceptStatus != null) |
| | | { |
| | | where= where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | switch (Param.distributionAcceptStatus) |
| | | { |
| | | case sendDistributionAcceptType.Accepted: |
| | | ///进行中,售后空 |
| | | where = where.And(x => x.sendDistributionAccept == sendDistributionAcceptType.Accepted |
| | | && x.order.status == (int)GlobalEnumVars.OrderStatus.Normal && !x.order.aftersalesItem1.Any()&& x.order.confirmStatus != (int)GlobalEnumVars.OrderConfirmStatus.ConfirmReceipt); |
| | | //where = where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | break; |
| | | case sendDistributionAcceptType.NoAccted: |
| | | ///未确认接受的,不能售后空 |
| | | where = where.And(x => x.sendDistributionAccept == sendDistributionAcceptType.NoAccted |
| | | && x.order.status == (int)GlobalEnumVars.OrderStatus.Normal && !x.order.aftersalesItem1.Any()); |
| | | //where = where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | break; |
| | | |
| | | case sendDistributionAcceptType.OderFreeComplete: |
| | | |
| | | where = where.And(x => x.sendDistributionAccept == sendDistributionAcceptType.Accepted |
| | | && x.order.status == (int)GlobalEnumVars.OrderStatus.Complete && !x.order.aftersalesItem1.Any()); |
| | | //where = where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | break; |
| | | case sendDistributionAcceptType.Cancelled: |
| | | |
| | | where = where.And(x =>( x.sendDistributionAccept == sendDistributionAcceptType.Cancelled |
| | | || x.order.status == (int)GlobalEnumVars.OrderStatus.Cancel || x.order.aftersalesItem1.Any())); |
| | | //where = where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | break; |
| | | case sendDistributionAcceptType.Delivered: |
| | | where = where.And(x => x.sendDistributionAccept == sendDistributionAcceptType.Delivered |
| | | || x.order.confirmStatus == (int)GlobalEnumVars.OrderConfirmStatus.ConfirmReceipt ); |
| | | //where = where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //where= where.And(x => x.sendDistributionAccept == Param.distributionAcceptStatus); |
| | | } |
| | | where= where.And(x => x.sendDistributionUserID == _user.ID); |
| | | //必须是出于发货状态 |
| | |
| | | //必须是有效状态 |
| | | //where= where.And(x => x.order.status == (int)GlobalEnumVars.OrderStatus.Normal); |
| | | RefAsync<int> totl = 0; |
| | | var list = await _unitOfWork.GetDbClient().Queryable<CoreCmsBillDelivery>().Includes(x => x.order, order => order.Orderitems, ite => ite.productInfo).Select(x => new CoreCmsBillDelivery |
| | | { |
| | | sendDistributionAccept = x.sendDistributionAccept == sendDistributionAcceptType.NoAccted ? |
| | | //用户没有同意但是订单已经取消了 需要赋值 取消状态 |
| | | (x.order.status== (int)GlobalEnumVars.OrderStatus.Normal ? sendDistributionAcceptType.NoAccted: sendDistributionAcceptType.Cancelled ): |
| | | ( |
| | | x.sendDistributionAccept== sendDistributionAcceptType.Accepted? |
| | | //用户已经同意了 |
| | | (x.order.confirmStatus == (int)GlobalEnumVars.OrderConfirmStatus.ConfirmReceipt? sendDistributionAcceptType.Delivered: sendDistributionAcceptType.Accepted) |
| | | : x.order.status==(int )GlobalEnumVars.OrderStatus.Cancel? sendDistributionAcceptType.Cancelled: x.sendDistributionAccept |
| | | ), |
| | | order=x.order, |
| | | },true).MergeTable() |
| | | .Where(where).OrderByDescending(x => x.createTime) |
| | | var list = await _unitOfWork.GetDbClient().Queryable<CoreCmsBillDelivery>() |
| | | .Includes(x => x.order, order => order.Orderitems, ite => ite.productInfo) |
| | | .Includes(x => x.order, Order => Order.aftersalesItem1) |
| | | .Where(where) |
| | | .Select(x => new CoreCmsBillDelivery |
| | | { |
| | | |
| | | order = x.order, |
| | | }, true) |
| | | .MergeTable() |
| | | //.Mapper(x => x.order.billAftersalesId = SqlFunc.Subqueryable<CoreCmsBillAftersales>().Where(core => core.orderId == x.orderId).Select(core => core.aftersalesId)) |
| | | .Mapper( |
| | | x => |
| | | { |
| | | switch (x.sendDistributionAccept) |
| | | { |
| | | case sendDistributionAcceptType.Accepted: |
| | | |
| | | if (x.order.status == (int)GlobalEnumVars.OrderStatus.Cancel) |
| | | x.sendDistributionAccept = sendDistributionAcceptType.Cancelled; |
| | | else |
| | | if (x.order.status == (int)GlobalEnumVars.OrderStatus.Complete && !x.order.aftersalesItem1.Any()) |
| | | x.sendDistributionAccept = sendDistributionAcceptType.OderFreeComplete; |
| | | if (x.order.status == (int)GlobalEnumVars.OrderStatus.Complete && x.order.aftersalesItem1.Any()) |
| | | x.sendDistributionAccept = sendDistributionAcceptType.Cancelled; |
| | | |
| | | else if (x.order.status == (int)GlobalEnumVars.OrderStatus.Normal && x.order.aftersalesItem1.Any()) |
| | | x.sendDistributionAccept = sendDistributionAcceptType.Cancelled; |
| | | else |
| | | if (x.order.confirmStatus == (int)GlobalEnumVars.OrderConfirmStatus.ConfirmReceipt) |
| | | x.sendDistributionAccept = sendDistributionAcceptType.Delivered; |
| | | else |
| | | x.sendDistributionAccept = x.sendDistributionAccept; |
| | | break; |
| | | case sendDistributionAcceptType.NoAccted: |
| | | ///未确认接受的,不能售后空 |
| | | if(x.order.status== (int)GlobalEnumVars.OrderStatus.Complete||x.order.status== (int)GlobalEnumVars.OrderStatus.Cancel|| x.order.aftersalesItem1.Any()) |
| | | x.sendDistributionAccept= sendDistributionAcceptType.Cancelled; |
| | | else |
| | | x.sendDistributionAccept = x.sendDistributionAccept; |
| | | break; |
| | | |
| | | case sendDistributionAcceptType.OderFreeComplete: |
| | | |
| | | //永远不会到这 |
| | | break; |
| | | case sendDistributionAcceptType.Cancelled: |
| | | //不需要处理 |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | ) |
| | | |
| | | .OrderByDescending(x => x.createTime) |
| | | .ToPageListAsync(Param.page, Param.limit, totl); |
| | | var listdata= new PageList<CoreCmsBillDelivery>(list, Param.page, Param.limit, totl); |
| | | |
| | |
| | | |
| | | public async Task<int> GetNoAcceptedDeliveryCount() |
| | | { |
| | | return await _dal.GetCountAsync(x => x.sendDistributionUserID == _user.ID && x.sendDistributionAccept == sendDistributionAcceptType.NoAccted); |
| | | var lista= await _unitOfWork.GetDbClient().Queryable<CoreCmsBillDelivery>().Includes(x => x.order,ord=>ord.aftersalesItem1) |
| | | .Where(x => x.sendDistributionUserID == _user.ID && x.sendDistributionAccept == sendDistributionAcceptType.NoAccted |
| | | && x.order.status != (int)GlobalEnumVars.OrderStatus.Complete ).ToListAsync(); |
| | | |
| | | return lista.Where(x=>(x.order.aftersalesItem1==null|| x.order.aftersalesItem1.Count()==0)).Count();//删选出没有售后申请的订单 |
| | | |
| | | |
| | | } |
| | | |
| | | public async Task<bool> GetShowDelivery() |
| | | { |
| | | return (await _coreCmsDistributionServices.GetCountAsync(x => x.userId == _user.ID && x.verifyStatus == (int)GlobalEnumVars.DistributionVerifyStatus.VerifyYes&&x.profession=="校园代理", isDataCache: true, cacheTimes: 60)>0); |
| | | } |
| | | public async Task<WebApiCallBack> SetDeliveryAccepted(sendDistributionAcceptType acceptType, string DeliveryID, string CancelledDec = null) |
| | | public async Task<WebApiCallBack> SetDeliveryAccepted(sendDistributionAcceptType acceptType, string DeliveryID, string CancelledDec = null) |
| | | { |
| | | |
| | | WebApiCallBack ret = new WebApiCallBack(); |
| | | |
| | | if (acceptType == sendDistributionAcceptType.OderFreeComplete) |
| | | { |
| | | //只有在完成订单中设置该状态,该状态会对配售收益进行提取整合 |
| | | ret.status = false; |
| | | ret.msg = "状态设置错误"; |
| | | return ret; |
| | | } |
| | | var data = await _dal.QueryByIdAsync(DeliveryID); |
| | | if (data == null) |
| | | { |
| | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | public async Task<WebApiCallBack> FinishOrder(string orderId) |
| | | { |
| | | |
| | | |
| | | var jm = new WebApiCallBack(); |
| | | |
| | | var order = await _orderServices.QueryByClauseAsync(p => |
| | | p.orderId == orderId && p.status == (int)GlobalEnumVars.OrderStatus.Complete); |
| | | if (order == null) |
| | | { |
| | | jm.msg = "订单查询失败"; |
| | | return jm; |
| | | } |
| | | var distributionSendOder = await _unitOfWork.GetDbClient().Queryable<DistributionSendOder>().Includes(x=>x.delivery) |
| | | .Where(x=>x.delivery.orderId==order.orderId&&(x.sendDistributionAccept== sendDistributionAcceptType.Accepted|| x.sendDistributionAccept== sendDistributionAcceptType.Shipped||x.sendDistributionAccept== sendDistributionAcceptType.Delivered)) |
| | | .ToListAsync(); |
| | | if( distributionSendOder.Count==1) |
| | | { |
| | | //满足所有条件开始分配逻辑 |
| | | var mQ = new ActiveDistributionSendOderMQ |
| | | { |
| | | |
| | | SendOderActive = sendDistributionAcceptType.OderFreeComplete, |
| | | deliveryID = distributionSendOder[0].deliveryID, |
| | | userID = order.userId |
| | | }; |
| | | |
| | | await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.ActiveDistributionSendOderMQ, JsonConvert.SerializeObject(mQ)); |
| | | jm.status = true; |
| | | |
| | | } |
| | | else if( distributionSendOder.Count>1) |
| | | { |
| | | jm.status= false; |
| | | jm.msg = "发现多个配送订单,需要手动排查"; |
| | | NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Order, "处理经销商配送收益时错误", $"订单ID{orderId} 发现多个满足经销商派送单,放弃处理,需排查"); |
| | | |
| | | } |
| | | jm.status = true; |
| | | return jm; |
| | | |
| | | //if (order.shipStatus is (int)GlobalEnumVars.OrderShipStatus.No or (int)GlobalEnumVars.OrderShipStatus.PartialYes) |
| | | // { |
| | | // return jm; |
| | | // } |
| | | |
| | | } |
| | | } |
| | | } |