From 04cc9448c42b8b3fd7977578909161eb8d067148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Sat, 10 Aug 2024 14:50:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=AB=AF=E7=A1=AE=E8=AE=A4=E6=94=B6=E8=B4=A7?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A8=E9=80=81=E3=80=90=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E8=B4=A7=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86=E3=80=91?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=A1=AE=E8=AE=A4=E6=94=B6=E8=B4=A7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreShop/common/request/http.api.js | 10 +- .../pages/member/order/detail/detail.vue | 93 +++++++++++----- .../pages/member/order/index/index.vue | 72 ++++++++++--- .../Controllers/OrderController.cs | 102 +++++++++++++++++- 4 files changed, 234 insertions(+), 43 deletions(-) diff --git a/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js b/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js index aebc43c9..94adcf8e 100644 --- a/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js +++ b/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js @@ -435,6 +435,11 @@ const install = (Vue, vm) => { //支付宝小程序手机授权(拉取手机号码) let loginByGetPhoneNumberForAli = (params, config = {}) => http.post('/Api/User/DecryptPhoneNumberByAli', params, { custom: { methodName: 'user.loginByGetPhoneNumberForAli', needToken: false } }); + //查询当前订单是否接入微信发货信息管理 + let orderShippingList = (params, config = {}) => http.post('/Api/Order/OrderShippingList', params, { custom: { methodName: 'order.orderShippingList', needToken: true } }); + //根据订单编号获取当前订单的支付信息 + let getOrderPayInfo = (params, config = {}) => http.post('/Api/Order/GetOrderPayInfo', params, { custom: { methodName: 'order.getOrderPayInfo', needToken: true } }); + // 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下 vm.$u.api = { shopConfigV2, @@ -641,7 +646,10 @@ const install = (Vue, vm) => { submitInvoiceApply, getAliPayAppAuthTokenBYCode, - loginByGetPhoneNumberForAli + loginByGetPhoneNumberForAli, + + orderShippingList, + getOrderPayInfo }; } diff --git a/CoreCms.Net.Uni-App/CoreShop/pages/member/order/detail/detail.vue b/CoreCms.Net.Uni-App/CoreShop/pages/member/order/detail/detail.vue index f91aabe2..82e1c7b6 100644 --- a/CoreCms.Net.Uni-App/CoreShop/pages/member/order/detail/detail.vue +++ b/CoreCms.Net.Uni-App/CoreShop/pages/member/order/detail/detail.vue @@ -729,34 +729,73 @@ tackDeliery(orderId) { let _this = this; this.$common.modelShow('提示', '确认收货操作吗?', () => { - let data = { - id: orderId - } - _this.$u.api.confirmOrder(data).then(res => { - if (res.status) { - _this.$refs.uToast.show({ - message: '确认收货成功', type: 'success', complete: function () { - // 更改订单列表页的订单状态 - let pages = getCurrentPages(); // 当前页 - let beforePage = pages[pages.length - 2]; // 上个页面 - if (beforePage !== undefined && beforePage.route === 'pages/member/order/index/index') { - // #ifdef MP-WEIXIN - beforePage.$vm.isReload = true - // #endif - // #ifdef APP-PLUS || APP-PLUS-NVUE - beforePage.isReload = true - // #endif - // #ifdef MP-ALIPAY || MP-TOUTIAO - _this.$db.set('orderUserShip', true, true); - // #endif - } - _this.orderDetail() - } - }) - } else { - _this.$u.toast(res.msg) + // #ifdef MP-WEIXIN + if (_this.orderInfo.paymentItem[0].paymentCode == 'wechatpay' && _this.orderInfo.paymentItem[0].status == 2) { + let payData = { + id: _this.orderInfo.paymentItem[0].tradeNo } - }) + _this.$u.api.orderShippingList(payData).then(res => { + if (res.status && res.data == true) { + //拉起确认收货组件 + if (wx.openBusinessView) { + wx.openBusinessView({ + businessType: 'weappOrderConfirm', + extraData: { + transaction_id: _this.orderInfo.paymentItem[0].tradeNo + }, + success(e) { + _this.doTackDeliery(orderId); + }, + fail() { }, + complete() { } + }); + } else { + _this.$u.toast("您的微信版本过低,请升级微信"); + } + } else { + _this.doTackDeliery(orderId); + } + }) + } else { + _this.doTackDeliery(orderId); + } + // #endif + + // #ifndef MP-WEIXIN + _this.doTackDeliery(orderId); + // #endif + }) + }, + //执行确认收货. + doTackDeliery(orderId) { + let _this = this; + let data = { + id: orderId + } + _this.$u.api.confirmOrder(data).then(res => { + if (res.status) { + _this.$refs.uToast.show({ + message: '确认收货成功', type: 'success', complete: function () { + // 更改订单列表页的订单状态 + let pages = getCurrentPages(); // 当前页 + let beforePage = pages[pages.length - 2]; // 上个页面 + if (beforePage !== undefined && beforePage.route === 'pages/member/order/index/index') { + // #ifdef MP-WEIXIN + beforePage.$vm.isReload = true; + // #endif + // #ifdef APP-PLUS || APP-PLUS-NVUE + beforePage.isReload = true; + // #endif + // #ifdef MP-ALIPAY || MP-TOUTIAO + _this.$db.set('orderUserShip', true, true); + // #endif + } + _this.orderDetail() + } + }) + } else { + _this.$u.toast(res.msg) + } }) }, // 申请售后 diff --git a/CoreCms.Net.Uni-App/CoreShop/pages/member/order/index/index.vue b/CoreCms.Net.Uni-App/CoreShop/pages/member/order/index/index.vue index d12870d8..9abf860d 100644 --- a/CoreCms.Net.Uni-App/CoreShop/pages/member/order/index/index.vue +++ b/CoreCms.Net.Uni-App/CoreShop/pages/member/order/index/index.vue @@ -172,25 +172,73 @@ // 确认收货 tackDelivery(index, orderIndex) { let _this = this; - this.$common.modelShow('提示', '确认执行收货操作吗?', () => { - let data = { - id: _this.listData[orderIndex].orderId + var orderId = _this.listData[orderIndex].orderId; + this.$common.modelShow('提示', '确认收货操作吗?', () => { + // #ifdef MP-WEIXIN + let payInfoData = { + id: orderId } - _this.$u.api.confirmOrder(data).then(res => { - if (res.status) { - _this.$refs.uToast.show({ - message: '确认收货成功', type: 'success', complete: function () { - if (this.tab !== 0) { - _this.listData.splice(orderIndex, 1) + _this.$u.api.getOrderPayInfo(payInfoData).then(resPayInfo => { + console.log(resPayInfo); + if (resPayInfo.status && resPayInfo.data.paymentCode == 'wechatpay' && resPayInfo.data.status == 2) { + let payData = { + id: resPayInfo.data.tradeNo + } + _this.$u.api.orderShippingList(payData).then(res => { + if (res.status && res.data == true) { + //拉起确认收货组件 + if (wx.openBusinessView) { + wx.openBusinessView({ + businessType: 'weappOrderConfirm', + extraData: { + transaction_id: resPayInfo.data.tradeNo + }, + success(e) { + _this.doTackDeliery(orderIndex, orderId); + }, + fail() { }, + complete() { } + }); } else { - _this.getOrders(); + _this.$u.toast("您的微信版本过低,请升级微信"); } + } else { + _this.doTackDeliery(orderIndex, orderId); } }) - } else { - _this.$u.toast(res.msg) + } else if (resPayInfo.status && resPayInfo.data.paymentCode != 'wechatpay' && resPayInfo.data.status == 2) { + _this.doTackDeliery(orderIndex, orderId); + } + else { + _this.$u.toast(resPayInfo.msg) } }) + // #endif + // #ifndef MP-WEIXIN + _this.doTackDeliery(orderIndex, orderId); + // #endif + }) + }, + //执行确认收货. + doTackDeliery(orderIndex, orderId) { + let _this = this; + let data = { + id: orderId + } + _this.$u.api.confirmOrder(data).then(res => { + if (res.status) { + _this.$refs.uToast.show({ + message: '确认收货成功', type: 'success', complete: function () { + if (this.tab !== 0) { + _this.listData.splice(orderIndex, 1) + } else { + _this.getOrders(); + } + } + }) + } else { + _this.$u.toast(res.msg) + } }) }, // 订单状态统一在这处理 diff --git a/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs b/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs index e2c278a9..5996ae93 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/OrderController.cs @@ -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; /// /// 构造函数 @@ -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 提交发票申请======================================================= /// @@ -765,9 +774,96 @@ namespace CoreCms.Net.Web.WebApi.Controllers #endregion + #region 查询当前订单是否接入微信发货信息管理 + /// + /// 查询当前订单是否接入微信发货信息管理 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task 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 根据订单编号获取当前订单的支付信息 + /// + /// 根据订单编号获取当前订单的支付信息 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task 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 } } \ No newline at end of file