mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:03:27 +08:00
【优化】移除旧版自定义交易组件。
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2022/6/29 16:22:45
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信交易组件下单前置检查 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsCheckBeforeAddOrderServices : BaseServices<CoreCmsCheckBeforeAddOrder>, ICoreCmsCheckBeforeAddOrderServices
|
||||
{
|
||||
private readonly ICoreCmsCheckBeforeAddOrderRepository _dal;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CoreCmsCheckBeforeAddOrderServices(IUnitOfWork unitOfWork, ICoreCmsCheckBeforeAddOrderRepository dal)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
||||
using CoreCms.Net.WeChat.Service.TransactionComponent.Enum;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -80,9 +79,6 @@ namespace CoreCms.Net.Services
|
||||
private readonly ICoreCmsPromotionRecordServices _promotionRecordServices;
|
||||
private readonly IRedisOperationRepository _redisOperationRepository;
|
||||
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
|
||||
private readonly IWeChatTransactionComponentOrderServices _tcOrderServices;
|
||||
private readonly ICoreCmsCheckBeforeAddOrderServices _checkBeforeAddOrderServices;
|
||||
private readonly IWeChatTransactionComponentOrderServices _chatTransactionComponentOrderServices;
|
||||
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
|
||||
private IUnitOfWork _unitOfWork;
|
||||
@@ -111,7 +107,7 @@ namespace CoreCms.Net.Services
|
||||
, ICoreCmsPaymentsServices paymentsServices
|
||||
, ICoreCmsBillRefundServices billRefundServices
|
||||
, ICoreCmsBillLadingServices billLadingServices
|
||||
, ICoreCmsBillReshipServices billReshipServices, ICoreCmsMessageCenterServices messageCenterServices, ICoreCmsGoodsCommentServices goodsCommentServices, ISysTaskLogServices taskLogServices, ICoreCmsPromotionRecordServices promotionRecordServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IWeChatTransactionComponentOrderServices tcOrderServices, ICoreCmsCheckBeforeAddOrderServices checkBeforeAddOrderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IWeChatTransactionComponentOrderServices chatTransactionComponentOrderServices, IUnitOfWork unitOfWork)
|
||||
, ICoreCmsBillReshipServices billReshipServices, ICoreCmsMessageCenterServices messageCenterServices, ICoreCmsGoodsCommentServices goodsCommentServices, ISysTaskLogServices taskLogServices, ICoreCmsPromotionRecordServices promotionRecordServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IUnitOfWork unitOfWork)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
@@ -146,10 +142,7 @@ namespace CoreCms.Net.Services
|
||||
_promotionRecordServices = promotionRecordServices;
|
||||
_redisOperationRepository = redisOperationRepository;
|
||||
_userWeChatInfoServices = userWeChatInfoServices;
|
||||
_tcOrderServices = tcOrderServices;
|
||||
_checkBeforeAddOrderServices = checkBeforeAddOrderServices;
|
||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
||||
_chatTransactionComponentOrderServices = chatTransactionComponentOrderServices;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
@@ -290,17 +283,6 @@ namespace CoreCms.Net.Services
|
||||
order.createTime = DateTime.Now;
|
||||
order.scene = scene;
|
||||
|
||||
|
||||
//插入获取的下单前的微信视频号直接数据
|
||||
var check = new CoreCmsCheckBeforeAddOrder();
|
||||
check.orderId = order.orderId;
|
||||
check.requireOrder = requireOrder;
|
||||
check.requiredFundType = requiredFundType;
|
||||
check.traceId = traceId;
|
||||
check.createTime = DateTime.Now;
|
||||
|
||||
await _checkBeforeAddOrderServices.InsertAsync(check);
|
||||
|
||||
//上面保存好订单表,下面保存订单的其他信息
|
||||
if (orderItems == null)
|
||||
{
|
||||
@@ -473,102 +455,6 @@ namespace CoreCms.Net.Services
|
||||
order.taxTitle = taxName;
|
||||
order.taxCode = taxCode;
|
||||
|
||||
|
||||
if (requireOrder == (int)GlobalEnumVars.RequireOrderType.需要)
|
||||
{
|
||||
|
||||
//获取小程序认证
|
||||
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
|
||||
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
||||
|
||||
var orderInfo = new ShopOrderAddRequest
|
||||
{
|
||||
AccessToken = accessToken,
|
||||
Scene = scene,
|
||||
//基础
|
||||
CreateTime = new DateTimeOffset(DateTime.Now),
|
||||
//FundType = (int)GlobalEnumVars.RequiredFundType.二级商户号订单,
|
||||
FundType = (int)GlobalEnumVars.RequiredFundType.二级商户号订单, //新版自定义交易组件,必须要走二级商户订单模式
|
||||
OutOrderId = order.orderId,
|
||||
PagePath = UniAppConst.OrderPath(order.orderId)
|
||||
};
|
||||
|
||||
var weChatUserInfo = await _userWeChatInfoServices.QueryByClauseAsync(p => p.userId == order.userId, true);
|
||||
if (weChatUserInfo != null)
|
||||
{
|
||||
orderInfo.OpenId = weChatUserInfo.openid;
|
||||
}
|
||||
orderInfo.OutUserId = order.userId.ToString();
|
||||
|
||||
//收货人信息
|
||||
orderInfo.Address = new ShopOrderAddRequest.Types.Address()
|
||||
{
|
||||
ReceiverName = order.shipName,
|
||||
Detail = order.shipAddress,
|
||||
TeleNumber = order.shipMobile,
|
||||
};
|
||||
//发货方式
|
||||
orderInfo.Delivery = new ShopOrderAddRequest.Types.Delivery()
|
||||
{
|
||||
DeliveryType = (int)DeliveryTypeEnum.正常快递
|
||||
};
|
||||
|
||||
orderInfo.OrderDetail = new ShopOrderAddRequest.Types.OrderDetail();
|
||||
|
||||
//支付信息
|
||||
orderInfo.OrderDetail.Payment = new ShopOrderAddRequest.Types.OrderDetail.Types.Payment()
|
||||
{
|
||||
PayType = (int)GlobalEnumVars.PayMethodType.微信支付
|
||||
};
|
||||
//价格体系
|
||||
orderInfo.OrderDetail.Amount = new ShopOrderAddRequest.Types.OrderDetail.Types.Amount()
|
||||
{
|
||||
OrderFee = Convert.ToInt32(order.orderAmount * 100),
|
||||
FreightFee = Convert.ToInt32(order.costFreight * 100),
|
||||
DiscountedFee = Convert.ToInt32((order.pointMoney + order.orderDiscountAmount + order.goodsDiscountAmount + order.couponDiscountAmount) * 100),
|
||||
AdditionalPrice = 0,
|
||||
AdditionalRemark = "无",
|
||||
};
|
||||
|
||||
//商品信息
|
||||
orderInfo.OrderDetail.ProductList = new List<ShopOrderAddRequest.Types.OrderDetail.Types.Product>();
|
||||
|
||||
|
||||
foreach (var item in orderItems)
|
||||
{
|
||||
orderInfo.OrderDetail.ProductList.Add(new ShopOrderAddRequest.Types.OrderDetail.Types.Product()
|
||||
{
|
||||
OutProductId = item.goodsId.ToString(),
|
||||
OutSKUId = item.productId.ToString(),
|
||||
Count = item.nums,
|
||||
SalePrice = Convert.ToInt32(item.amount * 100),
|
||||
SKURealPrice = Convert.ToInt32(item.amount * 100),
|
||||
PagePath = UniAppConst.GoodDetail(item.goodsId.ToString()),
|
||||
Title = item.name,
|
||||
HeadImageUrl = item.imageUrl
|
||||
});
|
||||
}
|
||||
|
||||
var shopOrderAddResponse = await client.ExecuteShopOrderAddAsync(orderInfo);
|
||||
if (shopOrderAddResponse.IsSuccessful())
|
||||
{
|
||||
var tcOrder = new WeChatTransactionComponentOrder
|
||||
{
|
||||
orderId = shopOrderAddResponse.Data.OrderId,
|
||||
outOrderId = shopOrderAddResponse.Data.OutOrderId,
|
||||
createTime = DateTime.Now,
|
||||
openid = orderInfo.OpenId
|
||||
};
|
||||
await _chatTransactionComponentOrderServices.InsertAsync(tcOrder);
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.Order, "自定义交易组件", "推送自定义交易组件创建订单成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Order, "自定义交易组件 ", "推送自定义交易组件创建订单失败");
|
||||
}
|
||||
jm.otherData = shopOrderAddResponse;
|
||||
}
|
||||
|
||||
//发送消息
|
||||
//0元订单记录支付成功
|
||||
if (order.orderAmount <= 0)
|
||||
@@ -1047,9 +933,6 @@ namespace CoreCms.Net.Services
|
||||
};
|
||||
}
|
||||
|
||||
order.tcOrder = await _tcOrderServices.QueryByClauseAsync(p => p.outOrderId == order.orderId);
|
||||
|
||||
|
||||
jm.status = true;
|
||||
jm.data = order;
|
||||
jm.msg = GlobalConstVars.GetDataSuccess;
|
||||
@@ -1693,9 +1576,6 @@ namespace CoreCms.Net.Services
|
||||
_goodsServices.ChangeStock(item.productId, GlobalEnumVars.OrderChangeStockType.cancel.ToString(), item.nums);
|
||||
}
|
||||
|
||||
var orderInfoIds = orderInfo.Select(p => p.orderId).ToList();
|
||||
await CloseOrder(orderInfoIds);
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "订单取消成功";
|
||||
}
|
||||
@@ -2093,7 +1973,7 @@ namespace CoreCms.Net.Services
|
||||
/// <param name="memo">发货描述</param>
|
||||
/// <param name="storeId">店铺收货地址</param>
|
||||
/// <param name="shipAreaId">省市区id</param>
|
||||
/// <param name="deliveryCompanyId">直播物流编码</param>
|
||||
/// <param name="deliveryCompanyId">第三方对接物流编码</param>
|
||||
/// <returns></returns>
|
||||
public async Task<WebApiCallBack> BatchShip(string[] ids, string logiCode, string logiNo,
|
||||
Dictionary<int, int> items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "")
|
||||
@@ -2120,7 +2000,7 @@ namespace CoreCms.Net.Services
|
||||
/// <param name="memo">发货描述</param>
|
||||
/// <param name="storeId">店铺收货地址</param>
|
||||
/// <param name="shipAreaId">省市区id</param>
|
||||
/// <param name="deliveryCompanyId">直播物流编码</param>
|
||||
/// <param name="deliveryCompanyId">第三方对接物流编码</param>
|
||||
/// <returns></returns>
|
||||
public async Task<WebApiCallBack> Ship(string orderId, string logiCode, string logiNo,
|
||||
Dictionary<int, int> items, string shipName, string shipMobile, string shipAddress, string memo, int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "")
|
||||
@@ -2393,11 +2273,8 @@ namespace CoreCms.Net.Services
|
||||
{
|
||||
var ids = orderInfos.Select(p => p.orderId).ToArray();
|
||||
jm = await CancelOrder(ids);
|
||||
|
||||
await CloseOrder(ids.ToList());
|
||||
}
|
||||
|
||||
|
||||
//插入日志
|
||||
var model = new SysTaskLog
|
||||
{
|
||||
@@ -2645,45 +2522,5 @@ namespace CoreCms.Net.Services
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 自定义交易组件-关闭订单
|
||||
|
||||
private async Task CloseOrder(ICollection<string> ids)
|
||||
{
|
||||
|
||||
//判断是否是自定义交易订单
|
||||
var coreCmsCheckBeforeAddOrders = await _checkBeforeAddOrderServices.QueryListByClauseAsync(p => ids.Contains(p.orderId) && p.requireOrder == (int)GlobalEnumVars.RequireOrderType.需要);
|
||||
if (coreCmsCheckBeforeAddOrders.Any())
|
||||
{
|
||||
var dataIds = coreCmsCheckBeforeAddOrders.Select(p => p.orderId).ToList();
|
||||
var orderInfos = await _dal.QueryListByClauseAsync(p => dataIds.Contains(p.orderId), p => p.createTime, OrderByType.Asc, true);
|
||||
|
||||
//获取小程序认证
|
||||
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
|
||||
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
||||
|
||||
|
||||
foreach (var item in orderInfos)
|
||||
{
|
||||
var request = new ShopOrderCloseRequest();
|
||||
request.AccessToken = accessToken;
|
||||
request.OutOrderId = item.orderId;
|
||||
|
||||
var user = await _userWeChatInfoServices.QueryByClauseAsync(p => p.userId == item.userId);
|
||||
if (user == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
request.OutOrderId = item.orderId;
|
||||
request.OpenId = user.openid;
|
||||
|
||||
var response = await client.ExecuteShopOrderCloseAsync(request);
|
||||
NLogUtil.WriteAll(response.IsSuccessful() ? NLog.LogLevel.Info : NLog.LogLevel.Error,
|
||||
LogType.Web, "自定义交易组件-关闭订单", JsonConvert.SerializeObject(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user