| @@ -289,6 +289,71 @@ public class WxOrderController extends BaseController { | |||
| map.put("params", JSON.toJSONString(paramMap)); | |||
| return map; | |||
| } | |||
| @ApiOperation(value = "更新订单状态", notes = "{\"payOrderId\":\"string\",\"composeOrderId\":\"string\",\"status\":integer,\"reason\":\"string\"}") | |||
| @PostMapping("/updatePayOrder") | |||
| public ResultData updatePayOrder(@RequestBody Map<String, Object> paramMap) { | |||
| logger.info("/api/pay/updatePayOrder" + paramMap.toString()); | |||
| String orderIdStr = (String) paramMap.get("composeOrderId"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| Long orderId = 0L; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error("orderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||
| } | |||
| WxBatchOrder batchOrder = wxOrderService.getWxBatchOrder(getTenantInfo(),orderId); | |||
| if(batchOrder == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到订单"); | |||
| } | |||
| WxPayOrder payOrder = new WxPayOrder(); | |||
| payOrder.setOrderId(orderId); | |||
| payOrder.updateTenantInfo(getTenantInfo()); | |||
| payOrder.setPayVendor(getPayWay().getCode()); | |||
| payOrder.setComposeOrder(batchOrder.getOrderType()); | |||
| try { | |||
| WxPayOrder byObj = wxPayOrderService.getByObj(payOrder); | |||
| if(byObj != null){ | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功"); | |||
| }else{ | |||
| WxComposeOrder composeOrder = orderFactory.getOrderAdapterService(payOrder.getComposeOrder()).getComposeOrder(payOrder.getOrderId(), payOrder.getTenantId()); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(payOrder, EnumPayWay.getEnum(payOrder.getPayVendor()).getPlat()); | |||
| //WxCUser user = getUser(); | |||
| //WxAppinfo appInfo = getAppInfo(user.getAppId()); | |||
| if (null == appInfo) { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "当前支付类型["+payOrder.getPayVendor()+"]找不到C端appInfo"); | |||
| } | |||
| WxPayAccount payAccount = wxPayAccountService.getById(appInfo.getPayId()); | |||
| try { | |||
| WxPayOrder wo = wxPayOrderService.handleWxOrderQuery(payOrder, composeOrder,appInfo, payAccount, IdWorker.get(),false); | |||
| if (null != wo) { | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", composeOrder); | |||
| } | |||
| }catch(MallinkException e) { | |||
| //已经同步了微信的支付状态,表示已经更新 | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", composeOrder); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "查询微信订单支付状态失败,请稍后!"); | |||
| } | |||
| } catch (MallinkException e) { | |||
| logger.error("支付状态更新失败2: " + payOrder.toString() + ", e:" + e.getMessage(),e); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage(),e); | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | |||
| } | |||
| } | |||
| @@ -2,25 +2,28 @@ package com.iformall.controller.callback; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxBatchOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.FmInsideNotifyRefundSuccessMsg; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.payv2.result.CreateOrderCallback; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.interceptor.BodyReaderHttpServletRequestWrapper; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.order.OrderFactory; | |||
| import com.iformall.service.order.entity.WxComposeOrder; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -28,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @@ -50,6 +54,9 @@ public class TtPayController extends BaseController { | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private OrderFactory orderFactory; | |||
| @@ -59,6 +66,9 @@ public class TtPayController extends BaseController { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private MaUtil maUtil; | |||
| /** | |||
| * timestamp number Unix 时间戳,10 位,整型数 | |||
| * nonce string 随机数 | |||
| @@ -75,51 +85,102 @@ public class TtPayController extends BaseController { | |||
| */ | |||
| @PostMapping(value = "/orderPay") | |||
| @ResponseBody | |||
| public Map<String,Object> createOrder( @RequestBody Map<String, Object> parameterMap){ | |||
| public Map<String,Object> createOrder( @RequestBody Map<String, Object> parameterMap,HttpServletRequest request){ | |||
| logger.debug("[" + getIpAddr() + "] TtOrderCallbackController::orderPay"); | |||
| Map<String,Object> resultMap = new HashMap<>(); | |||
| // String body = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | |||
| logger.info("抖音支付通知-----body{}"+parameterMap); | |||
| // Map<String, Object> parameterMap = JSONObject.parseObject(body, Map.class); | |||
| logger.info("抖音通知-----body{}"+parameterMap); | |||
| try { | |||
| // Map<String, Object> parameterMap = JSONObject.parseObject(body, Map.class); | |||
| String timestamp = (String) parameterMap.get("timestamp"); | |||
| String nonce = (String) parameterMap.get("nonce"); | |||
| // {"appid":"tt9da4eb19029c2bb301","cp_orderno":"557490321114062848","cp_extra":"","way":"2","channel_no":"2021052622001418391405536769","channel_gateway_no":"12105260162116189897","payment_order_no":"2021052622001418391405536769","out_channel_order_no":"","total_amount":100} | |||
| String msg = (String) parameterMap.get("msg"); | |||
| String type = (String) parameterMap.get("type"); | |||
| String msgSignature = (String) parameterMap.get("msg_signature"); | |||
| String version = (String) parameterMap.get("version"); | |||
| Map<String, Object> pMap = JSONObject.parseObject(msg, Map.class); | |||
| String appid = (String) pMap.get("appid"); | |||
| WxAppinfo appinfo = appinfoService.getByAppId(appid); | |||
| WxPayAccount payAccount = payAccountService.getById(appinfo.getPayId()); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("token",payAccount.getNotifyToken()); | |||
| paramMap.put("timestamp",timestamp); | |||
| paramMap.put("nonce",nonce); | |||
| paramMap.put("msg",msg); | |||
| String sign = DouYinPayHelper.getTTBackSign(paramMap, "SHA1"); | |||
| if(!msgSignature.equalsIgnoreCase(sign)){ | |||
| resultMap.put("err_tips","error"); | |||
| return resultMap; | |||
| String appid; | |||
| WxAppinfo appinfo; | |||
| WxPayAccount payAccount; | |||
| String out_order_no; | |||
| if(StringUtils.isNotBlank(version) && "2.0".equals(version)){//支付2.0 回调 | |||
| String msgSignature = request.getHeader("Byte-Signature"); | |||
| String timestamp = request.getHeader("Byte-Timestamp"); | |||
| String nonce = request.getHeader("Byte-Nonce-Str"); | |||
| appid = (String) pMap.get("app_id"); | |||
| appinfo = appinfoService.getByAppId(appid); | |||
| payAccount = payAccountService.getById(appinfo.getPayId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| String beforeSign = String.format("%s\n%s\n%s\n", | |||
| timestamp, | |||
| nonce, | |||
| JSON.toJSONString(parameterMap)); | |||
| boolean verify = ttPayService.getConfig().getVerifier().verify(beforeSign.getBytes(StandardCharsets.UTF_8), msgSignature); | |||
| if(!verify){ | |||
| logger.info("抖音通知(2.0)-----{}签名效验失败"); | |||
| resultMap.put("err_tips","error"); | |||
| return resultMap; | |||
| } | |||
| logger.info("抖音通知(2.0)-----{}签名效验成功"); | |||
| out_order_no = (String)pMap.get("out_order_no"); | |||
| }else{ | |||
| String msgSignature = (String) parameterMap.get("msg_signature"); | |||
| String timestamp = (String) parameterMap.get("timestamp"); | |||
| String nonce = (String) parameterMap.get("nonce"); | |||
| appid = (String) pMap.get("appid"); | |||
| appinfo = appinfoService.getByAppId(appid); | |||
| payAccount = payAccountService.getById(appinfo.getPayId()); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("token",payAccount.getNotifyToken()); | |||
| paramMap.put("timestamp",timestamp); | |||
| paramMap.put("nonce",nonce); | |||
| paramMap.put("msg",msg); | |||
| String sign = DouYinPayHelper.getTTBackSign(paramMap, "SHA1"); | |||
| if(!msgSignature.equalsIgnoreCase(sign)){ | |||
| logger.info("抖音通知-----{}签名效验失败"); | |||
| resultMap.put("err_tips","error"); | |||
| return resultMap; | |||
| } | |||
| logger.info("抖音通知-----{}签名效验成功"); | |||
| out_order_no = (String) pMap.get("cp_orderno"); | |||
| } | |||
| if("payment".equals(type)){//支付回调 | |||
| String cp_orderno = (String) pMap.get("cp_orderno");//开发者传入订单号 | |||
| String way = (String) pMap.get("way");//2-支付宝,1-微信 | |||
| if (!StringUtils.isNotBlank(cp_orderno)) { | |||
| if (!StringUtils.isNotBlank(out_order_no)) { | |||
| try { | |||
| Long payOrderId = Long.valueOf(cp_orderno); | |||
| WxPayOrder wxpayOrder = wxPayOrderService.getById(payOrderId, appinfo.getTenantId()); | |||
| Long orderId = Long.valueOf(out_order_no); | |||
| WxPayOrder wxpayOrder = wxPayOrderService.getById(orderId, appinfo.getTenantId()); | |||
| if(wxpayOrder == null){ | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.setTenantId(appinfo.getTenantId()); | |||
| tenantEntity.setParentTenantId(appinfo.getParentTenantId()); | |||
| WxBatchOrder batchOrder = wxOrderService.getWxBatchOrder(tenantEntity,orderId); | |||
| if(batchOrder == null){ | |||
| logger.error("未找到订单"+orderId); | |||
| } | |||
| wxpayOrder = new WxPayOrder(); | |||
| wxpayOrder.setOrderId(orderId); | |||
| wxpayOrder.updateTenantInfo(tenantEntity); | |||
| wxpayOrder.setPayVendor(batchOrder.getPayVendor()); | |||
| wxpayOrder.setComposeOrder(batchOrder.getOrderType()); | |||
| } | |||
| PayQueryAdapterResult queryResult = payServiceFactory.getPayAdapterService(wxpayOrder.getPayVendor()).queryPayStatus(wxpayOrder, appinfo, payAccount); | |||
| if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode() == queryResult.getCode()) { | |||
| WxComposeOrder composeOrder = orderFactory.getOrderAdapterService(wxpayOrder.getComposeOrder()).getComposeOrder(wxpayOrder.getOrderId(), wxpayOrder.getTenantId()); | |||
| wxPayOrderService.handleSuccessOrder(wxpayOrder, composeOrder, queryResult, true,false); | |||
| } | |||
| } catch (NumberFormatException e) { | |||
| logger.error("payOrderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | |||
| logger.error("payOrderId参数不正确: " + toString() + ", e:" + e.getMessage()); | |||
| } | |||
| } | |||
| @@ -353,7 +353,7 @@ public class OrderExpiringSchedule { | |||
| wxOrderMapper.updateById(updateOrder); | |||
| logger.info("券订单: " + order.getId() + " create at " + order.getCreateDate() + " expired at " + new Date()); | |||
| wxOrderService.sendInsideOrderPushMsg(order,order.getComposeOrderId()); | |||
| // wxOrderService.sendInsideOrderPushMsg(order,order.getComposeOrderId()); | |||
| } | |||
| @@ -23,19 +23,19 @@ public class TtOrderPushErrorSchedule { | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Async | |||
| @Scheduled(cron = "0 0 1 * * ?") | |||
| public void OrderPushErrorTaskSchedule() { | |||
| List<TtOrderPushError> orderPushErrors = ttOrderPushErrorMapper.findList(new TtOrderPushError()); | |||
| if(orderPushErrors != null && orderPushErrors.size() > 0){ | |||
| for (TtOrderPushError error:orderPushErrors) { | |||
| try{ | |||
| wxOrderService.sendInsideOrderPushMsg(error,error.getId()); | |||
| }catch(Exception e){ | |||
| logger.error("订单同步重试error"); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| // @Async | |||
| // @Scheduled(cron = "0 0 1 * * ?") | |||
| // public void OrderPushErrorTaskSchedule() { | |||
| // List<TtOrderPushError> orderPushErrors = ttOrderPushErrorMapper.findList(new TtOrderPushError()); | |||
| // if(orderPushErrors != null && orderPushErrors.size() > 0){ | |||
| // for (TtOrderPushError error:orderPushErrors) { | |||
| // try{ | |||
| // wxOrderService.sendInsideOrderPushMsg(error,error.getId()); | |||
| // }catch(Exception e){ | |||
| // logger.error("订单同步重试error"); | |||
| // } | |||
| // } | |||
| // } | |||
| // } | |||
| } | |||
| @@ -1,5 +1,8 @@ | |||
| package com.iformall.domain.po; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| @@ -59,4 +62,15 @@ public class WxBatchOrder extends TenantEntity { | |||
| return null; | |||
| } | |||
| public Object getExpParamValue(String key) { | |||
| if (StringUtils.isBlank(extParam)) { | |||
| return null; | |||
| } | |||
| JSONObject o = JSON.parseObject(extParam); | |||
| if (null == o ) { | |||
| return null; | |||
| } | |||
| return o.get(key); | |||
| } | |||
| } | |||
| @@ -106,7 +106,7 @@ public class TtPayOrderQueryV2Result implements Serializable { | |||
| * 担保支付单id | |||
| */ | |||
| @SerializedName(value = "payment_order_id") | |||
| private Integer paymentOrderId; | |||
| private String paymentOrderId; | |||
| /** | |||
| * 订单核销类型: | |||
| @@ -258,4 +258,6 @@ public interface WxOrderService { | |||
| WxBatchOrder batchOrderDetail(WxBatchOrder border); | |||
| void cancelOrderBatchOrder(WxBatchOrder border,WxPayOrder payOrder); | |||
| WxBatchOrder getWxBatchOrder(TenantEntity tenantInfo, Long orderId); | |||
| } | |||
| @@ -2266,10 +2266,10 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| logger.error("订单状态更新失败, e:" + e.getMessage(),e); | |||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
| } | |||
| if(ret == 1){ | |||
| //订单同步 | |||
| sendInsideOrderPushMsg(oldOrder,oldOrder.getComposeOrderId()); | |||
| } | |||
| // if(ret == 1){ | |||
| // //订单同步 | |||
| // sendInsideOrderPushMsg(oldOrder,oldOrder.getComposeOrderId()); | |||
| // } | |||
| return ret; | |||
| } | |||
| @@ -3554,6 +3554,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| @Override | |||
| public WxBatchOrder getWxBatchOrder(TenantEntity tenantInfo, Long orderId) { | |||
| return wxBatchOrderMapper.selectById(orderId,tenantInfo.getTenantId()); | |||
| } | |||
| private Map<Long,List<WxOrderCouponVo>> getBatchOrderMap(TenantEntity tenantEntity,List<Long> batchOrderIds){ | |||
| WxOrder recordQ = new WxOrder(); | |||
| recordQ.updateTenantInfo(tenantEntity); | |||
| @@ -12,6 +12,7 @@ import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| @@ -130,14 +131,112 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| @Override | |||
| public void handleSuccessOrder(WxPayOrder oldRecord,WxComposeOrder composeOrder,PayQueryAdapterResult queryResult,boolean isScheduleTask,boolean isOneChildOrder) { | |||
| Date curDate = new Date(); | |||
| if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) { | |||
| WxPayOrderServiceImpl proxy = (WxPayOrderServiceImpl) AopContext.currentProxy(); | |||
| //因为此处是处理订单支付成功了但是订单状态为未支付成功的异常状态,库存不应该再扣减 | |||
| //更新wxPayOrder | |||
| oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| if(EnumPayWay.PAY_WAY_TT.getCode().equals(oldRecord.getPayVendor()) && oldRecord.getId() == null){ | |||
| EnumPayShare isShare = EnumPayShare.NO; | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(oldRecord, EnumPayWay.getEnum(oldRecord.getPayVendor()).getPlat()); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| if (payAccount.checkShare()) { | |||
| isShare = EnumPayShare.YES; | |||
| } | |||
| TtPayOrderQueryV2Result result = (TtPayOrderQueryV2Result) queryResult.getData(); | |||
| WxBatchOrder batchOrder = wxBatchOrderMapper.selectById(oldRecord.getOrderId(), oldRecord.getTenantId()); | |||
| String open_id = (String) batchOrder.getExpParamValue("open_id"); | |||
| oldRecord.setId(oldRecord.getOrderId()); | |||
| oldRecord.setOpenId(open_id); | |||
| oldRecord.setComposeOrder(batchOrder.getOrderType()); | |||
| oldRecord.setCreateTime(curDate); | |||
| oldRecord.setUpdateTime(curDate); | |||
| oldRecord.setPayTimeStart(batchOrder.getCreateDate()); | |||
| oldRecord.setPayOrderNo(result.getPaymentOrderId()); | |||
| oldRecord.setPayAmount(result.getTotalFee()); | |||
| oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| oldRecord.setTtPayWay(result.getPayChannel()); | |||
| String timEndStr = queryResult.getEndTimeStr(); | |||
| Date timeEnd = null; | |||
| try { | |||
| timeEnd = Utility.getDateFromString(timEndStr); | |||
| } catch (ParseException e) { | |||
| logger.error("解析timeEnd失败"); | |||
| timeEnd = new Date(); | |||
| } | |||
| oldRecord.setPayTimeEnd(timeEnd); | |||
| oldRecord.setPayEndFrom(EnumPayEndFrom.QUERY.getCode()); | |||
| oldRecord.setTransactionId(queryResult.getTransactionId()); | |||
| oldRecord.setShare(isShare.getCode()); | |||
| if (isShare == EnumPayShare.YES) { | |||
| PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(oldRecord.getPayVendor()); | |||
| PayShareCalculateAmount recordShareAmount = payShareServie.calculateAmount(oldRecord.getPayAmount(), payAccount); | |||
| // 分账金额 | |||
| Integer share_amount = recordShareAmount.getShareAmount(); | |||
| oldRecord.setShareAmount(share_amount); | |||
| oldRecord.setRateAmount(recordShareAmount.getRateAmount()); | |||
| //设置子订单分账金额 | |||
| Map<String,WxComposeChildOrderShare> childShares = new HashMap<String,WxComposeChildOrderShare>(); | |||
| OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()); | |||
| List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); | |||
| if(null != orderList && orderList.size() > 0) { | |||
| for (WxOrder o : orderList) { | |||
| PayShareCalculateAmount oShareAmount = payShareServie.calculateAmount(o.getPayment(), payAccount); | |||
| Integer orderShareAmount = oShareAmount.getShareAmount(); | |||
| Integer orderRateAmount = oShareAmount.getRateAmount(); | |||
| childShares.put(String.valueOf(o.getId()), new WxComposeChildOrderShare(o.getPayment(), orderShareAmount, orderRateAmount)); | |||
| } | |||
| oldRecord.setChildOrderShare(JSON.toJSONString(childShares)); | |||
| } | |||
| } | |||
| int sqlRow = wxPayOrderMapper.insert(oldRecord); | |||
| WxPayOrderServiceImpl proxy = (WxPayOrderServiceImpl) AopContext.currentProxy(); | |||
| if (!EnumComposeOrder.isSingle(composeOrder.getComposeOrderType())) { | |||
| //如果是组合订单的单独处理。如定时处理的单个订单 | |||
| if (isOneChildOrder) { | |||
| //处理其他信息 | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(composeOrder.getSingleOrder(),oldRecord, queryResult.getTransactionId(),isScheduleTask); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| }else { | |||
| List<WxOrder> orderList = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()).getChildOrders(composeOrder, oldRecord.getTenantId()); | |||
| for (WxOrder o : orderList) { | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(o,oldRecord, queryResult.getTransactionId(), isScheduleTask); | |||
| }catch(Exception e) { | |||
| logger.error("handleSuccessOrder error.",e); | |||
| } | |||
| } | |||
| } | |||
| }else { | |||
| //处理其他信息 | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(composeOrder.getSingleOrder(),oldRecord, queryResult.getTransactionId(),isScheduleTask); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| }else if(oldRecord.getId() != null && oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_SUCCESS.getCode()){ | |||
| WxPayOrderServiceImpl proxy = (WxPayOrderServiceImpl) AopContext.currentProxy(); | |||
| //因为此处是处理订单支付成功了但是订单状态为未支付成功的异常状态,库存不应该再扣减 | |||
| //更新wxPayOrder | |||
| oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| oldRecord.setTtPayWay(queryResult.getWay()); | |||
| String timEndStr = queryResult.getEndTimeStr(); | |||
| Date timeEnd = null; | |||
| String timEndStr = queryResult.getEndTimeStr(); | |||
| Date timeEnd = null; | |||
| try { | |||
| timeEnd = Utility.getDateFromString(timEndStr); | |||
| } catch (ParseException e) { | |||
| @@ -149,39 +248,38 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| String transactionId = queryResult.getTransactionId(); | |||
| oldRecord.setTransactionId(transactionId); | |||
| oldRecord.setUpdateTime(curDate); | |||
| wxPayOrderMapper.updateById(oldRecord); | |||
| if (!EnumComposeOrder.isSingle(composeOrder.getComposeOrderType())) { | |||
| //如果是组合订单的单独处理。如定时处理的单个订单 | |||
| if (isOneChildOrder) { | |||
| //处理其他信息 | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(composeOrder.getSingleOrder(),oldRecord, transactionId,isScheduleTask); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| }else { | |||
| List<WxOrder> orderList = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()).getChildOrders(composeOrder, oldRecord.getTenantId()); | |||
| for (WxOrder o : orderList) { | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(o,oldRecord, transactionId, isScheduleTask); | |||
| }catch(Exception e) { | |||
| logger.error("handleSuccessOrder error.",e); | |||
| } | |||
| } | |||
| } | |||
| }else { | |||
| //处理其他信息 | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(composeOrder.getSingleOrder(),oldRecord, transactionId,isScheduleTask); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| //订单同步消息 | |||
| wxOrderService.sendInsideOrderPushMsg(composeOrder,composeOrder.getMainOrderId()); | |||
| wxPayOrderMapper.updateById(oldRecord); | |||
| } | |||
| if (!EnumComposeOrder.isSingle(composeOrder.getComposeOrderType())) { | |||
| //如果是组合订单的单独处理。如定时处理的单个订单 | |||
| if (isOneChildOrder) { | |||
| //处理其他信息 | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(composeOrder.getSingleOrder(),oldRecord, transactionId,isScheduleTask); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| }else { | |||
| List<WxOrder> orderList = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()).getChildOrders(composeOrder, oldRecord.getTenantId()); | |||
| for (WxOrder o : orderList) { | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(o,oldRecord, transactionId, isScheduleTask); | |||
| }catch(Exception e) { | |||
| logger.error("handleSuccessOrder error.",e); | |||
| } | |||
| } | |||
| } | |||
| }else { | |||
| //处理其他信息 | |||
| try { | |||
| proxy.handleOrderPaySingleOrderSuccess(composeOrder.getSingleOrder(),oldRecord, transactionId,isScheduleTask); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| //订单同步消息 | |||
| // wxOrderService.sendInsideOrderPushMsg(composeOrder,composeOrder.getMainOrderId()); | |||
| } | |||
| } | |||
| @@ -250,7 +348,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| String productName = orderAdapterService.getPayProductName(lastCoupon); | |||
| PayAdapterResult payResult = createPayOrder(appInfo, user, record,composeOrder,productName, payWay, params); | |||
| if (payResult.isSuccess()) { | |||
| wxOrderService.sendInsideOrderPushMsg(composeOrder,composeOrder.getMainOrderId()); | |||
| // wxOrderService.sendInsideOrderPushMsg(composeOrder,composeOrder.getMainOrderId()); | |||
| return new ResultData(Result.SUCCESS,"创建支付单成功",payResult.getData()); | |||
| }else { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), payResult.getMsg(), payResult.getData()); | |||
| @@ -49,7 +49,7 @@ public class FmInsideCouponVerifyMsgServiceImpl implements MsgSendService { | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "门店未找到" + msg.getMerchantId()); | |||
| } | |||
| orderService.sendInsideOrderPushMsg(couponOrder,couponOrder.getComposeOrderId()); | |||
| // orderService.sendInsideOrderPushMsg(couponOrder,couponOrder.getComposeOrderId()); | |||
| couponOrderService.actionAfterVerify(couponOrder, merchant); | |||
| } | |||
| @@ -1,12 +1,16 @@ | |||
| package com.iformall.service.pay.service.pay.douyin; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.douyin.miniapp.api.TtMaService; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.orderQuery.OrderQueryResult; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.MaUtil; | |||
| @@ -21,14 +25,43 @@ import java.io.File; | |||
| @Slf4j | |||
| public class BaseTtPayAdapterService { | |||
| @Autowired | |||
| protected MaUtil maUtil; | |||
| protected PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), oldRecord.getPayOrderNo(), null); | |||
| int code = DouYinPayHelper.getPayStatusFromOrderQueryResult(orderQueryResult,oldRecord.getPayOrderNo()); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(),orderQueryResult.getWay(), orderQueryResult,oldRecord.getTransactionId(),orderQueryResult.getPayTime()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtPayOrderQueryV2Result ttPayOrderQueryV2Result = ttPayService.queryOrderV2(null, oldRecord.getOrderId().toString()); | |||
| int code = getPayStatusFromOrderQueryResult(ttPayOrderQueryV2Result); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(), | |||
| ttPayOrderQueryV2Result.getPayChannel(), ttPayOrderQueryV2Result,ttPayOrderQueryV2Result.getOrderId(),ttPayOrderQueryV2Result.getPayTime()); | |||
| // OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), oldRecord.getPayOrderNo(), null); | |||
| // int code = DouYinPayHelper.getPayStatusFromOrderQueryResult(orderQueryResult,oldRecord.getPayOrderNo()); | |||
| // PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(),orderQueryResult.getWay(), orderQueryResult,oldRecord.getTransactionId(),orderQueryResult.getPayTime()); | |||
| return result; | |||
| } | |||
| private int getPayStatusFromOrderQueryResult(TtPayOrderQueryV2Result result){ | |||
| if(result == null){ | |||
| return EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode(); | |||
| } | |||
| String orderStatus = result.getOrderStatus(); | |||
| if(StringUtils.isBlank(orderStatus)){ | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getCode(); | |||
| }else if("PROCESS".equals(orderStatus)){ | |||
| return EnumPayStatus.PAY_STATUS_WAIT.getCode(); | |||
| }else if("SUCCESS".equals(orderStatus)){ | |||
| return EnumPayStatus.PAY_STATUS_SUCCESS.getCode(); | |||
| }else if("FAIL".equals(orderStatus)){ | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getCode(); | |||
| }else if("TIMEOUT".equals(orderStatus)){ | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getCode(); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询抖音支付状态失败"+result.getOutOrderNo()); | |||
| } | |||
| protected int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return statusObject.getCode(); | |||
| } | |||
| @@ -46,8 +79,7 @@ public class BaseTtPayAdapterService { | |||
| return new PayAdapterResult(true, "订单撤销成功", null, null); | |||
| } | |||
| @Autowired | |||
| protected MaUtil maUtil; | |||
| protected File getQrCode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws WxErrorException { | |||
| TtMaService ttappService = maUtil.getTtMaService(appinfo); | |||
| @@ -538,6 +538,11 @@ public final class Utility { | |||
| return sdf.parse(timeEnd); | |||
| } | |||
| public static Date getDateTtFromString(String timeEnd) throws ParseException { | |||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| return sdf.parse(timeEnd); | |||
| } | |||
| public static String getOrderNo() { | |||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| String dateStr = sdf.format(new Date()); | |||