| @@ -7,8 +7,12 @@ import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.TtRefundAuditMsgRequest; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.refund.RefundPayAdapterService; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -42,6 +46,9 @@ public class OrderRefundAuditSchedule { | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Autowired | |||
| private PayServiceFactory payServiceFactory; | |||
| @Async | |||
| @Scheduled(cron = "0 40 */1 * * ?")// | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| @@ -145,13 +152,10 @@ public class OrderRefundAuditSchedule { | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrder); | |||
| if(list != null && list.size() > 0){ | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| RefundPayAdapterService refundPayAdapterService = payServiceFactory.getRefundPayAdapterService(EnumPayWay.PAY_WAY_TT.getCode(), payAccount.getPayVersion()); | |||
| for (WxRefundOrder order:list) { | |||
| try { | |||
| TtRefundAuditMsgRequest request = new TtRefundAuditMsgRequest(); | |||
| request.setOutRefundNo(order.getId().toString()); | |||
| request.setRefundAuditStatus(1); | |||
| boolean b = ttPayService.merchantAuditCallback(request); | |||
| boolean b = refundPayAdapterService.merchantAuditCallback(appinfo,payAccount,refundOrder.getRefundId().toString(),1,null); | |||
| if(b){ | |||
| WxRefundOrder updRefundOrder = new WxRefundOrder(); | |||
| updRefundOrder.updateTenantInfo(appinfo); | |||
| @@ -160,7 +164,7 @@ public class OrderRefundAuditSchedule { | |||
| updRefundOrder.setUpdateTime(new Date()); | |||
| wxRefundOrderMapper.updateById(updRefundOrder); | |||
| } | |||
| } catch (TtPayException e) { | |||
| } catch (MallinkException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| @@ -10,6 +10,9 @@ import com.iformall.mapper.WxBatchOrderMapper; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| @@ -21,12 +24,16 @@ import org.springframework.stereotype.Component; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @Component | |||
| public class TtOrderQueryCpsSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private PayServiceFactory payServiceFactory; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @@ -51,13 +58,14 @@ public class TtOrderQueryCpsSchedule { | |||
| for (WxAppinfo appinfo:wxAppinfoList) { | |||
| try{ | |||
| WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| // payServiceFactory.getPayAdapterService(EnumPayWay.PAY_WAY_TT.getCode(),payAccount.getPayVersion()); | |||
| // TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| WxOrder orderQ = new WxOrder(); | |||
| orderQ.updateTenantInfo(appinfo); | |||
| orderQ.setType(EnumOrderType.COUPON.getCode()); | |||
| orderQ.setPayVendor(EnumPayWay.PAY_WAY_TT.getCode()); | |||
| orderQ.setPayVersion(EnumPayVersion.DY_PAY_V2.getCode()); | |||
| // orderQ.setPayVersion(EnumPayVersion.DY_PAY_V2.getCode()); | |||
| orderQ.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| orderQ.setCpsStatus(EnumOrderCpsStatus.ORDER_DEF_CPS.getCode()); | |||
| List<WxOrder> orderList = wxOrderService.findList(orderQ); | |||
| @@ -68,35 +76,29 @@ public class TtOrderQueryCpsSchedule { | |||
| order.setCpsStatus(EnumOrderCpsStatus.ORDER_NO_CPS.getCode()); | |||
| wxOrderService.updateCpsStatus(order); | |||
| } | |||
| TtPayCpsOrderQueryV2Result ttPayCpsOrderQueryV2Result = ttPayService.queryCpsOrderV2(null, order.getComposeOrderId().toString()); | |||
| if(ttPayCpsOrderQueryV2Result != null){ | |||
| PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(order.getPayVendor(), order.getPayVersion()); | |||
| PayAdapterResult result = payAdapterService.queryCpsOrder(appinfo, payAccount,order); | |||
| if(result != null && result.isSuccess()){ | |||
| Map cpsResult = (Map) result.getData(); | |||
| OrderCps cps = new OrderCps(); | |||
| cps.updateTenantInfo(order); | |||
| cps.setId(order.getId()); | |||
| cps.setComposeOrderId(order.getComposeOrderId()); | |||
| List<TtPayCpsOrderQueryV2Result.CpsItem> cpsList = ttPayCpsOrderQueryV2Result.getCpsInfo().getCpsItemList(); | |||
| for (TtPayCpsOrderQueryV2Result.CpsItem cpsItem: cpsList) { | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| if(StringUtils.isNotBlank(itemOrderId) && itemOrderId.equals(cpsItem.getItemOrderId())){ | |||
| cps.setItemOrderId(cpsItem.getItemOrderId()); | |||
| cps.setSellAmount(cpsItem.getSellAmount()); | |||
| cps.setSourceType(cpsItem.getSourceType()); | |||
| cps.setItemId(cpsItem.getItemId()); | |||
| cps.setCommissionAmount(cpsItem.getCommissionAmount()); | |||
| cps.setCommissionUserId(cpsItem.getCommissionUserId()); | |||
| cps.setCommissionRate(cpsItem.getCommissionRate()); | |||
| break; | |||
| } | |||
| } | |||
| if(StringUtils.isNotBlank(cps.getItemOrderId())){ | |||
| Date now = new Date(); | |||
| cps.setCreateDate(now); | |||
| cps.setUpdateDate(now); | |||
| int insert = orderCpsMapper.insert(cps); | |||
| if(insert == 1){ | |||
| order.setCpsStatus(EnumOrderCpsStatus.ORDER_IS_CPS.getCode()); | |||
| wxOrderService.updateCpsStatus(order); | |||
| } | |||
| cps.setItemOrderId((String) cpsResult.get("itemOrderId")); | |||
| cps.setSellAmount((Integer) cpsResult.get("sellAmount")); | |||
| cps.setSourceType((Integer) cpsResult.get("sourceType")); | |||
| cps.setItemId((Long) cpsResult.get("itemId")); | |||
| cps.setCommissionAmount((Integer) cpsResult.get("commissionAmount")); | |||
| cps.setCommissionUserId((Long) cpsResult.get("commissionUserId")); | |||
| cps.setCommissionRate((Integer) cpsResult.get("commissionRate")); | |||
| Date now = new Date(); | |||
| cps.setCreateDate(now); | |||
| cps.setUpdateDate(now); | |||
| int insert = orderCpsMapper.insert(cps); | |||
| if(insert == 1){ | |||
| order.setCpsStatus(EnumOrderCpsStatus.ORDER_IS_CPS.getCode()); | |||
| wxOrderService.updateCpsStatus(order); | |||
| } | |||
| }else{ | |||
| order.setCpsStatus(EnumOrderCpsStatus.ORDER_NO_CPS.getCode()); | |||
| @@ -3,6 +3,9 @@ package com.iformall.douyin.pay; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import java.util.List; | |||
| /** | |||
| * 支付V2-资金应用-分账 | |||
| @@ -43,6 +46,6 @@ public interface ProfitSharingV2Service { | |||
| * - 注意:对于担保交易和交易1.0的订单,如果需要根据order_id/out_order_no查询订单的分账记录,建议使用order_id(抖音开平侧支付单id查询),若使用out_order_no可能存在查询不到的情况 | |||
| * | |||
| */ | |||
| ProfitSharingResult getProfitSharingResult(String out_settle_no) throws TtPayException; | |||
| List<TtSettleResult> getProfitSharingResult(String out_settle_no) throws TtPayException; | |||
| } | |||
| @@ -11,11 +11,13 @@ import com.iformall.douyin.payv2.auth.Verifier; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.result.BaseTtPayResult; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import lombok.RequiredArgsConstructor; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.List; | |||
| /** | |||
| * 支付V2-资金应用-分账Service | |||
| @@ -44,12 +46,17 @@ public class ProfitSharingV2ServiceImpl implements ProfitSharingV2Service { | |||
| } | |||
| @Override | |||
| public ProfitSharingResult getProfitSharingResult(String out_settle_no) throws TtPayException { | |||
| public List<TtSettleResult> getProfitSharingResult(String out_settle_no) throws TtPayException { | |||
| String url = String.format("%s/api/apps/trade/v2/query_settle", this.payService.getPayBaseUrl()); | |||
| JsonObject jsonObject = new JsonObject(); | |||
| jsonObject.addProperty("out_settle_no",out_settle_no); | |||
| String result = this.payService.postV2(url,jsonObject.toString()); | |||
| return GSON.fromJson(result, ProfitSharingResult.class); | |||
| ProfitSharingResult sharingResult = GSON.fromJson(result, ProfitSharingResult.class); | |||
| if(sharingResult.isSuccess()){ | |||
| return sharingResult.getData(); | |||
| }else{ | |||
| throw new TtPayException(sharingResult.getErrTips()); | |||
| } | |||
| } | |||
| @@ -37,76 +37,6 @@ public class ProfitSharingResult implements Serializable { | |||
| * 订单的分账结果 | |||
| */ | |||
| @SerializedName("data") | |||
| private List<Receiver> data; | |||
| private List<TtSettleResult> data; | |||
| @Data | |||
| public static class Receiver implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| /** | |||
| * 开发者交易订单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("out_order_no") | |||
| private String outOrderNo; | |||
| /** | |||
| * 开发者分账单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("out_settle_no") | |||
| private String outSettleNo; | |||
| /** | |||
| * 小程序侧交易订单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("order_id") | |||
| private String orderId; | |||
| /** | |||
| * 小程序侧分账单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("settle_id") | |||
| private String settleId; | |||
| /** | |||
| * 分账金额,单位[分] | |||
| */ | |||
| @SerializedName("settle_amount") | |||
| private Integer settleAmount; | |||
| /** | |||
| * 分账状态:INIT,PROCESSING,SUCCESS,FAIL | |||
| */ | |||
| @SerializedName("settle_status") | |||
| private String settleStatus; | |||
| /** | |||
| * 分账详情,如“商户号ABC-分成金额(分)100” | |||
| */ | |||
| @SerializedName("settle_detail") | |||
| private String settleDetail; | |||
| /** | |||
| * 分账时间,13位时间戳,毫秒 | |||
| */ | |||
| @SerializedName("settle_time") | |||
| private Long settleTime; | |||
| /** | |||
| * 手续费,单位[分] | |||
| */ | |||
| @SerializedName("rake") | |||
| private Integer rake; | |||
| /** | |||
| * 佣金,单位[分] | |||
| */ | |||
| @SerializedName("commission") | |||
| private Integer commission; | |||
| /** | |||
| * 透传字段,开发者自定义,<=2048字节,不支持二进制数据 | |||
| */ | |||
| @SerializedName("cp_extra") | |||
| private String cpExtra; | |||
| } | |||
| } | |||
| @@ -0,0 +1,86 @@ | |||
| package com.iformall.douyin.payv2.result; | |||
| import com.google.gson.annotations.SerializedName; | |||
| import lombok.Data; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| /** | |||
| * 请求分账API返回的分账结果实体 | |||
| * | |||
| * @author pg | |||
| * @date 2021-6-24 | |||
| */ | |||
| @Data | |||
| public class TtSettleResult implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| /** | |||
| * 开发者交易订单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("out_order_no") | |||
| private String outOrderNo; | |||
| /** | |||
| * 开发者分账单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("out_settle_no") | |||
| private String outSettleNo; | |||
| /** | |||
| * 小程序侧交易订单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("order_id") | |||
| private String orderId; | |||
| /** | |||
| * 小程序侧分账单id,长度<=64byte,数字、ASCII字符组成 | |||
| */ | |||
| @SerializedName("settle_id") | |||
| private String settleId; | |||
| /** | |||
| * 分账金额,单位[分] | |||
| */ | |||
| @SerializedName("settle_amount") | |||
| private Integer settleAmount; | |||
| /** | |||
| * 分账状态:INIT,PROCESSING,SUCCESS,FAIL | |||
| */ | |||
| @SerializedName("settle_status") | |||
| private String settleStatus; | |||
| /** | |||
| * 分账详情,如“商户号ABC-分成金额(分)100” | |||
| */ | |||
| @SerializedName("settle_detail") | |||
| private String settleDetail; | |||
| /** | |||
| * 分账时间,13位时间戳,毫秒 | |||
| */ | |||
| @SerializedName("settle_time") | |||
| private Long settleTime; | |||
| /** | |||
| * 手续费,单位[分] | |||
| */ | |||
| @SerializedName("rake") | |||
| private Integer rake; | |||
| /** | |||
| * 佣金,单位[分] | |||
| */ | |||
| @SerializedName("commission") | |||
| private Integer commission; | |||
| /** | |||
| * 透传字段,开发者自定义,<=2048字节,不支持二进制数据 | |||
| */ | |||
| @SerializedName("cp_extra") | |||
| private String cpExtra; | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.douyin.web.api.web; | |||
| package com.iformall.douyin.web.api.basic; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.douyin.web.api.web; | |||
| package com.iformall.douyin.web.api.basic; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.douyin.web.api.web; | |||
| package com.iformall.douyin.web.api.basic; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.douyin.web.api.web; | |||
| package com.iformall.douyin.web.api.basic; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.douyin.web.api.web; | |||
| package com.iformall.douyin.web.api.basic; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| @@ -87,14 +87,12 @@ public class TtWebPostRequestExecutor implements RequestExecutor<String, String> | |||
| } | |||
| JSONObject jsonObject = JSON.parseObject(responseContent); | |||
| JSONObject data = jsonObject.getJSONObject("data"); | |||
| WxError error = WxError.fromJson(data.toJSONString()); | |||
| JSONObject extra = jsonObject.getJSONObject("extra"); | |||
| WxError error = WxError.fromJson(extra.toJSONString()); | |||
| if (error.getErrorCode() != 0) { | |||
| JSONObject extra = jsonObject.getJSONObject("extra"); | |||
| if(extra != null){ | |||
| String sub_description = extra.getString("sub_description"); | |||
| if(StringUtils.isNotBlank(sub_description)){ | |||
| error.setErrorMsg(sub_description); | |||
| } | |||
| String sub_description = extra.getString("sub_description"); | |||
| if(StringUtils.isNotBlank(sub_description)){ | |||
| error.setErrorMsg(sub_description); | |||
| } | |||
| throw new WxErrorException(error); | |||
| } | |||
| @@ -4,9 +4,9 @@ import com.alibaba.fastjson.TypeReference; | |||
| import com.google.gson.*; | |||
| import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasGoodsService; | |||
| import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsCategoryGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGoodsCategoryGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGoodsGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGoodsPostRequestExecutor; | |||
| import com.iformall.douyin.web.bean.*; | |||
| import lombok.AllArgsConstructor; | |||
| import me.chanjar.weixin.common.error.WxError; | |||
| @@ -0,0 +1,62 @@ | |||
| package com.iformall.douyin.web.api.order; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayOrderQueryV2Request; | |||
| import com.iformall.douyin.payv2.result.TtPayCpsOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.douyin.web.bean.*; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import java.util.List; | |||
| /** | |||
| * 接入商品库 | |||
| * | |||
| * @author | |||
| */ | |||
| public interface TtWebOrderService { | |||
| /** | |||
| *0 查询订单信息 | |||
| */ | |||
| String QUERY_ORDER = "/api/apps/trade/v2/order/query_order"; | |||
| /** | |||
| *1 查询券状态信息 | |||
| */ | |||
| String QUERY_ITEM_ORDER_INFO = "/api/apps/trade/v2/order/query_item_order_info"; | |||
| /** | |||
| *2 查询CPS信息 | |||
| */ | |||
| String QUERY_CPS = "/api/apps/trade/v2/order/query_cps"; | |||
| /** | |||
| *3 推送核销状态 | |||
| */ | |||
| String PUSH_DELIVERY = "/api/apps/trade/v2/fulfillment/push_delivery"; | |||
| /** | |||
| * <pre> | |||
| * 5. 订单信息接口 | |||
| */ | |||
| TtPayOrderQueryV2Result queryOrderV2(String orderId, String outOrderNo) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 5. 订单信息接口 | |||
| */ | |||
| TtPayOrderQueryV2Result queryOrderV2(TtPayOrderQueryV2Request request) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 5. cps订单信息接口 | |||
| */ | |||
| TtPayCpsOrderQueryV2Result queryCpsOrderV2(String orderId, String outOrderNo) throws WxErrorException; | |||
| /** | |||
| * 推送核销状态(非闭环核销) | |||
| */ | |||
| boolean pushDelivery(TtOrderPushDeliveryRequest request) throws WxErrorException; | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| package com.iformall.douyin.web.api.order; | |||
| import com.iformall.douyin.web.api.basic.TtBasicService; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsService; | |||
| import com.iformall.douyin.web.api.web.TtWebPoiPlanService; | |||
| import com.iformall.douyin.web.api.web.TtWebProductService; | |||
| import com.iformall.douyin.web.api.web.TtWebShopMatchService; | |||
| /** | |||
| * | |||
| */ | |||
| public interface TtWebPayService extends TtBasicService{ | |||
| /** | |||
| * 订单相关接口 | |||
| * | |||
| * @return | |||
| */ | |||
| TtWebOrderService getTtWebOrderService(); | |||
| /** | |||
| * 分账相关接口 | |||
| * | |||
| * @return | |||
| */ | |||
| TtWebShareService getTtWebShareService(); | |||
| /** | |||
| * 退款相关接口 | |||
| * | |||
| * @return | |||
| */ | |||
| TtWebRefundService getTtWebRefundService(); | |||
| } | |||
| @@ -0,0 +1,75 @@ | |||
| package com.iformall.douyin.web.api.order; | |||
| import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundQueryV2Request; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundV2Request; | |||
| import com.iformall.douyin.payv2.request.TtRefundAuditMsgRequest; | |||
| import com.iformall.douyin.payv2.result.RefundOrderCallback; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundV2Result; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import java.util.List; | |||
| /** | |||
| * 接入商品库 | |||
| * | |||
| * @author | |||
| */ | |||
| public interface TtWebRefundService { | |||
| /** | |||
| *0 发起退款 | |||
| */ | |||
| String CREATE_REFUND = "/api/apps/trade/v2/refund/create_refund"; | |||
| /** | |||
| *1 同步退款审核状态 | |||
| */ | |||
| String MERCHANT_AUDIT_CALLBACK = "/api/apps/trade/v2/refund/merchant_audit_callback"; | |||
| /** | |||
| *1 查询退款 | |||
| */ | |||
| String QUERY_REFUND = "/api/apps/trade/v2/refund/query_refund"; | |||
| /** | |||
| * <pre> | |||
| * 开发者可用该接口替用户发起退款,开发者发起的退款流程则不会有退款申请回调。 | |||
| * - 过期自动退说明 | |||
| * - 过期自动退的退款被拒绝退款后,不会再次发起。 | |||
| * - 在交易系统2.0产生的订单,如果用户购买的商品是过期退商品,交易系统2.0会自动发起退款,创建退款单,退款流程和用户发起退款流程相同。 | |||
| * - 发起过期自动退条件 | |||
| * - 非POI 商品 | |||
| * - 前端传入合法的商品过期时间 | |||
| * - 前端传入的goodsLabels中包含过期退标签 | |||
| * - POI 商品 | |||
| * - POI 商品设置了过期时间 | |||
| * - POI 商品的 sub_title包含过期退标签 | |||
| * - 旧订单系统不会自动发起过期自动退,仍需开发者处理。 | |||
| * - 过期自动退的退款单由系统创建,因此 退款申请回调和状态通知回调 cp_extra 会是空值。 | |||
| * - 外部退款单号说明 | |||
| * - 已经在担保支付或者交易1.0使用过的外部退款单号,请不要在交易2.0使用,当交易2.0系统发现该外部退款单号已经在担保支付或者交易1.0创建过退款单号时,会拒绝创建退款单。 | |||
| * - 已经升级到交易2.0的接口之后,不支持再降级使用交易1.0,否则产生的后果由开发者承担。 | |||
| */ | |||
| TtPayRefundV2Result refundV2(TtPayRefundV2Request request) throws WxErrorException; | |||
| /** | |||
| * 退款审核结果同步 | |||
| * @param request | |||
| * @return | |||
| * @throws TtPayException | |||
| */ | |||
| boolean merchantAuditCallback(TtRefundAuditMsgRequest request) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 查询退款 | |||
| * | |||
| */ | |||
| TtPayRefundQueryV2Result refundQueryV2(TtPayRefundQueryV2Request request) throws WxErrorException; | |||
| } | |||
| @@ -0,0 +1,65 @@ | |||
| package com.iformall.douyin.web.api.order; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayOrderQueryV2Request; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.douyin.payv2.result.TtPayCpsOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import java.util.List; | |||
| /** | |||
| * 接入商品库 | |||
| * | |||
| * @author | |||
| */ | |||
| public interface TtWebShareService { | |||
| /** | |||
| *0 发起分账 | |||
| */ | |||
| String CREATE_SETTLE = "/api/apps/trade/v2/settle/create_settle"; | |||
| /** | |||
| *1 查询分账 | |||
| */ | |||
| String QUERY_SETTLE = "/api/apps/trade/v2/settle/query_settle"; | |||
| /** | |||
| * <pre> | |||
| * 请求分账API | |||
| * 接口简介 | |||
| * 一笔订单完成后,开发者可以通过分账接口将这笔订单产生的资金结算给各个分账方。 | |||
| * - 结算规则统一为核销D+3; | |||
| * - CPS订单比较特殊,统一结算规则是核销D+3 | |||
| * - 结算规则为核销D+3,表示订单到达“终态”3天后可以分账,“终态”表示所有的券/商品已核销或已退款 | |||
| * - 如对上述结算规则有特殊需求,请联系对应行业经理(餐饮@Xinru Chen 酒旅@Jie Zhou @Yuekai Zhao 到综@Yankai Ouyang ) | |||
| * - 若分账失败,请参考文档进行自查分账失败如何自查 | |||
| * 核销D+3 | |||
| * - 例如用户的一笔订单买了5张团购券,其中3张先核销,剩余2张再退款,最终退款完成的时间就是订单到达终态的时间。订单到达终态3天后,则可以发起分账 | |||
| * | |||
| * 返回 小程序分账id,系统会确保不超过64个字节(数字+ASCII) | |||
| * | |||
| */ | |||
| String profitSharing(ProfitSharingRequest request) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 查询分账接口 | |||
| * out_order_no string 否 开发者交易订单id,长度<64byte,数字ASCII字符 | |||
| * out_settle_no string 否 开发者分账单id,长度<64byte,数字、ASCII字符 | |||
| * order_id string 否 抖音开平侧订单id,长度<64byte,数字、ASCII | |||
| * settle_id string 否 抖音开平侧分账单id,长度<64byte,数字、ASCII | |||
| * - 查询优先级: settle_id > order_id > out_settle_no > out_order_no,4个参数选填一个 | |||
| * - 例如:请求填写了settle_id和order_id,服务只会按settle_id来查询,忽略order_id | |||
| * - 如果未查询到结果,会返回空数组 | |||
| * - 注意:对于担保交易和交易1.0的订单,如果需要根据order_id/out_order_no查询订单的分账记录,建议使用order_id(抖音开平侧支付单id查询),若使用out_order_no可能存在查询不到的情况 | |||
| * | |||
| */ | |||
| List<TtSettleResult> getProfitSharingResult(String out_settle_no) throws WxErrorException; | |||
| } | |||
| @@ -0,0 +1,70 @@ | |||
| package com.iformall.douyin.web.api.order.impl; | |||
| import com.alibaba.fastjson.TypeReference; | |||
| import com.google.gson.Gson; | |||
| import com.google.gson.GsonBuilder; | |||
| import com.google.gson.JsonArray; | |||
| import com.google.gson.JsonObject; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayOrderQueryV2Request; | |||
| import com.iformall.douyin.payv2.result.BaseTtPayResult; | |||
| import com.iformall.douyin.payv2.result.TtPayCpsOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.douyin.web.api.basic.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.order.TtWebOrderService; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.douyin.web.api.web.*; | |||
| import com.iformall.douyin.web.bean.*; | |||
| import lombok.AllArgsConstructor; | |||
| import me.chanjar.weixin.common.error.WxError; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * | |||
| */ | |||
| @AllArgsConstructor | |||
| public class TtWebOrderServiceImpl implements TtWebOrderService { | |||
| private static final Gson GSON = new GsonBuilder().create(); | |||
| private TtWebPayService service; | |||
| @Override | |||
| public TtPayOrderQueryV2Result queryOrderV2(String orderId, String outOrderNo) throws WxErrorException { | |||
| TtPayOrderQueryV2Request request = new TtPayOrderQueryV2Request(); | |||
| request.setOutOrderNo(StringUtils.trimToNull(outOrderNo)); | |||
| request.setOrderId(StringUtils.trimToNull(orderId)); | |||
| return this.queryOrderV2(request); | |||
| } | |||
| @Override | |||
| public TtPayOrderQueryV2Result queryOrderV2(TtPayOrderQueryV2Request request) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| String result = this.service.execute(executor, this.QUERY_ORDER, GSON.toJson(request)); | |||
| return GSON.fromJson(result, TtPayOrderQueryV2Result.class); | |||
| } | |||
| @Override | |||
| public TtPayCpsOrderQueryV2Result queryCpsOrderV2(String orderId, String outOrderNo) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| TtPayOrderQueryV2Request request = new TtPayOrderQueryV2Request(); | |||
| request.setOutOrderNo(StringUtils.trimToNull(outOrderNo)); | |||
| request.setOrderId(StringUtils.trimToNull(orderId)); | |||
| String result = this.service.execute(executor, this.QUERY_CPS, GSON.toJson(request)); | |||
| return GSON.fromJson(result, TtPayCpsOrderQueryV2Result.class); | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(TtOrderPushDeliveryRequest request) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| String result = this.service.execute(executor, this.PUSH_DELIVERY, GSON.toJson(request)); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -0,0 +1,41 @@ | |||
| package com.iformall.douyin.web.api.order.impl; | |||
| import com.iformall.douyin.web.api.basic.TtBasicServiceImpl; | |||
| import com.iformall.douyin.web.api.order.TtWebOrderService; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.douyin.web.api.order.TtWebRefundService; | |||
| import com.iformall.douyin.web.api.order.TtWebShareService; | |||
| import com.iformall.douyin.web.api.web.*; | |||
| import com.iformall.douyin.web.api.web.impl.TtWebGoodsServiceImpl; | |||
| import com.iformall.douyin.web.api.web.impl.TtWebPoiPlanServiceImpl; | |||
| import com.iformall.douyin.web.api.web.impl.TtWebProductServiceImpl; | |||
| import com.iformall.douyin.web.api.web.impl.TtWebShopMatchServiceImpl; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| /** | |||
| * @author | |||
| */ | |||
| @Slf4j | |||
| public class TtWebPayServiceImpl extends TtBasicServiceImpl implements TtWebPayService { | |||
| private TtWebOrderService webOrderService = new TtWebOrderServiceImpl(this); | |||
| private TtWebShareService webShareService = new TtWebShareServiceImpl(this); | |||
| private TtWebRefundService webRefundService = new TtWebRefundServiceImpl(this); | |||
| @Override | |||
| public TtWebOrderService getTtWebOrderService() { | |||
| return this.webOrderService; | |||
| } | |||
| @Override | |||
| public TtWebShareService getTtWebShareService() { | |||
| return this.webShareService; | |||
| } | |||
| @Override | |||
| public TtWebRefundService getTtWebRefundService() { | |||
| return this.webRefundService; | |||
| } | |||
| } | |||
| @@ -0,0 +1,55 @@ | |||
| package com.iformall.douyin.web.api.order.impl; | |||
| import com.alibaba.fastjson.TypeReference; | |||
| import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; | |||
| import com.google.gson.Gson; | |||
| import com.google.gson.GsonBuilder; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParser; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundQueryV2Request; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundV2Request; | |||
| import com.iformall.douyin.payv2.request.TtRefundAuditMsgRequest; | |||
| import com.iformall.douyin.payv2.result.*; | |||
| import com.iformall.douyin.web.api.basic.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.douyin.web.api.order.TtWebRefundService; | |||
| import com.iformall.douyin.web.api.order.TtWebShareService; | |||
| import lombok.AllArgsConstructor; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import java.util.List; | |||
| /** | |||
| * | |||
| */ | |||
| @AllArgsConstructor | |||
| public class TtWebRefundServiceImpl implements TtWebRefundService { | |||
| private static final Gson GSON = new GsonBuilder().create(); | |||
| private TtWebPayService service; | |||
| @Override | |||
| public TtPayRefundV2Result refundV2(TtPayRefundV2Request request) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| String result = this.service.execute(executor, this.CREATE_REFUND, GSON.toJson(request)); | |||
| return GSON.fromJson(result, TtPayRefundV2Result.class); | |||
| } | |||
| @Override | |||
| public boolean merchantAuditCallback(TtRefundAuditMsgRequest request) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| String result = this.service.execute(executor, this.MERCHANT_AUDIT_CALLBACK, GSON.toJson(request)); | |||
| return true; | |||
| } | |||
| @Override | |||
| public TtPayRefundQueryV2Result refundQueryV2(TtPayRefundQueryV2Request request) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| String result = this.service.execute(executor, this.QUERY_REFUND, GSON.toJson(request)); | |||
| return GSON.fromJson(result, TtPayRefundQueryV2Result.class); | |||
| } | |||
| } | |||
| @@ -0,0 +1,57 @@ | |||
| package com.iformall.douyin.web.api.order.impl; | |||
| import com.alibaba.fastjson.TypeReference; | |||
| import com.google.gson.Gson; | |||
| import com.google.gson.GsonBuilder; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParser; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayOrderQueryV2Request; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.douyin.payv2.result.TtPayCpsOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import com.iformall.douyin.web.api.basic.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.order.TtWebOrderService; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.douyin.web.api.order.TtWebShareService; | |||
| import com.iformall.douyin.web.bean.GoodsCategory; | |||
| import lombok.AllArgsConstructor; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import java.util.List; | |||
| /** | |||
| * | |||
| */ | |||
| @AllArgsConstructor | |||
| public class TtWebShareServiceImpl implements TtWebShareService { | |||
| private static final Gson GSON = new GsonBuilder().create(); | |||
| private TtWebPayService service; | |||
| @Override | |||
| public String profitSharing(ProfitSharingRequest request) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| String result = this.service.execute(executor, this.CREATE_SETTLE, GSON.toJson(request)); | |||
| JsonParser parser = new JsonParser(); | |||
| JsonObject jsonObject = parser.parse(result).getAsJsonObject(); | |||
| return GsonHelper.getString(jsonObject,"settle_id"); | |||
| } | |||
| @Override | |||
| public List<TtSettleResult> getProfitSharingResult(String out_settle_no) throws WxErrorException { | |||
| final TtWebPostRequestExecutor executor = new TtWebPostRequestExecutor(this.service.getRequestHttp()); | |||
| JsonObject jsonObject = new JsonObject(); | |||
| jsonObject.addProperty("out_settle_no",out_settle_no); | |||
| String result = this.service.execute(executor, this.CREATE_SETTLE, jsonObject.toString()); | |||
| List<TtSettleResult> list = GSON.fromJson(result, | |||
| new TypeReference<List<TtSettleResult>>() {}.getType()); | |||
| return list; | |||
| } | |||
| } | |||
| @@ -1,13 +1,10 @@ | |||
| package com.iformall.douyin.web.api.web.impl; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.alibaba.fastjson.TypeReference; | |||
| import com.google.gson.*; | |||
| import com.iformall.douyin.web.api.*; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsCategoryGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGoodsCategoryGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGoodsGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGoodsPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebGoodsService; | |||
| import com.iformall.douyin.web.api.web.TtWebService; | |||
| import com.iformall.douyin.web.bean.*; | |||
| @@ -4,9 +4,8 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.google.gson.Gson; | |||
| import com.google.gson.GsonBuilder; | |||
| import com.iformall.douyin.web.api.*; | |||
| import com.iformall.douyin.web.api.web.TtWebPoiPlanService; | |||
| import com.iformall.douyin.web.api.web.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebService; | |||
| import com.iformall.douyin.web.bean.*; | |||
| import lombok.AllArgsConstructor; | |||
| @@ -1,9 +1,8 @@ | |||
| package com.iformall.douyin.web.api.web.impl; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.google.gson.JsonObject; | |||
| import com.iformall.douyin.web.api.web.TtWebGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebProductService; | |||
| import com.iformall.douyin.web.api.web.TtWebService; | |||
| import com.iformall.douyin.web.bean.*; | |||
| @@ -1,8 +1,8 @@ | |||
| package com.iformall.douyin.web.api.web.impl; | |||
| import com.google.gson.JsonObject; | |||
| import com.iformall.douyin.web.api.web.TtWebGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebGetRequestExecutor; | |||
| import com.iformall.douyin.web.api.basic.TtWebPostRequestExecutor; | |||
| import com.iformall.douyin.web.api.web.TtWebService; | |||
| import com.iformall.douyin.web.api.web.TtWebShopMatchService; | |||
| import com.iformall.douyin.web.bean.TtSupplierMatch; | |||
| @@ -9,6 +9,7 @@ public enum EnumPayVersion { | |||
| WX_PAY_V3(2, "微信支付3.0"), | |||
| WX_PAY_V3_SFT(7,"对接电商收付通版本"), | |||
| DY_PAY_V2(3,"抖音支付2.0,对接商品库"), | |||
| DY_PAY_V3(8,"抖音支付3.0,对接saas商品库"), | |||
| NEU_POS_V1(4,"东软POS支付1.0版本"), | |||
| NO_VERSION(5,"无需支付,无版本"), | |||
| ALI_PAY_V1(6,"支付宝支付1.0") | |||
| @@ -15,7 +15,7 @@ import com.iformall.mallcoo.biImport.VerifyGroup; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.EnumTtPayChannel; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| @@ -18,9 +18,7 @@ import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.AppUniformMsg; | |||
| import com.iformall.domain.po.msg.FmInsideCouponVerifyMsg; | |||
| import com.iformall.domain.po.msg.MpAppMsg; | |||
| import com.iformall.domain.po.msg.SmartAppMsg; | |||
| import com.iformall.domain.vo.*; | |||
| import com.iformall.douyin.pay.enums.MerchantImportStatus; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| @@ -33,17 +31,13 @@ import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.entity.WxComposeOrder; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.PayUtils; | |||
| import com.iformall.utils.RedisLock; | |||
| import org.apache.commons.beanutils.BeanUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.flowable.engine.runtime.Execution; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -9,44 +9,34 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxProfitShareAppInoDto; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCUserBasicInfoVo; | |||
| import com.iformall.domain.vo.WxProfitSharingOrderDetailsVo; | |||
| import com.iformall.domain.vo.WxProfitSharingOrderQueryVo; | |||
| import com.iformall.domain.vo.WxProfitSharingOrderVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.pay.*; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.fee.ServiceFeeAdapterService; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| import com.iformall.service.pay.service.share.entity.PayShareQueryResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareQueryResultReceivers; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.PayUtils; | |||
| 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; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Isolation; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| @@ -16,6 +16,7 @@ import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -79,6 +80,9 @@ public class FmInsideOrderPushDeliveryMsgServiceImpl implements MsgSendService { | |||
| @Autowired | |||
| private TtMerchantPoiMapper ttMerchantPoiMapper; | |||
| @Autowired | |||
| private PayServiceFactory payServiceFactory; | |||
| @Override | |||
| @@ -117,31 +121,11 @@ public class FmInsideOrderPushDeliveryMsgServiceImpl implements MsgSendService { | |||
| private void pushOrderTtDelivery(WxCouponOrder couponOrder,WxOrder order,WxMerchant merchant){ | |||
| try{ | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| String shop_name = merchant.getName(); | |||
| // String ext_valid_shop_id = couponOrder.getBMerchantId().toString(); | |||
| TtMerchantPoi poi = ttMerchantPoiService.getById(couponOrder.getBMerchantId()); | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(couponOrder,EnumPayWay.PAY_WAY_TT.getPlat()); | |||
| WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| TtOrderPushDeliveryRequest request = new TtOrderPushDeliveryRequest(); | |||
| request.setOutOrderNo(order.getComposeOrderId().toString()); | |||
| List<TtOrderPushDeliveryRequest.ItemOrder> itemOrderList = new ArrayList<>(); | |||
| TtOrderPushDeliveryRequest.ItemOrder itemOrder = new TtOrderPushDeliveryRequest.ItemOrder(); | |||
| itemOrder.setItemOrderId(itemOrderId); | |||
| itemOrderList.add(itemOrder); | |||
| request.setItemOrderList(itemOrderList); | |||
| JSONObject poiInfo = new JSONObject(); | |||
| poiInfo.put("shop_name",shop_name); | |||
| if(poi != null){ | |||
| poiInfo.put("ext_valid_shop_id",poi.getSupplierExtId()); | |||
| poiInfo.put("valid_poi_id_str",poi.getPoiId()); | |||
| } | |||
| request.setPoiInfo(poiInfo.toJSONString()); | |||
| boolean b = ttPayService.pushDelivery(request); | |||
| PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(order.getPayVendor(), order.getPayVersion()); | |||
| boolean b = payAdapterService.pushDelivery(appinfo, payAccount, order, merchant); | |||
| if(b){ | |||
| ttOrderPushErrorService.deleteSuccess(couponOrder,couponOrder.getId(),EnumMsgRecordType.INSIDE_ORDER_PUSH_DELIVERY.getCode(),EnumThirdPartyConfigType.TOUTIAO.getCode()); | |||
| } | |||
| @@ -7,10 +7,13 @@ import com.iformall.enums.EnumPayVersion; | |||
| import com.iformall.service.pay.service.fee.ServiceFeeAdapterService; | |||
| import com.iformall.service.pay.service.fee.TtServiceFeeService; | |||
| import com.iformall.service.pay.service.fee.WxServiceFeeService; | |||
| import com.iformall.service.pay.service.refund.douyin.TtRefundAdapterService; | |||
| import com.iformall.service.pay.service.pay.douyin.v3.open.TtOpenPayAdapterService; | |||
| import com.iformall.service.pay.service.refund.douyin.v2.TtRefundAdapterService; | |||
| import com.iformall.service.pay.service.refund.douyin.v3.TtOpenRefundAdapterService; | |||
| import com.iformall.service.pay.service.refund.wx.v2.WxRefundAdapterService; | |||
| import com.iformall.service.pay.service.refund.wx.v3.WxRefundV3AdapterService; | |||
| import com.iformall.service.pay.service.share.douyin.TtPayShareService; | |||
| import com.iformall.service.pay.service.share.douyin.v2.TtPayShareService; | |||
| import com.iformall.service.pay.service.share.douyin.v3.TtOpenShareService; | |||
| import com.iformall.service.pay.service.share.wx.sft.WxPayShareSFTService; | |||
| import com.iformall.service.pay.service.share.wx.v2.WxPayShareService; | |||
| import com.iformall.service.pay.service.share.wx.v3.WxPayShareV3Service; | |||
| @@ -26,7 +29,7 @@ import com.iformall.service.pay.service.cashout.wx.v2.WxCashOutQYFKAdapterServic | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.CPassivePayService; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.TtMiniAppPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.TtMiniAppPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.wx.sft.h5.WxH5PaySFTService; | |||
| import com.iformall.service.pay.service.pay.wx.sft.miniApp.appPay.WxMiniAppPaySFTAdapterService; | |||
| import com.iformall.service.pay.service.pay.wx.v2.h5.WxH5PayService; | |||
| @@ -67,6 +70,8 @@ public class PayServiceFactory { | |||
| @Autowired | |||
| TtMiniAppPayAdapterService ttMiniAppPayService; | |||
| @Autowired | |||
| TtOpenPayAdapterService ttOpenPayAdapterService; | |||
| @Autowired | |||
| WxPayShareService wxShareService; | |||
| @@ -77,6 +82,9 @@ public class PayServiceFactory { | |||
| @Autowired | |||
| TtPayShareService ttShareService; | |||
| @Autowired | |||
| TtOpenShareService ttOpenShareService; | |||
| @Autowired | |||
| WxRefundAdapterService wxRefundService; | |||
| @@ -85,6 +93,9 @@ public class PayServiceFactory { | |||
| @Autowired | |||
| TtRefundAdapterService ttRefundService; | |||
| @Autowired | |||
| TtOpenRefundAdapterService ttOpenRefundService; | |||
| @Autowired | |||
| WxCashOutQYFKAdapterService wxCashOutService; | |||
| @@ -113,6 +124,7 @@ public class PayServiceFactory { | |||
| serviceMap.put(EnumPayWay.PAY_WAY_WECHAT_WAP.getCode()+"_"+EnumPayVersion.WX_PAY_V2.getCode(), wxH5PayService); | |||
| serviceMap.put(EnumPayWay.PAY_WAY_WECHAT_WAP.getCode()+"_"+EnumPayVersion.WX_PAY_V3_SFT.getCode(), wxH5PaySFTService); | |||
| serviceMap.put(EnumPayWay.PAY_WAY_TT.getCode()+"_"+EnumPayVersion.DY_PAY_V2.getCode(),ttMiniAppPayService); | |||
| serviceMap.put(EnumPayWay.PAY_WAY_TT.getCode()+"_"+EnumPayVersion.DY_PAY_V3.getCode(),ttOpenPayAdapterService); | |||
| } | |||
| return serviceMap; | |||
| } | |||
| @@ -174,7 +186,9 @@ public class PayServiceFactory { | |||
| shareMap.put(EnumPayWay.PAY_WAY_NOT_UNPAY_PASSWD.getCode()+"_"+EnumPayVersion.WX_PAY_V3.getCode(), wxPayShareV3Service); | |||
| shareMap.put(EnumPayWay.PAY_WAY_NOT_UNPAY_CREDIT.getCode()+"_"+EnumPayVersion.WX_PAY_V3.getCode(), wxPayShareV3Service); | |||
| shareMap.put(EnumPayWay.PAY_WAY_NOT_UNPAY_GIFTLIST.getCode()+"_"+EnumPayVersion.WX_PAY_V3.getCode(), wxPayShareV3Service); | |||
| shareMap.put(EnumPayWay.PAY_WAY_TT.getCode()+"_"+EnumPayVersion.DY_PAY_V3.getCode(), ttOpenShareService); | |||
| shareMap.put(EnumPayWay.PAY_WAY_NOT_UNPAY_INJECT_SEND.getCode()+"_"+EnumPayVersion.DY_PAY_V3.getCode(), ttOpenShareService); | |||
| } | |||
| return shareMap; | |||
| @@ -188,6 +202,7 @@ public class PayServiceFactory { | |||
| refundMap.put(EnumPayWay.PAY_WAY_WECHAT.getCode()+"_"+EnumPayVersion.WX_PAY_V3.getCode(), wxRefundV3AdapterService); | |||
| refundMap.put(EnumPayWay.PAY_WAY_WECHAT_MA.getCode()+"_"+EnumPayVersion.WX_PAY_V3.getCode(), wxRefundV3AdapterService); | |||
| refundMap.put(EnumPayWay.PAY_WAY_TT.getCode()+"_"+EnumPayVersion.DY_PAY_V2.getCode(), ttRefundService); | |||
| refundMap.put(EnumPayWay.PAY_WAY_TT.getCode()+"_"+EnumPayVersion.DY_PAY_V3.getCode(), ttOpenRefundService); | |||
| } | |||
| return refundMap; | |||
| } | |||
| @@ -106,4 +106,23 @@ public interface PayAdapterService { | |||
| * @return | |||
| */ | |||
| PayAdapterResult noCreatePay(WxPayOrder record, WxComposeOrder composeOrder, List<WxOrder> childOrders); | |||
| /** | |||
| * 查询cps 信息 | |||
| * @param appinfo | |||
| * @param payAccount | |||
| * @param order | |||
| * @return | |||
| */ | |||
| PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception ; | |||
| /** | |||
| * 推送核销状态 | |||
| * @param appinfo | |||
| * @param payAccount | |||
| * @param order | |||
| * @return | |||
| */ | |||
| boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order,WxMerchant merchant) throws Exception ; | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.pay.douyin.v1; | |||
| package com.iformall.service.pay.service.pay.douyin; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -6,13 +6,10 @@ 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.order.entity.WxComposeOrder; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.MaUtil; | |||
| @@ -44,27 +41,8 @@ public class BaseTtPayAdapterService { | |||
| return JSON.toJSONString(map); | |||
| } | |||
| protected PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtPayOrderQueryV2Result ttPayOrderQueryV2Result = ttPayService.queryOrderV2(null, oldRecord.getPayOrderNo()); | |||
| if(ttPayOrderQueryV2Result != null){ | |||
| int code = getPayStatusFromOrderQueryResult(ttPayOrderQueryV2Result); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(), | |||
| ttPayOrderQueryV2Result.getPayChannel(), ttPayOrderQueryV2Result,ttPayOrderQueryV2Result.getPaymentOrderId(),ttPayOrderQueryV2Result.getPayTime()); | |||
| return result; | |||
| }else{ | |||
| return new PayQueryAdapterResult(EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode(),EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getMessage(), | |||
| null,null,null,null); | |||
| } | |||
| // 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){ | |||
| protected int getPayStatusFromOrderQueryResult(TtPayOrderQueryV2Result result){ | |||
| if(result == null){ | |||
| return EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode(); | |||
| } | |||
| @@ -89,11 +67,6 @@ public class BaseTtPayAdapterService { | |||
| protected int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return statusObject.getCode(); | |||
| } | |||
| protected int queryPayStatusCode(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return queryPayStatus(oldRecord,appInfo,payAccount).getCode(); | |||
| } | |||
| protected PayAdapterResult closeOrder(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) { | |||
| return new PayAdapterResult(true, "success", null, null); | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.pay.douyin.v1.miniApp; | |||
| package com.iformall.service.pay.service.pay.douyin.v2.miniApp; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.pay.douyin.v1.miniApp; | |||
| package com.iformall.service.pay.service.pay.douyin.v2.miniApp; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.pay.douyin.v1.miniApp; | |||
| package com.iformall.service.pay.service.pay.douyin.v2.miniApp; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| @@ -1,19 +1,14 @@ | |||
| package com.iformall.service.pay.service.pay.douyin.v1.miniApp; | |||
| package com.iformall.service.pay.service.pay.douyin.v2.miniApp; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.domain.vo.WxOrderCouponVo; | |||
| import com.iformall.douyin.miniapp.api.TtMaService; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.preOrder.CreatePreOrderResult; | |||
| import com.iformall.douyin.pay.preOrder.DouYinCreatePreOrder; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayUnifiedOrderV2Request; | |||
| import com.iformall.douyin.payv2.result.TtPayCpsOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayUnifiedOrderV2Result; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -25,15 +20,12 @@ import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.entity.WxComposeOrder; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.BaseTtPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.douyin.BaseTtPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -41,8 +33,6 @@ import org.springframework.stereotype.Service; | |||
| import java.io.File; | |||
| import java.util.*; | |||
| import static java.util.stream.Collectors.*; | |||
| @Slf4j | |||
| @Service | |||
| public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implements CDrivingPayService{ | |||
| @@ -224,7 +214,17 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
| @Override | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, | |||
| WxPayAccount payAccount) throws Exception { | |||
| return super.queryPayStatus(oldRecord,appInfo, payAccount); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtPayOrderQueryV2Result ttPayOrderQueryV2Result = ttPayService.queryOrderV2(null, oldRecord.getPayOrderNo()); | |||
| if(ttPayOrderQueryV2Result != null){ | |||
| int code = super.getPayStatusFromOrderQueryResult(ttPayOrderQueryV2Result); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(), | |||
| ttPayOrderQueryV2Result.getPayChannel(), ttPayOrderQueryV2Result,ttPayOrderQueryV2Result.getPaymentOrderId(),ttPayOrderQueryV2Result.getPayTime()); | |||
| return result; | |||
| }else{ | |||
| return new PayQueryAdapterResult(EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode(),EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getMessage(), | |||
| null,null,null,null); | |||
| } | |||
| } | |||
| @Override | |||
| @@ -235,7 +235,7 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
| @Override | |||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.queryPayStatusCode(oldRecord, appInfo, payAccount); | |||
| return queryPayStatus(oldRecord, appInfo, payAccount).getCode(); | |||
| } | |||
| @Override | |||
| @@ -479,4 +479,55 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
| return par; | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appInfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtPayCpsOrderQueryV2Result ttPayCpsOrderQueryV2Result = ttPayService.queryCpsOrderV2(null, order.getComposeOrderId().toString()); | |||
| if(ttPayCpsOrderQueryV2Result != null){ | |||
| List<TtPayCpsOrderQueryV2Result.CpsItem> cpsList = ttPayCpsOrderQueryV2Result.getCpsInfo().getCpsItemList(); | |||
| for (TtPayCpsOrderQueryV2Result.CpsItem cpsItem: cpsList) { | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| if(StringUtils.isNotBlank(itemOrderId) && itemOrderId.equals(cpsItem.getItemOrderId())){ | |||
| Map<String,Object> cps = new HashMap<>(); | |||
| cps.put("itemOrderId",cpsItem.getItemOrderId()); | |||
| cps.put("sellAmount",cpsItem.getSellAmount()); | |||
| cps.put("sourceType",cpsItem.getSourceType()); | |||
| cps.put("itemId",cpsItem.getItemId()); | |||
| cps.put("commissionAmount",cpsItem.getCommissionAmount()); | |||
| cps.put("commissionUserId",cpsItem.getCommissionUserId()); | |||
| cps.put("commissionRate",cpsItem.getCommissionRate()); | |||
| // break; | |||
| PayAdapterResult par = new PayAdapterResult(); | |||
| par.setSuccess(true); | |||
| par.setData(cps); | |||
| return par; | |||
| } | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| TtMerchantPoi poi = ttMerchantPoiMapper.selectById(merchant.getId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| TtOrderPushDeliveryRequest request = new TtOrderPushDeliveryRequest(); | |||
| request.setOutOrderNo(order.getComposeOrderId().toString()); | |||
| List<TtOrderPushDeliveryRequest.ItemOrder> itemOrderList = new ArrayList<>(); | |||
| TtOrderPushDeliveryRequest.ItemOrder itemOrder = new TtOrderPushDeliveryRequest.ItemOrder(); | |||
| itemOrder.setItemOrderId(itemOrderId); | |||
| itemOrderList.add(itemOrder); | |||
| request.setItemOrderList(itemOrderList); | |||
| JSONObject poiInfo = new JSONObject(); | |||
| poiInfo.put("shop_name",poi.getPoiName()); | |||
| if(poi != null){ | |||
| poiInfo.put("ext_valid_shop_id",poi.getSupplierExtId()); | |||
| poiInfo.put("valid_poi_id_str",poi.getPoiId()); | |||
| } | |||
| request.setPoiInfo(poiInfo.toJSONString()); | |||
| return ttPayService.pushDelivery(request); | |||
| } | |||
| } | |||
| @@ -0,0 +1,243 @@ | |||
| package com.iformall.service.pay.service.pay.douyin.v3.open; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.douyin.payv2.request.TtPayUnifiedOrderV2Request; | |||
| import com.iformall.douyin.payv2.result.TtPayCpsOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayOrderQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayUnifiedOrderV2Result; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.enums.EnumCouponOrderStatus; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.EnumPayMchType; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.order.OrderAdapterService; | |||
| import com.iformall.service.order.OrderFactory; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.entity.WxComposeOrder; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.douyin.BaseTtPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.EnumTtOrderStatus; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.EnumTtPoiOrderStatus; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.MaUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.io.File; | |||
| import java.util.*; | |||
| @Slf4j | |||
| @Service | |||
| public class TtOpenPayAdapterService extends BaseTtPayAdapterService implements CDrivingPayService{ | |||
| @Autowired | |||
| private WxAppinfoMapper wxAppinfoMapper; | |||
| @Autowired | |||
| private TtMerchantPoiMapper ttMerchantPoiMapper; | |||
| @Autowired | |||
| private TtCouponChannelPoiMapper ttCouponChannelPoiMapper; | |||
| @Autowired | |||
| private WxBatchOrderMapper wxBatchOrderMapper; | |||
| @Autowired | |||
| private WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| private WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @Autowired | |||
| private WxOrderMapper wxOrderMapper; | |||
| @Autowired | |||
| OrderFactory orderFactory; | |||
| @Autowired | |||
| private MaUtil maUtil; | |||
| @Override | |||
| public PayAdapterResult pay(WxPayAccount payAccount,WxPayOrder record,WxComposeOrder composeOrder,List<WxOrder> childOrders, | |||
| String productName,WxAppinfo appInfo,Date currentDate, PayExtraParam params,boolean isFreezen) throws Exception { | |||
| //抖音支付1.0,已经不再支持 | |||
| throw new MallinkException(ErrorCode.SYS_AUTH_ERROR.getCode(),"请升级抖音版本"); | |||
| } | |||
| @Override | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, | |||
| WxPayAccount payAccount) throws Exception { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| TtPayOrderQueryV2Result ttPayOrderQueryV2Result = ttWebPayService.getTtWebOrderService().queryOrderV2(null, oldRecord.getPayOrderNo()); | |||
| if(ttPayOrderQueryV2Result != null){ | |||
| int code = super.getPayStatusFromOrderQueryResult(ttPayOrderQueryV2Result); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(), | |||
| ttPayOrderQueryV2Result.getPayChannel(), ttPayOrderQueryV2Result,ttPayOrderQueryV2Result.getPaymentOrderId(),ttPayOrderQueryV2Result.getPayTime()); | |||
| return result; | |||
| }else{ | |||
| return new PayQueryAdapterResult(EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode(),EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getMessage(), | |||
| null,null,null,null); | |||
| } | |||
| } | |||
| @Override | |||
| public int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return super.queryPayStatus(statusObject, orderOutNo); | |||
| } | |||
| @Override | |||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return queryPayStatus(oldRecord, appInfo, payAccount).getCode(); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderClose(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception { | |||
| return super.closeOrder(appInfo, record, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.payOrderReverse(appInfo, record, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderPush(String openId,WxAppinfo appInfo, WxBatchOrder batchOrder,WxPayOrder payOrder) throws Exception { | |||
| return null; | |||
| } | |||
| private EnumTtOrderStatus getTtOrderStatus(Integer orderStatus, Integer couponOrderStatus) throws Exception { | |||
| if(EnumOrderStatus.getEnum(orderStatus).equals(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_0; | |||
| } | |||
| else if(EnumOrderStatus.getEnum(orderStatus).equals(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS)){ | |||
| if(EnumCouponOrderStatus.getEnum(couponOrderStatus).equals(EnumCouponOrderStatus.COUPON_ORDER_USED)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_4; | |||
| } | |||
| if(EnumCouponOrderStatus.getEnum(couponOrderStatus).equals(EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_3; | |||
| } | |||
| return EnumTtOrderStatus.ORDER_STATUS_1; | |||
| } | |||
| else if(EnumOrderStatus.getEnum(orderStatus).equals(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_2; | |||
| } | |||
| else if(EnumOrderStatus.getEnum(orderStatus).equals(EnumOrderStatus.ORDER_STATUS_PENDING_REFUND)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_5; | |||
| } | |||
| else if(EnumOrderStatus.getEnum(orderStatus).equals(EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_6; | |||
| } | |||
| else if(EnumOrderStatus.getEnum(orderStatus).equals(EnumOrderStatus.ORDER_STATUS_REFUND_FAILD)){ | |||
| return EnumTtOrderStatus.ORDER_STATUS_8; | |||
| } | |||
| log.error("订单状态异常 。。。"); | |||
| throw new Exception("订单状态异常"); | |||
| } | |||
| @Override | |||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception{ | |||
| 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.put("callbackData",JSONObject.parseObject(getCallbackData(record),Map.class)); | |||
| Map<String,Integer> payment = new HashMap(); | |||
| payment.put("totalAmount",composeOrder.getPayment()); | |||
| map.put("payment",payment); | |||
| List<Map<String,Object>> goodsList = new ArrayList<>(); | |||
| for (WxOrder o: childOrders) { | |||
| WxCoupon wxCoupon = wxCouponService.getById(o.getProductId(), record.getTenantId()); | |||
| Map<String,Object> good = new HashMap<>(); | |||
| good.put("quantity",o.getCouponNumber()); | |||
| good.put("price",o.getPayment()); | |||
| good.put("goodsName",wxCoupon.getTitle()); | |||
| good.put("goodsPhoto",wxCoupon.getCoverImg()); | |||
| good.put("goodsId",wxCoupon.getGoodsId()); | |||
| good.put("goodsType",composeOrder.getMainOrder().getIsTtPoiOrder()); | |||
| goodsList.add(good); | |||
| } | |||
| map.put("goodsList",goodsList); | |||
| } | |||
| par.setData(map); | |||
| return par; | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appInfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| TtPayCpsOrderQueryV2Result ttPayCpsOrderQueryV2Result = ttWebPayService.getTtWebOrderService().queryCpsOrderV2(null, order.getComposeOrderId().toString()); | |||
| if(ttPayCpsOrderQueryV2Result != null){ | |||
| List<TtPayCpsOrderQueryV2Result.CpsItem> cpsList = ttPayCpsOrderQueryV2Result.getCpsInfo().getCpsItemList(); | |||
| for (TtPayCpsOrderQueryV2Result.CpsItem cpsItem: cpsList) { | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| if(StringUtils.isNotBlank(itemOrderId) && itemOrderId.equals(cpsItem.getItemOrderId())){ | |||
| Map<String,Object> cps = new HashMap<>(); | |||
| cps.put("itemOrderId",cpsItem.getItemOrderId()); | |||
| cps.put("sellAmount",cpsItem.getSellAmount()); | |||
| cps.put("sourceType",cpsItem.getSourceType()); | |||
| cps.put("itemId",cpsItem.getItemId()); | |||
| cps.put("commissionAmount",cpsItem.getCommissionAmount()); | |||
| cps.put("commissionUserId",cpsItem.getCommissionUserId()); | |||
| cps.put("commissionRate",cpsItem.getCommissionRate()); | |||
| // break; | |||
| PayAdapterResult par = new PayAdapterResult(); | |||
| par.setSuccess(true); | |||
| par.setData(cps); | |||
| return par; | |||
| } | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| TtMerchantPoi poi = ttMerchantPoiMapper.selectById(merchant.getId()); | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appinfo); | |||
| TtOrderPushDeliveryRequest request = new TtOrderPushDeliveryRequest(); | |||
| request.setOutOrderNo(order.getComposeOrderId().toString()); | |||
| List<TtOrderPushDeliveryRequest.ItemOrder> itemOrderList = new ArrayList<>(); | |||
| TtOrderPushDeliveryRequest.ItemOrder itemOrder = new TtOrderPushDeliveryRequest.ItemOrder(); | |||
| itemOrder.setItemOrderId(itemOrderId); | |||
| itemOrderList.add(itemOrder); | |||
| request.setItemOrderList(itemOrderList); | |||
| JSONObject poiInfo = new JSONObject(); | |||
| poiInfo.put("shop_name",poi.getPoiName()); | |||
| if(poi != null){ | |||
| poiInfo.put("ext_valid_shop_id",poi.getSupplierExtId()); | |||
| poiInfo.put("valid_poi_id_str",poi.getPoiId()); | |||
| } | |||
| request.setPoiInfo(poiInfo.toJSONString()); | |||
| return ttWebPayService.getTtWebOrderService().pushDelivery(request); | |||
| } | |||
| } | |||
| @@ -79,4 +79,14 @@ public class WxH5PaySFTService extends BaseWxPaySFTAdapterService implements CDr | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -322,4 +322,14 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -75,4 +75,14 @@ public class WxH5PayService extends BaseWxPayV2AdapterService implements CDrivi | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -348,4 +348,14 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -297,5 +297,15 @@ public class WxMiniMaPayAdapterService extends BaseWxPayV2AdapterService impleme | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -364,4 +364,14 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| @Override | |||
| public PayAdapterResult queryCpsOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order) throws Exception { | |||
| return null; | |||
| } | |||
| @Override | |||
| public boolean pushDelivery(WxAppinfo appinfo, WxPayAccount payAccount, WxOrder order, WxMerchant merchant) throws Exception { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -39,4 +39,15 @@ public interface RefundPayAdapterService { | |||
| * @param payWay | |||
| */ | |||
| public RefundNotifyAdapterResult notify(Map<String, String> paramMap, EnumPayWay payWay); | |||
| /** | |||
| * 审核结果同步 | |||
| * @param | |||
| * @param refund_audit_status 1:同意退款 2:不同意退款 | |||
| * @param deny_message 不同意退款信息(不同意退款时必填),长度 <= 512 byte | |||
| * | |||
| */ | |||
| public boolean merchantAuditCallback(WxAppinfo appInfo,WxPayAccount payAccount, | |||
| String out_refund_no,Integer refund_audit_status,String deny_message); | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.refund.douyin; | |||
| package com.iformall.service.pay.service.refund.douyin.v2; | |||
| import com.alibaba.fastjson.JSON; | |||
| @@ -12,6 +12,7 @@ import com.iformall.douyin.pay.preOrder.CreateRefund; | |||
| import com.iformall.douyin.pay.preOrder.CreateRefundResult; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundQueryV2Request; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundV2Request; | |||
| import com.iformall.douyin.payv2.request.TtRefundAuditMsgRequest; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundV2Result; | |||
| import com.iformall.enums.EnumPayType; | |||
| @@ -220,4 +221,24 @@ public class TtRefundAdapterService implements RefundPayAdapterService{ | |||
| return notifySuccessResult(refundOrder.getPayOrderNo(), paramMap.get("cp_refundno"), refundOrder); | |||
| } | |||
| @Override | |||
| public boolean merchantAuditCallback(WxAppinfo appInfo, WxPayAccount payAccount, String out_refund_no, Integer refund_audit_status, String deny_message) { | |||
| try{ | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtRefundAuditMsgRequest request = new TtRefundAuditMsgRequest(); | |||
| request.setOutRefundNo(out_refund_no); | |||
| if(refund_audit_status == null || refund_audit_status.intValue() == 1){ | |||
| request.setRefundAuditStatus(1); | |||
| }else{ | |||
| request.setRefundAuditStatus(2); | |||
| request.setDenyMessage(deny_message); | |||
| } | |||
| return ttPayService.merchantAuditCallback(request); | |||
| }catch(TtPayException e){ | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"退款审核异常"); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,207 @@ | |||
| package com.iformall.service.pay.service.refund.douyin.v3; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundQueryV2Request; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundV2Request; | |||
| import com.iformall.douyin.payv2.request.TtRefundAuditMsgRequest; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundV2Result; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumRefundStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.mapper.WxRefundOrderMapper; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.pay.service.refund.RefundPayAdapterService; | |||
| import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; | |||
| import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.XmlUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.*; | |||
| @Slf4j | |||
| @Service | |||
| public class TtOpenRefundAdapterService implements RefundPayAdapterService{ | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| /** | |||
| * 做为分账的扩展数据 | |||
| * @param | |||
| * @return | |||
| */ | |||
| protected String getCpExtra(WxRefundOrder record) { | |||
| Map<String,String> map = new HashMap<>(); | |||
| map.put("tenantId",record.getTenantId()); | |||
| return JSON.toJSONString(map); | |||
| } | |||
| @Override | |||
| public RefundAdapterResult refund(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,Long orderId,EnumPayType payType) { | |||
| try { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| TtPayRefundV2Request request = new TtPayRefundV2Request(); | |||
| request.setOutOrderNo(payOrder.getPayOrderNo()); | |||
| request.setOutRefundNo(record.getId().toString()); | |||
| request.setCpExtra(getCpExtra(record)); | |||
| TtPayRefundV2Request.PageEntry pageEntry = new TtPayRefundV2Request.PageEntry(); | |||
| pageEntry.setPath(Constant.mainPageUrl); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("type","dt"); | |||
| paramMap.put("tenantId",payOrder.getTenantId()); | |||
| paramMap.put("orderId",payOrder.getId()); | |||
| pageEntry.setParams(JSON.toJSONString(paramMap)); | |||
| request.setOrderEntrySchema(pageEntry); | |||
| WxOrder order = wxOrderService.getById(record.getOrderId(), appInfo.getTenantId()); | |||
| if(StringUtils.isBlank(order.getExtParam())){ | |||
| request.setRefundTotalAmount(order.getPayment()); | |||
| }else{ | |||
| List<TtPayRefundV2Request.OrderDetail> list = new ArrayList<>(); | |||
| TtPayRefundV2Request.OrderDetail orderDetail = new TtPayRefundV2Request.OrderDetail(); | |||
| String itemOrderId = (String) order.getExpParamValue("itemOrderId"); | |||
| orderDetail.setItemOrderId(itemOrderId); | |||
| list.add(orderDetail); | |||
| request.setItemOrderDetail(list); | |||
| } | |||
| TtPayRefundV2Result result1 = ttWebPayService.getTtWebRefundService().refundV2(request); | |||
| record.setRefundId(result1.getRefundId()); | |||
| // record.setRefundVendor(payOrder.getTtPayWay()); | |||
| return new RefundAdapterResult(true, EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(), "退款订单申请成功", result1); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),e.getMessage(),null); | |||
| } | |||
| } | |||
| @Override | |||
| public RefundAdapterResult queryRefund(WxAppinfo appInfo,WxPayAccount payAccount, WxRefundOrder record) { | |||
| try { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| TtPayRefundQueryV2Request request = new TtPayRefundQueryV2Request(); | |||
| request.setOutRefundNo(record.getId().toString()); | |||
| TtPayRefundQueryV2Result ttPayRefundQueryV2Result = ttWebPayService.getTtWebRefundService().refundQueryV2(request); | |||
| if(ttPayRefundQueryV2Result != null){ | |||
| if("PROCESSING".equals(ttPayRefundQueryV2Result.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(),"退款订单申请成功",ttPayRefundQueryV2Result); | |||
| }else if("SUCCESS".equals(ttPayRefundQueryV2Result.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_SUCCESS.getCode(),"退款成功",ttPayRefundQueryV2Result); | |||
| }else if("FAIL".equals(ttPayRefundQueryV2Result.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_FAIL.getCode(),ttPayRefundQueryV2Result.getMessage(),ttPayRefundQueryV2Result); | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常"); | |||
| } | |||
| }else{ | |||
| return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),"退款订单申请失败",null); | |||
| } | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常"); | |||
| } | |||
| } | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| WxPayOrderMapper wxPayOrderMapper; | |||
| @Autowired | |||
| WxRefundOrderMapper wxRefundOrderMapper; | |||
| private RefundNotifyAdapterResult notifyErrorResult(String msg) { | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", msg); | |||
| return new RefundNotifyAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),msg,XmlUtil.getRequestXml(resultMap)); | |||
| } | |||
| private RefundNotifyAdapterResult notifySuccessResult(String transactionId,String refundId,WxRefundOrder refundOrder) { | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "SUCCESS"); | |||
| resultMap.put("return_msg", "OK"); | |||
| return new RefundNotifyAdapterResult(transactionId, refundId,refundOrder,XmlUtil.getRequestXml(resultMap)); | |||
| } | |||
| @Override | |||
| public RefundNotifyAdapterResult notify(Map<String, String> paramMap, EnumPayWay payWay) { | |||
| log.info("TtRefundAdapterService notify{}"+paramMap); | |||
| String tenantId = paramMap.get("tenantId"); | |||
| /** | |||
| * | |||
| */ | |||
| String refundno = paramMap.get("cp_refundno"); | |||
| Long refundOrderId = Long.valueOf(refundno); | |||
| WxRefundOrder refundOrder = wxRefundOrderMapper.selectById(refundOrderId); | |||
| String appId = paramMap.get("appid"); | |||
| WxAppinfo appinfo = wxAppinfoService.getByAppIdFromRedis(appId,tenantId); | |||
| if (appinfo == null) { | |||
| log.error("未找到appid信息:" + appId); | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); | |||
| if (payAccount == null) { | |||
| log.error("未找到mch_id信息:" + appId); | |||
| throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); | |||
| } | |||
| if (!"SUCCESS".equals(paramMap.get("status"))) { | |||
| log.error("notify refund, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| return notifyErrorResult("订单状态码非SUCCESS"); | |||
| } | |||
| // 验证退款金额 | |||
| if (!paramMap.get("refund_amount").equals(refundOrder.getRefundFee().toString())) { | |||
| log.error("notify refund, wxpay check refund_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| return notifyErrorResult("退款总金额不一致"); | |||
| } | |||
| log.info("notify refund, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| return notifySuccessResult(refundOrder.getPayOrderNo(), paramMap.get("cp_refundno"), refundOrder); | |||
| } | |||
| @Override | |||
| public boolean merchantAuditCallback(WxAppinfo appInfo, WxPayAccount payAccount, String out_refund_no, Integer refund_audit_status, String deny_message) { | |||
| try{ | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| TtRefundAuditMsgRequest request = new TtRefundAuditMsgRequest(); | |||
| request.setOutRefundNo(out_refund_no); | |||
| if(refund_audit_status == null || refund_audit_status.intValue() == 1){ | |||
| request.setRefundAuditStatus(1); | |||
| }else{ | |||
| request.setRefundAuditStatus(2); | |||
| request.setDenyMessage(deny_message); | |||
| } | |||
| return ttWebPayService.getTtWebRefundService().merchantAuditCallback(request); | |||
| }catch(WxErrorException e){ | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"退款审核异常"); | |||
| } | |||
| } | |||
| } | |||
| @@ -687,4 +687,9 @@ public class WxRefundAdapterService implements RefundPayAdapterService{ | |||
| return notifyErrorResult("FAILED"); | |||
| } | |||
| @Override | |||
| public boolean merchantAuditCallback(WxAppinfo appInfo, WxPayAccount payAccount, String out_refund_no, Integer refund_audit_status, String deny_message) { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -59,7 +59,6 @@ import lombok.extern.slf4j.Slf4j; | |||
| @Slf4j | |||
| @Service | |||
| public class WxRefundV3AdapterService implements RefundPayAdapterService{ | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @@ -279,4 +278,9 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ | |||
| } | |||
| } | |||
| @Override | |||
| public boolean merchantAuditCallback(WxAppinfo appInfo, WxPayAccount payAccount, String out_refund_no, Integer refund_audit_status, String deny_message) { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -1,52 +1,37 @@ | |||
| package com.iformall.service.pay.service.share.douyin; | |||
| package com.iformall.service.pay.service.share.douyin.v2; | |||
| 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.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.enums.MerchantImportStatus; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.pay.orderQuery.QuerySettleResult; | |||
| import com.iformall.douyin.pay.preOrder.Settle; | |||
| import com.iformall.douyin.pay.preOrder.SettleResult; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.TtGoodsCategoryService; | |||
| import com.iformall.service.WxProfitPaymentReceiverService; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| 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.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Qualifier; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import java.util.stream.Stream; | |||
| import static java.util.stream.Collectors.groupingBy; | |||
| @Slf4j | |||
| @Service | |||
| @@ -233,30 +218,16 @@ 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.getOutSettleNo().toString()); | |||
| if(profitSharingResult.isSuccess()){ | |||
| ProfitSharingResult.Receiver receiver = profitSharingResult.getData().get(0); | |||
| if("SUCCESS".equals(receiver.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_DONE.getCode(), "success",receiver, null); | |||
| } else if("FAIL".equals(receiver.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_FAILED.getCode(), "fail",receiver, null); | |||
| } | |||
| List<TtSettleResult> settleResultList = ttPayService.getProfitSharingV2Service().getProfitSharingResult(record.getOutSettleNo().toString()); | |||
| TtSettleResult settleResult = settleResultList.get(0); | |||
| if("SUCCESS".equals(settleResult.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_DONE.getCode(), "success",settleResult, null); | |||
| } | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), profitSharingResult.getErrTips()); | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_FAILED.getCode(), "fail",settleResult, null); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), e.getMessage()); | |||
| } | |||
| // QuerySettleResult querySettleResult = DouYinPayHelper.settleQuery(appInfo.getAppId(), payAccount.getApiKey(), record.getId().toString(), null); | |||
| // if(querySettleResult != null){ | |||
| // if(querySettleResult.getSettleStatus().equals("SUCCESS")){ | |||
| // return new PayShareQueryResult(true, 5, "success",querySettleResult, null); | |||
| // }else if(querySettleResult.getSettleStatus().equals("FAIL")){ | |||
| // return new PayShareQueryResult(true, 6, "fail",querySettleResult, null); | |||
| // } | |||
| // } | |||
| // throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), querySettleResult.getMsg()); | |||
| } | |||
| @Override | |||
| @@ -0,0 +1,250 @@ | |||
| package com.iformall.service.pay.service.share.douyin.v3; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.enums.MerchantImportStatus; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.douyin.payv2.result.TtSettleResult; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.douyin.web.api.web.TtWebService; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.TtGoodsCategoryService; | |||
| import com.iformall.service.WxProfitPaymentReceiverService; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.service.pay.service.pay.douyin.v2.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| 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 lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.*; | |||
| @Slf4j | |||
| @Service | |||
| public class TtOpenShareService extends PayShareBaseAdapterService{ | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| WxCouponOrderMapper wxCouponOrderMapper; | |||
| @Autowired | |||
| WxOrderMapper wxOrderMapper; | |||
| @Autowired | |||
| WxProfitSharingOrderMapper wxProfitSharingOrderMapper; | |||
| @Autowired | |||
| OrderCpsMapper orderCpsMapper; | |||
| @Autowired | |||
| TtGoodsCategoryService ttGoodsCategoryService; | |||
| @Lazy | |||
| @Autowired | |||
| WxProfitSharingReceiverService wxProfitSharingReceiverService; | |||
| @Lazy | |||
| @Autowired | |||
| WxProfitPaymentReceiverService wxProfitPaymentReceiverService; | |||
| /** | |||
| * 做为分账的扩展数据 | |||
| * @param | |||
| * @return | |||
| */ | |||
| protected String getCpExtra(WxProfitSharingOrder record) { | |||
| Map<String,String> map = new HashMap<>(); | |||
| map.put("tenantId",record.getTenantId()); | |||
| return JSON.toJSONString(map); | |||
| } | |||
| @Override | |||
| public Integer getSubsidyType() { | |||
| return EnumMerchantSubsidyType.DOUYIN.getCode(); | |||
| } | |||
| @Override | |||
| public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { | |||
| String before3dayStr = DateUtils.getTimeBefore(2, new Date()); | |||
| Date before3day = DateUtils.stringToDate(before3dayStr); | |||
| if(before3day.before(record.getCreateTime())){ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),"未满足结算周期..", null,null); | |||
| } | |||
| try { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| ProfitSharingRequest request = new ProfitSharingRequest(); | |||
| request.setOutOrderNo(record.getOrderId().toString()); | |||
| request.setCpExtra(getCpExtra(record)); | |||
| if(record.getOutSettleNo() == null){ | |||
| record.setOutSettleNo(record.getId()); | |||
| }else{ | |||
| record.setOutSettleNo(record.getOutSettleNo() + 1l); | |||
| } | |||
| request.setOutSettleNo(record.getOutSettleNo().toString()); | |||
| request.setSettleDesc("完结分账"); | |||
| String settleId = ttWebPayService.getTtWebShareService().profitSharing(request); | |||
| return new PayShareResult(true, null,"success", null,settleId); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),e.getMessage(), null,null); | |||
| } | |||
| } | |||
| @Override | |||
| public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers) throws MallinkException { | |||
| String before3dayStr = DateUtils.getTimeBefore(2, new Date()); | |||
| Date before3day = DateUtils.stringToDate(before3dayStr); | |||
| if(before3day.before(record.getCreateTime())){ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),"未满足结算周期..", null,null); | |||
| } | |||
| try { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| ProfitSharingRequest request = new ProfitSharingRequest(); | |||
| request.setOutOrderNo(record.getOrderId().toString()); | |||
| request.setCpExtra(getCpExtra(record)); | |||
| if(record.getOutSettleNo() == null){ | |||
| record.setOutSettleNo(record.getId()); | |||
| }else{ | |||
| record.setOutSettleNo(record.getOutSettleNo() + 1l); | |||
| } | |||
| request.setOutSettleNo(record.getOutSettleNo().toString()); | |||
| request.setSettleDesc("完结分账"); | |||
| List list = new ArrayList<>(); | |||
| 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); | |||
| } | |||
| request.setSettleParams(JSON.toJSONString(list)); | |||
| String settleId = ttWebPayService.getTtWebShareService().profitSharing(request); | |||
| return new PayShareResult(true, null,"success", null,settleId); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),e.getMessage(), null,null); | |||
| } | |||
| } | |||
| @Override | |||
| public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | |||
| try { | |||
| TtWebPayService ttWebPayService = maUtil.getTtWebPayService(appInfo); | |||
| List<TtSettleResult> settleResultList = ttWebPayService.getTtWebShareService().getProfitSharingResult(record.getOutSettleNo().toString()); | |||
| TtSettleResult settleResult = settleResultList.get(0); | |||
| if("SUCCESS".equals(settleResult.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_DONE.getCode(), "success",settleResult, null); | |||
| } | |||
| return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_FAILED.getCode(), "fail",settleResult, null); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public ShareNotifyAdapterResult notify(Map<String, String> paramMap,EnumPayWay payWay) { | |||
| //抖音不支持 | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); | |||
| } | |||
| @Override | |||
| public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { | |||
| //抖音需要页面添加帐号 | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); | |||
| } | |||
| @Override | |||
| public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount, | |||
| WxProfitSharingReceiver receiver) { | |||
| //抖音不支持 | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); | |||
| } | |||
| @Override | |||
| public int getCPSCommission(TenantEntity tenantEntity, Long orderId) { | |||
| WxOrder order = wxOrderMapper.selectById(orderId, tenantEntity.getTenantId()); | |||
| if(EnumOrderCpsStatus.ORDER_IS_CPS.getCode().equals(order.getCpsStatus())){ | |||
| OrderCps orderCps = orderCpsMapper.selectById(orderId, tenantEntity.getTenantId()); | |||
| return orderCps.getCommissionAmount(); | |||
| }else if(EnumOrderCpsStatus.ORDER_NO_CPS.getCode().equals(order.getCpsStatus())){ | |||
| return 0; | |||
| }else{ | |||
| return -1;//还未查询到达人佣金 | |||
| } | |||
| } | |||
| @Override | |||
| public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { | |||
| if(merchantId == null || merchantId.equals(0L)){ | |||
| return null; | |||
| } | |||
| WxProfitSharingReceiver record = wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.TOUTIAO); | |||
| if(record != null && ttPayWay != null){ | |||
| if(EnumTtPayChannel.WX_PAY.getCode().equals(ttPayWay) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(record.getWxImportStatus())){ | |||
| log.error("支付方式【"+EnumTtPayChannel.WX_PAY.getMessage()+"】未开通"); | |||
| return null; | |||
| }else if(EnumTtPayChannel.ALI_PAY.getCode().equals(ttPayWay) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(record.getAlipayImportStatus())){ | |||
| log.error("支付方式【"+EnumTtPayChannel.ALI_PAY.getMessage()+"】未开通"); | |||
| return null; | |||
| }else if(EnumTtPayChannel.HZ_PAY.getCode().equals(ttPayWay) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(record.getHzImportStatus())){ | |||
| log.error("支付方式【"+EnumTtPayChannel.HZ_PAY.getMessage()+"】未开通"); | |||
| return null; | |||
| } | |||
| } | |||
| return record; | |||
| } | |||
| @Override | |||
| public WxProfitPaymentReceiver getPaymantReceiver(TenantEntity tenantEntity, Long merchantId) { | |||
| if(merchantId == null || merchantId.equals(0L)){ | |||
| return null; | |||
| } | |||
| WxProfitPaymentReceiver record = wxProfitPaymentReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.TOUTIAO); | |||
| if(record != null && !MerchantImportStatus.improt_success.getCode().equals(record.getWxImportStatus()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(record.getAlipayImportStatus()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(record.getHzImportStatus())){ | |||
| log.error("该商户未开通支付"); | |||
| return null; | |||
| } | |||
| return record; | |||
| } | |||
| } | |||
| @@ -1,19 +1,12 @@ | |||
| package com.iformall.service.pay.service.share.wx.sft; | |||
| import java.text.ParseException; | |||
| 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.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.enums.MerchantImportStatus; | |||
| 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.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -22,26 +15,13 @@ import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.pay.WxProfitSharing; | |||
| import com.iformall.pay.WxProfitSharingFinishP; | |||
| import com.iformall.pay.WxProfitSharingP; | |||
| import com.iformall.pay.WxProfitSharingQueryP; | |||
| import com.iformall.pay.WxProfitSharingReceiverP; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| 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.ShareNotifyAdapterResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.Utility; | |||
| import com.iformall.utils.XmlUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| @@ -3,43 +3,30 @@ package com.iformall.service.pay.service.share.wx.v2; | |||
| import java.text.ParseException; | |||
| 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.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.enums.MerchantImportStatus; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxProfitPaymentReceiverService; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.utils.*; | |||
| import net.sf.saxon.trans.Err; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Qualifier; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Service; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.pay.WxProfitSharing; | |||
| import com.iformall.pay.WxProfitSharingFinishP; | |||
| import com.iformall.pay.WxProfitSharingP; | |||
| import com.iformall.pay.WxProfitSharingQueryP; | |||
| import com.iformall.pay.WxProfitSharingReceiverP; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| 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.ShareNotifyAdapterResult; | |||
| @@ -21,6 +21,8 @@ import com.iformall.douyin.pay.impl.TtPayServiceImpl; | |||
| import com.iformall.douyin.payv2.config.TtPayConfig; | |||
| import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; | |||
| import com.iformall.douyin.web.api.goodlifesaas.impl.TtGoodLifeSaasServiceImpl; | |||
| import com.iformall.douyin.web.api.order.TtWebPayService; | |||
| import com.iformall.douyin.web.api.order.impl.TtWebPayServiceImpl; | |||
| import com.iformall.douyin.web.api.web.TtWebService; | |||
| import com.iformall.douyin.web.api.web.impl.TtWebServiceImpl; | |||
| import com.iformall.douyin.web.config.TtWebDefaultConfigImpl; | |||
| @@ -58,6 +60,9 @@ public class MaUtil { | |||
| private static Map<String,TtWebService> webServiceMap = new ConcurrentHashMap<String,TtWebService>(); | |||
| private static Map<String,String> webServiceKeyMap = new ConcurrentHashMap<String,String>(); | |||
| private static Map<String,TtWebPayService> webPayServiceMap = new ConcurrentHashMap<String,TtWebPayService>(); | |||
| private static Map<String,String> webPayServiceKeyMap = new ConcurrentHashMap<String,String>(); | |||
| private static Map<String,TtGoodLifeSaasService> goodLifeSaasServiceMap = new ConcurrentHashMap<String,TtGoodLifeSaasService>(); | |||
| private static Map<String,String> goodLifeSaasServiceKeyMap = new ConcurrentHashMap<String,String>(); | |||
| @@ -295,6 +300,47 @@ public class MaUtil { | |||
| } | |||
| return service; | |||
| } | |||
| public TtWebPayService getTtWebPayService(WxAppinfo appinfo) { | |||
| TtWebDefaultConfigImpl config = new TtWebDefaultConfigImpl(); | |||
| config.setAppid(appinfo.getAppId()); | |||
| config.setSecret(appinfo.getSecret()); | |||
| config.setToken(appinfo.getToken()); | |||
| config.setAesKey(appinfo.getAesKey()); | |||
| config.setMsgDataFormat(appinfo.getMsgDataFormat()); | |||
| if (StringUtils.isNotBlank(appinfo.getAccessToken())) { | |||
| config.setAccessToken(appinfo.getAccessToken()); | |||
| config.setExpiresTime(appinfo.getLastTokenTime().getTime()+appinfo.getExpiresIn()*1000); | |||
| } | |||
| config.setApacheHttpClientBuilder(FmHttpClientBuilder.get()); | |||
| //默认抖音 | |||
| config.setApiBegin(TtWebApiBeginEnum.DY); | |||
| String key = appinfo.getAppId()+String.valueOf(config.getExpiresTime()); | |||
| TtWebPayService service = webPayServiceMap.get(key); | |||
| if ( null == service ) { | |||
| synchronized("getTtwebPayServiceBlock"+appinfo.getAppId()) { | |||
| service = webPayServiceMap.get(key); | |||
| if (null == service) { | |||
| //删除掉之前的 | |||
| String appServiceKey = webPayServiceKeyMap.get(appinfo.getAppId()); | |||
| if (!StringUtils.isBlank(appServiceKey)) { | |||
| if (webPayServiceMap.containsKey(appServiceKey)) { | |||
| webPayServiceMap.remove(appServiceKey); | |||
| } | |||
| webPayServiceKeyMap.remove(appinfo.getAppId()); | |||
| } | |||
| service = new TtWebPayServiceImpl(); | |||
| service.setTtWebConfig(config); | |||
| webPayServiceMap.put(key, service); | |||
| webPayServiceKeyMap.put(appinfo.getAppId(),key); | |||
| } | |||
| } | |||
| } | |||
| return service; | |||
| } | |||
| public TtGoodLifeSaasService getTtGoodLifeSassService(WxAppinfo appinfo) { | |||
| TtWebDefaultConfigImpl config = new TtWebDefaultConfigImpl(); | |||