| @@ -22,6 +22,10 @@ public class TtGoodsCategory extends BaseEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="parentId") | |||
| private Integer parentId; | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="serviceFee") | |||
| private Integer serviceFee; | |||
| @TableField(exist = false) | |||
| protected List<TtGoodsCategory> child; | |||
| @@ -46,6 +46,10 @@ public class WxProfitSharingReceiver extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="分账金额(分)",name="sharingAmount") | |||
| private Integer sharingAmount; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="真实费率",name="rateAmount") | |||
| private Integer rateAmount; | |||
| @io.swagger.annotations.ApiModelProperty(value = "0,不使用 1,使用", name = "isUse") | |||
| private Integer isUse; | |||
| @@ -66,4 +66,6 @@ public interface WxCouponChannelMapper extends CommonMapper<WxCouponChannel, Str | |||
| List<WxCouponChannel> batGetPriceAndStock(@Param("ids")List<Long> ids,@Param("tenantId")String tenantId); | |||
| List<TtCouponChannelVo> ttChannelList(TtCouponChannelVo ttChannelVo); | |||
| Long findCouponIdById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| } | |||
| @@ -123,4 +123,6 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> { | |||
| List<Long> findIdsListHasConditons(WxCoupon couponQ); | |||
| List<TtCouponVo> ttCouponList(TtCouponVo ttCouponVo); | |||
| Integer findCategoryIdById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| } | |||
| @@ -1742,13 +1742,13 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); | |||
| } | |||
| wxSharingOrderDto.setPayAmount(wxPayOrder.getPayAmount()); | |||
| wxSharingOrderDto.setShareAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getShareAmount()); | |||
| wxSharingOrderDto.setRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRateAmount()); | |||
| wxSharingOrderDto.setOrderId(wxPayOrder.getId()); | |||
| wxSharingOrderDto.setPayTimeStart(wxPayOrder.getPayTimeStart()); | |||
| wxSharingOrderDto.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); | |||
| wxSharingOrderDto.updateTenantInfo(wxPayOrder); | |||
| wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId()); | |||
| wxSharingOrderDto.setShareAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getShareAmount()); | |||
| wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto,payWay,wxPayOrder.getShare()); | |||
| } | |||
| } catch (Exception e) { | |||
| @@ -2542,13 +2542,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| sharingOrder.setMerchantId(wxMerchantBUser.getMerchantId()); | |||
| sharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); | |||
| sharingOrder.setPayAmount(wxPayOrder.getPayAmount()); | |||
| sharingOrder.setShareAmount(wxPayOrder.getChildOrderShare(orderId).getShareAmount()); | |||
| sharingOrder.setRateAmount(wxPayOrder.getChildOrderShare(orderId).getRateAmount()); | |||
| sharingOrder.setOrderId(wxPayOrder.getId()); | |||
| sharingOrder.setPayTimeStart(wxPayOrder.getPayTimeStart()); | |||
| sharingOrder.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); | |||
| sharingOrder.updateTenantInfo(wxPayOrder); | |||
| sharingOrder.setTransactionId(wxPayOrder.getTransactionId()); | |||
| sharingOrder.setShareAmount(wxPayOrder.getChildOrderShare(orderId).getShareAmount()); | |||
| wxProfitSharingOrderService.createSharingOrder(sharingOrder,payWay.getCode(),wxPayOrder.getShare()); | |||
| } else { | |||
| logger.error("微信分账: 未找到payorder or merchant at orderid-" + orderId); | |||
| @@ -398,22 +398,29 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| if (isShare == EnumPayShare.YES) { | |||
| PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode()); | |||
| PayShareCalculateAmount recordShareAmount = payShareServie.calculateAmount(record.getPayAmount(), payAccount); | |||
| // 分账金额 | |||
| Integer share_amount = recordShareAmount.getShareAmount(); | |||
| record.setShareAmount(share_amount); | |||
| record.setRateAmount(recordShareAmount.getRateAmount()); | |||
| // PayShareCalculateAmount recordShareAmount = payShareServie.calculateAmount(record.getPayAmount(), payAccount); | |||
| // // 分账金额 | |||
| // Integer share_amount = recordShareAmount.getShareAmount(); | |||
| // record.setShareAmount(share_amount); | |||
| // record.setRateAmount(recordShareAmount.getRateAmount()); | |||
| //设置子订单分账金额 | |||
| Map<String,WxComposeChildOrderShare> childShares = new HashMap<String,WxComposeChildOrderShare>(); | |||
| OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()); | |||
| List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); | |||
| if(null != orderList && orderList.size() > 0) { | |||
| int share_amount = 0; | |||
| int rate_amount = 0; | |||
| for (WxOrder o : orderList) { | |||
| PayShareCalculateAmount oShareAmount = payShareServie.calculateAmount(o.getPayment(), payAccount); | |||
| int rate = payShareServie.getOfficialCommission(o,payAccount); | |||
| PayShareCalculateAmount oShareAmount = payShareServie.calculateAmount(o.getPayment(),rate, payAccount); | |||
| share_amount += oShareAmount.getShareAmount(); | |||
| rate_amount += oShareAmount.getRateAmount(); | |||
| Integer orderShareAmount = oShareAmount.getShareAmount(); | |||
| Integer orderRateAmount = oShareAmount.getRateAmount(); | |||
| childShares.put(String.valueOf(o.getId()), new WxComposeChildOrderShare(o.getPayment(), orderShareAmount, orderRateAmount)); | |||
| } | |||
| record.setShareAmount(share_amount); | |||
| record.setRateAmount(rate_amount); | |||
| record.setChildOrderShare(JSON.toJSONString(childShares)); | |||
| } | |||
| } | |||
| @@ -308,6 +308,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| { | |||
| if (r.getParameter() == null){ | |||
| r.setSharingAmount(sharingOrderDto.getShareAmount()); | |||
| r.setRateAmount(sharingOrderDto.getRateAmount()); | |||
| } else { | |||
| r.setSharingAmount(sharingOrderDto.getShareAmount()*Integer.valueOf(r.getParameter())/10000); | |||
| } | |||
| @@ -353,6 +354,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| jo.put("type",payServiceFactory.getPayShareAdapterService(payWay).getShareAccount(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", receiver.getSharingAmount()); | |||
| jo.put("rateAmount", receiver.getRateAmount()); | |||
| //jo.put("description",receiver.getReceiverComments()); //改为存ID, | |||
| jo.put("description",receiver.getId().toString()); //为重试做准备 | |||
| receivers.add(jo); | |||
| @@ -3,10 +3,7 @@ package com.iformall.service.pay.service.share; | |||
| import java.util.Map; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxProfitSharingOrder; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.enums.EnumProfitSharingReceiverType; | |||
| @@ -38,7 +35,7 @@ public interface PayShareAdapterService { | |||
| /** | |||
| * 计算商场分账金额和实际费率金额 | |||
| */ | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,WxPayAccount payAccount); | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,Integer officialCommissionRate,WxPayAccount payAccount); | |||
| /** | |||
| * 无分账接收方分账 ,钱直接分给小程序方 调用API分账 | |||
| @@ -104,6 +101,13 @@ public interface PayShareAdapterService { | |||
| * @param payAccount | |||
| * @param receiver | |||
| */ | |||
| public ShareAccountResult deleteShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver); | |||
| public ShareAccountResult deleteShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver); | |||
| /** | |||
| * 获取官方佣金率 | |||
| * @param o | |||
| * @param payAccount | |||
| * @return | |||
| */ | |||
| int getOfficialCommission(WxOrder o, WxPayAccount payAccount); | |||
| } | |||
| @@ -15,6 +15,9 @@ import com.iformall.douyin.payv2.request.ProfitSharingRequest; | |||
| import com.iformall.douyin.payv2.result.ProfitSharingResult; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.TtGoodsCategoryMapper; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxCouponMapper; | |||
| import com.iformall.service.order.util.OrderHelper; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; | |||
| @@ -23,6 +26,7 @@ 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 com.iformall.utils.PayUtils; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -39,6 +43,15 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| TtGoodsCategoryMapper TtGoodsCategoryMapper; | |||
| @Override | |||
| public Integer getSubsidyType() { | |||
| return EnumMerchantSubsidyType.DOUYIN.getCode(); | |||
| @@ -50,10 +63,11 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| } | |||
| @Override | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount, WxPayAccount payAccount) { | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,Integer officialCommissionRate, WxPayAccount payAccount) { | |||
| int mallCharge = OrderHelper.getMallCharge(payAmount, payAccount,true); | |||
| Integer realRateAmount = OrderHelper.getRealRateAmount(payAmount, payAccount); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount); | |||
| int officialCommission = PayUtils.getPayRate(payAmount, officialCommissionRate, true); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge+officialCommission,realRateAmount+officialCommission); | |||
| } | |||
| @Override | |||
| @@ -104,12 +118,20 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| request.setOutSettleNo(record.getId().toString()); | |||
| request.setSettleDesc("merchant_reciver_share"); | |||
| List list = new ArrayList<>(); | |||
| int mall_account = 0; | |||
| for (Object o: receivers) { | |||
| JSONObject jo = (JSONObject) o; | |||
| Map<String,Object> settleParams = new HashMap<>(); | |||
| settleParams.put("merchant_uid",jo.getString("account")); | |||
| settleParams.put("amount",jo.getInteger("amount")); | |||
| list.add(settleParams); | |||
| mall_account += jo.getInteger("amount") - (jo.getInteger("rateAmount") == null?0:jo.getInteger("rateAmount")); | |||
| } | |||
| if(mall_account > 0){ | |||
| Map<String,Object> settleParams = new HashMap<>(); | |||
| settleParams.put("merchant_uid",payAccount.getSubMchId()); | |||
| settleParams.put("amount",mall_account); | |||
| list.add(settleParams); | |||
| } | |||
| request.setSettleParams(JSON.toJSONString(list)); | |||
| String settleId = ttPayService.getProfitSharingV2Service().profitSharing(request); | |||
| @@ -195,4 +217,21 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); | |||
| } | |||
| @Override | |||
| public int getOfficialCommission(WxOrder o, WxPayAccount payAccount) { | |||
| Long couponId = wxCouponChannelMapper.findCouponIdById(o.getId(), o.getTenantId()); | |||
| Integer categoryId = wxCouponMapper.findCategoryIdById(couponId,o.getTenantId()); | |||
| if(categoryId != null){ | |||
| TtGoodsCategory ttGoodsCategory = TtGoodsCategoryMapper.selectById(categoryId); | |||
| if(ttGoodsCategory != null && ttGoodsCategory.getServiceFee() != null){ | |||
| Integer realRate = payAccount.getRealRate(); | |||
| if(realRate==null){ | |||
| realRate = 60; | |||
| } | |||
| return ttGoodsCategory.getServiceFee().intValue() - realRate; | |||
| } | |||
| } | |||
| return 0; | |||
| } | |||
| } | |||
| @@ -12,7 +12,7 @@ public class PayShareCalculateAmount implements Serializable{ | |||
| private static final long serialVersionUID = -3701322871877301001L; | |||
| private Integer payAmount; | |||
| private Integer mallCharge;//商场拿走的钱 | |||
| private Integer mallCharge;//商场拿走的钱+平台手续费 | |||
| private Integer realRateAmount;//平台手续费 | |||
| //分账的钱 | |||
| @@ -6,6 +6,7 @@ import java.util.Map; | |||
| import java.util.SortedMap; | |||
| import java.util.TreeMap; | |||
| import com.iformall.domain.po.*; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -15,11 +16,6 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.WxProfitSharingOrder; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.enums.EnumMerchantSubsidyType; | |||
| import com.iformall.enums.EnumPayEndFrom; | |||
| import com.iformall.enums.EnumPayWay; | |||
| @@ -75,7 +71,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| } | |||
| @Override | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount, WxPayAccount payAccount) { | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,Integer officialCommissionRate, WxPayAccount payAccount) { | |||
| int mallCharge = OrderHelper.getMallCharge(payAmount, payAccount); | |||
| Integer realRateAmount = OrderHelper.getRealRateAmount(payAmount, payAccount); | |||
| return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount); | |||
| @@ -438,7 +434,12 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| return new ShareAccountResult(true, null, "success", returnMap); | |||
| } | |||
| private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { | |||
| @Override | |||
| public int getOfficialCommission(WxOrder o, WxPayAccount payAccount) { | |||
| return 0; | |||
| } | |||
| private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { | |||
| WxProfitSharingP psCmd = new WxProfitSharingP(); | |||
| psCmd.setMch_id(mchId);//服务商商户id | |||
| psCmd.setNonce_str(Utility.generate32UUID()); | |||
| @@ -520,4 +520,11 @@ | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </select> | |||
| <select id="findCouponIdById" parameterType="java.util.HashMap" resultType="long"> | |||
| select coupon_id from wx_coupon_channel | |||
| where `tenant_id` = #{tenantId} | |||
| and id = #{id} | |||
| </select> | |||
| </mapper> | |||
| @@ -1424,5 +1424,13 @@ | |||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||
| </select> | |||
| <select id="findCategoryIdById" parameterType="java.util.HashMap" resultType="Integer"> | |||
| select category_id | |||
| from wx_coupon | |||
| where id = #{id} | |||
| and tenant_id = #{tenantId} | |||
| </select> | |||
| </mapper> | |||