【优化】移除旧版自定义交易组件。

This commit is contained in:
jianweie code
2023-09-02 01:49:22 +08:00
parent 651dc6b231
commit 0a07f3e005
108 changed files with 181 additions and 14817 deletions

View File

@@ -1,166 +0,0 @@
/***********************************************************************
* 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.Model.Entities;
using CoreCms.Net.WeChat.Service.Enums;
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
{
/// <summary>
/// 自定义交易组件-同步创建售后单
/// </summary>
public class TCOrderAfterSaleCreateSyncSubscribe : IRedisSubscribe
{
private readonly string _wxOpenAppId = AppSettingsConstVars.WxOpenAppId;
private readonly string _wxOpenAppSecret = AppSettingsConstVars.WxOpenAppSecret;
private readonly ICoreCmsOrderServices _orderServices;
private readonly IWeChatTransactionComponentOrderServices _tcOrderServices;
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
private readonly ICoreCmsBillAftersalesServices _billAftersalesServices;
private readonly ICoreCmsBillAftersalesItemServices _billAftersalesItemServices;
public TCOrderAfterSaleCreateSyncSubscribe(ICoreCmsOrderServices orderServices, IWeChatTransactionComponentOrderServices tcOrderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, ICoreCmsBillAftersalesServices billAftersalesServices, ICoreCmsBillAftersalesItemServices billAftersalesItemServices)
{
_orderServices = orderServices;
_tcOrderServices = tcOrderServices;
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
_billAftersalesServices = billAftersalesServices;
_billAftersalesItemServices = billAftersalesItemServices;
}
/// <summary>
/// 自定义交易组件-同步创建售后单
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[Subscribe(RedisMessageQueueKey.TransactionComponentAfterSaleCreateSync)]
private async Task TransactionComponentAfterSaleCreateSync(string msg)
{
try
{
var orderModel = JsonConvert.DeserializeObject<CoreCmsOrder>(msg);
if (orderModel is { scene: > 0 })
{
var tcOrderModel = await _tcOrderServices.QueryByClauseAsync(p => p.outOrderId == orderModel.orderId, true);
if (tcOrderModel == null)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步创建售后单", "未查询到远程订单推送记录");
return;
}
var orderInfo = await _orderServices.QueryByClauseAsync(p => p.orderId == orderModel.orderId, true);
if (orderInfo == null)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步创建售后单", "订单信息获取失败");
return;
}
//获取售后单
var aftersale = await _billAftersalesServices.QueryByClauseAsync(p => p.aftersalesId == orderModel.billAftersalesId);
//获取售后单详情
var aftersaleItems = await _billAftersalesItemServices.QueryListByClauseAsync(p => p.aftersalesId == orderModel.billAftersalesId);
//获取小程序认证
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new ShopECAftersaleAddRequest();
request.AccessToken = accessToken;
request.OutOrderId = orderModel.orderId;
request.OutAftersaleOrderId = orderModel.billAftersalesId;
request.OpenId = tcOrderModel.openid;
//request.PagePath = "pages/member/afterSales/detail/detail?aftersalesId=" + orderModel.billAftersalesId;
request.RefundAmount = Convert.ToInt32(aftersale.refundAmount * 100);
if (aftersale.refundAmount > 0 && aftersale.type == (int)GlobalEnumVars.BillAftersalesIsReceive.Refund)
{
request.Type = (int)AfterSalesEnum.AfterSaleType.退;
}
else if (aftersale.refundAmount > 0 && aftersale.type == (int)GlobalEnumVars.BillAftersalesIsReceive.Reship)
{
request.Type = (int)AfterSalesEnum.AfterSaleType.退退;
}
else if (Convert.ToInt32(aftersale.refundAmount) == 0 && aftersale.type == (int)GlobalEnumVars.BillAftersalesIsReceive.Reship)
{
request.Type = (int)AfterSalesEnum.AfterSaleType.退退;
}
else if (Convert.ToInt32(aftersale.refundAmount) == 0 && aftersale.type == (int)GlobalEnumVars.BillAftersalesIsReceive.Refund)
{
request.Type = (int)AfterSalesEnum.AfterSaleType.退;
}
request.RefundReasonType = (int)AfterSalesEnum.AfterSalesReasonType.;
request.RefundReason = aftersale.reason;
//新自定义交易组件,只能申请一个商品售后。
request.Product = new ShopECAftersaleAddRequest.Types.Product()
{
Count = aftersaleItems[0].nums,
OutProductId = aftersaleItems[0].goodsId.ToString(),
OutSKUId = aftersaleItems[0].productId.ToString()
};
//aftersaleItems.ForEach(p =>
//{
// var product = new ShopECAftersaleAddRequest.Types.Product();
// product.Count = p.nums;
// product.OutProductId = p.goodsId.ToString();
// product.OutSKUId = p.productId.ToString();
// request.Product.Add(product);
//});
var response = await client.ExecuteShopECAftersaleAddAsync(request);
NLogUtil.WriteAll(response.IsSuccessful() ? NLog.LogLevel.Info : 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,
};
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步创建售后单", JsonConvert.SerializeObject(obj), ex);
throw;
}
await Task.CompletedTask;
}
}
}

View File

@@ -1,114 +0,0 @@
/***********************************************************************
* 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.Threading.Tasks;
using CoreCms.Net.Caching.AccressToken;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.WeChat.Service.HttpClients;
using InitQ.Abstractions;
using InitQ.Attributes;
using Newtonsoft.Json;
using NLog;
using SKIT.FlurlHttpClient.Wechat.Api;
using SKIT.FlurlHttpClient.Wechat.Api.Models;
namespace CoreCms.Net.RedisMQ
{
/// <summary>
/// 自定义交易组件-同步订单确认收货
/// </summary>
public class TCOrderDeliveryRecieveSyncSubscribe : IRedisSubscribe
{
private readonly ICoreCmsBillDeliveryServices _billDeliveryServices;
private readonly ICoreCmsOrderItemServices _orderItemServices;
private readonly ICoreCmsOrderServices _orderServices;
private readonly IWeChatTransactionComponentOrderServices _tcOrderServices;
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
private readonly ICoreCmsUserWeChatInfoServices _weChatInfoServices;
public TCOrderDeliveryRecieveSyncSubscribe(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.TransactionComponentOrderDeliveryRecieveSync)]
private async Task TransactionComponentOrderDeliveryRecieveSync(string msg)
{
try
{
var orderModel = JsonConvert.DeserializeObject<CoreCmsOrder>(msg);
if (orderModel is {scene: > 0})
{
var tcOrderModel =
await _tcOrderServices.QueryByClauseAsync(p => p.outOrderId == orderModel.orderId, true);
if (tcOrderModel == null)
{
NLogUtil.WriteAll(LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单确认收货",
"未查询到远程订单推送记录");
return;
}
var orderInfo = await _orderServices.QueryByClauseAsync(p => p.orderId == orderModel.orderId, true);
if (orderInfo == null)
{
NLogUtil.WriteAll(LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单确认收货", "订单信息获取失败");
return;
}
//获取小程序认证
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new ShopDeliveryReceiveRequest();
request.AccessToken = accessToken;
request.OpenId = tcOrderModel.openid;
request.OutOrderId = orderModel.orderId;
var response = await client.ExecuteShopDeliveryReceiveAsync(request);
NLogUtil.WriteAll(response.IsSuccessful() ? LogLevel.Info : LogLevel.Error,
LogType.RedisMessageQueue, "自定义交易组件-同步订单确认收货", JsonConvert.SerializeObject(response));
}
else
{
NLogUtil.WriteAll(LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单确认收货", "订单获取失败");
}
}
catch (Exception ex)
{
NLogUtil.WriteAll(LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单确认收货", msg, ex);
throw;
}
await Task.CompletedTask;
}
}
}

View File

@@ -1,176 +0,0 @@
/***********************************************************************
* 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
{
/// <summary>
/// 自定义交易组件-同步发货信息
/// </summary>
public class TCOrderShipSyncSubscribe : IRedisSubscribe
{
private readonly string _wxOpenAppId = AppSettingsConstVars.WxOpenAppId;
private readonly string _wxOpenAppSecret = AppSettingsConstVars.WxOpenAppSecret;
private readonly ICoreCmsBillDeliveryServices _billDeliveryServices;
private readonly ICoreCmsBillDeliveryItemServices _billDeliveryItemServices;
private readonly ICoreCmsOrderServices _orderServices;
private readonly ICoreCmsOrderItemServices _orderItemServices;
private readonly IWeChatTransactionComponentOrderServices _tcOrderServices;
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
public TCOrderShipSyncSubscribe(ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsOrderServices orderServices, IWeChatTransactionComponentOrderServices tcOrderServices, ICoreCmsOrderItemServices orderItemServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, ICoreCmsBillDeliveryItemServices billDeliveryItemServices)
{
_billDeliveryServices = billDeliveryServices;
_orderServices = orderServices;
_tcOrderServices = tcOrderServices;
_orderItemServices = orderItemServices;
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
_billDeliveryItemServices = billDeliveryItemServices;
}
/// <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 items = await _billDeliveryItemServices.QueryListByClauseAsync(p => p.deliveryId == billDelivery.deliveryId);
//判断是否发货发完
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;
var delivery = new ShopDeliverySendRequest.Types.Delivery
{
DeliveryId = billDelivery.thirdPartylogiCode,
WaybillId = billDelivery.logiNo,
ProductList = new List<ShopDeliverySendRequest.Types.Delivery.Types.Product>()
};
items.ForEach(p =>
{
delivery.ProductList.Add(new ShopDeliverySendRequest.Types.Delivery.Types.Product()
{
OutProductId = p.goodsId.ToString(),
OutSKUId = p.productId.ToString(),
Count = p.nums
});
});
request.DeliveryList = new List<ShopDeliverySendRequest.Types.Delivery>()
{
delivery
};
request.ShipDoneTime = new DateTimeOffset(billDelivery.createTime);
}
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;
}
}
}

View File

@@ -1,101 +0,0 @@
/***********************************************************************
* 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.Threading.Tasks;
using CoreCms.Net.Caching.AccressToken;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
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
{
/// <summary>
/// 自定义交易组件-同步订单状态(弃用,新版已经取消了同步)
/// </summary>
public class TCPayOrderSyncSubscribe : IRedisSubscribe
{
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
public TCPayOrderSyncSubscribe(ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
{
_userWeChatInfoServices = userWeChatInfoServices;
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
}
/// <summary>
/// 自定义交易组件-同步订单状态
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[Subscribe(RedisMessageQueueKey.TransactionComponentPayOrderSync)]
private async Task TransactionComponentPayOrderSync(string msg)
{
try
{
var orderModel = JsonConvert.DeserializeObject<CoreCmsOrder>(msg);
if (orderModel is { scene: > 0 })
{
//获取小程序认证
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var userInfo = await _userWeChatInfoServices.QueryByClauseAsync(p => p.userId == orderModel.userId);
if (userInfo != null)
{
var payment = orderModel.paymentItem[0];
//获取同步地址接口地址
var request = new ShopOrderPayRequest();
request.AccessToken = accessToken;
request.OutOrderId = orderModel.orderId;
request.OpenId = userInfo.openid;
request.ActionType = 1;
request.TransactionId = payment.tradeNo;
request.PayTime = payment.createTime;
var response = await client.ExecuteShopOrderPayAsync(request);
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单状态", JsonConvert.SerializeObject(response));
}
else
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单状态", "微信用户数据获取失败");
}
}
else
{
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "自定义交易组件-同步订单状态", "商品获取失败");
}
}
catch (Exception ex)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "自定义交易组件-同步订单状态", msg, ex);
throw;
}
await Task.CompletedTask;
}
}
}