| @@ -241,7 +241,7 @@ public class WxOrderController extends BaseController { | |||
| WxComposeOrder order = (WxComposeOrder) resultData.data; | |||
| Map<String, Object> data = new HashMap<>(); | |||
| data.put("out_order_no",order.getMainOrderId()); | |||
| data.put("order_entry_schema",getOrderEntrySchema(order.getMainOrderId())); | |||
| data.put("order_entry_schema",wxOrderService.getOrderEntrySchema(order.getMainOrderId())); | |||
| List<Map<String,Object>> goodsValid = new ArrayList<>(); | |||
| for (Long goodId:order.getCouponChannelMap().keySet()) { | |||
| Map<String,Object> goodsValidMap = new HashMap<>(); | |||
| @@ -280,16 +280,6 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| } | |||
| private Map<String,String> getOrderEntrySchema(Long batchOrderId){ | |||
| Map<String,String> map = new HashMap<>(); | |||
| map.put("path", Constant.mainPageUrl); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("type","dt"); | |||
| paramMap.put("orderId",batchOrderId); | |||
| map.put("params", JSON.toJSONString(paramMap)); | |||
| return map; | |||
| } | |||
| @ApiOperation(value = "更新订单状态", notes = "{\"payOrderId\":\"string\",\"composeOrderId\":\"string\",\"status\":integer,\"reason\":\"string\"}") | |||
| @PostMapping("/updatePayOrder") | |||
| public ResultData updatePayOrder(@RequestBody Map<String, Object> paramMap) { | |||
| @@ -39,6 +39,8 @@ public class MqBaseConsumer { | |||
| @Autowired | |||
| private FmInsideOrderPushMsgServiceImpl fmInsideOrderPushMsgService; | |||
| @Autowired | |||
| private FmInsideOrderPushDeliveryMsgServiceImpl fmInsideOrderPushDeliveryMsgServiceImpl; | |||
| @Autowired | |||
| private FmInsideCLoginMsgServiceImpl fmInsideCLoginMsgService; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @@ -115,6 +117,11 @@ public class MqBaseConsumer { | |||
| FmInsideOrderPushMsg msg = (FmInsideOrderPushMsg)JsonUtil.readValue(message,FmInsideOrderPushMsg.class); | |||
| fmInsideOrderPushMsgService.send(msg); | |||
| } | |||
| else if(EnumMsgRecordType.INSIDE_ORDER_PUSH_DELIVERY.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 2.0核销同步 | |||
| FmInsideOrderPushMsg msg = (FmInsideOrderPushMsg)JsonUtil.readValue(message,FmInsideOrderPushMsg.class); | |||
| fmInsideOrderPushDeliveryMsgServiceImpl.send(msg); | |||
| } | |||
| //else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 微信支付通知 | |||
| //FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); | |||
| @@ -0,0 +1,75 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.domain.po.*; | |||
| 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.mapper.*; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.List; | |||
| @Component | |||
| public class OrderRefundAuditSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderMapper wxOrderMapper; | |||
| @Autowired | |||
| WxAppinfoMapper wxAppinfoMapper; | |||
| @Autowired | |||
| WxRefundOrderMapper wxRefundOrderMapper; | |||
| @Autowired | |||
| WxPayAccountMapper wxPayAccountMapper; | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| private List<WxAppinfo> getAppInfos() { | |||
| WxAppinfo appinfo =new WxAppinfo(); | |||
| appinfo.setPlat(EnumAppPlat.TOUTIAO.getCode()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| return wxAppinfoMapper.findList(appinfo); | |||
| } | |||
| @Scheduled(cron = "0 */10 * * * *?") // 每10分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void merchantAuditCallback() { | |||
| List<WxAppinfo> appInfos = getAppInfos(); | |||
| for (WxAppinfo appinfo : appInfos) { | |||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||
| refundOrder.updateTenantInfo(appinfo); | |||
| refundOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrder); | |||
| if(list != null && list.size() > 0){ | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| for (WxRefundOrder order:list) { | |||
| try { | |||
| TtRefundAuditMsgRequest request = new TtRefundAuditMsgRequest(); | |||
| request.setOutRefundNo(order.getId().toString()); | |||
| request.setRefundAuditStatus(1); | |||
| ttPayService.merchantAuditCallback(request); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -12,4 +12,7 @@ public class FmInsideOrderPushMsg extends BaseMsg{ | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "composeOrderId") | |||
| private Long batchOrderId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "couponOrderId") | |||
| private Long couponOrderId; | |||
| } | |||
| @@ -43,6 +43,6 @@ public interface ProfitSharingV2Service { | |||
| * - 注意:对于担保交易和交易1.0的订单,如果需要根据order_id/out_order_no查询订单的分账记录,建议使用order_id(抖音开平侧支付单id查询),若使用out_order_no可能存在查询不到的情况 | |||
| * | |||
| */ | |||
| ProfitSharingResult getProfitSharingResult(String order_id) throws TtPayException; | |||
| ProfitSharingResult getProfitSharingResult(String out_settle_no) throws TtPayException; | |||
| } | |||
| @@ -44,10 +44,10 @@ public class ProfitSharingV2ServiceImpl implements ProfitSharingV2Service { | |||
| } | |||
| @Override | |||
| public ProfitSharingResult getProfitSharingResult(String order_id) throws TtPayException { | |||
| public ProfitSharingResult 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("order_id",order_id); | |||
| jsonObject.addProperty("out_settle_no",out_settle_no); | |||
| String result = this.payService.postV2(url,jsonObject.toString()); | |||
| return GSON.fromJson(result, ProfitSharingResult.class); | |||
| } | |||
| @@ -199,7 +199,7 @@ public class CreateOrderCallback implements Serializable { | |||
| * 是 | |||
| * 商品item_order信息,详情见 item_order_info_list部分 | |||
| */ | |||
| @SerializedName(value = "item_order_info_list") | |||
| @SerializedName(value = "item_order_info") | |||
| protected List<ItemOrderInfo> itemOrderInfoList; | |||
| } | |||
| @@ -25,6 +25,8 @@ public enum EnumMsgRecordType { | |||
| INSIDE_PRODUCT_PUSH(109, "商品状态或库存同步"), | |||
| MALL_COO_USER_PUSH(110, "猫酷同步会员"), | |||
| INSIDE_ORDER_PUSH_DELIVERY(200, "2.0核销同步"), | |||
| ; | |||
| public static EnumMsgRecordType getEnum(Integer code) { | |||
| @@ -251,6 +251,8 @@ public interface WxOrderService { | |||
| void sendInsideOrderPushMsg(TenantEntity tenantEntity,Long composeOrderId); | |||
| void sendInsideOrderPushDeliveryMsg(TenantEntity tenantEntity,Long composeOrderId,Long couponOrderId); | |||
| PageInfo<WxOrderCouponVo> listGoodsCAsPage(WxOrder wxOrder, Integer pageNum, Integer pageSize); | |||
| PageInfo<WxBatchOrder> listBatchOrderAsPage(WxOrder wxOrder, Integer pageNum, Integer pageSize); | |||
| @@ -260,4 +262,6 @@ public interface WxOrderService { | |||
| void cancelOrderBatchOrder(WxBatchOrder border,WxPayOrder payOrder); | |||
| WxBatchOrder getWxBatchOrder(TenantEntity tenantInfo, Long orderId); | |||
| Map<String,String> getOrderEntrySchema(Long mainOrderId); | |||
| } | |||
| @@ -3470,6 +3470,22 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| @Override | |||
| public void sendInsideOrderPushDeliveryMsg(TenantEntity tenantEntity, Long composeOrderId,Long couponOrderId) { | |||
| try{ | |||
| FmInsideOrderPushMsg orderPush = new FmInsideOrderPushMsg(); | |||
| orderPush.setDelayTimeLevel(5); | |||
| orderPush.setMsgType(EnumMsgRecordType.INSIDE_ORDER_PUSH_DELIVERY.getCode()); | |||
| orderPush.updateTenantInfo(tenantEntity); | |||
| orderPush.setBatchOrderId(composeOrderId); | |||
| orderPush.setCouponOrderId(couponOrderId); | |||
| logger.info(">>>>>>>>>>>send sendInsideOrderPushMsg :"+orderPush); | |||
| mqBaseProducer.sendMessage(orderPush, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| }catch(Exception e){ | |||
| logger.info(">>>>>>>>>>>send sendInsideOrderPushMsg : error"+e.getMessage()); | |||
| } | |||
| } | |||
| //TODO 待优化重做 | |||
| @Override | |||
| public PageInfo<WxOrderCouponVo> listGoodsCAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | |||
| @@ -3559,6 +3575,17 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| return wxBatchOrderMapper.selectById(orderId,tenantInfo.getTenantId()); | |||
| } | |||
| @Override | |||
| public Map<String,String> getOrderEntrySchema(Long mainOrderId) { | |||
| Map<String,String> map = new HashMap<>(); | |||
| map.put("path", Constant.mainPageUrl); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("type","dt"); | |||
| paramMap.put("orderId",mainOrderId); | |||
| map.put("params", JSON.toJSONString(paramMap)); | |||
| return map; | |||
| } | |||
| private Map<Long,List<WxOrderCouponVo>> getBatchOrderMap(TenantEntity tenantEntity,List<Long> batchOrderIds){ | |||
| WxOrder recordQ = new WxOrder(); | |||
| recordQ.updateTenantInfo(tenantEntity); | |||
| @@ -152,7 +152,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| oldRecord.setUpdateTime(curDate); | |||
| oldRecord.setPayTimeStart(batchOrder.getCreateDate()); | |||
| oldRecord.setPayOrderNo(result.getPaymentOrderId()); | |||
| oldRecord.setPayOrderNo(result.getOutOrderNo()); | |||
| oldRecord.setPayAmount(result.getTotalFee()); | |||
| oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| @@ -168,7 +168,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| oldRecord.setPayTimeEnd(timeEnd); | |||
| oldRecord.setPayEndFrom(EnumPayEndFrom.QUERY.getCode()); | |||
| oldRecord.setTransactionId(queryResult.getTransactionId()); | |||
| oldRecord.setTransactionId(result.getPaymentOrderId()); | |||
| oldRecord.setShare(isShare.getCode()); | |||
| if (isShare == EnumPayShare.YES) { | |||
| @@ -48,7 +48,7 @@ public class FmInsideCouponVerifyMsgServiceImpl implements MsgSendService { | |||
| logger.error("门店未找到: " + msg.getMerchantId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "门店未找到" + msg.getMerchantId()); | |||
| } | |||
| orderService.sendInsideOrderPushDeliveryMsg(couponOrder,null,couponOrder.getId()); | |||
| // orderService.sendInsideOrderPushMsg(couponOrder,couponOrder.getComposeOrderId()); | |||
| couponOrderService.actionAfterVerify(couponOrder, merchant); | |||
| @@ -0,0 +1,110 @@ | |||
| package com.iformall.service.msg.impl; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.domain.po.msg.FmInsideOrderPushMsg; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.payv2.request.TtOrderPushDeliveryRequest; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.TtCUserMapper; | |||
| import com.iformall.mapper.TtOrderPushErrorMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| /** | |||
| * | |||
| * @author Stormeye Wu | |||
| * @date 2019/5/10 | |||
| */ | |||
| @Service | |||
| public class FmInsideOrderPushDeliveryMsgServiceImpl implements MsgSendService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| private WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| private WxCouponOrderService wxCouponOrderService; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxMerchantService wxMerchantService; | |||
| @Autowired | |||
| private TtMerchantPoiService ttMerchantPoiService; | |||
| @Autowired | |||
| private MaUtil maUtil; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) throws Exception{ | |||
| FmInsideOrderPushMsg msg = (FmInsideOrderPushMsg)baseMsg; | |||
| try{ | |||
| Thread.currentThread().sleep(1000);//延时秒 | |||
| }catch(Exception e){} | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.setTenantId(msg.getTenantId()); | |||
| tenantEntity.setParentTenantId(msg.getParentTenantId()); | |||
| WxCouponOrder couponOrder = wxCouponOrderService.getById(msg.getCouponOrderId(), tenantEntity.getTenantId()); | |||
| if(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode().equals(couponOrder.getCouponOrderStatus()) | |||
| && EnumPayWay.PAY_WAY_TT.getCode().equals(couponOrder.getPayVendor())){ | |||
| WxOrder order = wxOrderService.getById(couponOrder.getOrderId(), tenantEntity.getTenantId()); | |||
| String item_order_id = (String) order.getExpParamValue("item_order_id"); | |||
| WxMerchant merchant = wxMerchantService.getById(couponOrder.getBMerchantId()); | |||
| String shop_name = merchant.getName(); | |||
| String ext_valid_shop_id = couponOrder.getBMerchantId().toString(); | |||
| TtMerchantPoi poi = ttMerchantPoiService.getById(couponOrder.getBMerchantId()); | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity,EnumPayWay.PAY_WAY_TT.getPlat()); | |||
| WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| TtOrderPushDeliveryRequest request = new TtOrderPushDeliveryRequest(); | |||
| List<TtOrderPushDeliveryRequest.ItemOrder> itemOrderList = new ArrayList<>(); | |||
| TtOrderPushDeliveryRequest.ItemOrder itemOrder = new TtOrderPushDeliveryRequest.ItemOrder(); | |||
| itemOrder.setItemOrderId(item_order_id); | |||
| itemOrderList.add(itemOrder); | |||
| request.setItemOrderList(itemOrderList); | |||
| JSONObject poiInfo = new JSONObject(); | |||
| poiInfo.put("shop_name",shop_name); | |||
| poiInfo.put("ext_valid_shop_id",ext_valid_shop_id); | |||
| if(poi != null){ | |||
| poiInfo.put("valid_poi_id_str",poi.getPoiId()); | |||
| } | |||
| request.setPoiInfo(poiInfo.toJSONString()); | |||
| ttPayService.pushDelivery(request); | |||
| } | |||
| } | |||
| } | |||
| @@ -34,7 +34,7 @@ public class BaseTtPayAdapterService { | |||
| TtPayOrderQueryV2Result ttPayOrderQueryV2Result = ttPayService.queryOrderV2(null, oldRecord.getOrderId().toString()); | |||
| int code = getPayStatusFromOrderQueryResult(ttPayOrderQueryV2Result); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, EnumPayStatus.getEnum(code).getMessage(), | |||
| ttPayOrderQueryV2Result.getPayChannel(), ttPayOrderQueryV2Result,ttPayOrderQueryV2Result.getOrderId(),ttPayOrderQueryV2Result.getPayTime()); | |||
| ttPayOrderQueryV2Result.getPayChannel(), ttPayOrderQueryV2Result,ttPayOrderQueryV2Result.getPaymentOrderId(),ttPayOrderQueryV2Result.getPayTime()); | |||
| // OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), oldRecord.getPayOrderNo(), null); | |||
| // int code = DouYinPayHelper.getPayStatusFromOrderQueryResult(orderQueryResult,oldRecord.getPayOrderNo()); | |||
| @@ -1,15 +1,17 @@ | |||
| package com.iformall.service.pay.service.refund.douyin; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.WxRefundOrder; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.pay.orderQuery.QueryRefundResult; | |||
| import com.iformall.douyin.pay.preOrder.CreateRefund; | |||
| import com.iformall.douyin.pay.preOrder.CreateRefundResult; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundV2Request; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundV2Result; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumRefundStatus; | |||
| @@ -18,46 +20,87 @@ import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.mapper.WxRefundOrderMapper; | |||
| import com.iformall.service.WxOrderService; | |||
| 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 org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.Map; | |||
| import java.util.SortedMap; | |||
| import java.util.TreeMap; | |||
| import java.util.*; | |||
| @Slf4j | |||
| @Service | |||
| public class TtRefundAdapterService implements RefundPayAdapterService{ | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Override | |||
| public RefundAdapterResult refund(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,EnumPayType payType) { | |||
| CreateRefund createRefund = new CreateRefund(); | |||
| createRefund.setAppId(appInfo.getAppId()); | |||
| createRefund.setSalt(payAccount.getApiKey()); | |||
| createRefund.setOutOrderNo(payOrder.getPayOrderNo()); | |||
| createRefund.setOutRefundNo(String.valueOf(record.getId())); | |||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||
| createRefund.setReason("B端商户退款"); | |||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||
| createRefund.setReason("管理端商户退款"); | |||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||
| createRefund.setReason("超期自动退款"); | |||
| } else if (payType == EnumPayType.PAY_C_REFUND){ | |||
| createRefund.setReason("用户自己退款"); | |||
| } | |||
| createRefund.setRefundAmount(record.getRefundFee()); | |||
| CreateRefundResult refund = DouYinPayHelper.createRefund(createRefund); | |||
| if(refund.isSuccess()){ | |||
| return new RefundAdapterResult(true, EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(), "退款订单申请成功", refund); | |||
| }else{ | |||
| return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),refund.getMsg(),refund); | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtPayRefundV2Request request = new TtPayRefundV2Request(); | |||
| request.setOutOrderNo(payOrder.getPayOrderNo()); | |||
| request.setOutRefundNo(record.getId().toString()); | |||
| TtPayRefundV2Request.PageEntry pageEntry = new TtPayRefundV2Request.PageEntry(); | |||
| pageEntry.setPath(Constant.mainPageUrl); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("type","dt"); | |||
| 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 refund_total_amount = (String) order.getExpParamValue("refund_total_amount"); | |||
| orderDetail.setItemOrderId(refund_total_amount); | |||
| list.add(orderDetail); | |||
| request.setItemOrderDetail(list); | |||
| } | |||
| TtPayRefundV2Result result1 = ttPayService.refundV2(request); | |||
| return new RefundAdapterResult(true, EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(), "退款订单申请成功", result1); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),e.getMessage(),null); | |||
| } | |||
| // CreateRefund createRefund = new CreateRefund(); | |||
| // createRefund.setAppId(appInfo.getAppId()); | |||
| // createRefund.setSalt(payAccount.getApiKey()); | |||
| // createRefund.setOutOrderNo(payOrder.getPayOrderNo()); | |||
| // createRefund.setOutRefundNo(String.valueOf(record.getId())); | |||
| // if (payType == EnumPayType.PAY_B_REFUND) { | |||
| // createRefund.setReason("B端商户退款"); | |||
| // } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||
| // createRefund.setReason("管理端商户退款"); | |||
| // } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||
| // createRefund.setReason("超期自动退款"); | |||
| // } else if (payType == EnumPayType.PAY_C_REFUND){ | |||
| // createRefund.setReason("用户自己退款"); | |||
| // } | |||
| // createRefund.setRefundAmount(record.getRefundFee()); | |||
| // | |||
| // CreateRefundResult refund = DouYinPayHelper.createRefund(createRefund); | |||
| // if(refund.isSuccess()){ | |||
| // return new RefundAdapterResult(true, EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(), "退款订单申请成功", refund); | |||
| // }else{ | |||
| // return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),refund.getMsg(),refund); | |||
| // } | |||
| } | |||
| @Override | |||
| @@ -6,9 +6,13 @@ import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| 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.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| @@ -18,7 +22,9 @@ 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.MaUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.ArrayList; | |||
| @@ -30,6 +36,9 @@ import java.util.Map; | |||
| @Service | |||
| public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Override | |||
| public Integer getSubsidyType() { | |||
| return EnumMerchantSubsidyType.DOUYIN.getCode(); | |||
| @@ -49,71 +58,122 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| @Override | |||
| public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { | |||
| Settle settle = new Settle(); | |||
| settle.setAppId(appInfo.getAppId()); | |||
| settle.setSalt(payAccount.getApiKey()); | |||
| settle.setOutSettleNo(record.getId().toString()); | |||
| settle.setOutOrderNo(record.getOrderId().toString()); | |||
| settle.setSettleDesc("自主完结分账"); | |||
| // if(order.getSettlementAmount() != null && order.getSettlementAmount().intValue() > 0){ | |||
| // List list = new ArrayList<>(); | |||
| // Map<String,Object> settleParams = new HashMap<>(); | |||
| // settleParams.put("merchant_uid",merchantUid); | |||
| // settleParams.put("amount",order.getPayment()-order.getSettlementAmount()); | |||
| // list.add(settleParams); | |||
| // settle.setSettleParams(JSON.toJSONString(list)); | |||
| // } | |||
| SettleResult settleResult = DouYinPayHelper.settle(settle); | |||
| if (settleResult.isSuccess()) { | |||
| return new PayShareResult(true, null,"success", settleResult,settleResult.getSettleNo()); | |||
| }else{ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),settleResult.getMsg(), null,null); | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| ProfitSharingRequest request = new ProfitSharingRequest(); | |||
| request.setOutOrderNo(record.getOrderId().toString()); | |||
| request.setOutSettleNo(record.getId().toString()); | |||
| request.setSettleDesc("自主完结分账"); | |||
| String settleId = ttPayService.getProfitSharingV2Service().profitSharing(request); | |||
| return new PayShareResult(true, null,"success", null,settleId); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),e.getMessage(), null,null); | |||
| } | |||
| // Settle settle = new Settle(); | |||
| // settle.setAppId(appInfo.getAppId()); | |||
| // settle.setSalt(payAccount.getApiKey()); | |||
| // settle.setOutSettleNo(record.getId().toString()); | |||
| // settle.setOutOrderNo(record.getOrderId().toString()); | |||
| // settle.setSettleDesc("自主完结分账"); | |||
| //// if(order.getSettlementAmount() != null && order.getSettlementAmount().intValue() > 0){ | |||
| //// List list = new ArrayList<>(); | |||
| //// Map<String,Object> settleParams = new HashMap<>(); | |||
| //// settleParams.put("merchant_uid",merchantUid); | |||
| //// settleParams.put("amount",order.getPayment()-order.getSettlementAmount()); | |||
| //// list.add(settleParams); | |||
| //// settle.setSettleParams(JSON.toJSONString(list)); | |||
| //// } | |||
| // SettleResult settleResult = DouYinPayHelper.settle(settle); | |||
| // | |||
| // if (settleResult.isSuccess()) { | |||
| // return new PayShareResult(true, null,"success", settleResult,settleResult.getSettleNo()); | |||
| // }else{ | |||
| // return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),settleResult.getMsg(), null,null); | |||
| // } | |||
| } | |||
| @Override | |||
| public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException { | |||
| Settle settle = new Settle(); | |||
| settle.setAppId(appInfo.getAppId()); | |||
| settle.setSalt(payAccount.getApiKey()); | |||
| settle.setOutSettleNo(record.getId().toString()); | |||
| settle.setOutOrderNo(record.getOrderId().toString()); | |||
| settle.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); | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| ProfitSharingRequest request = new ProfitSharingRequest(); | |||
| request.setOutOrderNo(record.getOrderId().toString()); | |||
| request.setOutSettleNo(record.getId().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 = ttPayService.getProfitSharingV2Service().profitSharing(request); | |||
| return new PayShareResult(true, null,"success", null,settleId); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),e.getMessage(), null,null); | |||
| } | |||
| settle.setSettleParams(JSON.toJSONString(list)); | |||
| SettleResult settleResult = DouYinPayHelper.settle(settle); | |||
| if (settleResult.isSuccess()) { | |||
| return new PayShareResult(true, null,"success", settleResult,settleResult.getSettleNo()); | |||
| }else{ | |||
| return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),settleResult.getMsg(), null,null); | |||
| } | |||
| // Settle settle = new Settle(); | |||
| // settle.setAppId(appInfo.getAppId()); | |||
| // settle.setSalt(payAccount.getApiKey()); | |||
| // settle.setOutSettleNo(record.getId().toString()); | |||
| // settle.setOutOrderNo(record.getOrderId().toString()); | |||
| // settle.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); | |||
| // } | |||
| // | |||
| // settle.setSettleParams(JSON.toJSONString(list)); | |||
| // SettleResult settleResult = DouYinPayHelper.settle(settle); | |||
| // | |||
| // if (settleResult.isSuccess()) { | |||
| // return new PayShareResult(true, null,"success", settleResult,settleResult.getSettleNo()); | |||
| // }else{ | |||
| // return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),settleResult.getMsg(), null,null); | |||
| // } | |||
| } | |||
| @Override | |||
| public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | |||
| 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); | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| ProfitSharingResult profitSharingResult = ttPayService.getProfitSharingV2Service().getProfitSharingResult(record.getId().toString()); | |||
| if(profitSharingResult.isSuccess()){ | |||
| ProfitSharingResult.Receiver receiver = profitSharingResult.getData().get(0); | |||
| if("SUCCESS".equals(receiver.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, 5, "success",receiver, null); | |||
| } else if("FAIL".equals(receiver.getSettleStatus())){ | |||
| return new PayShareQueryResult(true, 6, "fail",receiver, null); | |||
| } | |||
| } | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), profitSharingResult.getErrTips()); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), e.getMessage()); | |||
| } | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), querySettleResult.getMsg()); | |||
| // 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 | |||