|
|
@@ -67,6 +67,10 @@ import com.github.pagehelper.PageInfo;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -79,6 +83,8 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import static com.fs.hisStore.constants.UserAppsLockConstant.LOCK_KEY_PAY;
|
|
|
+
|
|
|
/**
|
|
|
* 订单Controller
|
|
|
*
|
|
|
@@ -90,6 +96,9 @@ import java.util.concurrent.TimeUnit;
|
|
|
@RequestMapping("/app/live/liveOrder")
|
|
|
public class LiveOrderController extends AppBaseController
|
|
|
{
|
|
|
+ Logger logger= LoggerFactory.getLogger(getClass());
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
@Autowired
|
|
|
private ILiveOrderService orderService;
|
|
|
|
|
|
@@ -118,26 +127,6 @@ public class LiveOrderController extends AppBaseController
|
|
|
@Autowired
|
|
|
private HuiFuService huiFuService;
|
|
|
|
|
|
- @Autowired
|
|
|
- @Qualifier("erpOrderServiceImpl")
|
|
|
- private IErpOrderService gyOrderService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- @Qualifier("wdtErpOrderServiceImpl")
|
|
|
- private IErpOrderService wdtOrderService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- @Qualifier("k9OrderScrmServiceImpl")
|
|
|
- private IErpOrderService k9OrderService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ConfigUtil configUtil;
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IFsExpressService expressService;
|
|
|
- @Autowired
|
|
|
- private JwtUtils jwtUtils;
|
|
|
|
|
|
/**
|
|
|
* 查询订单列表
|
|
|
@@ -316,6 +305,151 @@ public class LiveOrderController extends AppBaseController
|
|
|
return orderService.createLiveOrder(param);
|
|
|
}
|
|
|
|
|
|
+// @Login
|
|
|
+// @ApiOperation("支付")
|
|
|
+// @PostMapping("/pay")
|
|
|
+// @Transactional
|
|
|
+// //@Synchronized
|
|
|
+// public R pay(HttpServletRequest request, @Validated @RequestBody LiveOrderPayParam param)
|
|
|
+// {
|
|
|
+// LiveOrder order=orderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+// if(order==null){
|
|
|
+// return R.error("订单不存在");
|
|
|
+// }
|
|
|
+// if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
|
|
|
+// return R.error("订单状态不正确");
|
|
|
+// }
|
|
|
+// String orderId=redisCache.getCacheObject("isPaying:"+order.getOrderId());
|
|
|
+// if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getOrderId().toString())){
|
|
|
+// return R.error("正在支付中...");
|
|
|
+// }
|
|
|
+//
|
|
|
+// FsUserScrm user=userService.selectFsUserById(Long.valueOf(order.getUserId()));
|
|
|
+// if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
|
|
|
+// //已改价处理
|
|
|
+// if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
+// //改过价不做处理
|
|
|
+//
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// String config=configService.selectConfigByKey("his.store");
|
|
|
+// StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
|
|
|
+// if(param.getPayType().equals(1)){
|
|
|
+// order.setPayType("1");
|
|
|
+// order.setPayMoney(order.getPayPrice());
|
|
|
+// order.setPayDelivery(BigDecimal.ZERO);
|
|
|
+// }
|
|
|
+// else if(param.getPayType().equals(2)){
|
|
|
+// order.setPayType("2");
|
|
|
+// BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
|
|
|
+// payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
|
|
|
+// order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
+// order.setPayMoney(payMoney);
|
|
|
+// }
|
|
|
+// else if(param.getPayType().equals(3)){
|
|
|
+// //货到付款
|
|
|
+// order.setPayType("3");
|
|
|
+// BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getOrderId());
|
|
|
+// BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
+// if (amount != null){
|
|
|
+// payMoney=amount;
|
|
|
+// }
|
|
|
+// order.setPayMoney(payMoney);
|
|
|
+// order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
+//// order.setPayMoney(BigDecimal.ZERO);
|
|
|
+// }
|
|
|
+// orderService.updateLiveOrder(order);
|
|
|
+// }
|
|
|
+// String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+//// order.setOrderCode(orderCode);
|
|
|
+//// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
|
+// if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
|
|
|
+// String json = configService.selectConfigByKey("his.pay");
|
|
|
+// FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+// LiveOrderPayment storePayment=new LiveOrderPayment();
|
|
|
+// storePayment.setCompanyId(order.getCompanyId());
|
|
|
+// storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+// storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+// storePayment.setStatus(0);
|
|
|
+// storePayment.setPayCode(payCode);
|
|
|
+// storePayment.setPayMoney(order.getPayMoney());
|
|
|
+// storePayment.setCreateTime(new Date());
|
|
|
+// storePayment.setPayTypeCode("weixin");
|
|
|
+// storePayment.setBusinessType(2);
|
|
|
+// storePayment.setRemark("直播订单支付");
|
|
|
+// storePayment.setOpenId(user.getRealName());
|
|
|
+// storePayment.setUserId(user.getUserId());
|
|
|
+// storePayment.setBusinessId(String.valueOf(order.getOrderId()));
|
|
|
+// liveOrderPaymentMapper.insertLiveOrderPayment(storePayment);
|
|
|
+//
|
|
|
+// if (fsPayConfig.getType().equals("hf")){
|
|
|
+// HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+// o.setTradeType("T_MINIAPP");
|
|
|
+// o.setOpenid(user.getMaOpenId());
|
|
|
+// o.setReqSeqId("live-"+storePayment.getPayCode());
|
|
|
+// o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+// o.setGoodsDesc("直播订单支付");
|
|
|
+// if (param != null && StringUtils.isNotBlank(param.getAppId())) {
|
|
|
+// o.setAppId(param.getAppId());
|
|
|
+// }
|
|
|
+// HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+// if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
+// LiveOrderPayment mt=new LiveOrderPayment();
|
|
|
+// mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+// mt.setTradeNo(result.getHf_seq_id());
|
|
|
+// liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
+// redisCache.setCacheObject("isPaying:"+order.getOrderId(),order.getOrderId().toString(),1, TimeUnit.MINUTES);
|
|
|
+// Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+// String s = (String) resultMap.get("package");
|
|
|
+// resultMap.put("packageValue",s);
|
|
|
+// return R.ok().put("payType",param.getPayType()).put("result",resultMap);
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// return R.error(result.getResp_desc());
|
|
|
+// }
|
|
|
+// }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+// WxPayConfig payConfig = new WxPayConfig();
|
|
|
+// payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+// payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+// payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+// payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+// payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+// payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
+// payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+// wxPayService.setConfig(payConfig);
|
|
|
+// WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+// orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+// orderRequest.setBody("直播订单支付");
|
|
|
+// orderRequest.setOutTradeNo("live-" + storePayment.getPayCode());
|
|
|
+// orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
+// //orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
|
|
|
+// orderRequest.setTradeType("JSAPI");
|
|
|
+// orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+// //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+// try {
|
|
|
+// WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
+// return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType",param.getPayType());
|
|
|
+// } catch (WxPayException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// throw new CustomException("支付失败" + e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//// else if(order.getPayType().equals("3")){
|
|
|
+// else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
|
|
|
+// //货到付款
|
|
|
+// orderService.payConfirm(2,order.getOrderId(),null,null,null,null);
|
|
|
+// return R.ok().put("payType",param.getPayType());
|
|
|
+// }
|
|
|
+// return R.error();
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// return R.error("用户OPENID不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ /*
|
|
|
@Login
|
|
|
@ApiOperation("支付")
|
|
|
@PostMapping("/pay")
|
|
|
@@ -323,6 +457,37 @@ public class LiveOrderController extends AppBaseController
|
|
|
//@Synchronized
|
|
|
public R pay(HttpServletRequest request, @Validated @RequestBody LiveOrderPayParam param)
|
|
|
{
|
|
|
+ Long orderId = param.getOrderId();
|
|
|
+ logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
|
|
|
+
|
|
|
+ RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
|
|
|
+ R result = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ if (!locked) {
|
|
|
+ logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
|
|
|
+ return R.error("订单正在处理中,请勿重复提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ result = orderService.pay(param);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error("获取支付锁的过程被中断, 订单号: {}", orderId, e);
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ return R.error("支付处理被中断,请稍后重试");
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("支付过程中发生异常, 订单号: {}", orderId, e);
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ logger.debug("支付锁已释放, 订单号: {}", orderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
LiveOrder order=orderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
if(order==null){
|
|
|
return R.error("订单不存在");
|
|
|
@@ -459,7 +624,92 @@ public class LiveOrderController extends AppBaseController
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取订单详细信息
|
|
|
+ */
|
|
|
+ @Login
|
|
|
+ @GetMapping(value = "/info/{orderId}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("orderId") String orderId)
|
|
|
+ {
|
|
|
+ log.info("获取订单详细信息 参数: {}",orderId);
|
|
|
|
|
|
+ return AjaxResult.success(orderService.selectLiveOrderByOrderId(orderId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @ApiOperation("支付")
|
|
|
+ @PostMapping("/pay")
|
|
|
+ @Transactional
|
|
|
+ public R pay(HttpServletRequest request, @Validated @RequestBody LiveOrderPayParam param)
|
|
|
+ {
|
|
|
+ Long orderId = param.getOrderId();
|
|
|
+ logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
|
|
|
+
|
|
|
+ RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
|
|
|
+ R result = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ if (!locked) {
|
|
|
+ logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
|
|
|
+ return R.error("订单正在处理中,请勿重复提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ result = orderService.handleLiveOrderPay(param);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error("获取支付锁的过程被中断, 订单号: {}", orderId, e);
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ return R.error("支付处理被中断,请稍后重试");
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("支付过程中发生异常, 订单号: {}", orderId, e);
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ logger.debug("支付锁已释放, 订单号: {}", orderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @ApiOperation("取消支付")
|
|
|
+ @PostMapping("/cancelPay")
|
|
|
+ public R cancelPay(@Validated @RequestBody LiveOrderPayParam param) {
|
|
|
+ Long orderId = param.getOrderId();
|
|
|
+ logger.info("用户取消支付 订单号: {}, 支付类型: {}", orderId, param.getPayType());
|
|
|
+ RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
|
|
|
+ try {
|
|
|
+ boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
|
|
|
+ if (!locked) {
|
|
|
+ logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
|
|
|
+ return R.error("订单正在处理中,请稍后再试");
|
|
|
+ }
|
|
|
+ handleCancelLiveOrderPay(param);
|
|
|
+ return R.ok();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error("获取取消支付锁的过程被中断, 订单号: {}", orderId, e);
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ return R.error("取消支付处理被中断,请稍后重试");
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("取消支付过程中发生异常, 订单号: {}", orderId, e);
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ logger.debug("取消支付锁已释放, 订单号: {}", orderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void handleCancelLiveOrderPay(LiveOrderPayParam param) {
|
|
|
+ redisCache.deleteObject("isPaying:"+param.getOrderId());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
@@ -519,8 +769,6 @@ public class LiveOrderController extends AppBaseController
|
|
|
else if(param.getPayType().equals(3)){
|
|
|
//货到付款
|
|
|
order.setPayType("3");
|
|
|
-// order.setPayDelivery(order.getPayPrice() );
|
|
|
-// order.setPayMoney(BigDecimal.ZERO);
|
|
|
BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getOrderId());
|
|
|
BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
if (amount != null){
|