mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 05:19:49 +08:00
2022-01-11
## 1.2.9 开源社区版: 【修复】修复全局定义微信配置引用的配置文件命名错误问题。 【修复】修复自动生成sku模式价格出现货号重复情况,#I4Q4WU ## 0.0.6 会员先行版: 【新增】新增微信自定义交易组件,实现微信视频号直播带货功能。
This commit is contained in:
158
CoreCms.Net.RedisMQ/Subscribe/TCOrderShipSyncSubscribe.cs
Normal file
158
CoreCms.Net.RedisMQ/Subscribe/TCOrderShipSyncSubscribe.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/7/10 22:41:46
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.AccressToken;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
||||
using InitQ.Abstractions;
|
||||
using InitQ.Attributes;
|
||||
using Newtonsoft.Json;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
||||
|
||||
namespace CoreCms.Net.RedisMQ.Subscribe
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义交易组件-同步发货信息
|
||||
/// </summary>
|
||||
public class TCOrderShipSyncSubscribe : IRedisSubscribe
|
||||
{
|
||||
private readonly string _wxOpenAppId = AppSettingsConstVars.WxOpenAppId;
|
||||
private readonly string _wxOpenAppSecret = AppSettingsConstVars.WxOpenAppSecret;
|
||||
|
||||
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
|
||||
private readonly ICoreCmsBillDeliveryServices _billDeliveryServices;
|
||||
private readonly ICoreCmsOrderServices _orderServices;
|
||||
private readonly ICoreCmsOrderItemServices _orderItemServices;
|
||||
private readonly ICoreCmsUserWeChatInfoServices _weChatInfoServices;
|
||||
private readonly IWeChatTransactionComponentOrderServices _tcOrderServices;
|
||||
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
|
||||
|
||||
|
||||
public TCOrderShipSyncSubscribe(ICoreCmsUserWeChatInfoServices userWeChatInfoServices, ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsOrderServices orderServices, ICoreCmsUserWeChatInfoServices weChatInfoServices, IWeChatTransactionComponentOrderServices tcOrderServices, ICoreCmsOrderItemServices orderItemServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
|
||||
{
|
||||
_userWeChatInfoServices = userWeChatInfoServices;
|
||||
_billDeliveryServices = billDeliveryServices;
|
||||
_orderServices = orderServices;
|
||||
_weChatInfoServices = weChatInfoServices;
|
||||
_tcOrderServices = tcOrderServices;
|
||||
_orderItemServices = orderItemServices;
|
||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义交易组件-同步发货信息
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
[Subscribe(RedisMessageQueueKey.TransactionComponentOrderShipSync)]
|
||||
private async Task TransactionComponentOrderShipSync(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
var deliveryId = msg;
|
||||
if (!string.IsNullOrEmpty(deliveryId))
|
||||
{
|
||||
var billDelivery = await _billDeliveryServices.QueryByClauseAsync(p => p.deliveryId == deliveryId, true);
|
||||
if (billDelivery == null)
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", "同步发货信息");
|
||||
return;
|
||||
}
|
||||
|
||||
var tcOrderModel = await _tcOrderServices.QueryByClauseAsync(p => p.outOrderId == billDelivery.orderId, true);
|
||||
if (tcOrderModel == null)
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", "未查询到远程订单推送记录");
|
||||
return;
|
||||
}
|
||||
|
||||
var orderInfo = await _orderServices.QueryByClauseAsync(p => p.orderId == billDelivery.orderId, true);
|
||||
if (orderInfo == null)
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", "订单信息获取失败");
|
||||
return;
|
||||
}
|
||||
|
||||
//判断是否发货发完
|
||||
var finishAllDelivery = false;
|
||||
|
||||
//总发货数量
|
||||
var allNeedSendNum = await _orderItemServices.GetSumAsync(p => p.orderId == orderInfo.orderId, p => p.nums, true);
|
||||
//已经发货数量
|
||||
var isSendNum = await _orderItemServices.GetSumAsync(p => p.orderId == orderInfo.orderId, p => p.sendNums, true);
|
||||
|
||||
finishAllDelivery = allNeedSendNum == isSendNum ? true : false;
|
||||
|
||||
//获取小程序认证
|
||||
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
|
||||
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
||||
var request = new ShopDeliverySendRequest();
|
||||
request.AccessToken = accessToken;
|
||||
|
||||
if (orderInfo.receiptType == (int)GlobalEnumVars.OrderReceiptType.Logistics)
|
||||
{
|
||||
request.OutOrderId = orderInfo.orderId;
|
||||
request.OpenId = tcOrderModel.openid;
|
||||
request.IsFinishAll = finishAllDelivery;
|
||||
request.DeliveryList = new List<ShopDeliverySendRequest.Types.Delivery>
|
||||
{
|
||||
new ShopDeliverySendRequest.Types.Delivery()
|
||||
{
|
||||
DeliveryId = billDelivery.thirdPartylogiCode, WaybillId = billDelivery.logiNo
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
request.OutOrderId = orderInfo.orderId;
|
||||
request.OpenId = tcOrderModel.openid;
|
||||
request.IsFinishAll = true;
|
||||
}
|
||||
|
||||
var response = await client.ExecuteShopDeliverySendAsync(request);
|
||||
if (response.IsSuccessful())
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", JsonConvert.SerializeObject(response));
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", JsonConvert.SerializeObject(response));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", "发货单编号获取失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var obj = new
|
||||
{
|
||||
wxOpenAppId = _wxOpenAppId,
|
||||
wxOpenAppSecret = _wxOpenAppSecret,
|
||||
msg
|
||||
};
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步发货信息", JsonConvert.SerializeObject(obj), ex);
|
||||
throw;
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user