diff --git a/CoreCms.Net.Configuration/GlobalConstVars.cs b/CoreCms.Net.Configuration/GlobalConstVars.cs index 7fac4e9..a3a06e5 100644 --- a/CoreCms.Net.Configuration/GlobalConstVars.cs +++ b/CoreCms.Net.Configuration/GlobalConstVars.cs @@ -358,6 +358,10 @@ /// public const string OrderFinishCommand = "OrderFinishCommandQueue"; /// + /// 订单完成时,门店订单自动发货 + /// + public const string OrderAutomaticDelivery = "OrderAutomaticDeliveryQueue"; + /// /// 订单完结后走打印模块 /// public const string OrderPrint = "OrderPrintQueue"; diff --git a/CoreCms.Net.Configuration/SystemSettingConstVars.cs b/CoreCms.Net.Configuration/SystemSettingConstVars.cs index 3d8bf81..8a9a9ba 100644 --- a/CoreCms.Net.Configuration/SystemSettingConstVars.cs +++ b/CoreCms.Net.Configuration/SystemSettingConstVars.cs @@ -96,6 +96,10 @@ namespace CoreCms.Net.Configuration /// public const string RemindOrderTime = "remindOrderTime"; + /// + /// 门店订单自动发货 + /// + public const string StoreOrderAutomaticDelivery = "storeOrderAutomaticDelivery"; //分销功能(老分销)============================================================= /// diff --git a/CoreCms.Net.Configuration/SystemSettingDictionary.cs b/CoreCms.Net.Configuration/SystemSettingDictionary.cs index 479bd50..81a21de 100644 --- a/CoreCms.Net.Configuration/SystemSettingDictionary.cs +++ b/CoreCms.Net.Configuration/SystemSettingDictionary.cs @@ -73,6 +73,11 @@ namespace CoreCms.Net.Configuration di.Add(SystemSettingConstVars.ReshipAddress, new DictionaryKeyValues() { sKey = "退货详细地址", sValue = "" }); di.Add(SystemSettingConstVars.ReshipCoordinate, new DictionaryKeyValues() { sKey = "退货坐标", sValue = "" }); + + di.Add(SystemSettingConstVars.StoreOrderAutomaticDelivery, new DictionaryKeyValues() { sKey = "门店自提自动发货", sValue = "2" }); + + + //分销功能 di.Add(SystemSettingConstVars.OpenDistribution, new DictionaryKeyValues() { sKey = "是否开启三级分销", sValue = "1" }); @@ -226,5 +231,24 @@ namespace CoreCms.Net.Configuration }; return list; } + + + + /// + /// 获取系统默认发货物流方式 + /// + /// + public static List GetSystemLogistics() + { + var list = new List + { + new CommonKeyValues() {sDescription = "本地同城配送", sValue = "无", sKey = "benditongcheng"}, + new CommonKeyValues() {sDescription = "本地上门自提", sValue = "无", sKey = "shangmenziti"}, + }; + return list; + } + + + } } diff --git a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs index 1aee3f1..d9a26bf 100644 --- a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs +++ b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs @@ -29,6 +29,7 @@ namespace CoreCms.Net.Core.Config //对应的订阅者类,需要new一个实例对象,当然你也可以传参,比如日志对象 m.ListSubscribe = new List() { typeof(OrderAgentOrDistributionSubscribe), + typeof(OrderAutomaticDeliverySubscribe), typeof(OrderFinishCommandSubscribe), typeof(OrderPrintSubscribe), diff --git a/CoreCms.Net.IServices/Bill/ICoreCmsBillDeliveryServices.cs b/CoreCms.Net.IServices/Bill/ICoreCmsBillDeliveryServices.cs index 2b0d57c..14502ac 100644 --- a/CoreCms.Net.IServices/Bill/ICoreCmsBillDeliveryServices.cs +++ b/CoreCms.Net.IServices/Bill/ICoreCmsBillDeliveryServices.cs @@ -47,6 +47,27 @@ namespace CoreCms.Net.IServices string memo = ""); + /// + /// 发货,单个订单发货 + /// + /// 英文逗号分隔的订单号 + /// 物流公司编码 + /// 物流单号 + /// 发货明细 + /// 店铺收货地址 + /// 收货人姓名 + /// 收货人电话 + /// 省市区id + /// 收货地址 + /// 发货描述 + /// + Task Ship(string orderId, string logiCode, string logiNo, Dictionary items, + int storeId = 0, string shipName = "", string shipMobile = "", int shipAreaId = 0, string shipAddress = "", + string memo = ""); + + + + /// /// 物流信息查询根据快递编码和单号查询(快递100)未使用 /// diff --git a/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs b/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs index c1e72db..779a13e 100644 --- a/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs +++ b/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs @@ -148,6 +148,11 @@ namespace CoreCms.Net.IServices /// Task GetOrderShipInfo(string[] ids); + /// + /// 构建单个需要发货的数据,和发货单密切关联 + /// + /// + Task GetOrderShipInfo(string orderId); /// /// 发货改状态 @@ -158,6 +163,24 @@ namespace CoreCms.Net.IServices Task EditShipStatus(string orderId, Dictionary items); + /// + /// 批量订单发货 + /// + /// 订单标号 + /// 物流公司编码 + /// 物流单号 + /// 发货明细 + /// 收货人姓名 + /// 收货人电话 + /// 收货地址 + /// 发货描述 + /// 店铺收货地址 + /// 省市区id + /// + Task BatchShip(string[] ids, string logiCode, string logiNo, + Dictionary items, string shipName, string shipMobile, string shipAddress, string memo, + int storeId = 0, int shipAreaId = 0); + /// /// 订单发货 /// @@ -172,10 +195,12 @@ namespace CoreCms.Net.IServices /// 店铺收货地址 /// 省市区id /// - Task OrderShip(string[] ids, string logiCode, string logiNo, + Task Ship(string ids, string logiCode, string logiNo, Dictionary items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0); + + /// /// 后台完成订单 /// diff --git a/CoreCms.Net.Model/ViewModels/View/OrderDTO.cs b/CoreCms.Net.Model/ViewModels/View/OrderDTO.cs index ed1a341..ba26ef9 100644 --- a/CoreCms.Net.Model/ViewModels/View/OrderDTO.cs +++ b/CoreCms.Net.Model/ViewModels/View/OrderDTO.cs @@ -318,7 +318,7 @@ namespace CoreCms.Net.Model.ViewModels.View /// - /// 后端订单发货返回实体 + /// 后端订单发货返回集合实体 /// public class AdminOrderShipResult { @@ -338,6 +338,28 @@ namespace CoreCms.Net.Model.ViewModels.View public List orders { get; set; } } + /// + /// 后端订单发货返回单个实体 + /// + public class AdminOrderShipOneResult + { + public string orderId { get; set; } + public decimal weight { get; set; } = 0; + public string memo { get; set; } + public decimal costFreight { get; set; } = 0; + public int storeId { get; set; } = 0; + public int shipAreaId { get; set; } = 0; + public string shipAddress { get; set; } + public string shipName { get; set; } + public string shipMobile { get; set; } + public int logisticsId { get; set; } = 0; + public CoreCmsShip ship { get; set; } = null; + public string logisticsName { get; set; } + public List items { get; set; } + public CoreCmsOrder orderInfo { get; set; } + } + + /// /// 前端提交售后单提交参数 /// diff --git a/CoreCms.Net.RedisMQ/Subscribe/OrderAutomaticDeliverySubscribe.cs b/CoreCms.Net.RedisMQ/Subscribe/OrderAutomaticDeliverySubscribe.cs new file mode 100644 index 0000000..321fa84 --- /dev/null +++ b/CoreCms.Net.RedisMQ/Subscribe/OrderAutomaticDeliverySubscribe.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using CoreCms.Net.Configuration; +using CoreCms.Net.IServices; +using CoreCms.Net.Loging; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.ViewModels.UI; +using CoreCms.Net.Utility.Extensions; +using CoreCms.Net.Utility.Helper; +using Essensoft.Paylink.WeChatPay.V2; +using Essensoft.Paylink.WeChatPay.V2.Notify; +using InitQ.Abstractions; +using InitQ.Attributes; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace CoreCms.Net.RedisMQ.Subscribe +{ + /// + /// 门店订单自动发货 + /// + public class OrderAutomaticDeliverySubscribe : IRedisSubscribe + { + + private readonly ICoreCmsOrderServices _orderServices; + private readonly ICoreCmsOrderItemServices _orderItemServices; + private readonly ICoreCmsSettingServices _settingServices; + + + public OrderAutomaticDeliverySubscribe(ICoreCmsSettingServices settingServices, ICoreCmsAgentOrderServices agentOrderServices, ICoreCmsOrderServices orderServices, ICoreCmsOrderItemServices orderItemServices) + { + _settingServices = settingServices; + _orderServices = orderServices; + _orderItemServices = orderItemServices; + } + + /// + /// 订单完成时,门店订单自动发货 + /// + /// + /// + [Subscribe(RedisMessageQueueKey.OrderAutomaticDelivery)] + + private async Task OrderAutomaticDelivery(string msg) + { + try + { + var order = JsonConvert.DeserializeObject(msg); + if (order != null) + { + var goodItems = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); + if (!goodItems.Any()) + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单自动发货", "明细获取失败"); + return; + } + + Dictionary items = new Dictionary(); + + goodItems.ForEach(p => + { + items.Add(p.productId, p.nums); + }); + + var result = new WebApiCallBack(); + + if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery) + { + result = await _orderServices.Ship(order.orderId, "shangmenziti", "无", items, order.shipName, order.shipMobile, order.shipAddress, order.memo, order.storeId, order.shipAreaId); + } + else if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.IntraCityService) + { + result = await _orderServices.Ship(order.orderId, "benditongcheng", "无", items, order.shipName, order.shipMobile, order.shipAddress, order.memo, order.storeId, order.shipAreaId); + } + + NLogUtil.WriteAll(result.status ? NLog.LogLevel.Info : NLog.LogLevel.Error, + LogType.RedisMessageQueue, "订单自动发货", JsonConvert.SerializeObject(result)); + } + else + { + NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "订单自动发货", "订单获取失败"); + } + + } + catch (Exception ex) + { + NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "订单自动发货", msg, ex); + throw; + } + await Task.CompletedTask; + } + + + + + } +} diff --git a/CoreCms.Net.Services/Bill/CoreCmsBillDeliveryServices.cs b/CoreCms.Net.Services/Bill/CoreCmsBillDeliveryServices.cs index b6dbfcb..bbf7a13 100644 --- a/CoreCms.Net.Services/Bill/CoreCmsBillDeliveryServices.cs +++ b/CoreCms.Net.Services/Bill/CoreCmsBillDeliveryServices.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using CoreCms.Net.Caching.AutoMate.RedisCache; using CoreCms.Net.Configuration; using CoreCms.Net.IRepository; using CoreCms.Net.IRepository.UnitOfWork; @@ -23,6 +24,7 @@ using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.View; using CoreCms.Net.Utility.Helper; using Flurl.Http; +using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; @@ -39,20 +41,22 @@ namespace CoreCms.Net.Services private readonly ICoreCmsBillDeliveryRepository _dal; private readonly ICoreCmsStoreServices _storeServices; private readonly ICoreCmsBillDeliveryItemServices _billDeliveryItemServices; - private readonly ICoreCmsBillDeliveryOrderRelServices _billDeliveryOrderRelServices; private readonly ICoreCmsOrderLogServices _orderLogServices; private readonly ICoreCmsSettingServices _settingServices; private readonly IUnitOfWork _unitOfWork; private readonly IServiceProvider _serviceProvider; + private readonly IRedisOperationRepository _redisOperationRepository; + + + public CoreCmsBillDeliveryServices( IUnitOfWork unitOfWork, IServiceProvider serviceProvider , ICoreCmsBillDeliveryRepository dal , ICoreCmsStoreServices storeServices , ICoreCmsBillDeliveryItemServices billDeliveryItemServices - , ICoreCmsBillDeliveryOrderRelServices billDeliveryOrderRelServices , ICoreCmsOrderLogServices orderLogServices - , ICoreCmsSettingServices settingServices) + , ICoreCmsSettingServices settingServices, IRedisOperationRepository redisOperationRepository) { this._dal = dal; base.BaseDal = dal; @@ -60,9 +64,9 @@ namespace CoreCms.Net.Services _serviceProvider = serviceProvider; _storeServices = storeServices; _billDeliveryItemServices = billDeliveryItemServices; - _billDeliveryOrderRelServices = billDeliveryOrderRelServices; _orderLogServices = orderLogServices; _settingServices = settingServices; + _redisOperationRepository = redisOperationRepository; } @@ -77,8 +81,6 @@ namespace CoreCms.Net.Services return await _dal.GetDeliveryList(orderId); } - - /// /// 批量发货,可以支持多个订单合并发货,单个订单拆分发货等。 /// @@ -150,6 +152,7 @@ namespace CoreCms.Net.Services billDelivery.memo = memo; billDelivery.createTime = DateTime.Now; + //设置发货明细 var bdRel = new List(); @@ -174,6 +177,21 @@ namespace CoreCms.Net.Services } //构建发货单明细 + //dInfo.items.ForEach(p => + //{ + // var bdItem = new CoreCmsBillDeliveryItem(); + // bdItem.deliveryId = billDelivery.deliveryId; + // bdItem.orderId = p.orderId; + // bdItem.productId = p.productId; + // bdItem.goodsId = p.goodsId; + // bdItem.bn = p.bn; + // bdItem.sn = p.sn; + // bdItem.weight = p.weight; + // bdItem.name = p.name; + // bdItem.addon = !string.IsNullOrEmpty(p.addon) ? p.addon : ""; + // bdItem.nums = orderItem.nums; + // bdRel.Add(bdItem); + //}); var bdItem = new CoreCmsBillDeliveryItem(); bdItem.deliveryId = billDelivery.deliveryId; bdItem.productId = orderItem.productId; @@ -195,26 +213,15 @@ namespace CoreCms.Net.Services //插入发货单主体表 - await base.InsertAsync(billDelivery); + await _dal.InsertAsync(billDelivery); //插入发货单明细表 await _billDeliveryItemServices.InsertAsync(bdRel); //订单更新发货状态,发送各种消息 - var rels = new List(); //关系表 foreach (var order in orders) { - await orderShip(order, items, billDelivery, storeId); - var rel = new CoreCmsBillDeliveryOrderRel - { - deliveryId = billDelivery.deliveryId, - orderId = order.orderId - }; - rels.Add(rel); - } - if (rels.Any()) - { - await _billDeliveryOrderRelServices.InsertAsync(rels); + await OrderShip(order, items, billDelivery, storeId); } var stock = new CoreCmsStock @@ -236,6 +243,154 @@ namespace CoreCms.Net.Services } + /// + /// 发货,单个订单发货 + /// + /// 英文逗号分隔的订单号 + /// 物流公司编码 + /// 物流单号 + /// 发货明细 + /// 店铺收货地址 + /// 收货人姓名 + /// 收货人电话 + /// 省市区id + /// 收货地址 + /// 发货描述 + /// + public async Task Ship(string orderId, string logiCode, string logiNo, Dictionary items, int storeId = 0, string shipName = "", string shipMobile = "", int shipAreaId = 0, string shipAddress = "", string memo = "") + { + using var container = _serviceProvider.CreateScope(); + var jm = new WebApiCallBack(); + + var orderService = container.ServiceProvider.GetService(); + var stockServices = container.ServiceProvider.GetService(); + + //获取订单详情 + var dInfoResult = await orderService.GetOrderShipInfo(orderId); + if (!dInfoResult.status) + { + return dInfoResult; + } + var dInfo = dInfoResult.data as AdminOrderShipOneResult; + var orderInfo = dInfo.orderInfo; + + //校验门店自提和普通订单收货地址是否填写 + if (storeId != 0) + { + var storeModel = await _storeServices.QueryByIdAsync(storeId); + if (storeModel == null) + { + jm.msg = GlobalErrorCodeVars.Code10000; + jm.data = 1000; + jm.code = 1000; + return jm; + } + shipName = storeModel.storeName; + shipMobile = storeModel.mobile; + shipAreaId = storeModel.areaId; + shipAddress = storeModel.address; + } + if (string.IsNullOrEmpty(shipName) || string.IsNullOrEmpty(shipMobile) || string.IsNullOrEmpty(shipAddress) || shipAreaId == 0) + { + jm.msg = "收货地址信息不全"; + jm.otherData = new + { + shipName, + shipMobile, + shipAddress, + shipAreaId + }; + return jm; + } + var billDelivery = new CoreCmsBillDelivery(); + billDelivery.orderId = string.Join(",", orderId); + billDelivery.deliveryId = CommonHelper.GetSerialNumberType((int)GlobalEnumVars.SerialNumberType.发货单编号); + billDelivery.logiCode = logiCode; + billDelivery.logiNo = logiNo; + billDelivery.shipAreaId = shipAreaId; + billDelivery.shipAddress = shipAddress; + billDelivery.shipName = shipName; + billDelivery.shipMobile = shipMobile; + billDelivery.status = (int)GlobalEnumVars.BillDeliveryStatus.Already; + billDelivery.memo = memo; + billDelivery.createTime = DateTime.Now; + + + //设置发货明细 + var bdRel = new List(); + + //校验发货内容 + var tNum = 0; + foreach (var item in items) + { + var orderItem = dInfo.items.Find(p => p.productId == item.Key); + if (orderItem == null) + { + //发货的商品不在发货明细里,肯定有问题 + jm.msg = GlobalErrorCodeVars.Code10000; + return jm; + } + //判断总发货数量 + tNum = tNum + item.Value; + + if ((orderItem.nums - orderItem.sendNums - (orderItem.reshipNums - orderItem.reshipedNums)) < item.Value) + { + jm.msg = orderItem.name + "发超了"; + return jm; + } + + //构建发货单明细 + dInfo.items.ForEach(p => + { + var bdItem = new CoreCmsBillDeliveryItem(); + bdItem.deliveryId = billDelivery.deliveryId; + bdItem.productId = p.productId; + bdItem.goodsId = p.goodsId; + bdItem.bn = p.bn; + bdItem.sn = p.sn; + bdItem.weight = p.weight; + bdItem.name = p.name; + bdItem.addon = !string.IsNullOrEmpty(p.addon) ? p.addon : ""; + bdItem.nums = orderItem.nums; + bdRel.Add(bdItem); + }); + } + if (tNum < 1) + { + jm.msg = "请至少发生一件商品!"; + return jm; + } + //事务处理开始 + + + //插入发货单主体表 + await _dal.InsertAsync(billDelivery); + + //插入发货单明细表 + await _billDeliveryItemServices.InsertAsync(bdRel); + + //订单更新发货状态,发送各种消息 + await OrderShip(orderInfo, items, billDelivery, storeId); + + var stock = new CoreCmsStock + { + manager = 0, + id = billDelivery.deliveryId, + createTime = DateTime.Now, + type = (int)GlobalEnumVars.StockType.DeliverGoods, + memo = "订单发货操作,发货单号:" + billDelivery.deliveryId + }; + + await stockServices.InsertAsync(stock); + + jm.status = true; + jm.msg = "发货成功"; + + return jm; + } + + + /// /// 给订单发货 /// @@ -243,7 +398,7 @@ namespace CoreCms.Net.Services /// 总的发货包裹内容 /// 发货单信息 /// 门店自提还是普通订单,0是普通订单,其他是门店自提 - private async Task orderShip(CoreCmsOrder orderInfo, Dictionary items, CoreCmsBillDelivery deliveryInfo, int storeId = 0) + private async Task OrderShip(CoreCmsOrder orderInfo, Dictionary items, CoreCmsBillDelivery deliveryInfo, int storeId = 0) { using var container = _serviceProvider.CreateScope(); var orderService = container.ServiceProvider.GetService(); @@ -323,6 +478,15 @@ namespace CoreCms.Net.Services if (stockLogs.Any()) { + //var stock = new CoreCmsStock + //{ + // manager = 0, + // id = deliveryInfo.deliveryId, + // createTime = DateTime.Now, + // type = (int)GlobalEnumVars.StockType.DeliverGoods, + // memo = log.msg + //}; + //await stockServices.InsertAsync(stock); await stockLogServices.InsertAsync(stockLogs); } @@ -375,9 +539,8 @@ namespace CoreCms.Net.Services param = jsonParamData, sign = signStr }; - var result = await postUrl.WithHeader("Content-Type ", "application/x-www-form-urlencoded") - .PostJsonAsync(postData) - .ReceiveJson(); + + var result = await postUrl.PostUrlEncodedAsync(postData).ReceiveJson(); if (result.status == "200") { jm.status = true; diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs index 81806c6..9397b6b 100644 --- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs +++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs @@ -821,7 +821,7 @@ namespace CoreCms.Net.Services } } //把退款金额和退货商品查出来 - AftersalesVal(order, aftersaleLevel); + AfterSalesVal(order, aftersaleLevel); //促销信息 if (!string.IsNullOrEmpty(order.promotionList)) { @@ -859,7 +859,7 @@ namespace CoreCms.Net.Services /// /// /// 取售后单的时候,售后单的等级,0:待审核的和审核通过的售后单,1未审核的,2审核通过的 - private void AftersalesVal(CoreCmsOrder order, int aftersaleLevel) + public void AfterSalesVal(CoreCmsOrder order, int aftersaleLevel) { var addAftersalesStatus = false; var res = _billAftersalesServices.OrderToAftersales(order.orderId, aftersaleLevel); @@ -1300,6 +1300,20 @@ namespace CoreCms.Net.Services await _invoiceServices.InsertAsync(taxInfo); } + //如果是门店自提,应该自动跳过发货,生成提货单信息,使用提货单核销。 + 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.OrderAgentOrDistribution, JsonConvert.SerializeObject(order)); //易联云打印机打印 @@ -1453,9 +1467,9 @@ namespace CoreCms.Net.Services } #endregion - #region 构建需要发货的数据,和发货单密切关联 + #region 构建多个需要发货的数据,和发货单密切关联 /// - /// 构建需要发货的数据,和发货单密切关联 + /// 构建多个需要发货的数据,和发货单密切关联 /// /// public async Task GetOrderShipInfo(string[] ids) @@ -1517,7 +1531,7 @@ namespace CoreCms.Net.Services jm.msg = "订单号:" + item.orderId + "有未审核的售后单,请先处理掉才能发货。"; return jm; } - AftersalesVal(item, 0); + AfterSalesVal(item, 0); } if (!jm.status) @@ -1624,6 +1638,108 @@ namespace CoreCms.Net.Services } #endregion + #region 构建单个需要发货的数据,和发货单密切关联 + /// + /// 构建单个需要发货的数据,和发货单密切关联 + /// + /// + public async Task GetOrderShipInfo(string orderId) + { + var jm = new WebApiCallBack { status = true }; + + var orderInfo = await _dal.QueryByClauseAsync(p => p.orderId == orderId); + if (orderInfo == null) + { + jm.msg = "请选择订单"; + return jm; + } + orderInfo.items = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == orderId); + var isStoreId = 0;//校验是普通快递收货,还是门店自提,这两种收货方式不能混着发 + //更改状态和库存 + + if (orderInfo.status != (int)GlobalEnumVars.OrderStatus.Normal) + { + jm.status = false; + jm.msg = "订单号:" + orderInfo.orderId + "非正常状态不能发货。
"; + } + else if (orderInfo.payStatus == (int)GlobalEnumVars.OrderPayStatus.No) + { + jm.status = false; + jm.msg = "订单号:" + orderInfo.orderId + "未支付不能发货。
"; + } + else if (orderInfo.shipStatus != (int)GlobalEnumVars.OrderShipStatus.No && orderInfo.shipStatus != (int)GlobalEnumVars.OrderShipStatus.PartialYes) + { + jm.status = false; + jm.msg = "订单号:" + orderInfo.orderId + "不是待发货和部分发货状态不能发货。
"; + } + //校验,不能普通快递和门店自提,不能混发 + isStoreId = orderInfo.storeId; + + //判断是否有未审核的售后单,如果有,就不能发货,已做拦截 + var isHaveBillAfterSales = await _billAftersalesServices.ExistsAsync(p => + p.orderId == orderInfo.orderId && + p.status == (int)GlobalEnumVars.BillAftersalesStatus.WaitAudit); + if (isHaveBillAfterSales) + { + jm.status = false; + jm.msg = "订单号:" + orderInfo.orderId + "有未审核的售后单,请先处理掉才能发货。"; + return jm; + } + AfterSalesVal(orderInfo, 0); + + + if (!jm.status) + { + return jm; + } + + var newOrder = new AdminOrderShipOneResult() + { + orderId = orderId, + weight = orderInfo.weight, + costFreight = orderInfo.costFreight, + storeId = orderInfo.storeId, + shipAreaId = orderInfo.shipAreaId, + shipAddress = orderInfo.shipAddress, + shipName = orderInfo.shipName, + shipMobile = orderInfo.shipMobile, + logisticsId = orderInfo.logisticsId, + logisticsName = orderInfo.logisticsName, + items = new List(), + orderInfo = orderInfo, + memo = orderInfo.memo + }; + + if (newOrder.logisticsId > 0) + { + newOrder.ship = await _shipServices.QueryByClauseAsync(p => p.id == newOrder.logisticsId); + } + + //组合总运费 + foreach (var orderItem in orderInfo.items) + { + var model = newOrder.items.FirstOrDefault(p => p.productId == orderItem.productId); + if (model == null) + { + newOrder.items.Add(orderItem); + } + else + { + var index = newOrder.items.IndexOf(model); + newOrder.items[index].nums += orderItem.nums;//总数量 + newOrder.items[index].weight += orderItem.weight;//总重量 + newOrder.items[index].sendNums += orderItem.sendNums;//已发送数量 + newOrder.items[index].reshipNums += orderItem.reshipNums;//退货数量 + } + } + + jm.status = true; + jm.data = newOrder; + + return jm; + } + #endregion + #region 发货改状态 /// /// 发货改状态 @@ -1663,10 +1779,10 @@ namespace CoreCms.Net.Services } #endregion - #region 订单发货 + #region 订单批量发货 /// - /// 订单发货 + /// 订单批量发货 /// /// 订单标号 /// 物流公司编码 @@ -1679,7 +1795,7 @@ namespace CoreCms.Net.Services /// 店铺收货地址 /// 省市区id /// - public async Task OrderShip(string[] ids, string logiCode, string logiNo, + public async Task BatchShip(string[] ids, string logiCode, string logiNo, Dictionary items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0) { @@ -1689,6 +1805,34 @@ namespace CoreCms.Net.Services } #endregion + #region 订单单个发货 + + /// + /// 订单单个发货 + /// + /// 订单编号 + /// 物流公司编码 + /// 物流单号 + /// 发货明细 + /// 收货人姓名 + /// 收货人电话 + /// 收货地址 + /// 发货描述 + /// 店铺收货地址 + /// 省市区id + /// 直播物流编码 + /// + public async Task Ship(string orderId, string logiCode, string logiNo, + Dictionary items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0) + { + var result = await _billDeliveryServices.Ship(orderId, logiCode, logiNo, items, storeId, shipName, shipMobile, shipAreaId, shipAddress, memo); + return result; + + } + #endregion + + + #region 完成订单 /// /// 完成订单 diff --git a/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs b/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs index fd87697..8c41286 100644 --- a/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs +++ b/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs @@ -94,16 +94,21 @@ namespace CoreCms.Net.Services var list = new List(); - var logistics = new CoreCmsLogistics(); - logistics.logiCode = "benditongcheng"; - logistics.logiName = "本地同城配送"; - logistics.imgUrl = ""; - logistics.phone = shopMobile; - logistics.url = ""; - logistics.sort = -1; - logistics.isDelete = false; + var systemLogistics = SystemSettingDictionary.GetSystemLogistics(); + systemLogistics.ForEach(p => + { + var logistics = new CoreCmsLogistics(); + logistics.logiCode = p.sKey; + logistics.logiName = p.sDescription; + logistics.imgUrl = ""; + logistics.phone = shopMobile; + logistics.url = ""; + logistics.sort = -1; + logistics.isDelete = false; + + list.Add(logistics); + }); - list.Add(logistics); var count = 0; person.showapi_res_body.expressList.ForEach(p => diff --git a/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs b/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs index eb6355c..457ca1f 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs @@ -1312,11 +1312,14 @@ namespace CoreCms.Net.Web.Admin.Controllers return Json(jm); } - if (entity.code == "benditongcheng") + var systemLogistics = SystemSettingDictionary.GetSystemLogistics(); + foreach (var p in systemLogistics) { - jm.code = 1; - jm.msg = "本地同城配送不支持轨迹查询"; - return Json(jm); + if (entity.code == p.sKey) + { + jm.msg = p.sDescription + "不支持轨迹查询"; + return Json(jm); + } } jm = await _logisticsServices.ExpressPoll(entity.code, entity.no, entity.mobile); diff --git a/CoreCms.Net.Web.Admin/Controllers/Order/CoreCmsOrderController.cs b/CoreCms.Net.Web.Admin/Controllers/Order/CoreCmsOrderController.cs index 78c3183..dad4c9b 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Order/CoreCmsOrderController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Order/CoreCmsOrderController.cs @@ -499,9 +499,16 @@ namespace CoreCms.Net.Web.Admin.Controllers { var jm = new AdminUiCallBack(); - var ids = entity.orderId.Split(","); - - var result = await _coreCmsOrderServices.OrderShip(ids, entity.logiCode, entity.logiNo, entity.items, entity.shipName, entity.shipMobile, entity.shipAddress, entity.memo, entity.storeId, entity.shipAreaId); + WebApiCallBack result; + if (entity.orderId.Contains(",")) + { + var ids = entity.orderId.Split(","); + result = await _coreCmsOrderServices.BatchShip(ids, entity.logiCode, entity.logiNo, entity.items, entity.shipName, entity.shipMobile, entity.shipAddress, entity.memo, entity.storeId, entity.shipAreaId); + } + else + { + result = await _coreCmsOrderServices.Ship(entity.orderId, entity.logiCode, entity.logiNo, entity.items, entity.shipName, entity.shipMobile, entity.shipAddress, entity.memo, entity.storeId, entity.shipAreaId); + } jm.code = result.status ? 0 : 1; jm.msg = result.msg; diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/details - 复制.html b/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/details - 复制.html new file mode 100644 index 0000000..e9168f9 --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/details - 复制.html @@ -0,0 +1,324 @@ + + \ No newline at end of file diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/details.html b/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/details.html new file mode 100644 index 0000000..9282a61 --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/details.html @@ -0,0 +1,361 @@ + + \ No newline at end of file diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/index.html index 8f82680..65464e9 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/good/goods/index.html @@ -273,12 +273,16 @@ }); }); //监听行双击事件 - //table.on('rowDouble(LAY-app-CoreCmsGoods-tableBox)', function (obj) { - //}); + table.on('rowDouble(LAY-app-CoreCmsGoods-tableBox)', function (obj) { + //查看详情 + doDetails(obj); + }); //监听工具条 table.on('tool(LAY-app-CoreCmsGoods-tableBox)', function (obj) { - if (obj.event === 'del') { + if (obj.event === 'detail') { + doDetails(obj); + } else if (obj.event === 'del') { doDelete(obj); } else if (obj.event === 'edit') { doEdit(obj) @@ -547,6 +551,31 @@ function doEdit(obj) { location.hash = '/good/goods/edit/id=' + obj.data.id; } + + //执行预览操作 + function doDetails(obj) { + coreHelper.Post("Api/CoreCmsGoods/GetDetails", { id: obj.data.id }, function (e) { + if (e.code === 0) { + admin.popup({ + shadeClose: false, + title: '查看详情', + area: ['1200px', '90%'], + id: 'LAY-popup-CoreCmsGoods-details', + success: function (layero, index) { + view(this.id).render('good/goods/details', { data: e.data }).done(function () { + form.render(); + }); + // 禁止弹窗出现滚动条 + $(layero).children('.layui-layer-content').css('overflow', 'visible'); + } + }); + } else { + layer.msg(e.msg); + } + }); + } + + //执行单个删除 function doDelete(obj) { coreHelper.Post("Api/CoreCmsGoods/DoDelete", { id: obj.data.id }, function (e) { diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html index aebf040..75e1f39 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html @@ -356,6 +356,18 @@
退货的详细地址
+ +
+ 发货相关 +
+
+ +
+ + +
+
+
diff --git a/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs b/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs index b497a48..70feb91 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs @@ -508,10 +508,14 @@ namespace CoreCms.Net.Web.WebApi.Controllers return Json(jm); } - if (entity.code == "benditongcheng") + var systemLogistics = SystemSettingDictionary.GetSystemLogistics(); + foreach (var p in systemLogistics) { - jm.msg = "本地同城配送不支持轨迹查询"; - return Json(jm); + if (entity.code == p.sKey) + { + jm.msg = p.sDescription + "不支持轨迹查询"; + return Json(jm); + } } jm = await _logisticsServices.ExpressPoll(entity.code, entity.no, entity.mobile);