diff --git a/ARW.Model/Dto/Api/Pay/AddPayOrderDtoApi.cs b/ARW.Model/Dto/Api/Pay/AddPayOrderDtoApi.cs
new file mode 100644
index 0000000..5897a9c
--- /dev/null
+++ b/ARW.Model/Dto/Api/Pay/AddPayOrderDtoApi.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using ARW.Model.Models.Business.Carts;
+
+namespace ARW.Model.Dto.Api.Carts
+{
+
+ ///
+ /// 添加下单订单信息Dto对象Api
+ ///
+ /// @author lwh
+ /// @date 2023-09-24
+ ///
+ public class AddPayOrderDtoApi
+ {
+ ///
+ /// 客户Guid
+ ///
+ public long UserId { get; set; }
+
+ ///
+ /// 支付类型
+ ///
+ public int PayType { get; set; }
+
+ ///
+ /// 小程序用户OpenId
+ ///
+ public string OpenId { get; set; }
+
+
+ ///
+ /// 核销前价格
+ ///
+ public decimal BeforeMoney { get; set; }
+
+
+ ///
+ /// 核销后价格/操作金额
+ ///
+ public decimal Money { get; set; }
+
+ ///
+ /// 留言
+ ///
+ public string Remark { get; set; }
+
+ }
+}
diff --git a/ARW.Model/Dto/Api/Pay/CommitPayDtoApi.cs b/ARW.Model/Dto/Api/Pay/CommitPayDtoApi.cs
index 0d59678..d1318d4 100644
--- a/ARW.Model/Dto/Api/Pay/CommitPayDtoApi.cs
+++ b/ARW.Model/Dto/Api/Pay/CommitPayDtoApi.cs
@@ -15,32 +15,41 @@ namespace ARW.Model.Dto.Api.Carts
public class CommitPayDtoApi
{
///
- /// 客户guid
+ /// 客户Guid
///
- public long CustomerGuid { get; set; }
+ public long UserId { get; set; }
///
/// 支付类型
///
- public int type { get; set; }
+ public int PayType { get; set; }
///
/// 小程序用户OpenId
///
- public string openId { get; set; }
+ public string OpenId { get; set; }
///
- /// 待结算的商品集合
+ /// 核销前价格
///
- public string goodsRequestList { get; set; }
+ public decimal BeforeMoney { get; set; }
///
- /// 发票信息
+ /// 核销后价格/操作金额
///
- public string invoiceRequest { get; set; }
+ public decimal Money { get; set; }
+ ///
+ /// 留言
+ ///
+ public string Remark { get; set; }
+
+ ///
+ /// 优惠券Id
+ ///
+ public int CouponId { get; set;}
}
}
diff --git a/ARW.Service/Api/BusinessService/PayManage/PayServiceApi.cs b/ARW.Service/Api/BusinessService/PayManage/PayServiceApi.cs
index 9fbff80..0623c66 100644
--- a/ARW.Service/Api/BusinessService/PayManage/PayServiceApi.cs
+++ b/ARW.Service/Api/BusinessService/PayManage/PayServiceApi.cs
@@ -11,6 +11,11 @@ using Senparc.CO2NET.HttpUtility;
using ARW.Service.Api.IBusinessService.PayManage;
using ARW.Repository.Business.Payments;
using ARW.Repository.Business.OrderManage.Orders;
+using ARW.Model.Models.Business.OrderManage.Orders;
+using ARW.Model.Dto.Api.Carts;
+using ARW.Repository.Business.Marketing.CouponManage.Coupons;
+using Org.BouncyCastle.Crypto.Prng;
+using Aliyun.Acs.Core.Logging;
namespace ARW.Service.Api.BusinessService.PaymentManage
{
@@ -28,20 +33,24 @@ namespace ARW.Service.Api.BusinessService.PaymentManage
private readonly CustomerRepository _CustomerRepository;
private readonly OrderRepository _OrderRepository;
private readonly PaymentRepository _PaymentRepository;
+ private readonly CouponRepository _CouponRepository;
private readonly SenparcHttpClient _httpClient;
- public PayServiceApi(ShopRepository ShopRepository, GoodsCategoryRepository goodsCategoryRepository, CustomerRepository customerRepository)
+ public PayServiceApi(ShopRepository ShopRepository, GoodsCategoryRepository goodsCategoryRepository, CustomerRepository customerRepository, OrderRepository orderRepository, PaymentRepository paymentRepository, CouponRepository couponRepository)
{
this._ShopRepository = ShopRepository;
_GoodsCategoryRepository = goodsCategoryRepository;
_CustomerRepository = customerRepository;
+ _OrderRepository = orderRepository;
+ _PaymentRepository = paymentRepository;
+ _CouponRepository = couponRepository;
}
#region Api接口代码
- public async Task HandelPrePay(PayDto parm)
+ public async Task HandelPrePay(CommitPayDtoApi parm)
{
// 获取金额
var price = 1;//单位:分
@@ -61,7 +70,9 @@ namespace ARW.Service.Api.BusinessService.PaymentManage
#region 业务处理
/* 添加订单流水 */
- var paymentGuid = await AddPayment(parm.UserId, orderNo, parm.PayType, parm.BeforeMoney, parm.Money);
+ var paymentGuid = await AddPayment(parm, orderNo);
+ /* 添加业务订单 */
+ var orderGuid = await AddOrder(parm, orderNo, paymentGuid);
@@ -83,26 +94,24 @@ namespace ARW.Service.Api.BusinessService.PaymentManage
#region 业务方法调用
+
///
/// 添加订单流水
///
- /// 客户id
+ /// 下单信息Dto对象
/// 订单号
- /// 支付类型
- /// 核销前价格
- /// 核销后价格/操作金额
///
///
- public async Task AddPayment(long userId, string orderNo, int payType, decimal beforeMoney, decimal money)
+ public async Task AddPayment(CommitPayDtoApi parm, string orderNo)
{
// 添加订单流水
- Payment payment = new Payment
+ Payment payment = new()
{
- CustomerGuid = userId,
+ CustomerGuid = parm.UserId,
PaymentNumber = orderNo,
- PaymentBuytype = payType,
- PaymentBeforeMoney = beforeMoney,
- PaymentMoney = money,
+ PaymentBuytype = parm.PayType,
+ PaymentBeforeMoney = parm.BeforeMoney,
+ PaymentMoney = parm.Money,
PaymentStatus = 1
};
var response = await _PaymentRepository.InsertReturnSnowflakeIdAsync(payment);
@@ -113,21 +122,58 @@ namespace ARW.Service.Api.BusinessService.PaymentManage
}
- // 添加业务订单
- public async Task AddOrder(long userId, string orderNo, int payType, decimal beforeMoney, decimal money)
+ ///
+ /// 添加业务订单
+ ///
+ /// 下单信息Dto对象
+ /// 订单号
+ /// 支付订单流水guid
+ ///
+ ///
+ public async Task AddOrder(CommitPayDtoApi parm, string orderNo, long paymentGuid)
{
- Payment payment = new Payment
+ Order order = new()
{
- CustomerGuid = userId,
- PaymentNumber = orderNo,
- PaymentBuytype = payType,
- PaymentBeforeMoney = beforeMoney,
- PaymentMoney = money,
- PaymentStatus = 1
+ PaymentGuid = paymentGuid,
+ CustomerGuid = parm.UserId,
+ OrderNumber = orderNo,
+ GoodsTotalAmoun = parm.BeforeMoney,
+ OrderAmount = parm.Money,
+ PayPrice = parm.Money,
+ OrderRemark = parm.Remark,
+ PayType = parm.PayType,
+ PayStatus = 1,
};
- var response = await _PaymentRepository.InsertReturnSnowflakeIdAsync(payment);
+
+ // 优惠券减免价格
+ if (parm.CouponId != 0)
+ {
+ var coupon = await _CouponRepository.GetFirstAsync(s => s.CouponId == parm.CouponId);
+ if (coupon != null)
+ {
+ order.CouponGuid = coupon.CouponGuid;
+ order.CouponMoney = coupon.CouponDeductionMoney;
+
+ order.PayPrice = order.OrderAmount - coupon.CouponDeductionMoney;
+ }
+ else
+ {
+ throw new CustomException($"优惠券Id为 {parm.CouponId} 找不到");
+ }
+ }
+
+
+ // 运费计算
+
+
+
+ // TODO:余额支付
+
+
+
+ var response = await _OrderRepository.InsertReturnSnowflakeIdAsync(order);
if (response == 0)
- throw new CustomException("订单流水数据加入失败");
+ throw new CustomException("业务订单数据加入失败");
return response;
}
diff --git a/ARW.Service/Api/IBusinessService/PayManage/IPayServiceApi.cs b/ARW.Service/Api/IBusinessService/PayManage/IPayServiceApi.cs
index 993c75d..fbf911e 100644
--- a/ARW.Service/Api/IBusinessService/PayManage/IPayServiceApi.cs
+++ b/ARW.Service/Api/IBusinessService/PayManage/IPayServiceApi.cs
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
+using ARW.Model.Dto.Api.Carts;
using ARW.Model.Models.Business.Payments;
using static Infrastructure.WeChat.TenPay.Pay;
@@ -17,7 +18,7 @@ namespace ARW.Service.Api.IBusinessService.PayManage
///
///
///
- Task HandelPrePay(PayDto parm);
+ Task HandelPrePay(CommitPayDtoApi parm);
}
diff --git a/ARW.WebApi/Controllers/Api/Custom/HistorySearchs/HistorySearchApiController.cs b/ARW.WebApi/Controllers/Api/Custom/HistorySearchs/HistorySearchApiController.cs
index 56cb78c..bc57064 100644
--- a/ARW.WebApi/Controllers/Api/Custom/HistorySearchs/HistorySearchApiController.cs
+++ b/ARW.WebApi/Controllers/Api/Custom/HistorySearchs/HistorySearchApiController.cs
@@ -18,6 +18,7 @@ using Geocoding;
using ARW.Model.Dto.Business.Custom.HistorySearchs;
using ARW.Service.Business.IBusinessService.Custom.HistorySearchs;
using ARW.Admin.WebApi.Framework;
+using System.Reflection;
namespace ARW.WebApi.Controllers.Api.Custom.HistorySearchs
{
@@ -104,5 +105,18 @@ namespace ARW.WebApi.Controllers.Api.Custom.HistorySearchs
}
+ ///
+ /// 清空历史搜索
+ ///
+ ///
+ [HttpDelete("deleteAll")]
+ [Log(Title = "历史搜索清空", BusinessType = BusinessType.DELETE)]
+ public IActionResult DeleteAll()
+ {
+ var user = JwtUtil.GetLoginUser(App.HttpContext);
+ var response = _HistorySearchServiceApi.DeleteAsync(s => s.CustomerGuid == user.UserId);
+ return SUCCESS("清空成功!");
+ }
+
}
}
diff --git a/ARW.WebApi/Controllers/Api/Wechat/WxPay/WxPayController.cs b/ARW.WebApi/Controllers/Api/Wechat/WxPay/WxPayController.cs
index aedbfd1..ff2f804 100644
--- a/ARW.WebApi/Controllers/Api/Wechat/WxPay/WxPayController.cs
+++ b/ARW.WebApi/Controllers/Api/Wechat/WxPay/WxPayController.cs
@@ -13,6 +13,7 @@ using Senparc.Weixin.WxOpen.AdvancedAPIs.WxApp;
using ARW.Service.Business.IBusinessService.Custom.Customers;
using ARW.Service.Api.IBusinessService.PayManage;
using ARW.Service.Api.BusinessService.PaymentManage;
+using ARW.Model.Dto.Api.Carts;
namespace ARW.WebApi.Controllers.Api.Wechat.WxPay
{
@@ -44,7 +45,7 @@ namespace ARW.WebApi.Controllers.Api.Wechat.WxPay
///
///
[HttpPost("wxPay")]
- public async Task WxPay([FromBody] PayDto parm)
+ public async Task WxPay([FromBody] CommitPayDtoApi parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
@@ -67,13 +68,12 @@ namespace ARW.WebApi.Controllers.Api.Wechat.WxPay
{
try
{
- logger.Info("进入微信支付回调!", "2134234234");
+ logger.Info("进入微信支付回调!");
Pay pay = new Pay(_httpClient);
var res = await pay.PayNotifyUrl();
if (res.trade_state == "SUCCESS")
{
- logger.Info("微信支付回调之业务:", res.trade_state);
// 业务
var respones = _PayServiceApi.UpdateAsync(f => new Payment
{
@@ -86,11 +86,10 @@ namespace ARW.WebApi.Controllers.Api.Wechat.WxPay
}
- return SUCCESS("66666");
+ return SUCCESS("");
}
catch (Exception e)
{
- logger.Error("微信支付回调错误信息:", e);
throw;
}
}
diff --git a/ARW.WebApi/appsettings.json b/ARW.WebApi/appsettings.json
index eb4920e..c9c4ccc 100644
--- a/ARW.WebApi/appsettings.json
+++ b/ARW.WebApi/appsettings.json
@@ -9,7 +9,7 @@
"ConnectionStrings": {
"conn_db": "server=47.242.159.172;Database=shop_template;Uid=shop_template;Pwd=tKFJjWwL2kxMYtJK;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;",
//"conn_db": "server=127.0.0.1;Database=shop;Uid=root;Pwd=root;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;",
- "conn_db_type": "0" //数据库类型 MySql = 0, SqlServer = 1
+ "conn_db_type": "8" //数据库类型 MySql = 0, SqlServer = 1
},
"urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
"corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
diff --git a/Infrastructure/WeChat/TenPay/Pay.cs b/Infrastructure/WeChat/TenPay/Pay.cs
index bc9ad0e..029d279 100644
--- a/Infrastructure/WeChat/TenPay/Pay.cs
+++ b/Infrastructure/WeChat/TenPay/Pay.cs
@@ -401,6 +401,11 @@ namespace Infrastructure.WeChat.TenPay
/// 核销后价格/操作金额
///
public decimal Money { get; set; }
+
+ ///
+ /// 留言
+ ///
+ public string Remark { get; set; }
}
///