移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
CoreCms.Net.Services/Bill/CoreCmsBillDeliveryServices.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: 暂无
 ***********************************************************************/
@@ -12,22 +12,27 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration;
using CoreCms.Net.DTO;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.baifenbingfa.DistributionSendOder;
using CoreCms.Net.Model.ViewModels.Api;
using CoreCms.Net.Model.ViewModels.DTO;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Helper;
using Essensoft.Paylink.Alipay.Domain;
using Flurl.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinExpressDeliveryOpenMessageGetDeliveryListResponse.Types;
namespace CoreCms.Net.Services
@@ -45,7 +50,9 @@
        private readonly IUnitOfWork _unitOfWork;
        private readonly IServiceProvider _serviceProvider;
        private readonly IRedisOperationRepository _redisOperationRepository;
        private readonly ICoreCmsDistributionRepository _coreCmsDistributionRepository;
        private readonly IHttpContextUser _user;
        public CoreCmsBillDeliveryServices(
@@ -55,7 +62,10 @@
            , ICoreCmsStoreServices storeServices
            , ICoreCmsBillDeliveryItemServices billDeliveryItemServices
            , ICoreCmsOrderLogServices orderLogServices
            , ICoreCmsSettingServices settingServices, IRedisOperationRepository redisOperationRepository)
            , ICoreCmsSettingServices settingServices
            , IRedisOperationRepository redisOperationRepository,
                ICoreCmsDistributionRepository coreCmsDistributionRepository
            , IHttpContextUser user)
        {
            this._dal = dal;
            base.BaseDal = dal;
@@ -66,6 +76,9 @@
            _orderLogServices = orderLogServices;
            _settingServices = settingServices;
            _redisOperationRepository = redisOperationRepository;
            _coreCmsDistributionRepository = coreCmsDistributionRepository;
            _user = user;
        }
@@ -83,12 +96,17 @@
        /// <param name="shipAddress">收货地址</param>
        /// <param name="memo">发货描述</param>
        /// <param name="deliveryCompanyId">第三方对接物流编码</param>
        /// <param name="sendDistributionID">送货供应商ID</param>
        /// <returns></returns>
        public async Task<WebApiCallBack> BatchShip(string[] orderId, string logiCode, string logiNo, Dictionary<int, int> items, int storeId = 0, string shipName = "", string shipMobile = "", int shipAreaId = 0, string shipAddress = "", string memo = "", string deliveryCompanyId = "")
        public async Task<WebApiCallBack> BatchShip(string[] orderId, string logiCode, string logiNo, Dictionary<int, int> items, int storeId = 0, string shipName = "", string shipMobile = "", int shipAreaId = 0, string shipAddress = "", string memo = "", string deliveryCompanyId = "", int? sendDistributionID = null)
        {
            using var container = _serviceProvider.CreateScope();
            var jm = new WebApiCallBack();
            if(sendDistributionID > 0)
            {
                jm.msg = "经销商发货不支持批量发货";
                return jm;
            }
            var orderService = container.ServiceProvider.GetService<ICoreCmsOrderServices>();
            var stockServices = container.ServiceProvider.GetService<ICoreCmsStockServices>();
            //获取订单详情
@@ -180,7 +198,7 @@
            }
            if (tNum < 1)
            {
                jm.msg = "请至少发生一件商品!";
                jm.msg = "请至少发一件商品!";
                return jm;
            }
            //事务处理开始
@@ -231,12 +249,13 @@
        /// <param name="shipAddress">收货地址</param>
        /// <param name="memo">发货描述</param>
        /// <param name="deliveryCompanyId">第三方对接物流编码</param>
        /// <param name="sendDistributionID">经销商送货ID</param>
        /// <returns></returns>
        public async Task<WebApiCallBack> Ship(string orderId, string logiCode, string logiNo, Dictionary<int, int> items, int storeId = 0, string shipName = "", string shipMobile = "", int shipAreaId = 0, string shipAddress = "", string memo = "", string deliveryCompanyId = "")
        public async Task<WebApiCallBack> Ship(string orderId, string logiCode, string logiNo, Dictionary<int, int> items, int storeId = 0, string shipName = "", string shipMobile = "", int shipAreaId = 0, string shipAddress = "", string memo = "", string deliveryCompanyId = "",int? sendDistributionID=null)
        {
            using var container = _serviceProvider.CreateScope();
            var jm = new WebApiCallBack();
            var orderService = container.ServiceProvider.GetService<ICoreCmsOrderServices>();
            //获取订单详情
            var dInfoResult = await orderService.GetOrderShipInfo(orderId);
@@ -288,7 +307,33 @@
            billDelivery.memo = memo;
            billDelivery.createTime = DateTime.Now;
            billDelivery.thirdPartylogiCode = deliveryCompanyId;
            if(sendDistributionID>0)
            {
              var a=  _coreCmsDistributionRepository.QueryById(sendDistributionID);
                if(a==null)
                {
                    jm.msg = "经销商不存在";
                    return jm;
                }
                billDelivery.sendDistributionUserID= a.userId;
                billDelivery.sendDistributionID = sendDistributionID;
                billDelivery.sendDistributionAccept = sendDistributionAcceptType.NoAccted;
                var mQ = new DistributionSendOder
                {
                    sendDistributionAccept = sendDistributionAcceptType.NoAccted,
                    distributionID = (int)sendDistributionID,
                    sendMangerID = _user.ID,
                    deliveryID = billDelivery.deliveryId,
                     sendTime = DateTime.Now,
                      userID= a.userId
                };
                //记录操作记录
                await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.AddDistributionSendOderMQ, JsonConvert.SerializeObject(mQ));
            }
            //设置发货明细
            var bdRel = new List<CoreCmsBillDeliveryItem>();
@@ -335,7 +380,10 @@
            //插入发货单主体表
            await _dal.InsertAsync(billDelivery);
         await _dal.InsertAsync(billDelivery);
            //插入发货单明细表
            await _billDeliveryItemServices.InsertAsync(bdRel);