配置测试环境支付成功回调
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
import com.chaozhanggui.system.cashierservice.service.OrderService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
@@ -20,24 +23,44 @@ import java.util.Map;
|
||||
public class NotifyController {
|
||||
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
public NotifyController(OrderService orderService) {
|
||||
this.orderService = orderService;
|
||||
}
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@RequestMapping("notifyPay")
|
||||
public String notifyPay(HttpServletRequest request,@RequestParam Map<String,Object> map){
|
||||
log.info("request ip:{}", request.getRemoteAddr());
|
||||
Map<String, String[]> params = ServletUtil.getParams(request);
|
||||
public Result notifyPay(HttpServletRequest request) {
|
||||
String body = ServletUtil.getBody(request);
|
||||
log.info("notifyPay params:{}", JSON.toJSONString(params));
|
||||
log.info("notifyPay body:{}", body);
|
||||
return null;
|
||||
JSONObject resp = JSON.parseObject(body);
|
||||
|
||||
String code = resp.getString("code");
|
||||
String msg = resp.getString("msg");
|
||||
if (!"000000".equals(code)) {
|
||||
log.error("支付失败:{}", resp.getString("msg"));
|
||||
return Result.fail(msg);
|
||||
}
|
||||
JSONObject bizData = JSON.parseObject(resp.getString("bizData"));
|
||||
String state = bizData.getString("state");
|
||||
String note = bizData.getString("note");
|
||||
String payOrderId = bizData.getString("payOrderId");
|
||||
String payType = bizData.getString("payType");
|
||||
String payTime = bizData.getString("payTime");
|
||||
long paidTime = DateUtil.parseDateTime(payTime).getTime();
|
||||
if (!"TRADE_SUCCESS".equals(state)) {
|
||||
log.error("支付失败:{},{}", state, note);
|
||||
return Result.fail(state + ":" + note);
|
||||
}
|
||||
TbOrderInfo entity = orderService.selectByPayOrderNo(payOrderId);
|
||||
if (entity == null) {
|
||||
return Result.fail("订单不存在");
|
||||
}
|
||||
entity.setPaidTime(paidTime);
|
||||
orderService.payCallbackCloseOrder(entity, payType);
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付取消
|
||||
*
|
||||
* @return 影响数量
|
||||
*/
|
||||
@PostMapping("cancel")
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.chaozhanggui.system.cashierservice.dao;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderPayment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TbOrderPaymentMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
@@ -18,4 +19,6 @@ public interface TbOrderPaymentMapper {
|
||||
int updateByPrimaryKey(TbOrderPayment record);
|
||||
|
||||
TbOrderPayment selectByOrderId(String orderId);
|
||||
|
||||
List<TbOrderPayment> selectListByOrderId(@Param("orderId") String orderId);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -18,7 +19,10 @@ import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnCartDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.CartPo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.OrderPo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.SkuInfoPo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.exception.NotPrintException;
|
||||
@@ -39,6 +43,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -117,6 +122,9 @@ public class OrderService {
|
||||
@Autowired
|
||||
private RabbitMsgUtils rabbitMsgUtils;
|
||||
|
||||
@Resource
|
||||
private TbOrderPaymentMapper tbOrderPaymentMapper;
|
||||
|
||||
|
||||
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper,
|
||||
TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper,
|
||||
@@ -401,7 +409,7 @@ public class OrderService {
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
query.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
.eq(TbCashierCart::getMasterId, MasterId);
|
||||
}else {
|
||||
} else {
|
||||
query.eq(TbCashierCart::getTableId, tableId).and(query2 -> query2.and(query3 -> query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
.eq(TbCashierCart::getMasterId, MasterId))
|
||||
.or(query4 -> query4.isNull(TbCashierCart::getTradeDay)
|
||||
@@ -464,7 +472,7 @@ public class OrderService {
|
||||
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
|
||||
shopOpenIds.forEach(item -> {
|
||||
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
|
||||
product.getStockNumber() - num , item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopId);
|
||||
product.getStockNumber() - num, item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopId);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -852,7 +860,6 @@ public class OrderService {
|
||||
orderDetails.add(orderDetail);
|
||||
|
||||
|
||||
|
||||
// 库存预警校验
|
||||
if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) {
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(tbProduct, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber()));
|
||||
@@ -1112,7 +1119,7 @@ public class OrderService {
|
||||
mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getOrderId, tbOrderInfo.getId())
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.set(TbCashierCart::getStatus, "refund"));
|
||||
|
||||
mpOrderDetailService.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
@@ -1857,4 +1864,36 @@ public class OrderService {
|
||||
.eq(TbOrderInfo::getStatus, "paying")
|
||||
.set(TbOrderInfo::getStatus, "unpaid"));
|
||||
}
|
||||
|
||||
public TbOrderInfo selectByPayOrderNo(String payOrderNo) {
|
||||
return mPOrderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getPayOrderNo, payOrderNo));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void payCallbackCloseOrder(TbOrderInfo entity, String payType) {
|
||||
mPOrderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, entity.getId())
|
||||
.eq(TbOrderInfo::getStatus, "paying")
|
||||
.set(TbOrderInfo::getStatus, "closed")
|
||||
.set(TbOrderInfo::getPaidTime, entity.getPaidTime())
|
||||
.set(TbOrderInfo::getUpdatedAt, System.currentTimeMillis())
|
||||
);
|
||||
List<TbOrderPayment> list = tbOrderPaymentMapper.selectListByOrderId(Convert.toStr(entity.getId()));
|
||||
for (TbOrderPayment payment : list) {
|
||||
payment.setTradeNumber(entity.getPayOrderNo());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
if ("WECHAT".equals(payType)) {
|
||||
payment.setPayName("微信支付");
|
||||
payment.setPayType("wechatPay");
|
||||
} else if ("ALIPAY".equals(payType)) {
|
||||
payment.setPayName("支付宝支付");
|
||||
payment.setPayType("aliPay");
|
||||
} else {
|
||||
payment.setPayName(payType);
|
||||
payment.setPayType(payType);
|
||||
}
|
||||
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,4 +260,8 @@
|
||||
<select id="selectByOrderId" resultMap="BaseResultMap">
|
||||
select * from tb_order_payment where order_id=#{orderId}
|
||||
</select>
|
||||
|
||||
<select id="selectListByOrderId" resultType="com.chaozhanggui.system.cashierservice.entity.TbOrderPayment">
|
||||
select * from tb_order_payment where order_id = #{orderId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user