【新增】小程序端确认收货增加推送【微信发货信息管理】同步确认收货功能。

This commit is contained in:
大灰灰
2024-08-10 14:50:26 +08:00
parent 1876ff05d1
commit 04cc9448c4
4 changed files with 234 additions and 43 deletions

View File

@@ -13,6 +13,7 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Caching.AccressToken;
using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
@@ -24,9 +25,13 @@ using CoreCms.Net.Model.ViewModels.DTO;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.WeChat.Service.Enums;
using CoreCms.Net.WeChat.Service.HttpClients;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SKIT.FlurlHttpClient.Wechat.Api;
using SKIT.FlurlHttpClient.Wechat.Api.Models;
using SqlSugar;
namespace CoreCms.Net.Web.WebApi.Controllers
@@ -51,7 +56,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers
private readonly ICoreCmsUserServices _userServices;
private readonly ICoreCmsClerkServices _clerkServices;
private readonly ICoreCmsInvoiceServices _invoiceServices;
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
private readonly ICoreCmsBillPaymentsServices _billPaymentsServices;
/// <summary>
/// 构造函数
@@ -61,7 +68,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
, ICoreCmsBillAftersalesServices aftersalesServices
, ICoreCmsSettingServices settingServices
, ICoreCmsAreaServices areaServices
, ICoreCmsBillReshipServices reshipServices, ICoreCmsShipServices shipServices, ICoreCmsLogisticsServices logisticsServices, ICoreCmsOrderDistributionModelServices orderDistributionModelServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserServices userServices, ICoreCmsClerkServices clerkServices, ICoreCmsInvoiceServices invoiceServices)
, ICoreCmsBillReshipServices reshipServices, ICoreCmsShipServices shipServices, ICoreCmsLogisticsServices logisticsServices, ICoreCmsOrderDistributionModelServices orderDistributionModelServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserServices userServices, ICoreCmsClerkServices clerkServices, ICoreCmsInvoiceServices invoiceServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, ICoreCmsBillPaymentsServices billPaymentsServices)
{
_user = user;
_orderServices = orderServices;
@@ -76,6 +83,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers
_userServices = userServices;
_clerkServices = clerkServices;
_invoiceServices = invoiceServices;
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
_userWeChatInfoServices = userWeChatInfoServices;
_billPaymentsServices = billPaymentsServices;
}
@@ -701,7 +711,6 @@ namespace CoreCms.Net.Web.WebApi.Controllers
#endregion
#region =======================================================
/// <summary>
@@ -765,9 +774,96 @@ namespace CoreCms.Net.Web.WebApi.Controllers
#endregion
#region
/// <summary>
/// 查询当前订单是否接入微信发货信息管理
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiCallBack> OrderShippingList([FromBody] FMStringId entity)
{
var jm = new WebApiCallBack
{
data = false
};
var user = await _userWeChatInfoServices.QueryByClauseAsync(p => p.userId == _user.ID);
if (user == null)
{
jm.msg = "微信用户信息获取失败";
return jm;
}
//构建请求
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var request = new WxaSecOrderGetOrderListRequest()
{
AccessToken = accessToken,
OpenId = user.openid
};
var response = await client.ExecuteWxaSecOrderGetOrderListAsync(request, HttpContext.RequestAborted);
if (response.ErrorCode == (int)WeChatReturnCode.ReturnCode.)
{
var isHave = response.OrderList.Any(p => p.TransactionId == entity.id && p.OrderState == 2);
jm.status = true;
jm.code = 0;
jm.data = isHave;
}
else
{
jm.code = 1;
jm.msg = response.ErrorMessage;
}
return jm;
}
#endregion
#region
/// <summary>
/// 根据订单编号获取当前订单的支付信息
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiCallBack> GetOrderPayInfo([FromBody] FMStringId entity)
{
var jm = new WebApiCallBack
{
data = false
};
var user = await _userServices.QueryByClauseAsync(p => p.id == _user.ID);
if (user == null)
{
jm.msg = "用户获取失败";
return jm;
}
var order = await _orderServices.QueryByClauseAsync(p => p.orderId == entity.id && p.userId == user.id);
if (order == null)
{
jm.msg = "订单获取失败";
return jm;
}
var payment = await _billPaymentsServices.QueryByClauseAsync(p => p.userId == user.id && p.sourceId == order.orderId && p.status == (int)GlobalEnumVars.BillPaymentsStatus.Payed);
if (payment == null)
{
jm.msg = "订单未支付";
return jm;
}
jm.code = 0;
jm.status = true;
jm.data = payment;
return jm;
}
#endregion
}
}