|
@@ -190,7 +190,7 @@ namespace Central.Control.WebApi.Service
|
|
|
#endregion
|
|
|
|
|
|
// 写入订单日志
|
|
|
- _ywLogService.WriteOrderLog(order.Id, "下单", "下单成功", session.UserId);
|
|
|
+ _ywLogService.WriteOrderLog(order.Id, "下单", "下单成功", session.UserName);
|
|
|
|
|
|
return new ApiResult<OrderResponseDto>(new OrderResponseDto()
|
|
|
{
|
|
@@ -200,6 +200,31 @@ namespace Central.Control.WebApi.Service
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 根据id获取商品信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="orderId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public ApiResult<OrderInfoResponseDto> GetQueueOrder(string orderId)
|
|
|
+ {
|
|
|
+ var session = _userService.GetLoginSession();
|
|
|
+
|
|
|
+ var order = _dbContent.Set<YW_Order>().FirstOrDefault(p => p.IsDelete == 0 && p.Id == orderId && p.DeviceId == session.UserId);
|
|
|
+ if (order == null)
|
|
|
+ {
|
|
|
+ return new ApiResult<OrderInfoResponseDto>(ApiStatusCode.InvalidParameter, "订单不存在");
|
|
|
+ }
|
|
|
+ OrderInfoResponseDto result = new OrderInfoResponseDto() {
|
|
|
+ Id = order.Id,
|
|
|
+ Name = order.Name,
|
|
|
+ Price = order.Price,
|
|
|
+ PayStatus = order.PayStatus,
|
|
|
+ PaySerialId = order.PaySerialId,
|
|
|
+ PayWay = order.PayWay
|
|
|
+ };
|
|
|
+ return new ApiResult<OrderInfoResponseDto>(result);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取待烧烤的商品列表
|
|
|
/// <summary>
|
|
@@ -258,6 +283,18 @@ namespace Central.Control.WebApi.Service
|
|
|
{
|
|
|
return new ApiResult(ApiStatusCode.InvalidParameter, "当前订单不是未支付状态,不能取消");
|
|
|
}
|
|
|
+
|
|
|
+ // 需要试试查询支付宝或者
|
|
|
+ if (order.PayWay == PayWayEnum.AliPay)
|
|
|
+ {
|
|
|
+ var tradeQueryResult = serviceClient.tradeQuery(order.Id);
|
|
|
+ if (tradeQueryResult.Status == ResultEnum.SUCCESS && tradeQueryResult.response.TradeStatus == "TRADE_SUCCESS")
|
|
|
+ {
|
|
|
+ // 已经支付成功
|
|
|
+ return new ApiResult(ApiStatusCode.InvalidParameter, "当前订单已经支付成功,不能取消");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
order.PayStatus = PayStatusEnum.Cancel;
|
|
|
order.OrderStatus = OrderStatusEnum.Cancel;
|
|
|
_dbContent.SaveChanges();
|
|
@@ -324,6 +361,16 @@ namespace Central.Control.WebApi.Service
|
|
|
{
|
|
|
return "http://api.rgtech.ltd/html/ordernotexist.html";
|
|
|
}
|
|
|
+ if (order.PayStatus == PayStatusEnum.Cancel)
|
|
|
+ {
|
|
|
+ // 订单已取消,不能支付再次支付
|
|
|
+ return "http://api.rgtech.ltd/html/ordercancel.html";
|
|
|
+ }
|
|
|
+ if (order.PayWay != PayWayEnum.UnKnow && order.PayWay != PayWayEnum.AliPay)
|
|
|
+ {
|
|
|
+ // 上次请求非支付宝支付、返回失败
|
|
|
+ return "http://api.rgtech.ltd/html/errorpayway.html";
|
|
|
+ }
|
|
|
string result = "http://api.rgtech.ltd/html/error.html";
|
|
|
|
|
|
// 查询订单详情
|
|
@@ -345,7 +392,7 @@ namespace Central.Control.WebApi.Service
|
|
|
//订单名称
|
|
|
builder.subject = order.Name;
|
|
|
//自定义超时时间
|
|
|
- builder.timeout_express = "10m";
|
|
|
+ builder.timeout_express = "2m";
|
|
|
//订单描述
|
|
|
builder.body = "";
|
|
|
//门店编号,很重要的参数,可以用作之后的营销
|
|
@@ -370,8 +417,6 @@ namespace Central.Control.WebApi.Service
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//如果需要接收扫码支付异步通知,那么请把下面两行注释代替本行。
|
|
|
//推荐使用轮询撤销机制,不推荐使用异步通知,避免单边账问题发生。
|
|
|
//AlipayF2FPrecreateResult precreateResult = new AlipayF2FPrecreateResult();
|
|
@@ -379,7 +424,10 @@ namespace Central.Control.WebApi.Service
|
|
|
|
|
|
switch (precreateResult.Status)
|
|
|
{
|
|
|
- case ResultEnum.SUCCESS:
|
|
|
+ case ResultEnum.SUCCESS:// 申请支付成功,写入订单支付方式(以便于其他人再次扫码使用不同支付方式)
|
|
|
+ order.PayWay = PayWayEnum.AliPay;
|
|
|
+ order.ModifyDT = DateTime.Now;
|
|
|
+ _dbContent.SaveChanges();
|
|
|
result = precreateResult.response.QrCode;
|
|
|
break;
|
|
|
case ResultEnum.FAILED:
|
|
@@ -467,7 +515,7 @@ namespace Central.Control.WebApi.Service
|
|
|
{
|
|
|
var order = _dbContent.Set<YW_Order>().FirstOrDefault(p => p.IsDelete == 0 && p.Id == orderId);
|
|
|
|
|
|
- if (order.PayStatus != PayStatusEnum.RefundApply)
|
|
|
+ if (order.PayStatus != PayStatusEnum.Paid)
|
|
|
{
|
|
|
// 订单状态不可退款
|
|
|
return new ApiResult(ApiStatusCode.InvalidParameter, "当前订单状态不可退款");
|
|
@@ -480,7 +528,7 @@ namespace Central.Control.WebApi.Service
|
|
|
break;
|
|
|
case PayWayEnum.AliPay:
|
|
|
// 支付宝退款
|
|
|
- result = AliPayRefund(order.Id, order.PaySerialId, order.Price, "客户发起退款");
|
|
|
+ result = AliPayRefund(order.Id, order.PaySerialId, order.Price, order.Id, "客户发起退款");
|
|
|
break;
|
|
|
default:
|
|
|
result = new ApiResult(ApiStatusCode.Forbidden, "未知支付方式,无法在线自动退款");
|
|
@@ -511,7 +559,7 @@ namespace Central.Control.WebApi.Service
|
|
|
// 2、请求支付宝退款接口查询是否已退款成功
|
|
|
// 3、退款成功或失败时,回写到订单中
|
|
|
var modifyDt = DateTime.Now.AddMinutes(-2);// 查询2分钟以前的订单,因为退款需要一定时间,马上查询会返回失败
|
|
|
- var order = _dbContent.Set<YW_Order>().Where(p => p.IsDelete == 0 && p.PayStatus == PayStatusEnum.RefundApply && p.ModifyDT < modifyDt).OrderBy(p => p.ModifyDT).FirstOrDefault();
|
|
|
+ var order = _dbContent.Set<YW_Order>().Where(p => p.IsDelete == 0 && p.PayStatus == PayStatusEnum.Refunding && p.ModifyDT < modifyDt).OrderBy(p => p.ModifyDT).FirstOrDefault();
|
|
|
if (order == null)
|
|
|
{
|
|
|
return new ApiResult(ApiStatusCode.InvalidParameter, "无退款中订单");
|
|
@@ -519,6 +567,15 @@ namespace Central.Control.WebApi.Service
|
|
|
// 更新modifydt以便下次捞取别的订单
|
|
|
order.ModifyDT = DateTime.Now;
|
|
|
|
|
|
+ // 测试
|
|
|
+ //var order = new YW_Order()
|
|
|
+ //{
|
|
|
+ // Id = "GBJUJCBWD3E26SIV",
|
|
|
+ // PaySerialId = "2022040322001434260501434677",
|
|
|
+ // DeviceId = string.Empty,// "cb8b354c-b713-4dd7-9752-a6f3217004a0",
|
|
|
+ // PayWay = PayWayEnum.AliPay
|
|
|
+ //};
|
|
|
+
|
|
|
ApiResult result = null;
|
|
|
switch (order.PayWay)
|
|
|
{
|
|
@@ -527,7 +584,7 @@ namespace Central.Control.WebApi.Service
|
|
|
break;
|
|
|
case PayWayEnum.AliPay:
|
|
|
// 查询支付宝退款
|
|
|
- result = AliPayRefundQuery(order.Id, order.PaySerialId, order.DeviceId);
|
|
|
+ result = AliPayRefundQuery(order.Id, order.PaySerialId, order.Price);
|
|
|
break;
|
|
|
default:
|
|
|
result = new ApiResult(ApiStatusCode.Forbidden, "未知支付方式,无法进行查询");
|
|
@@ -547,7 +604,7 @@ namespace Central.Control.WebApi.Service
|
|
|
else
|
|
|
{
|
|
|
// 退款失败,将订单更新成错误,并记录订单日志
|
|
|
- order.PayStatus = PayStatusEnum.Fail;
|
|
|
+ // order.PayStatus = PayStatusEnum.Fail;
|
|
|
order.OrderStatus = OrderStatusEnum.Cancel;
|
|
|
order.ModifyDT = DateTime.Now;
|
|
|
order.ModifyBY = "用户申请";
|
|
@@ -634,14 +691,14 @@ namespace Central.Control.WebApi.Service
|
|
|
/// <param name="refundAmount"></param>
|
|
|
/// <param name="refundReason"></param>
|
|
|
/// <returns></returns>
|
|
|
- private ApiResult AliPayRefund(string orderId,string paySerialId,decimal refundAmount, string refundReason)
|
|
|
+ private ApiResult AliPayRefund(string orderId,string paySerialId,decimal refundAmount, string out_request_no, string refundReason)
|
|
|
{
|
|
|
AlipayTradeRefundContentBuilder builder = new AlipayTradeRefundContentBuilder()
|
|
|
{
|
|
|
trade_no = paySerialId,
|
|
|
out_trade_no = orderId,
|
|
|
refund_amount = refundAmount.ToString(),
|
|
|
- out_request_no = string.Empty,
|
|
|
+ out_request_no = out_request_no,
|
|
|
refund_reason = refundReason,
|
|
|
};
|
|
|
ApiResult result = null;
|
|
@@ -673,27 +730,27 @@ namespace Central.Control.WebApi.Service
|
|
|
/// </summary>
|
|
|
/// <param name="orderId"></param>
|
|
|
/// <param name="paySerialId"></param>
|
|
|
- /// <param name="deviceId"></param>
|
|
|
+ /// <param name="orderPrice"></param>
|
|
|
/// <returns></returns>
|
|
|
- private ApiResult AliPayRefundQuery(string orderId, string paySerialId, string deviceId)
|
|
|
+ private ApiResult AliPayRefundQuery(string orderId, string paySerialId, decimal orderPrice)
|
|
|
{
|
|
|
var builder = new AlipayTradeFastpayRefundQueryContentBuilder()
|
|
|
{
|
|
|
trade_no = paySerialId,
|
|
|
out_trade_no = orderId,
|
|
|
- out_request_no = deviceId
|
|
|
+ out_request_no = orderId
|
|
|
};
|
|
|
ApiResult result = null;
|
|
|
// 支付宝退款
|
|
|
_log4NetHelper.Error($"[AliPayRefund]-AliPayRefundQuery-start:request:{JsonConvert.SerializeObject(builder)}");
|
|
|
var refundQueryResult = serviceClient.tradeFastpayRefundQuery(builder);
|
|
|
- _log4NetHelper.Error($"[AliPayRefund]-AliPayRefundQuery-end:request:{JsonConvert.SerializeObject(refundQueryResult)}");
|
|
|
+ _log4NetHelper.Error($"[AliPayRefund]-AliPayRefundQuery-end:response:{JsonConvert.SerializeObject(refundQueryResult)}");
|
|
|
|
|
|
switch (refundQueryResult.Status)
|
|
|
{
|
|
|
case ResultEnum.SUCCESS:
|
|
|
string content = "成功";
|
|
|
- if (refundQueryResult.response.RefundStatus == "REFUND_SUCCESS")
|
|
|
+ if (ConvertHelper.ToDecimal(refundQueryResult.response.RefundAmount) == orderPrice)
|
|
|
{
|
|
|
// 退款成功
|
|
|
result = new ApiResult();
|
|
@@ -881,5 +938,10 @@ namespace Central.Control.WebApi.Service
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ public AlipayF2FQueryResult tradeQuery(string orderId)
|
|
|
+ {
|
|
|
+ return serviceClient.tradeQuery(orderId);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|