| @@ -0,0 +1,204 @@ | |||
| UPDATE `mallink`.`wx_appinfo` SET `tenant_id` = '0', `type` = 10 WHERE `app_id` = 'awf1mjtw8wtn5t85'; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_0` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_1` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_2` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_3` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_4` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_5` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_6` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_7` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_8` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_9` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_10` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_11` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_12` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_13` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_14` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_15` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_16` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_17` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_18` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_19` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_20` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_21` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_22` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_23` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_24` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_25` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_26` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_27` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_28` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_29` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_30` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_31` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_32` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_33` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_34` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_35` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_36` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_37` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_38` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_39` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_40` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_41` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_42` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_43` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_44` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_45` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_46` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_47` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_48` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_49` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_50` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_51` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_52` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_53` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_54` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_55` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_56` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_57` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_58` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_59` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_60` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_61` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_62` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_63` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_64` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_65` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_66` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_67` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_68` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_69` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_70` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_71` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_72` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_73` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_74` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_75` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_76` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_77` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_78` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_79` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_80` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_81` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_82` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_83` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_84` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_85` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_86` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_87` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_88` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_89` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_90` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_91` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_92` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_93` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_94` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_95` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_96` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_97` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_98` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| ALTER TABLE `mallink`.`wx_profit_sharing_order_99` | |||
| ADD COLUMN `out_settle_no` bigint(20) AFTER `parent_tenant_id`; | |||
| @@ -44,7 +44,7 @@ public class SharingOrderRedoSchedule { | |||
| @Async | |||
| // @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨02:00分账重试 | |||
| @Scheduled(cron = "0 0/10 * * * ?") // 测试 | |||
| public void sharingOrderResultSchedule() { | |||
| public void sharingOrderRedoSchedule() { | |||
| List<WxMall> malls = getMalls(); | |||
| for (WxMall mall: malls) { | |||
| WxProfitSharingOrder wxProfitSharingOrder = new WxProfitSharingOrder(); | |||
| @@ -115,4 +115,37 @@ public class SharingOrderRedoSchedule { | |||
| } | |||
| } | |||
| @Async | |||
| // @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨02:00分账重试 | |||
| @Scheduled(cron = "0 0/10 * * * ?") // 测试 | |||
| public void sharingOrderHanderSchedule() { | |||
| List<WxMall> malls = getMalls(); | |||
| for (WxMall mall: malls) { | |||
| WxProfitSharingOrder wxProfitSharingOrder = new WxProfitSharingOrder(); | |||
| wxProfitSharingOrder.setTenantId(mall.getTenantId()); | |||
| wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode()); | |||
| List<WxProfitSharingOrder> list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); | |||
| if (null != list) { | |||
| list.stream().forEach(sharingOrder->{ | |||
| try { | |||
| ResultData result = wxProfitSharingOrderService.handerSharingOrder(sharingOrder); | |||
| if (result.code != ResultData.SUCCESS) { | |||
| logger.error("处理分账数据失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getMessage() | |||
| + " ID:" +sharingOrder.getId() | |||
| + " RES:" + result.message); | |||
| } | |||
| } catch (Exception e){ | |||
| logger.error("处理分账数据失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getMessage() | |||
| + " ID:" +sharingOrder.getId() | |||
| + " MSG:" + e.getMessage()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -25,6 +25,9 @@ public class WxSharingOrderDto extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="分账通道费差()",name="rateAmount") | |||
| private Integer rateAmount; | |||
| private Integer realRateAmount;//平台手续费 | |||
| private Integer commissionAmount;//平台佣金 | |||
| @io.swagger.annotations.ApiModelProperty(value="支付发起时间",name="payTimeStart") | |||
| private Date payTimeStart; | |||
| @io.swagger.annotations.ApiModelProperty(value="支付结束时间",name="payTimeEnd") | |||
| @@ -74,12 +74,13 @@ public class WxPayOrder extends TenantEntity { | |||
| public WxComposeChildOrderShare getChildOrderShare(Long wxOrderId) { | |||
| if (StringUtils.isBlank(this.childOrderShare)) { | |||
| return new WxComposeChildOrderShare(this.payAmount, this.shareAmount, this.rateAmount); | |||
| return new WxComposeChildOrderShare(this.payAmount, this.shareAmount, this.rateAmount,null,null); | |||
| } | |||
| Map childs = JSON.parseObject(this.childOrderShare, Map.class); | |||
| JSONObject childOrderShare = (JSONObject) childs.get(String.valueOf(wxOrderId)); | |||
| if (null != childOrderShare) { | |||
| return new WxComposeChildOrderShare(childOrderShare.getInteger("realPayMent"), childOrderShare.getInteger("shareAmount"), childOrderShare.getInteger("rateAmount")); | |||
| return new WxComposeChildOrderShare(childOrderShare.getInteger("realPayMent"), childOrderShare.getInteger("shareAmount"), childOrderShare.getInteger("rateAmount"), | |||
| childOrderShare.getInteger("realRateAmount"), childOrderShare.getInteger("commissionAmount")); | |||
| } | |||
| return null; | |||
| } | |||
| @@ -14,6 +14,8 @@ public class WxProfitSharingOrder extends TenantEntity { | |||
| protected Long id; | |||
| private Long outSettleNo; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId") | |||
| private Long merchantId; | |||
| @io.swagger.annotations.ApiModelProperty(value="订单ID",name="orderId") | |||
| @@ -49,6 +49,12 @@ public class WxProfitSharingReceiver extends TenantEntity { | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="真实费率",name="rateAmount") | |||
| private Integer rateAmount; | |||
| @TableField(exist = false) | |||
| private Integer realRateAmount;//平台手续费 | |||
| @TableField(exist = false) | |||
| private Integer commissionAmount;//平台佣金 | |||
| @io.swagger.annotations.ApiModelProperty(value = "0,不使用 1,使用", name = "isUse") | |||
| private Integer isUse; | |||
| @@ -173,7 +173,8 @@ public abstract class BaseTtPayServiceImpl implements TtPayService { | |||
| if(baseTtPayResult.isSuccess()){ | |||
| return baseTtPayResult.getData(); | |||
| }else{ | |||
| if(baseTtPayResult.getErrNo().intValue() == 20004){//{"data":null,"resp_extra":{"logid":"2022070417115501015816204403C85851"},"err_no":20004,"err_tips":"订单不属于cps订单"} | |||
| if(baseTtPayResult.getErrNo().intValue() == 20000 //{"logid":"20220707000000010212150024092FBB3B"},"err_no":20000,"err_tips":"订单不存在"} | |||
| || baseTtPayResult.getErrNo().intValue() == 20004){//{"data":null,"resp_extra":{"logid":"2022070417115501015816204403C85851"},"err_no":20004,"err_tips":"订单不属于cps订单"} | |||
| return null; | |||
| } | |||
| throw new TtPayException(baseTtPayResult.getErrTips()); | |||
| @@ -4,9 +4,10 @@ package com.iformall.enums; | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumProfitSharingOrderStatus { | |||
| PROFIT_SHARING_UNKNOWN(0, "未知"), | |||
| PROFIT_SHARING_UNKNOWN(-1, "未知"), | |||
| PROFIT_SHARING_READY(0, "准备分账"), | |||
| PROFIT_SHARING_REQ_FAILED(1, "提交订单失败"), | |||
| PROFIT_SHARING_APPLY_FAILED(2, "提交业务失败"), | |||
| PROFIT_SHARING_APPLY_FAILED(2, "提交业务失败"),//重试状态 | |||
| PROFIT_SHARING_ACCEPTED(3, "受理成功"), | |||
| PROFIT_SHARING_PROCESSING(4, "处理中"), | |||
| PROFIT_SHARING_DONE(5, "处理完成"), | |||
| @@ -5,6 +5,7 @@ package com.iformall.enums; | |||
| */ | |||
| public enum EnumProfitSharingResultStatus { | |||
| PROFIT_SHARING_UNKNOWN(-1, "未知"), | |||
| PROFIT_SHARING_READY(0, "准备分账"), | |||
| PROFIT_SHARING_RESULT_PENDING(1, "待分账"), | |||
| PROFIT_SHARING_RESULT_SUCCESS(2, "分账成功"), | |||
| PROFIT_SHARING_RESULT_ADJUST(3, "分账失败待调账"), | |||
| @@ -54,4 +54,5 @@ public interface WxProfitSharingOrderService { | |||
| void updatetttttttttttttt(String tenantId); | |||
| ResultData handerSharingOrder(WxProfitSharingOrder sharingOrder); | |||
| } | |||
| @@ -1684,18 +1684,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay,boolean mulityShare) { | |||
| // 微信分账 | |||
| try { | |||
| //如果是抖音支付 只能单次分账 | |||
| if(EnumPayWay.PAY_WAY_TT.getCode().equals(payWay) && mulityShare){ | |||
| mulityShare = false; | |||
| // logger.error("抖音支付 只能单次分账: "); | |||
| // return; | |||
| } | |||
| WxPayOrder wxPayOrder = new WxPayOrder(); | |||
| // Long orderId = couponOrder.getOrderId(); | |||
| // | |||
| // if (!EnumComposeOrder.isSingle(couponOrder.getComposeOrderType())) { | |||
| // orderId = couponOrder.getComposeOrderId(); | |||
| // } | |||
| wxPayOrder.updateTenantInfo(couponOrder); | |||
| wxPayOrder.setOrderId(couponOrder.getComposeOrderId()); | |||
| @@ -1744,6 +1734,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| wxSharingOrderDto.setPayAmount(wxPayOrder.getPayAmount()); | |||
| wxSharingOrderDto.setShareAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getShareAmount()); | |||
| wxSharingOrderDto.setRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRateAmount()); | |||
| wxSharingOrderDto.setRealRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRealRateAmount()); | |||
| wxSharingOrderDto.setCommissionAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getCommissionAmount()); | |||
| wxSharingOrderDto.setOrderId(wxPayOrder.getId()); | |||
| wxSharingOrderDto.setPayTimeStart(wxPayOrder.getPayTimeStart()); | |||
| wxSharingOrderDto.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); | |||
| @@ -2551,6 +2551,8 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| sharingOrder.setPayAmount(wxPayOrder.getPayAmount()); | |||
| sharingOrder.setShareAmount(wxPayOrder.getChildOrderShare(orderId).getShareAmount()); | |||
| sharingOrder.setRateAmount(wxPayOrder.getChildOrderShare(orderId).getRateAmount()); | |||
| sharingOrder.setRealRateAmount(wxPayOrder.getChildOrderShare(orderId).getRealRateAmount()); | |||
| sharingOrder.setCommissionAmount(wxPayOrder.getChildOrderShare(orderId).getCommissionAmount()); | |||
| sharingOrder.setOrderId(wxPayOrder.getId()); | |||
| sharingOrder.setPayTimeStart(wxPayOrder.getPayTimeStart()); | |||
| sharingOrder.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); | |||
| @@ -3501,7 +3503,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| public void sendInsideOrderPushDeliveryMsg(TenantEntity tenantEntity, Long composeOrderId,Long couponOrderId) { | |||
| try{ | |||
| FmInsideOrderPushMsg orderPush = new FmInsideOrderPushMsg(); | |||
| orderPush.setDelayTimeLevel(5); | |||
| orderPush.setDelayTimeLevel(3); | |||
| orderPush.setMsgType(EnumMsgRecordType.INSIDE_ORDER_PUSH_DELIVERY.getCode()); | |||
| orderPush.updateTenantInfo(tenantEntity); | |||
| orderPush.setBatchOrderId(composeOrderId); | |||
| @@ -417,7 +417,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| record.setShare(isShare.getCode()); | |||
| record.setComposeOrder(composeOrder.getComposeOrderType()); | |||
| if (isShare == EnumPayShare.YES) { | |||
| // if (isShare == EnumPayShare.YES) { | |||
| PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode()); | |||
| // PayShareCalculateAmount recordShareAmount = payShareServie.calculateAmount(record.getPayAmount(), payAccount); | |||
| @@ -429,23 +429,24 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| 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) { | |||
| int share_amount = 0; | |||
| int rate_amount = 0; | |||
| for (WxOrder o : orderList) { | |||
| int rate = payShareServie.getOfficialCommission(o,payAccount); | |||
| PayShareCalculateAmount oShareAmount = payShareServie.calculateAmount(o.getPayment(),rate, payAccount); | |||
| share_amount += oShareAmount.getShareAmount(); | |||
| rate_amount += oShareAmount.getRateAmount(); | |||
| Integer orderShareAmount = oShareAmount.getShareAmount(); | |||
| Integer orderRateAmount = oShareAmount.getRateAmount(); | |||
| childShares.put(String.valueOf(o.getId()), new WxComposeChildOrderShare(o.getPayment(), orderShareAmount, orderRateAmount)); | |||
| } | |||
| record.setShareAmount(share_amount); | |||
| record.setRateAmount(rate_amount); | |||
| record.setChildOrderShare(JSON.toJSONString(childShares)); | |||
| } | |||
| } | |||
| if(orderList == null || orderList.isEmpty()){ | |||
| logger.error("getChildOrders null" + record.toString()); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); | |||
| } | |||
| int share_amount = 0; | |||
| int rate_amount = 0; | |||
| //todo 注意购物车模式(需测试)每笔子订单算法可能与总订单算法有差 | |||
| for (WxOrder o : orderList) { | |||
| int rate = payShareServie.getOfficialCommission(o,payAccount);//抖音分佣率 | |||
| PayShareCalculateAmount oShareAmount = payShareServie.calculateAmount(o.getPayment(),rate, payAccount); | |||
| share_amount += oShareAmount.getShareAmount(); | |||
| rate_amount += oShareAmount.getRateAmount(); | |||
| childShares.put(String.valueOf(o.getId()), new WxComposeChildOrderShare(oShareAmount)); | |||
| } | |||
| record.setShareAmount(share_amount); | |||
| record.setRateAmount(rate_amount); | |||
| record.setChildOrderShare(JSON.toJSONString(childShares)); | |||
| // } | |||
| int sqlRow = wxPayOrderMapper.insert(record); | |||
| record.setCreatPay(true); | |||
| @@ -455,41 +456,17 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| } | |||
| } | |||
| PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payWay.getCode()); | |||
| if(!isCreatePay){ | |||
| PayAdapterResult par = new PayAdapterResult(); | |||
| par.setSuccess(true); | |||
| Map<String,Object> map = new HashMap<>(); | |||
| map.put("outOrderNo",record.getOrderId()); | |||
| map.put("createPay",record.isCreatPay()); | |||
| if(record.isCreatPay()){ | |||
| Map<String,Integer> payment = new HashMap(); | |||
| payment.put("totalAmount",composeOrder.getPayment()); | |||
| map.put("payment",payment); | |||
| List<Map<String,Object>> goodsList = new ArrayList<>(); | |||
| Map<Long, List<WxOrder>> collect = childOrders.stream().collect(groupingBy(WxOrder::getCouponChannelId)); | |||
| for (Long key: collect.keySet()) { | |||
| Map<String,Object> good = new HashMap<>(); | |||
| Long couponId = wxCouponChannelMapper.findCouponIdById(key, record.getTenantId()); | |||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponId, record.getTenantId()); | |||
| TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(appInfo.getTenantId(), couponId); | |||
| int quantity = collect.get(key).size(); | |||
| good.put("quantity",quantity); | |||
| good.put("price",wxCoupon.getSalePrice()*quantity); | |||
| good.put("goodsName",wxCoupon.getTitle()); | |||
| good.put("goodsPhoto",wxCoupon.getCoverImg()); | |||
| good.put("goodsId",ttCouponChannelPoi.getSpuId()); | |||
| good.put("goodsType",1); | |||
| goodsList.add(good); | |||
| } | |||
| map.put("goodsList",goodsList); | |||
| } | |||
| par.setData(map); | |||
| return par; | |||
| PayAdapterResult payResult = payAdapterService.noCreatePay(record,composeOrder,childOrders); | |||
| return payResult; | |||
| } | |||
| logger.debug("wxPayRecord md5 before:"+record.toString()); | |||
| String beforemd5 = HashUtil.md5(record.toString()); | |||
| PayAdapterResult payResult = payServiceFactory.getPayAdapterService(payWay.getCode()).pay(payAccount, record,composeOrder,productName,isShare,appInfo, currentDate, params); | |||
| PayAdapterResult payResult = payAdapterService.pay(payAccount, record,composeOrder,productName,isShare,appInfo, currentDate, params); | |||
| String aftermd5 = HashUtil.md5(record.toString()); | |||
| if (beforemd5.equals(aftermd5)) { | |||
| logger.error("支付方式["+payWay.getCode()+"]支付接口【pay】过程中 WxPayOrder 未做更新.record:"+record.toString()); | |||
| @@ -24,6 +24,7 @@ import com.iformall.pay.*; | |||
| import com.iformall.service.ExcelService; | |||
| import com.iformall.service.WxProfitSharingOrderService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareQueryResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| @@ -32,6 +33,7 @@ import com.iformall.utils.Utility; | |||
| import cn.afterturn.easypoi.handler.inter.IExcelExportServer; | |||
| import net.sf.saxon.trans.Err; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -205,13 +207,15 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay()).haveReciversShare(appInfo, payAccount, frecord, | |||
| sharingOrder.getTransactionId(), JSONArray.parseArray(JSON.toJSONString(receivers)), EnumProfitSharingOrderType.getEnum(sharingOrder.getType())); | |||
| if (!shareResult.isSuccess()) { | |||
| sharingOrder.setOutSettleNo(frecord.getOutSettleNo()); | |||
| sharingOrder.setSharingStatus(shareResult.getCode()); | |||
| sharingOrder.setErrorMsg("REDO:"+shareResult.getMsg()); | |||
| sharingOrder.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(sharingOrder); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),sharingOrder.getErrorMsg()); | |||
| } | |||
| sharingOrder.setOutSettleNo(frecord.getOutSettleNo()); | |||
| sharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); | |||
| sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); | |||
| sharingOrder.setErrorMsg("REDO:重试分账成功"); | |||
| @@ -249,155 +253,66 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| } | |||
| @Override | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| // @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payWay,Integer share) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payWay); | |||
| if ((EnumPayWay.PAY_WAY_WECHAT.getCode().equals(payWay) | |||
| || EnumPayWay.PAY_WAY_WECHAT_MA.getCode().equals(payWay) | |||
| || EnumPayWay.PAY_WAY_WECHAT_WAP.getCode().equals(payWay)) | |||
| && EnumPayShare.NO.getCode().equals(share)){ | |||
| logger.info("微信支付不分账模式下无需分账"); | |||
| return new ResultData(); | |||
| } | |||
| WxProfitSharingOrder record = payShareAdapterService.createSharingOrder(sharingOrderDto,share); | |||
| if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) && | |||
| !sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| //准备分账列表 | |||
| WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); | |||
| psReceiverQ.updateTenantInfo(payAccount); | |||
| psReceiverQ.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| psReceiverQ.setSharingType(payServiceFactory.getPayShareAdapterService(payWay).getProfitSharingType()); | |||
| psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); | |||
| psReceiverQ.setPlat(EnumPayWay.getEnum(payWay).getPlat().getCode()); | |||
| if(EnumAppPlat.TOUTIAO.getCode().equals(psReceiverQ.getPlat())){ | |||
| psReceiverQ.setIsUse(EnumProfitSharingUse.YES.getCode()); | |||
| } | |||
| List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); | |||
| if (psReceiverList != null && psReceiverList.size() > 50) { | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); | |||
| EnumProfitSharingOrderType shareType = EnumProfitSharingOrderType.getEnum(sharingOrderDto.getType()); | |||
| if (null == shareType) { | |||
| new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),sharingOrderDto.getType()+"在分账方式中不存在。EnumProfitSharingOrderType"); | |||
| } | |||
| if(StringUtils.isNotBlank(record.getReceivers())){ | |||
| JSONArray jsonArray = JSONArray.parseArray(record.getReceivers()); | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| if (psReceiverList == null || psReceiverList.size() == 0) { //没有分账账户,直接结束分账 | |||
| if (sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) | |||
| sharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()); | |||
| if (sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_UNKNOWN); | |||
| if(sharingOrderDto.getRateAmount() != null) { | |||
| // 分账完结 | |||
| sharingOrderDto.setShareAmount(sharingOrderDto.getShareAmount()+sharingOrderDto.getRateAmount()); | |||
| PayShareResult shareResult = payShareAdapterService.haveReciversShare(appInfo, payAccount, record, | |||
| sharingOrderDto.getTransactionId(), jsonArray, shareType); | |||
| if (!shareResult.isSuccess()) { | |||
| record.setSharingStatus(shareResult.getCode()); | |||
| record.setErrorMsg(shareResult.getMsg()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),record.getErrorMsg()); | |||
| } | |||
| // sharingOrderDto.setShareAmount(sharingOrderDto.getPayAmount()); | |||
| return finishSharingOrder(sharingOrderDto,payWay,share); | |||
| } | |||
| //计算分账账户合法性 | |||
| if (psReceiverList.size() > 1 && | |||
| psReceiverList.stream().filter(r->(r.getParameter() == null)).count() > 0) { | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); | |||
| } | |||
| record.setSharingOrderNo(shareResult.getShareOrderNo()); | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| //计算分账金额合法性 | |||
| psReceiverList.stream().forEach(r-> | |||
| { | |||
| if (r.getParameter() == null){ | |||
| r.setSharingAmount(sharingOrderDto.getShareAmount()); | |||
| r.setRateAmount(sharingOrderDto.getRateAmount()); | |||
| } else { | |||
| r.setSharingAmount(sharingOrderDto.getShareAmount()*Integer.valueOf(r.getParameter())/10000); | |||
| } | |||
| }); | |||
| if (psReceiverList.stream().mapToInt(r->r.getSharingAmount()).sum() > sharingOrderDto.getShareAmount()){ | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); | |||
| } | |||
| final IdWorker idworker = IdWorker.get(); | |||
| try { | |||
| jsonArray.stream().forEach(obj -> { | |||
| JSONObject receiver =(JSONObject) obj; | |||
| Date currentDate = new Date(); | |||
| WxProfitSharingResult result = new WxProfitSharingResult(); | |||
| result.setId(idworker.nextId()); | |||
| result.updateTenantInfo(sharingOrderDto); | |||
| result.setMerchantId(record.getMerchantId()); | |||
| result.setSharingOrderId(record.getId()); | |||
| result.setSharingReceiverId(Long.valueOf(receiver.getString("description"))); | |||
| result.setPayAmount(receiver.getInteger("amount")); | |||
| result.setCreateTime(currentDate); | |||
| result.setUpdateTime(currentDate); | |||
| result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); | |||
| wxProfitSharingResultMapper.insert(result); | |||
| }); | |||
| }catch (Exception e) { | |||
| logger.error("分账详细信息为null"); | |||
| // return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); | |||
| } | |||
| //单次分账检查是否已创建分账订单 | |||
| WxProfitSharingOrder record = new WxProfitSharingOrder(); | |||
| record.updateTenantInfo(payAccount); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record = wxProfitSharingOrderMapper.selectOne(new QueryWrapper(record)); | |||
| if (record == null) { | |||
| //创建分账订单 | |||
| Date currentDate = new Date(); | |||
| record = new WxProfitSharingOrder(); | |||
| record.setId(idworker.nextId()); | |||
| record.updateTenantInfo(payAccount); | |||
| record.setTransactionId(sharingOrderDto.getTransactionId()); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record.setPayAmount(sharingOrderDto.getPayAmount()); | |||
| record.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode()); | |||
| record.setCreateTime(currentDate); | |||
| record.setUpdateTime(currentDate); | |||
| record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); | |||
| record.setPayTimeEnd(sharingOrderDto.getPayTimeEnd()); | |||
| record.setType(sharingOrderDto.getType()); | |||
| wxProfitSharingOrderMapper.insert(record); | |||
| return new ResultData(shareResult.getData()); | |||
| } | |||
| return new ResultData(); | |||
| // 添加分账接收方 | |||
| final WxProfitSharingOrder frecord = record; | |||
| JSONArray receivers = new JSONArray(); | |||
| List <WxProfitSharingResult> resultList = new ArrayList<WxProfitSharingResult>(); | |||
| psReceiverList.stream().forEach(receiver->{ | |||
| Date currentDate = new Date(); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",payServiceFactory.getPayShareAdapterService(payWay).getShareAccount(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", receiver.getSharingAmount()); | |||
| jo.put("rateAmount", receiver.getRateAmount()); | |||
| //jo.put("description",receiver.getReceiverComments()); //改为存ID, | |||
| jo.put("description",receiver.getId().toString()); //为重试做准备 | |||
| receivers.add(jo); | |||
| WxProfitSharingResult result = new WxProfitSharingResult(); | |||
| result.setId(idworker.nextId()); | |||
| result.updateTenantInfo(payAccount); | |||
| result.setMerchantId(frecord.getMerchantId()); | |||
| result.setSharingOrderId(frecord.getId()); | |||
| result.setSharingReceiverId(receiver.getId()); | |||
| result.setPayAmount(receiver.getSharingAmount()); | |||
| result.setCreateTime(currentDate); | |||
| result.setUpdateTime(currentDate); | |||
| result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); | |||
| resultList.add(result); | |||
| }); | |||
| record.setReceivers(receivers.toJSONString()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| EnumProfitSharingOrderType shareType = EnumProfitSharingOrderType.getEnum(sharingOrderDto.getType()); | |||
| if (null == shareType) { | |||
| new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),sharingOrderDto.getType()+"在分账方式中不存在。EnumProfitSharingOrderType"); | |||
| } | |||
| PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(payWay).haveReciversShare(appInfo, payAccount, frecord, | |||
| sharingOrderDto.getTransactionId(), receivers, shareType); | |||
| if (!shareResult.isSuccess()) { | |||
| record.setSharingStatus(shareResult.getCode()); | |||
| record.setErrorMsg(shareResult.getMsg()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),record.getErrorMsg()); | |||
| } | |||
| record.setSharingOrderNo(shareResult.getShareOrderNo()); | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| for (WxProfitSharingResult result:resultList) { | |||
| wxProfitSharingResultMapper.insert(result); | |||
| } | |||
| return new ResultData(shareResult.getData()); | |||
| } | |||
| @Override | |||
| @@ -426,6 +341,10 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| if(EnumPayWay.PAY_WAY_TT.getCode().equals(dto.getPayWay())){ | |||
| return new ResultData(shareResult.getData()); | |||
| } | |||
| String receivers = shareResult.getReceivers(); | |||
| if (receivers != null) { | |||
| @@ -447,8 +366,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| int i = 0; | |||
| for (i = 0; i < wxProfitSharingResultList.size(); i++) { | |||
| WxProfitSharingResult wxProfitSharingResult = wxProfitSharingResultList.get(i); | |||
| WxProfitSharingReceiver wxProfitSharingReceiver = wxProfitSharingReceiverMapper | |||
| .selectById(wxProfitSharingResult.getSharingReceiverId()); | |||
| WxProfitSharingReceiver wxProfitSharingReceiver = wxProfitSharingReceiverMapper.selectById(wxProfitSharingResult.getSharingReceiverId()); | |||
| if (wxProfitSharingReceiver == null) continue; | |||
| if (res.getString("type").equals(EnumProfitSharingReceiverType.getEnum(wxProfitSharingReceiver.getReceiverType()).getMessage()) | |||
| @@ -515,6 +433,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payWay); | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| @@ -529,7 +449,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| record.setPayAmount(sharingOrderDto.getPayAmount()); | |||
| record.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode()); | |||
| record.setSharingStatus(payShareAdapterService.getSharingOrderInitialStatus()); | |||
| record.setCreateTime(currentDate); | |||
| record.setUpdateTime(currentDate); | |||
| record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); | |||
| @@ -538,7 +458,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| wxProfitSharingOrderMapper.insert(record); | |||
| //分账提交 | |||
| PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(payWay).noReciverShare(appInfo,payAccount,record,sharingOrderDto.getTransactionId(),sharingOrderDto.getShareAmount()); | |||
| PayShareResult shareResult = payShareAdapterService.noReciverShare(appInfo,payAccount,record,sharingOrderDto.getTransactionId(),sharingOrderDto.getShareAmount()); | |||
| if (!shareResult.isSuccess()) { | |||
| record.setSharingStatus(shareResult.getCode()); | |||
| record.setErrorMsg(shareResult.getMsg()); | |||
| @@ -753,4 +673,15 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| }); | |||
| } | |||
| @Override | |||
| public ResultData handerSharingOrder(WxProfitSharingOrder sharingOrder) { | |||
| WxPayOrder payOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId(), sharingOrder.getTenantId()); | |||
| if(payOrder != null && EnumPayStatus.PAY_STATUS_SUCCESS.getCode().equals(payOrder.getPayOrderStatus())){ | |||
| PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payOrder.getPayVendor()); | |||
| return payShareAdapterService.handerSharingOrder(payOrder,sharingOrder); | |||
| }else{ | |||
| return new ResultData(ErrorCode.PAY_ORDER_NOT_FOUND); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.service.order.entity; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| import lombok.Data; | |||
| /** | |||
| @@ -10,15 +11,28 @@ import lombok.Data; | |||
| @Data | |||
| public class WxComposeChildOrderShare { | |||
| public WxComposeChildOrderShare(Integer realPayMent,Integer shareAmount,Integer rateAmount) { | |||
| public WxComposeChildOrderShare(Integer realPayMent,Integer shareAmount,Integer rateAmount,Integer realRateAmount,Integer commissionAmount) { | |||
| this.realPayMent = realPayMent; | |||
| this.shareAmount = shareAmount; | |||
| this.rateAmount = rateAmount; | |||
| this.realRateAmount = realRateAmount; | |||
| this.commissionAmount = commissionAmount; | |||
| } | |||
| public WxComposeChildOrderShare(PayShareCalculateAmount shareCalculateAmount) { | |||
| this.realPayMent = shareCalculateAmount.getPayAmount(); | |||
| this.shareAmount = shareCalculateAmount.getShareAmount(); | |||
| this.rateAmount = shareCalculateAmount.getRateAmount(); | |||
| this.realRateAmount = shareCalculateAmount.getRealRateAmount(); | |||
| this.commissionAmount = shareCalculateAmount.getCommissionAmount(); | |||
| } | |||
| private Integer realPayMent; | |||
| private Integer shareAmount; | |||
| private Integer realPayMent;//付款金额 | |||
| private Integer rateAmount; | |||
| private Integer shareAmount;//分账的钱(分给商户的) | |||
| private Integer rateAmount;//通道费(广场收的) | |||
| private Integer realRateAmount;//平台手续费 | |||
| private Integer commissionAmount;//平台佣金 | |||
| } | |||
| @@ -2,6 +2,7 @@ package com.iformall.service.pay.service.pay; | |||
| import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import com.iformall.domain.po.*; | |||
| @@ -95,4 +96,13 @@ public interface PayAdapterService { | |||
| * @return | |||
| */ | |||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception; | |||
| /** | |||
| * 无需创建支付单返回 | |||
| * @param record | |||
| * @param composeOrder | |||
| * @param childOrders | |||
| * @return | |||
| */ | |||
| PayAdapterResult noCreatePay(WxPayOrder record, WxComposeOrder composeOrder, List<WxOrder> childOrders); | |||
| } | |||
| @@ -56,6 +56,12 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
| @Autowired | |||
| private WxBatchOrderMapper wxBatchOrderMapper; | |||
| @Autowired | |||
| private WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| private WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| private WxOrderMapper wxOrderMapper; | |||
| @@ -428,4 +434,37 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
| return super.getQrCode(appinfo, pageUrl, type, sceneParam); | |||
| } | |||
| @Override | |||
| public PayAdapterResult noCreatePay(WxPayOrder record, WxComposeOrder composeOrder, List<WxOrder> childOrders) { | |||
| PayAdapterResult par = new PayAdapterResult(); | |||
| par.setSuccess(true); | |||
| Map<String,Object> map = new HashMap<>(); | |||
| map.put("outOrderNo",record.getOrderId()); | |||
| map.put("createPay",record.isCreatPay()); | |||
| if(record.isCreatPay()){ | |||
| Map<String,Integer> payment = new HashMap(); | |||
| payment.put("totalAmount",composeOrder.getPayment()); | |||
| map.put("payment",payment); | |||
| List<Map<String,Object>> goodsList = new ArrayList<>(); | |||
| Map<Long, List<WxOrder>> collect = childOrders.stream().collect(groupingBy(WxOrder::getCouponChannelId)); | |||
| for (Long key: collect.keySet()) { | |||
| Map<String,Object> good = new HashMap<>(); | |||
| Long couponId = wxCouponChannelMapper.findCouponIdById(key, record.getTenantId()); | |||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponId, record.getTenantId()); | |||
| TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(record.getTenantId(), couponId); | |||
| int quantity = collect.get(key).size(); | |||
| good.put("quantity",quantity); | |||
| good.put("price",wxCoupon.getSalePrice()*quantity); | |||
| good.put("goodsName",wxCoupon.getTitle()); | |||
| good.put("goodsPhoto",wxCoupon.getCoverImg()); | |||
| good.put("goodsId",ttCouponChannelPoi.getSpuId()); | |||
| good.put("goodsType",1); | |||
| goodsList.add(good); | |||
| } | |||
| map.put("goodsList",goodsList); | |||
| } | |||
| par.setData(map); | |||
| return null; | |||
| } | |||
| } | |||
| @@ -3,6 +3,8 @@ package com.iformall.service.pay.service.share; | |||
| import java.util.Map; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| @@ -31,6 +33,12 @@ public interface PayShareAdapterService { | |||
| * @return | |||
| */ | |||
| public Integer getProfitSharingType(); | |||
| /** | |||
| * 获取分账订单初始状态 | |||
| * @return | |||
| */ | |||
| public Integer getSharingOrderInitialStatus(); | |||
| /** | |||
| * 计算商场分账金额和实际费率金额 | |||
| @@ -110,4 +118,9 @@ public interface PayShareAdapterService { | |||
| * @return | |||
| */ | |||
| int getOfficialCommission(WxOrder o, WxPayAccount payAccount); | |||
| ResultData handerSharingOrder(WxPayOrder payOrder, WxProfitSharingOrder sharingOrder); | |||
| WxProfitSharingOrder createSharingOrder(WxSharingOrderDto sharingOrderDto, Integer share); | |||
| } | |||
| @@ -3,7 +3,11 @@ package com.iformall.service.pay.service.share.douyin; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| @@ -15,9 +19,8 @@ import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.TtGoodsCategoryMapper; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxCouponMapper; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| @@ -25,16 +28,17 @@ import com.iformall.service.pay.service.share.entity.PayShareQueryResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.PayUtils; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import static java.util.stream.Collectors.groupingBy; | |||
| @Slf4j | |||
| @Service | |||
| @@ -49,9 +53,24 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| WxCouponOrderMapper wxCouponOrderMapper; | |||
| @Autowired | |||
| WxOrderMapper wxOrderMapper; | |||
| @Autowired | |||
| WxProfitSharingOrderMapper wxProfitSharingOrderMapper; | |||
| @Autowired | |||
| WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; | |||
| @Autowired | |||
| TtGoodsCategoryMapper TtGoodsCategoryMapper; | |||
| @Autowired | |||
| OrderCpsMapper orderCpsMapper; | |||
| @Override | |||
| public Integer getSubsidyType() { | |||
| return EnumMerchantSubsidyType.DOUYIN.getCode(); | |||
| @@ -61,22 +80,40 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| public Integer getProfitSharingType() { | |||
| return EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN.getCode(); | |||
| } | |||
| @Override | |||
| @Override | |||
| public Integer getSharingOrderInitialStatus() { | |||
| return EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode(); | |||
| } | |||
| @Override | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,Integer officialCommissionRate, WxPayAccount payAccount) { | |||
| int mallCharge = OrderHelper.getMallCharge(payAmount, payAccount,true); | |||
| Integer realRateAmount = OrderHelper.getRealRateAmount(payAmount, payAccount); | |||
| int officialCommission = PayUtils.getPayRate(payAmount, officialCommissionRate, true); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge+officialCommission,realRateAmount+officialCommission); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount,officialCommission); | |||
| } | |||
| @Override | |||
| public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { | |||
| if(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode().equals(record.getSharingStatus())){ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode(),"分账准备中", null,null); | |||
| } | |||
| String before3dayStr = DateUtils.getTimeBefore(3, new Date()); | |||
| Date before3day = DateUtils.stringToDate(before3dayStr); | |||
| if(before3day.before(record.getCreateTime())){ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_READY.getCode(),"未满足D+3", null,null); | |||
| } | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| ProfitSharingRequest request = new ProfitSharingRequest(); | |||
| request.setOutOrderNo(record.getOrderId().toString()); | |||
| request.setOutSettleNo(record.getId().toString()); | |||
| if(record.getOutSettleNo() == null){ | |||
| record.setOutSettleNo(record.getId()); | |||
| }else{ | |||
| record.setOutSettleNo(record.getOutSettleNo() + 1l); | |||
| } | |||
| request.setOutSettleNo(record.getOutSettleNo().toString()); | |||
| request.setSettleDesc("mall_reciver_share"); | |||
| String settleId = ttPayService.getProfitSharingV2Service().profitSharing(request); | |||
| return new PayShareResult(true, null,"success", null,settleId); | |||
| @@ -111,28 +148,33 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| @Override | |||
| public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException { | |||
| if(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode().equals(record.getSharingStatus())){ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode(),"分账准备中", null,null); | |||
| } | |||
| String before3dayStr = DateUtils.getTimeBefore(3, new Date()); | |||
| Date before3day = DateUtils.stringToDate(before3dayStr); | |||
| if(before3day.before(record.getCreateTime())){ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_READY.getCode(),"未满足D+3", null,null); | |||
| } | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| ProfitSharingRequest request = new ProfitSharingRequest(); | |||
| request.setOutOrderNo(record.getOrderId().toString()); | |||
| request.setOutSettleNo(record.getId().toString()); | |||
| if(record.getOutSettleNo() == null){ | |||
| record.setOutSettleNo(record.getId()); | |||
| }else{ | |||
| record.setOutSettleNo(record.getOutSettleNo() + 1l); | |||
| } | |||
| request.setOutSettleNo(record.getOutSettleNo().toString()); | |||
| request.setSettleDesc("merchant_reciver_share"); | |||
| List list = new ArrayList<>(); | |||
| int mall_account = 0; | |||
| for (Object o: receivers) { | |||
| JSONObject jo = (JSONObject) o; | |||
| Map<String,Object> settleParams = new HashMap<>(); | |||
| settleParams.put("merchant_uid",jo.getString("account")); | |||
| settleParams.put("amount",jo.getInteger("amount")); | |||
| list.add(settleParams); | |||
| mall_account += jo.getInteger("amount") - (jo.getInteger("rateAmount") == null?0:jo.getInteger("rateAmount")); | |||
| } | |||
| // if(mall_account > 0){ | |||
| // Map<String,Object> settleParams = new HashMap<>(); | |||
| // settleParams.put("merchant_uid",payAccount.getSubMchId()); | |||
| // settleParams.put("amount",mall_account); | |||
| // list.add(settleParams); | |||
| // } | |||
| request.setSettleParams(JSON.toJSONString(list)); | |||
| String settleId = ttPayService.getProfitSharingV2Service().profitSharing(request); | |||
| return new PayShareResult(true, null,"success", null,settleId); | |||
| @@ -172,13 +214,13 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| ProfitSharingResult profitSharingResult = ttPayService.getProfitSharingV2Service().getProfitSharingResult(record.getId().toString()); | |||
| ProfitSharingResult profitSharingResult = ttPayService.getProfitSharingV2Service().getProfitSharingResult(record.getOutSettleNo().toString()); | |||
| if(profitSharingResult.isSuccess()){ | |||
| ProfitSharingResult.Receiver receiver = profitSharingResult.getData().get(0); | |||
| if("SUCCESS".equals(receiver.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, 5, "success",receiver, null); | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_DONE.getCode(), "success",receiver, null); | |||
| } else if("FAIL".equals(receiver.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, 6, "fail",receiver, null); | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_FAILED.getCode(), "fail",receiver, null); | |||
| } | |||
| } | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), profitSharingResult.getErrTips()); | |||
| @@ -234,4 +276,125 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| return 0; | |||
| } | |||
| @Override | |||
| public ResultData handerSharingOrder(WxPayOrder payOrder, WxProfitSharingOrder sharingOrder) { | |||
| if(!EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrder.getType()) | |||
| && !EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrder.getType())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"分账类型错误"); | |||
| } | |||
| WxCouponOrder couponOrder = new WxCouponOrder(); | |||
| couponOrder.updateTenantInfo(payOrder); | |||
| couponOrder.setComposeOrderId(payOrder.getId()); | |||
| List<WxCouponOrder> list = wxCouponOrderMapper.findList(couponOrder); | |||
| if(list.stream().filter(co->(!EnumCouponOrderStatus.COUPON_ORDER_USED.getCode().equals(co.getCouponOrderStatus()))).count() > 0){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"存在未核销的券"); | |||
| } | |||
| if(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrder.getType())){ | |||
| WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); | |||
| updSharingOrder.setId(sharingOrder.getId()); | |||
| updSharingOrder.updateTenantInfo(payOrder); | |||
| updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| updSharingOrder.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(); | |||
| } | |||
| if(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrder.getType())){ | |||
| WxOrder order = new WxOrder(); | |||
| order.updateTenantInfo(payOrder); | |||
| order.setComposeOrderId(payOrder.getId()); | |||
| List<WxOrder> list1 = wxOrderMapper.findList(order); | |||
| if(list1.size() != list.size()){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"订单与卷码不匹配"); | |||
| } | |||
| if(list1.stream().filter(o->(EnumOrderCpsStatus.ORDER_DEF_CPS.getCode().equals(o.getCpsStatus()))).count() > 0){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"存在未同步cps的订单"); | |||
| } | |||
| JSONArray receivers = new JSONArray(); | |||
| Map<Long,WxCouponOrder> map = list.stream().collect(Collectors.toMap(WxCouponOrder::getOrderId, co -> co)); | |||
| for (WxOrder o:list1) { | |||
| WxCouponOrder co = map.get(o.getId()); | |||
| WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); | |||
| psReceiverQ.updateTenantInfo(payOrder); | |||
| psReceiverQ.setMerchantId(co.getBMerchantId()); | |||
| psReceiverQ.setSharingType(this.getProfitSharingType()); | |||
| psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); | |||
| psReceiverQ.setPlat(EnumAppPlat.TOUTIAO.getCode()); | |||
| psReceiverQ.setIsUse(EnumProfitSharingUse.YES.getCode()); | |||
| List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); | |||
| if(psReceiverList == null || psReceiverList.isEmpty() || psReceiverList.size() > 1){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"分账帐号异常{WxCouponOrder.getBMerchantId}"+co.getBMerchantId()); | |||
| } | |||
| WxProfitSharingReceiver receiver = psReceiverList.get(0); | |||
| WxComposeChildOrderShare childOrderShare = payOrder.getChildOrderShare(o.getId()); | |||
| int darenTakeAmount = 0; | |||
| if(EnumOrderCpsStatus.ORDER_IS_CPS.getCode().equals(o.getCpsStatus())){ | |||
| OrderCps orderCps = orderCpsMapper.selectById(o.getId(), payOrder.getTenantId()); | |||
| darenTakeAmount = orderCps.getCommissionAmount(); | |||
| } | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",this.getShareAccount(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", childOrderShare.getShareAmount() - darenTakeAmount); | |||
| jo.put("rateAmount", childOrderShare.getRateAmount()); | |||
| jo.put("realRateAmount", childOrderShare.getRateAmount()); | |||
| jo.put("commissionAmount", childOrderShare.getCommissionAmount()); | |||
| jo.put("darenTakeAmount", darenTakeAmount); | |||
| //jo.put("description",receiver.getReceiverComments()); //改为存ID, | |||
| jo.put("description",receiver.getId().toString()); //为重试做准备 | |||
| receivers.add(jo); | |||
| } | |||
| WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); | |||
| updSharingOrder.setId(sharingOrder.getId()); | |||
| updSharingOrder.updateTenantInfo(payOrder); | |||
| updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| updSharingOrder.setReceivers(receivers.toJSONString()); | |||
| updSharingOrder.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(); | |||
| } | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"数据异常-----end"); | |||
| } | |||
| @Override | |||
| public WxProfitSharingOrder createSharingOrder(WxSharingOrderDto sharingOrderDto, Integer share) { | |||
| if(!EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrderDto.getType()) | |||
| && !EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrderDto.getType())){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"分账类型错误"); | |||
| } | |||
| WxProfitSharingOrder record = new WxProfitSharingOrder(); | |||
| record.updateTenantInfo(sharingOrderDto); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record = wxProfitSharingOrderMapper.selectOne(new QueryWrapper(record)); | |||
| if (record == null) { | |||
| //创建分账订单 | |||
| Date currentDate = new Date(); | |||
| record = new WxProfitSharingOrder(); | |||
| final IdWorker idworker = IdWorker.get(); | |||
| record.setId(idworker.nextId()); | |||
| record.updateTenantInfo(sharingOrderDto); | |||
| record.setTransactionId(sharingOrderDto.getTransactionId()); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record.setPayAmount(sharingOrderDto.getPayAmount()); | |||
| record.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| record.setSharingStatus(this.getSharingOrderInitialStatus()); | |||
| record.setCreateTime(currentDate); | |||
| record.setUpdateTime(currentDate); | |||
| record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); | |||
| record.setPayTimeEnd(sharingOrderDto.getPayTimeEnd()); | |||
| if(EnumPayShare.YES.getCode().equals(share)){ | |||
| record.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); | |||
| }else{ | |||
| record.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()); | |||
| } | |||
| wxProfitSharingOrderMapper.insert(record); | |||
| } | |||
| return record; | |||
| } | |||
| } | |||
| @@ -14,13 +14,14 @@ public class PayShareCalculateAmount implements Serializable{ | |||
| private Integer payAmount; | |||
| private Integer mallCharge;//商场拿走的钱+平台手续费 | |||
| private Integer realRateAmount;//平台手续费 | |||
| private Integer commissionAmount;//平台佣金 | |||
| //分账的钱 | |||
| public Integer getShareAmount() { | |||
| return payAmount - mallCharge; | |||
| return payAmount - mallCharge - commissionAmount; | |||
| } | |||
| //费率差 | |||
| //商场拿走的钱 | |||
| public Integer getRateAmount() { | |||
| return mallCharge - realRateAmount; | |||
| } | |||
| @@ -1,12 +1,15 @@ | |||
| package com.iformall.service.pay.service.share.wx; | |||
| import java.text.ParseException; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import java.util.SortedMap; | |||
| import java.util.TreeMap; | |||
| import java.util.*; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import net.sf.saxon.trans.Err; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -16,19 +19,7 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.enums.EnumMerchantSubsidyType; | |||
| import com.iformall.enums.EnumPayEndFrom; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderStatus; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.enums.EnumProfitSharingReceiverStatus; | |||
| import com.iformall.enums.EnumProfitSharingReceiverType; | |||
| import com.iformall.enums.EnumProfitSharingType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.mapper.WxProfitSharingReceiverMapper; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.pay.WxProfitSharing; | |||
| import com.iformall.pay.WxProfitSharingFinishP; | |||
| @@ -53,6 +44,9 @@ import lombok.extern.slf4j.Slf4j; | |||
| @Service | |||
| public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| @Autowired | |||
| WxProfitSharingOrderMapper wxProfitSharingOrderMapper; | |||
| final JSONObject statusMap = JSON.parseObject( | |||
| "{\"ACCEPTED\":3," + | |||
| "\"PROCESSING\": 4," + | |||
| @@ -69,12 +63,17 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| public Integer getProfitSharingType() { | |||
| return EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode(); | |||
| } | |||
| @Override | |||
| @Override | |||
| public Integer getSharingOrderInitialStatus() { | |||
| return EnumProfitSharingOrderStatus.PROFIT_SHARING_READY.getCode(); | |||
| } | |||
| @Override | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,Integer officialCommissionRate, WxPayAccount payAccount) { | |||
| int mallCharge = OrderHelper.getMallCharge(payAmount, payAccount); | |||
| Integer realRateAmount = OrderHelper.getRealRateAmount(payAmount, payAccount); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount,0); | |||
| } | |||
| @Override | |||
| @@ -439,6 +438,99 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| return 0; | |||
| } | |||
| @Override | |||
| public ResultData handerSharingOrder(WxPayOrder payOrder, WxProfitSharingOrder sharingOrder) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"微信分账无需处理"); | |||
| } | |||
| @Override | |||
| public WxProfitSharingOrder createSharingOrder(WxSharingOrderDto sharingOrderDto, Integer share) { | |||
| if(EnumYesOrNo.NO.getCode().equals(share)){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"微信不分账"); | |||
| } | |||
| //是否已创建分账订单 | |||
| WxProfitSharingOrder record = new WxProfitSharingOrder(); | |||
| record.updateTenantInfo(sharingOrderDto); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record = wxProfitSharingOrderMapper.selectOne(new QueryWrapper(record)); | |||
| if (record == null) { | |||
| //创建分账订单 | |||
| Date currentDate = new Date(); | |||
| record = new WxProfitSharingOrder(); | |||
| final IdWorker idworker = IdWorker.get(); | |||
| record.setId(idworker.nextId()); | |||
| record.updateTenantInfo(sharingOrderDto); | |||
| record.setTransactionId(sharingOrderDto.getTransactionId()); | |||
| record.setOrderId(sharingOrderDto.getOrderId()); | |||
| record.setPayAmount(sharingOrderDto.getPayAmount()); | |||
| record.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| record.setSharingStatus(this.getSharingOrderInitialStatus()); | |||
| record.setCreateTime(currentDate); | |||
| record.setUpdateTime(currentDate); | |||
| record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); | |||
| record.setPayTimeEnd(sharingOrderDto.getPayTimeEnd()); | |||
| record.setType(sharingOrderDto.getType()); | |||
| wxProfitSharingOrderMapper.insert(record); | |||
| } | |||
| //准备分账列表 | |||
| WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); | |||
| psReceiverQ.updateTenantInfo(sharingOrderDto); | |||
| psReceiverQ.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| psReceiverQ.setSharingType(this.getProfitSharingType()); | |||
| psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); | |||
| psReceiverQ.setPlat(EnumAppPlat.WX.getCode()); | |||
| List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); | |||
| if (psReceiverList != null && psReceiverList.size() > 50) { | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); | |||
| } | |||
| if (psReceiverList == null || psReceiverList.size() == 0) { //没有分账账户, | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_UNKNOWN); | |||
| } | |||
| if (psReceiverList.size() > 1 &&//计算分账账户合法性 | |||
| psReceiverList.stream().filter(r->(r.getParameter() == null)).count() > 0) { | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); | |||
| } | |||
| //计算分账金额合法性 | |||
| psReceiverList.stream().forEach(r-> | |||
| { | |||
| if (r.getParameter() == null){ | |||
| r.setSharingAmount(sharingOrderDto.getShareAmount()); | |||
| r.setRateAmount(sharingOrderDto.getRateAmount()); | |||
| r.setRealRateAmount(sharingOrderDto.getRealRateAmount()); | |||
| r.setCommissionAmount(sharingOrderDto.getCommissionAmount()); | |||
| } else { | |||
| r.setSharingAmount(sharingOrderDto.getShareAmount()*Integer.valueOf(r.getParameter())/10000); | |||
| } | |||
| }); | |||
| if (psReceiverList.stream().mapToInt(r->r.getSharingAmount()).sum() > sharingOrderDto.getShareAmount()){ | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_UNKNOWN); | |||
| } | |||
| // 添加分账接收方 | |||
| JSONArray receivers = new JSONArray(); | |||
| psReceiverList.stream().forEach(receiver->{ | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",this.getShareAccount(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", receiver.getSharingAmount()); | |||
| jo.put("rateAmount", receiver.getRateAmount()); | |||
| jo.put("realRateAmount", receiver.getRateAmount()); | |||
| jo.put("commissionAmount", receiver.getCommissionAmount()); | |||
| //jo.put("description",receiver.getReceiverComments()); //改为存ID, | |||
| jo.put("description",receiver.getId().toString()); //为重试做准备 | |||
| receivers.add(jo); | |||
| }); | |||
| record.setReceivers(receivers.toJSONString()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return record; | |||
| } | |||
| private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { | |||
| WxProfitSharingP psCmd = new WxProfitSharingP(); | |||
| psCmd.setMch_id(mchId);//服务商商户id | |||
| @@ -5,6 +5,8 @@ | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | |||
| <result column="out_settle_no" jdbcType="BIGINT" property="outSettleNo" /> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | |||
| <result column="order_id" jdbcType="BIGINT" property="orderId" /> | |||
| <result column="pay_vendor" jdbcType="INTEGER" property="payVendor"/> | |||
| @@ -22,7 +24,7 @@ | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`order_id`,`pay_vendor`,`pay_amount`,`pay_time_end`,`pay_time_start`,`transaction_id`,`sharing_order_no`,`type`,`receivers`,`error_msg`,`sharing_status`,`update_time`,`create_time` | |||
| `id`,`tenant_id`,`parent_tenant_id`,`out_settle_no`,`merchant_id`,`order_id`,`pay_vendor`,`pay_amount`,`pay_time_end`,`pay_time_start`,`transaction_id`,`sharing_order_no`,`type`,`receivers`,`error_msg`,`sharing_status`,`update_time`,`create_time` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -38,7 +40,11 @@ | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| </if> | |||
| <if test=" null != outSettleNo "> | |||
| and `out_settle_no` = #{outSettleNo} | |||
| </if> | |||
| <if test=" null != merchantId "> | |||
| and `merchant_id` = #{merchantId} | |||