【新增】新增【微信发货信息管理】功能对接。实现微信小程序二次发货功能平移到后台业务,减少繁琐的二次发货操作。

This commit is contained in:
jianweie code
2023-10-08 02:08:22 +08:00
parent ac0cc6c148
commit 55e84b78af
35 changed files with 3329 additions and 33 deletions

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
@@ -61,6 +62,7 @@ namespace CoreCms.Net.Services
private readonly ICoreCmsTopUpTypeServices _topUpTypeServices;
private readonly ICoreCmsUserPointLogServices _userPointLogServices;
private readonly WeChatOptions _weChatOptions;
private readonly IRedisOperationRepository _redisOperationRepository;
@@ -77,7 +79,7 @@ namespace CoreCms.Net.Services
, IServiceProvider serviceProvider, ICoreCmsServicesServices servicesServices
, ICoreCmsUserServicesOrderServices userServicesOrderServices
, ICoreCmsUserWeChatInfoServices userWeChatInfoServices
, IOptions<WeChatOptions> weChatOptions, ICoreCmsTopUpTypeServices topUpTypeServices, ICoreCmsUserPointLogServices userPointLogServices)
, IOptions<WeChatOptions> weChatOptions, ICoreCmsTopUpTypeServices topUpTypeServices, ICoreCmsUserPointLogServices userPointLogServices, IRedisOperationRepository redisOperationRepository)
{
this._dal = dal;
base.BaseDal = dal;
@@ -97,6 +99,7 @@ namespace CoreCms.Net.Services
_userWeChatInfoServices = userWeChatInfoServices;
_topUpTypeServices = topUpTypeServices;
_userPointLogServices = userPointLogServices;
_redisOperationRepository = redisOperationRepository;
_weChatOptions = weChatOptions.Value;
}
@@ -126,7 +129,6 @@ namespace CoreCms.Net.Services
|| type == (int)GlobalEnumVars.BillPaymentsType.Bargain
|| type == (int)GlobalEnumVars.BillPaymentsType.Giveaway
|| type == (int)GlobalEnumVars.BillPaymentsType.Solitaire
|| type == (int)GlobalEnumVars.BillPaymentsType.TransactionComponent
)
{
//如果是订单生成支付单的话取第一条订单的店铺id后面的所有订单都要保证是此店铺的id
@@ -286,7 +288,6 @@ namespace CoreCms.Net.Services
|| type == (int)GlobalEnumVars.BillPaymentsType.Bargain
|| type == (int)GlobalEnumVars.BillPaymentsType.Giveaway
|| type == (int)GlobalEnumVars.BillPaymentsType.Solitaire
|| type == (int)GlobalEnumVars.BillPaymentsType.TransactionComponent
)
{
//如果是订单生成支付单的话取第一条订单的店铺id后面的所有订单都要保证是此店铺的id
@@ -694,7 +695,6 @@ namespace CoreCms.Net.Services
|| billPaymentInfo.type == (int)GlobalEnumVars.BillPaymentsType.Bargain
|| billPaymentInfo.type == (int)GlobalEnumVars.BillPaymentsType.Giveaway
|| billPaymentInfo.type == (int)GlobalEnumVars.BillPaymentsType.Solitaire
|| billPaymentInfo.type == (int)GlobalEnumVars.BillPaymentsType.TransactionComponent
)
{
//如果是订单类型,做支付后处理
@@ -733,6 +733,10 @@ namespace CoreCms.Net.Services
{
//::todo 其他业务逻辑
}
//微信发货信息管理API发货
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.WeChatPayShipping, billPaymentInfo.paymentId);
}
jm.status = true;
jm.data = paymentId;
@@ -792,7 +796,7 @@ namespace CoreCms.Net.Services
|| entity.type == (int)GlobalEnumVars.BillPaymentsType.Bargain
|| entity.type == (int)GlobalEnumVars.BillPaymentsType.Giveaway
|| entity.type == (int)GlobalEnumVars.BillPaymentsType.Solitaire
|| entity.type == (int)GlobalEnumVars.BillPaymentsType.TransactionComponent)
)
{
var orderItem = await _orderItemServices.QueryByClauseAsync(p => p.orderId == entity.sourceId);
if (orderItem != null)
@@ -852,7 +856,6 @@ namespace CoreCms.Net.Services
|| type == (int)GlobalEnumVars.BillPaymentsType.Bargain
|| type == (int)GlobalEnumVars.BillPaymentsType.Giveaway
|| type == (int)GlobalEnumVars.BillPaymentsType.Solitaire
|| type == (int)GlobalEnumVars.BillPaymentsType.TransactionComponent
)
{
var orderInfo = await orderServices.QueryByIdAsync(orderId);

View File

@@ -0,0 +1,175 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2023/9/15 23:09:53
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.AccressToken;
using CoreCms.Net.Configuration;
using CoreCms.Net.DTO.WeChatShipping;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Api;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.WeChat.Service.HttpClients;
using Flurl.Http;
using SKIT.FlurlHttpClient.Wechat.Api.Models;
using SqlSugar;
namespace CoreCms.Net.Services
{
/// <summary>
/// 微信发货快递公司信息 接口实现
/// </summary>
public class WeChatShippingDeliveryServices : BaseServices<WeChatShippingDelivery>, IWeChatShippingDeliveryServices
{
private readonly IWeChatShippingDeliveryRepository _dal;
private readonly IUnitOfWork _unitOfWork;
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
public WeChatShippingDeliveryServices(IUnitOfWork unitOfWork, IWeChatShippingDeliveryRepository dal, IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
{
this._dal = dal;
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
base.BaseDal = dal;
_unitOfWork = unitOfWork;
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public async Task<AdminUiCallBack> InsertAsync(WeChatShippingDelivery entity)
{
return await _dal.InsertAsync(entity);
}
/// <summary>
/// 重写异步更新方法方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> UpdateAsync(WeChatShippingDelivery entity)
{
return await _dal.UpdateAsync(entity);
}
/// <summary>
/// 重写异步更新方法方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> UpdateAsync(List<WeChatShippingDelivery> entity)
{
return await _dal.UpdateAsync(entity);
}
/// <summary>
/// 重写删除指定ID的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> DeleteByIdAsync(object id)
{
return await _dal.DeleteByIdAsync(id);
}
/// <summary>
/// 重写删除指定ID集合的数据(批量删除)
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
{
return await _dal.DeleteByIdsAsync(ids);
}
#endregion
#region ==========================================================
/// <summary>
/// 获取缓存的所有数据
/// </summary>
/// <returns></returns>
public async Task<List<WeChatShippingDelivery>> GetCaChe()
{
return await _dal.GetCaChe();
}
#endregion
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public async Task<IPageList<WeChatShippingDelivery>> QueryPageAsync(Expression<Func<WeChatShippingDelivery, bool>> predicate,
Expression<Func<WeChatShippingDelivery, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
}
#endregion
/// <summary>
/// 通过接口更新所有快递公司信息
/// </summary>
public async Task<AdminUiCallBack> DoUpdateCompany()
{
var jm = new AdminUiCallBack();
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var url = $"https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list?access_token={accessToken}";
var postData = new { accessToken };
var result = await url.PostJsonAsync(postData).ReceiveJson<GetDeliveryListResult>();
var bl = result != null;
if (result is { errcode: 0 })
{
//先清空历史表
await _dal.DeleteAsync(p => p.id > 0, true);
//组装插入数据
var insertData = result.delivery_list.Select(item => new WeChatShippingDelivery() { deliveryId = item.delivery_id, deliveryName = item.delivery_name }).ToList();
//更新数据库
bl = await _dal.InsertAsync(insertData, true) > 0;
}
jm.data = result;
jm.code = bl ? 0 : 1;
jm.msg = bl ? "数据刷新成功" : "数据刷新失败";
return jm;
}
}
}