Explorar el Código

优化房屋收费页面

wuxw hace 2 años
padre
commit
7a9ac5d05c
Se han modificado 18 ficheros con 774 adiciones y 386 borrados
  1. 105 0
      java110-bean/src/main/java/com/java110/dto/integral/GiftIntegralDto.java
  2. 3 4
      java110-bean/src/main/java/com/java110/dto/integral/IntegralRuleConfigDto.java
  3. 23 0
      java110-bean/src/main/java/com/java110/dto/payment/PaymentOrderDto.java
  4. 0 1
      java110-core/src/main/java/com/java110/core/smo/IComputeFeeSMO.java
  5. 0 26
      java110-core/src/main/java/com/java110/core/smo/impl/ComputeFeeSMOImpl.java
  6. 4 0
      java110-interface/src/main/java/com/java110/intf/job/IMallInnerServiceSMO.java
  7. 49 0
      java110-utils/src/main/java/com/java110/utils/util/PayUtil.java
  8. 3 3
      service-acct/src/main/java/com/java110/acct/cmd/integral/ComputePayFeeIntegralCmd.java
  9. 16 0
      service-acct/src/main/java/com/java110/acct/integral/IComputeGiftIntegral.java
  10. 8 0
      service-acct/src/main/java/com/java110/acct/integral/IGiftIntegral.java
  11. 97 0
      service-acct/src/main/java/com/java110/acct/integral/impl/ComputeGiftIntegralImpl.java
  12. 48 0
      service-acct/src/main/java/com/java110/acct/integral/impl/GiftIntegralImpl.java
  13. 281 0
      service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatIntegralShareAcct.java
  14. 96 20
      service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java
  15. 18 1
      service-acct/src/main/java/com/java110/acct/payment/business/payFee/PayFeePaymentBusiness.java
  16. 0 323
      service-job/src/main/java/com/java110/job/adapt/payment/integral/PayFeeGiftIntegralAdapt.java
  17. 0 5
      service-job/src/main/java/com/java110/job/adapt/payment/integral/package-info.java
  18. 23 3
      service-job/src/main/java/com/java110/job/smo/impl/MallInnerServiceSMOImpl.java

+ 105 - 0
java110-bean/src/main/java/com/java110/dto/integral/GiftIntegralDto.java

@@ -0,0 +1,105 @@
+package com.java110.dto.integral;
+
+import java.io.Serializable;
+
+public class GiftIntegralDto implements Serializable {
+
+    public GiftIntegralDto() {
+    }
+
+    public GiftIntegralDto(int integral, double money) {
+        this.integral = integral;
+        this.money = money;
+    }
+
+    private int integral;
+
+    private double money;
+
+    private String platformMchId;
+
+    private String platformMchName;
+
+    private String appId;
+
+    private String mchId;
+
+    private String mchKey;
+
+    private String certPath;
+
+    private String userId;
+
+
+    public int getIntegral() {
+        return integral;
+    }
+
+    public void setIntegral(int integral) {
+        this.integral = integral;
+    }
+
+    public double getMoney() {
+        return money;
+    }
+
+    public void setMoney(double money) {
+        this.money = money;
+    }
+
+    public String getPlatformMchId() {
+        return platformMchId;
+    }
+
+    public void setPlatformMchId(String platformMchId) {
+        this.platformMchId = platformMchId;
+    }
+
+    public String getPlatformMchName() {
+        return platformMchName;
+    }
+
+    public void setPlatformMchName(String platformMchName) {
+        this.platformMchName = platformMchName;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getMchId() {
+        return mchId;
+    }
+
+    public void setMchId(String mchId) {
+        this.mchId = mchId;
+    }
+
+    public String getMchKey() {
+        return mchKey;
+    }
+
+    public void setMchKey(String mchKey) {
+        this.mchKey = mchKey;
+    }
+
+    public String getCertPath() {
+        return certPath;
+    }
+
+    public void setCertPath(String certPath) {
+        this.certPath = certPath;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+}

+ 3 - 4
java110-bean/src/main/java/com/java110/dto/integral/IntegralRuleConfigDto.java

@@ -15,10 +15,9 @@ import java.util.Date;
  **/
 public class IntegralRuleConfigDto extends PageDto implements Serializable {
 
-    //计算公式 1001 面积*单价 2002 金额乘以单价 3003 固定积分
-    public static final String COMPUTING_FORMULA_AREA = "1001";
-    public static final String COMPUTING_FORMULA_MONEY = "2002";
-    public static final String COMPUTING_FORMULA_FIXED = "3003";
+    //计算公式 1001 金额 2002 月份
+    public static final String COMPUTING_FORMULA_MONEY = "1001";
+    public static final String COMPUTING_FORMULA_MONTH = "2002";
 
     public static final String SCALE_UP = "3";
     public static final String SCALE_DOWN = "4";

+ 23 - 0
java110-bean/src/main/java/com/java110/dto/payment/PaymentOrderDto.java

@@ -1,5 +1,6 @@
 package com.java110.dto.payment;
 
+import com.java110.dto.integral.GiftIntegralDto;
 import org.springframework.http.ResponseEntity;
 
 import java.io.Serializable;
@@ -10,6 +11,8 @@ import java.io.Serializable;
  */
 public class PaymentOrderDto implements Serializable{
 
+    public static final String SHARE_ACCT = "Y";
+
     private String orderId;
 
     private String transactionId;
@@ -25,6 +28,10 @@ public class PaymentOrderDto implements Serializable{
 
     private String userId;
 
+    private String isShare;
+
+    private GiftIntegralDto giftIntegralDto;
+
 
     private ResponseEntity<String> responseEntity;
 
@@ -93,4 +100,20 @@ public class PaymentOrderDto implements Serializable{
     public void setUserId(String userId) {
         this.userId = userId;
     }
+
+    public String getIsShare() {
+        return isShare;
+    }
+
+    public void setIsShare(String isShare) {
+        this.isShare = isShare;
+    }
+
+    public GiftIntegralDto getGiftIntegralDto() {
+        return giftIntegralDto;
+    }
+
+    public void setGiftIntegralDto(GiftIntegralDto giftIntegralDto) {
+        this.giftIntegralDto = giftIntegralDto;
+    }
 }

+ 0 - 1
java110-core/src/main/java/com/java110/core/smo/IComputeFeeSMO.java

@@ -206,6 +206,5 @@ public interface IComputeFeeSMO {
      */
     void dealRentRateCustEndTime(FeeDto feeDto, Date custEndTime);
 
-    long computeOneIntegralQuantity(IntegralRuleConfigDto integralRuleConfigDto, JSONObject reqJson);
 
 }

+ 0 - 26
java110-core/src/main/java/com/java110/core/smo/impl/ComputeFeeSMOImpl.java

@@ -2052,33 +2052,7 @@ public class ComputeFeeSMOImpl implements IComputeFeeSMO {
 
     }
 
-    @Override
-    public long computeOneIntegralQuantity(IntegralRuleConfigDto integralRuleConfigDto, JSONObject reqJson) {
-        String computingFormula = integralRuleConfigDto.getComputingFormula();
-        BigDecimal amountDec = null;
-        long amount = 0;
-        if (IntegralRuleConfigDto.COMPUTING_FORMULA_AREA.equals(computingFormula)) { //面积乘以单价
-            BigDecimal areaDec = new BigDecimal(Double.parseDouble(reqJson.getString("area")));
-            BigDecimal squarePriceDec = new BigDecimal(Double.parseDouble(integralRuleConfigDto.getSquarePrice()));
-            amountDec = areaDec.multiply(squarePriceDec).setScale(2, BigDecimal.ROUND_HALF_UP);
-        } else if (IntegralRuleConfigDto.COMPUTING_FORMULA_MONEY.equals(computingFormula)) { // 金额乘以单价
-            BigDecimal aDec = new BigDecimal(Double.parseDouble(reqJson.getString("amount")));
-            BigDecimal squarePriceDec = new BigDecimal(Double.parseDouble(integralRuleConfigDto.getSquarePrice()));
-            amountDec = aDec.multiply(squarePriceDec).setScale(2, BigDecimal.ROUND_HALF_UP);
-        } else if (IntegralRuleConfigDto.COMPUTING_FORMULA_FIXED.equals(computingFormula)) { // 固定积分
-            amountDec = new BigDecimal(Double.parseDouble(integralRuleConfigDto.getAdditionalAmount()));
-        } else {
-            amountDec = new BigDecimal(0);
-        }
 
-        if (IntegralRuleConfigDto.SCALE_UP.equals(integralRuleConfigDto.getScale())) {
-            amount = new Double(Math.ceil(amountDec.doubleValue())).longValue();
-        } else {
-            amount = new Double(Math.floor(amountDec.doubleValue())).longValue();
-        }
-        integralRuleConfigDto.setQuantity(amount + "");
-        return amount;
-    }
 
     /**
      * 租金处理

+ 4 - 0
java110-interface/src/main/java/com/java110/intf/job/IMallInnerServiceSMO.java

@@ -48,4 +48,8 @@ public interface IMallInnerServiceSMO {
 
     @RequestMapping(value = "/sendUserInfo", method = RequestMethod.POST)
     ResultVo sendUserInfo(@RequestBody UserDto userDto);
+
+
+    @RequestMapping(value = "/computeIntegralMoney", method = RequestMethod.POST)
+    double computeIntegralMoney(@RequestBody int quantity);
 }

+ 49 - 0
java110-utils/src/main/java/com/java110/utils/util/PayUtil.java

@@ -14,6 +14,8 @@ import org.springframework.util.StringUtils;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -411,4 +413,51 @@ public class PayUtil {
             return money;
         }
     }
+
+    public static String createSignSha256(SortedMap<String, String> parameters, String key) {
+        StringBuffer sb = new StringBuffer();
+        Set es = parameters.entrySet();
+        Iterator<?> it = es.iterator();
+        while (it.hasNext()) {
+            Map.Entry entry = (Map.Entry) it.next();
+            String k = (String) entry.getKey();
+            if (entry.getValue() != null || !"".equals(entry.getValue())) {
+                String v = String.valueOf(entry.getValue());
+                if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
+                    sb.append(k + "=" + v + "&");
+                }
+            }
+        }
+        sb.append("key=" + key);
+        logger.debug("加密前串:" + sb.toString());
+        //String sign = md5(sb.toString()).toUpperCase();
+        String sign = "";
+        try {
+            Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
+            SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(), "HmacSHA256");
+            sha256_HMAC.init(secret_key);
+            //  utf-8 : 解决中文加密不一致问题,必须指定编码格式
+            sign = byteArrayToHexString(sha256_HMAC.doFinal(sb.toString().getBytes("utf-8"))).toUpperCase();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return sign;
+    }
+    /**
+     * 将加密后的字节数组转换成字符串
+     *
+     * @param b 字节数组
+     * @return 字符串
+     */
+    private static String byteArrayToHexString(byte[] b) {
+        StringBuilder hs = new StringBuilder();
+        String stmp;
+        for (int n = 0; b != null && n < b.length; n++) {
+            stmp = Integer.toHexString(b[n] & 0XFF);
+            if (stmp.length() == 1)
+                hs.append('0');
+            hs.append(stmp);
+        }
+        return hs.toString().toLowerCase();
+    }
 }

+ 3 - 3
service-acct/src/main/java/com/java110/acct/cmd/integral/ComputePayFeeIntegralCmd.java

@@ -121,9 +121,9 @@ public class ComputePayFeeIntegralCmd extends Cmd {
     private long computeIntegralQuantity(List<IntegralRuleConfigDto> integralRuleConfigDtos,JSONObject reqJson) {
 
         long quantity = 0;
-        for(IntegralRuleConfigDto integralRuleConfigDto:integralRuleConfigDtos){
-            quantity += computeFeeSMOImpl.computeOneIntegralQuantity(integralRuleConfigDto,reqJson);
-        }
+//        for(IntegralRuleConfigDto integralRuleConfigDto:integralRuleConfigDtos){
+//            quantity += computeFeeSMOImpl.computeOneIntegralQuantity(integralRuleConfigDto,reqJson);
+//        }
         return quantity;
     }
 

+ 16 - 0
service-acct/src/main/java/com/java110/acct/integral/IComputeGiftIntegral.java

@@ -0,0 +1,16 @@
+package com.java110.acct.integral;
+
+import com.java110.dto.integral.GiftIntegralDto;
+
+public interface IComputeGiftIntegral {
+
+    /**
+     * 赠送积分和金额计算
+     *
+     * @param payMoney
+     * @param month
+     * @param communityId
+     * @return
+     */
+    GiftIntegralDto gift(double payMoney, int month, String communityId);
+}

+ 8 - 0
service-acct/src/main/java/com/java110/acct/integral/IGiftIntegral.java

@@ -0,0 +1,8 @@
+package com.java110.acct.integral;
+
+import com.java110.dto.integral.GiftIntegralDto;
+
+public interface IGiftIntegral {
+
+    void gift(GiftIntegralDto giftIntegralDto);
+}

+ 97 - 0
service-acct/src/main/java/com/java110/acct/integral/impl/ComputeGiftIntegralImpl.java

@@ -0,0 +1,97 @@
+package com.java110.acct.integral.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.integral.IComputeGiftIntegral;
+import com.java110.dto.integral.GiftIntegralDto;
+import com.java110.dto.integral.IntegralRuleConfigDto;
+import com.java110.dto.integral.IntegralRuleFeeDto;
+import com.java110.intf.acct.IIntegralRuleConfigV1InnerServiceSMO;
+import com.java110.intf.acct.IIntegralRuleFeeV1InnerServiceSMO;
+import com.java110.intf.job.IMallInnerServiceSMO;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.ListUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 计算赠送积分
+ */
+@Service
+public class ComputeGiftIntegralImpl implements IComputeGiftIntegral {
+    private static final String MALL_DOMAIN = "MALL";
+
+    @Autowired
+    private IMallInnerServiceSMO mallInnerServiceSMOImpl;
+
+    @Autowired
+    private IIntegralRuleFeeV1InnerServiceSMO integralRuleFeeV1InnerServiceSMOImpl;
+
+
+    @Autowired
+    private IIntegralRuleConfigV1InnerServiceSMO integralRuleConfigV1InnerServiceSMOImpl;
+
+
+    @Override
+    public GiftIntegralDto gift(double payMoney, int month, String communityId) {
+
+        String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
+
+        if (!"ON".equals(mallSwitch)) {
+            return new GiftIntegralDto(0, 0);
+        }
+
+        IntegralRuleFeeDto integralRuleFeeDto = new IntegralRuleFeeDto();
+        integralRuleFeeDto.setCurTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+        integralRuleFeeDto.setCommunityId(communityId);
+        List<IntegralRuleFeeDto> integralRuleFeeDtos = integralRuleFeeV1InnerServiceSMOImpl.queryIntegralRuleFees(integralRuleFeeDto);
+
+        if (ListUtil.isNull(integralRuleFeeDtos)) {
+            return new GiftIntegralDto(0, 0);
+        }
+
+        List<String> ruleIds = new ArrayList<>();
+        for (IntegralRuleFeeDto tmpCouponRuleFeeDto : integralRuleFeeDtos) {
+            ruleIds.add(tmpCouponRuleFeeDto.getRuleId());
+        }
+
+        IntegralRuleConfigDto integralRuleConfigDto = new IntegralRuleConfigDto();
+        integralRuleConfigDto.setRuleIds(ruleIds.toArray(new String[ruleIds.size()]));
+        List<IntegralRuleConfigDto> integralRuleConfigDtos = integralRuleConfigV1InnerServiceSMOImpl.queryIntegralRuleConfigs(integralRuleConfigDto);
+
+        if (ListUtil.isNull(integralRuleConfigDtos)) {
+            return new GiftIntegralDto(0, 0);
+        }
+
+        int quantity = computeOneIntegralQuantity(integralRuleConfigDtos.get(0), payMoney, month);
+
+        if(quantity <= 0){
+            return new GiftIntegralDto(0, 0);
+        }
+
+        double money = mallInnerServiceSMOImpl.computeIntegralMoney(quantity);
+
+
+        return new GiftIntegralDto(quantity, money);
+    }
+
+    public int computeOneIntegralQuantity(IntegralRuleConfigDto integralRuleConfigDto, double payMoney, int month) {
+        String computingFormula = integralRuleConfigDto.getComputingFormula();
+        int amount = 0;
+        if (IntegralRuleConfigDto.COMPUTING_FORMULA_MONEY.equals(computingFormula)) { // 满金额送积分
+            if (payMoney >= Double.parseDouble(integralRuleConfigDto.getSquarePrice())) {
+                amount = Integer.parseInt(integralRuleConfigDto.getAdditionalAmount());
+            }
+        } else if (IntegralRuleConfigDto.COMPUTING_FORMULA_MONTH.equals(computingFormula)) { // 满月送积分
+            if (month >= Double.parseDouble(integralRuleConfigDto.getSquarePrice())) {
+                amount = Integer.parseInt(integralRuleConfigDto.getAdditionalAmount());
+            }
+        }
+        return amount;
+    }
+}

+ 48 - 0
service-acct/src/main/java/com/java110/acct/integral/impl/GiftIntegralImpl.java

@@ -0,0 +1,48 @@
+package com.java110.acct.integral.impl;
+
+import com.java110.acct.integral.IGiftIntegral;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.fee.FeeAttrDto;
+import com.java110.dto.integral.GiftIntegralDto;
+import com.java110.intf.acct.IIntegralGiftDetailV1InnerServiceSMO;
+import com.java110.po.integral.IntegralGiftDetailPo;
+import com.java110.utils.cache.MappingCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class GiftIntegralImpl implements IGiftIntegral {
+
+    private static final String MALL_DOMAIN = "MALL";
+
+    @Autowired
+    private IIntegralGiftDetailV1InnerServiceSMO integralGiftDetailV1InnerServiceSMOImp;
+
+    @Override
+    public void gift(GiftIntegralDto giftIntegralDto) {
+        String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
+
+        if (!"ON".equals(mallSwitch)) {
+            return ;
+        }
+
+
+
+        //先加明细
+//        IntegralGiftDetailPo integralGiftDetailPo = new IntegralGiftDetailPo();
+//        integralGiftDetailPo.setCommunityId(giftIntegralDto.get());
+//        integralGiftDetailPo.setAcctId(accountDto.getAcctId());
+//        integralGiftDetailPo.setAcctName(accountDto.getAcctName());
+//        integralGiftDetailPo.setAcctDetailId("-1");
+//        integralGiftDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId("11"));
+//        integralGiftDetailPo.setConfigId(integralRuleConfigDto.getConfigId());
+//        integralGiftDetailPo.setConfigName(integralRuleConfigDto.getConfigName());
+//        integralGiftDetailPo.setRuleId(integralRuleConfigDto.getRuleId());
+//        integralGiftDetailPo.setRuleName(integralRuleConfigDto.getRuleName());
+//        integralGiftDetailPo.setQuantity(integralRuleConfigDto.getQuantity());
+//        integralGiftDetailPo.setCreateUserId(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_ID));
+//        integralGiftDetailPo.setUserName(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_NAME));
+//        integralGiftDetailPo.setTel(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_LINK));
+//        integralGiftDetailV1InnerServiceSMOImpl.saveIntegralGiftDetail(integralGiftDetailPo);
+    }
+}

+ 281 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatIntegralShareAcct.java

@@ -0,0 +1,281 @@
+package com.java110.acct.payment.adapt.wechat;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.integral.IGiftIntegral;
+import com.java110.core.client.FtpUploadTemplate;
+import com.java110.core.client.OssUploadTemplate;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.file.FileDto;
+import com.java110.dto.integral.GiftIntegralDto;
+import com.java110.dto.payment.PaymentOrderDto;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.MappingConstant;
+import com.java110.utils.util.OSSUtil;
+import com.java110.utils.util.PayUtil;
+import com.java110.utils.util.StringUtil;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContexts;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import javax.net.ssl.SSLContext;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+@Service
+public class WechatIntegralShareAcct {
+
+    private static final Logger logger = LoggerFactory.getLogger(WechatIntegralShareAcct.class);
+
+
+    //微信支付
+    public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
+    // 微信服务商支付开关
+    public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
+
+    //开关ON打开
+    public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
+
+
+    private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
+
+    private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
+
+    // 添加分账接收方API
+    private static final String ADD_RECEIVER_URL = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
+    private static final String FINISH_RECEIVER_URL = "https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish";
+
+    // 删除分账接收方api
+    private static final String DELETE_RECEIVER_URL = "https://api.mch.weixin.qq.com/pay/profitsharingremovereceiver";
+
+    // 请求分账API
+    private static final String PROFIT_SHARING_URL = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing";
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+    @Autowired
+    private FtpUploadTemplate ftpUploadTemplate;
+
+    @Autowired
+    private OssUploadTemplate ossUploadTemplate;
+
+    @Autowired
+    private IGiftIntegral giftIntegralImpl;
+
+    public JSONArray addReceivers(GiftIntegralDto giftIntegralDto) throws Exception {
+        JSONArray params = new JSONArray();
+        JSONObject param = new JSONObject();
+        param.put("type", "MERCHANT_ID");
+        param.put("account", giftIntegralDto.getPlatformMchId());
+        param.put("amount", PayUtil.moneyToIntegerStr(giftIntegralDto.getMoney()));
+        param.put("description", "积分费用");
+
+        params.add(param);
+
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("type", "MERCHANT_ID");
+        paramIn.put("account", giftIntegralDto.getPlatformMchId());
+        paramIn.put("name", giftIntegralDto.getPlatformMchName());
+        paramIn.put("relation_type", "PARTNER");
+
+        SortedMap<String, String> paramMap = new TreeMap<String, String>();
+        paramMap.put("appid", giftIntegralDto.getAppId());
+        paramMap.put("mch_id", giftIntegralDto.getMchId());
+        paramMap.put("nonce_str", PayUtil.makeUUID(32));
+
+        String paySwitch = MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_PAY_SWITCH);
+        if (WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) {
+            paramMap.put("appid", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_APP_ID));  //服务商appid,是服务商注册时公众号的id
+            paramMap.put("mch_id", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_MCH_ID));  //服务商商户号
+            //paramMap.put("sub_appid", smallWeChatDto.getAppId());//起调小程序appid
+            paramMap.put("sub_mch_id", giftIntegralDto.getMchId());//起调小程序的商户号
+        }
+        paramMap.put("receiver", paramIn.toJSONString());
+        paramMap.put("sign", PayUtil.createSignSha256(paramMap, giftIntegralDto.getMchKey()));
+        //转换为xml
+        String xmlData = PayUtil.mapToXml(paramMap);
+
+        logger.debug("调用添加接收方接口" + xmlData);
+        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(
+                ADD_RECEIVER_URL, xmlData, String.class);
+        logger.debug("添加接收方接口返回" + responseEntity);
+        System.out.println("调用添加接收方接口" + xmlData + ";添加接收方接口返回" + responseEntity);
+
+        return params;
+    }
+
+
+    /**
+     * 申请分账
+     *
+     * @return
+     * @throws Exception
+     */
+    public JSONObject applyProfileShare(PaymentOrderDto paymentOrderDto, GiftIntegralDto giftIntegralDto, JSONArray params) throws Exception {
+        SortedMap<String, String> paramMap = new TreeMap<String, String>();
+        paramMap.put("appid", giftIntegralDto.getAppId());
+        paramMap.put("mch_id", giftIntegralDto.getMchId());
+        paramMap.put("nonce_str", PayUtil.makeUUID(32));
+        paramMap.put("transaction_id", paymentOrderDto.getTransactionId());
+        paramMap.put("out_order_no", "FZ" + paymentOrderDto.getOrderId());
+
+        String paySwitch = MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_PAY_SWITCH);
+        if (WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) {
+            paramMap.put("appid", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_APP_ID));  //服务商appid,是服务商注册时公众号的id
+            paramMap.put("mch_id", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_MCH_ID));  //服务商商户号
+            //paramMap.put("sub_appid", smallWeChatDto.getAppId());//起调小程序appid
+            paramMap.put("sub_mch_id", giftIntegralDto.getMchId());//起调小程序的商户号
+        }
+        paramMap.put("receivers", params.toJSONString());
+        paramMap.put("sign", PayUtil.createSignSha256(paramMap, giftIntegralDto.getMchKey()));
+        //转换为xml
+        String xmlData = PayUtil.mapToXml(paramMap);
+
+        JSONObject paramOut = request(PROFIT_SHARING_URL, xmlData, giftIntegralDto, paramMap.get("mch_id"));
+        logger.debug("请求分账 信息{},返回分账信息{}", xmlData, paramOut.toJSONString());
+        return paramOut;
+
+    }
+
+
+    public void deleteReceivers(GiftIntegralDto giftIntegralDto) throws Exception {
+
+        JSONArray deleteParams = new JSONArray();
+        JSONObject param = null;
+        Double amount = 0.0;
+
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("type", "MERCHANT_ID");
+        paramIn.put("account", giftIntegralDto.getPlatformMchId());
+        deleteParams.add(paramIn);
+
+        SortedMap<String, String> paramMap = new TreeMap<String, String>();
+        paramMap.put("appid", giftIntegralDto.getAppId());
+        paramMap.put("mch_id", giftIntegralDto.getMchId());
+        paramMap.put("nonce_str", PayUtil.makeUUID(32));
+
+        String paySwitch = MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_PAY_SWITCH);
+        if (WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) {
+            paramMap.put("appid", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_APP_ID));  //服务商appid,是服务商注册时公众号的id
+            paramMap.put("mch_id", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_MCH_ID));  //服务商商户号
+            // paramMap.put("sub_appid", smallWeChatDto.getAppId());//起调小程序appid
+            paramMap.put("sub_mch_id", giftIntegralDto.getMchId());//起调小程序的商户号
+        }
+        paramMap.put("receiver", deleteParams.toJSONString());
+        paramMap.put("sign", PayUtil.createSignSha256(paramMap, giftIntegralDto.getMchKey()));
+        //转换为xml
+        String xmlData = PayUtil.mapToXml(paramMap);
+
+        logger.debug("调用添加接收方接口" + xmlData);
+        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(
+                DELETE_RECEIVER_URL, xmlData, String.class);
+        logger.debug("添加接收方接口返回" + responseEntity);
+
+    }
+
+    private JSONObject request(String url, String reqData, GiftIntegralDto giftIntegralDto, String key) {
+
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(getPkcs12(giftIntegralDto.getCertPath()));
+        JSONObject paramOut = null;
+        CloseableHttpClient httpclient = null;
+        CloseableHttpResponse response = null;
+        try {
+            KeyStore keyStore = KeyStore.getInstance("PKCS12");
+            //这里写密码..默认是你的MCHID
+            keyStore.load(inputStream, key.toCharArray());
+
+            SSLContext sslcontext = SSLContexts.custom()
+                    //这里也是写密码的
+                    .loadKeyMaterial(keyStore, key.toCharArray())
+                    .build();
+            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
+                    sslcontext,
+                    SSLConnectionSocketFactory.getDefaultHostnameVerifier());
+            httpclient = HttpClients.custom()
+                    .setSSLSocketFactory(sslsf)
+                    .build();
+            String jsonStr = "";
+
+            HttpPost httpost = new HttpPost(url);
+            httpost.setEntity(new StringEntity(reqData, "UTF-8"));
+            httpost.setHeader("Accept", "text/xml, text/plain");
+            httpost.setHeader("Content-Type", "text/xml; charset=utf-8");
+            httpost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
+            response = httpclient.execute(httpost);
+
+            HttpEntity entity = response.getEntity();
+            //接受到返回信息
+            jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
+            EntityUtils.consume(entity);
+            System.out.println("调用添加接收方接口" + reqData + ";添加接收方接口返回" + jsonStr);
+            paramOut = JSONObject.parseObject(JSONObject.toJSONString(PayUtil.xmlStrToMap(jsonStr)));
+        } catch (Exception e) {
+            logger.error("请求微信异常", e);
+            throw new IllegalArgumentException(e.getMessage());
+        } finally {
+            if (httpclient != null) {
+                try {
+                    httpclient.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        return paramOut;
+
+    }
+
+    private byte[] getPkcs12(String fileName) {
+        List<FileDto> fileDtos = new ArrayList<>();
+
+        byte[] context = null;
+        String ftpPath = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PATH);
+
+        String ossSwitch = MappingCache.getValue(MappingConstant.FILE_DOMAIN, OSSUtil.OSS_SWITCH);
+        if (StringUtil.isEmpty(ossSwitch) || !OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
+            String ftpServer = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER);
+            int ftpPort = Integer.parseInt(MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT));
+            String ftpUserName = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME);
+            String ftpUserPassword = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD);
+            context = ftpUploadTemplate.downFileByte(ftpPath, fileName, ftpServer,
+                    ftpPort, ftpUserName,
+                    ftpUserPassword);
+        } else {
+            context = ossUploadTemplate.downFileByte(ftpPath, fileName, "",
+                    0, "",
+                    "");
+        }
+
+        return context;
+    }
+
+    public void sendIntegral(GiftIntegralDto giftIntegralDto) {
+
+        giftIntegralImpl.gift(giftIntegralDto);
+    }
+}

+ 96 - 20
service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java

@@ -1,5 +1,6 @@
 package com.java110.acct.payment.adapt.wechat;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.acct.payment.IPaymentFactoryAdapt;
 import com.java110.core.client.RestTemplate;
@@ -8,6 +9,8 @@ import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.core.factory.WechatFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.dto.app.AppDto;
+import com.java110.dto.integral.GiftIntegralDto;
+import com.java110.dto.paymentPool.PaymentPoolDto;
 import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
 import com.java110.dto.wechat.OnlinePayDto;
 import com.java110.dto.owner.OwnerAppUserDto;
@@ -15,28 +18,24 @@ import com.java110.dto.payment.NotifyPaymentOrderDto;
 import com.java110.dto.payment.PaymentOrderDto;
 import com.java110.dto.wechat.SmallWeChatDto;
 import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
+import com.java110.intf.acct.IPaymentPoolV1InnerServiceSMO;
 import com.java110.intf.acct.IPaymentPoolValueV1InnerServiceSMO;
 import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
 import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
 import com.java110.po.wechat.OnlinePayPo;
+import com.java110.utils.cache.CommonCache;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.cache.UrlCache;
 import com.java110.utils.constant.MappingConstant;
 import com.java110.utils.constant.WechatConstant;
-import com.java110.utils.exception.CmdException;
-import com.java110.utils.util.BeanConvertUtil;
-import com.java110.utils.util.PayUtil;
-import com.java110.utils.util.StringUtil;
+import com.java110.utils.util.*;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.*;
 
 /**
  * 微信支付厂家类
@@ -70,6 +69,9 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
 
     public static final String wxPayUnifiedOrder = "https://api.mch.weixin.qq.com/pay/unifiedorder";
 
+
+
+
     @Autowired
     private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
 
@@ -84,9 +86,16 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
     @Autowired
     private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IPaymentPoolV1InnerServiceSMO paymentPoolV1InnerServiceSMOImpl;
+
     @Autowired
     private RestTemplate outRestTemplate;
 
+    @Autowired
+    private WechatIntegralShareAcct wechatIntegralShareAcct;
+
+
 
     @Override
     public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception {
@@ -99,7 +108,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         String appId = context.getReqHeaders().get("app-id");
         String userId = context.getReqHeaders().get("user-id");
         String tradeType = reqJson.getString("tradeType");
-        String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/wechat/992020011134400001/"+paymentPoolId;
+        String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/wechat/992020011134400001/" + paymentPoolId;
 
         String openId = reqJson.getString("openId");
 
@@ -118,7 +127,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
             ownerAppUserDto.setAppType(appType);
             List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
 
-            if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+            if (ListUtil.isNull(ownerAppUserDtos)) {
                 throw new IllegalArgumentException("未找到开放账号信息");
             }
             openId = ownerAppUserDtos.get(0).getOpenId();
@@ -135,10 +144,11 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         paymentPoolValueDto.setPpId(paymentPoolId);
         List<PaymentPoolValueDto> paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
 
-        if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
+        if (ListUtil.isNull(paymentPoolValueDtos)) {
             throw new IllegalArgumentException("配置错误,未配置参数");
         }
 
+
         Map<String, String> resMap = null;
         resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
                 paymentOrderDto.getOrderId(),
@@ -147,7 +157,8 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
                 openId,
                 smallWeChatDto,
                 paymentPoolValueDtos,
-                notifyUrl
+                notifyUrl,
+                paymentOrderDto
         );
 
         String key = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_KEY");
@@ -189,12 +200,13 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
                                                      String tradeType, double payAmount, String openid,
                                                      SmallWeChatDto smallWeChatDto,
                                                      List<PaymentPoolValueDto> paymentPoolValueDtos,
-                                                     String notifyUrl) throws Exception {
+                                                     String notifyUrl,
+                                                     PaymentOrderDto paymentOrderDto
+    ) throws Exception {
 
         //String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME);
 
 
-
         String mchId = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_MCHID");
         String key = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_KEY");
 
@@ -213,6 +225,15 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
         paramMap.put("trade_type", tradeType);
         paramMap.put("openid", openid);
+        //加入分账申请
+        if (PaymentOrderDto.SHARE_ACCT.equals(paymentOrderDto.getIsShare())) {
+            paramMap.put("profit_sharing", "Y");
+            paymentOrderDto.getGiftIntegralDto().setAppId(smallWeChatDto.getAppId());
+            paymentOrderDto.getGiftIntegralDto().setMchId(mchId);
+            paymentOrderDto.getGiftIntegralDto().setMchKey(key);
+            paymentOrderDto.getGiftIntegralDto().setCertPath(getWechatCertPath(paymentPoolValueDtos.get(0).getPpId()));
+            CommonCache.setValue("integral_share_acct_" + paymentOrderDto.getOrderId(), JSONObject.toJSONString(paymentOrderDto.getGiftIntegralDto()), CommonCache.PAY_DEFAULT_EXPIRE_TIME);
+        }
 
         String paySwitch = MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_PAY_SWITCH);
         if (WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) {
@@ -237,10 +258,29 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         if (responseEntity.getStatusCode() != HttpStatus.OK) {
             throw new IllegalArgumentException("支付失败" + responseEntity.getBody());
         }
-        doSaveOnlinePay(smallWeChatDto, openid, orderNum, feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付",paymentPoolValueDtos.get(0).getPpId());
+        doSaveOnlinePay(smallWeChatDto, openid, orderNum, feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付", paymentPoolValueDtos.get(0).getPpId());
         return PayUtil.xmlStrToMap(responseEntity.getBody());
     }
 
+    private String getWechatCertPath(String ppId) {
+
+        //todo
+
+        PaymentPoolDto paymentPoolDto = new PaymentPoolDto();
+        paymentPoolDto.setPpId(ppId);
+        List<PaymentPoolDto> paymentPoolDtos = paymentPoolV1InnerServiceSMOImpl.queryPaymentPools(paymentPoolDto);
+
+        if (ListUtil.isNull(paymentPoolDtos)) {
+            throw new IllegalArgumentException("未配置支付");
+        }
+
+        if (StringUtil.isEmpty(paymentPoolDtos.get(0).getCertPath())) {
+            throw new IllegalArgumentException("未配置证书");
+        }
+
+        return paymentPoolDtos.get(0).getCertPath();
+    }
+
 
     @Override
     public PaymentOrderDto java110NotifyPayment(NotifyPaymentOrderDto notifyPaymentOrderDto) {
@@ -280,7 +320,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         return paymentOrderDto;
     }
 
-    public int confirmPayFee(Map<String, Object> map, PaymentOrderDto paymentOrderDto, NotifyPaymentOrderDto notifyPaymentOrderDto) {
+    public int confirmPayFee(Map<String, Object> map, PaymentOrderDto paymentOrderDto, NotifyPaymentOrderDto notifyPaymentOrderDto) throws Exception {
         String appId = "";
         //兼容 港币交易时 或者微信有时不会掉参数的问题
         if (map.containsKey("wId")) {
@@ -304,11 +344,11 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         paymentPoolValueDto.setCommunityId(notifyPaymentOrderDto.getCommunityId());
         List<PaymentPoolValueDto> paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
 
-        if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
+        if (ListUtil.isNull(paymentPoolValueDtos)) {
             throw new IllegalArgumentException("配置错误,未配置参数");
         }
 
-       // String mchId = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_MCHID");
+        // String mchId = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_MCHID");
         String key = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_KEY");
 
         String sign = PayUtil.createSign(paramMap, key);
@@ -322,10 +362,46 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         paymentOrderDto.setTransactionId(map.get("transaction_id").toString());
 
         doUpdateOnlinePay(outTradeNo, OnlinePayDto.STATE_COMPILE, "支付成功");
+
+        String giftIntegralDtoStr = CommonCache.getAndRemoveValue("integral_share_acct_" + paymentOrderDto.getOrderId());
+
+        if (StringUtil.isEmpty(giftIntegralDtoStr)) {
+            return 1;
+        }
+
+        GiftIntegralDto giftIntegralDto = JSONObject.parseObject(giftIntegralDtoStr, GiftIntegralDto.class);
+        if (giftIntegralDto == null) {
+            return 1;
+        }
+
+        //todo 添加分账商家
+        JSONArray params = wechatIntegralShareAcct.addReceivers(giftIntegralDto);
+
+
+        //todo 申请分账
+        JSONObject applyResult = wechatIntegralShareAcct.applyProfileShare(paymentOrderDto, giftIntegralDto, params);
+
+        if (applyResult.containsKey("result_code") && "SUCCESS".equals(applyResult.getString("result_code"))) {
+            JSONObject finishParam = new JSONObject();
+            finishParam.put("out_order_no", applyResult.getString("order_id"));
+            //完结分账 单次分账
+            //finishProfileShare(storeOrderDto, smallWeChatDto, finishParam);
+        } else {
+            throw new IllegalArgumentException("分账失败:" + applyResult.toJSONString());
+        }
+
+        // 删除接收方
+        wechatIntegralShareAcct.deleteReceivers(giftIntegralDto);
+
+        // todo 给用户赠送积分
+        wechatIntegralShareAcct.sendIntegral(giftIntegralDto);
+
         return 1;
     }
 
 
+
+
     private SmallWeChatDto getSmallWechat(JSONObject paramIn) {
 
         SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
@@ -335,7 +411,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         smallWeChatDto.setRow(1);
         List<SmallWeChatDto> smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto);
 
-        if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
+        if (ListUtil.isNull(smallWeChatDtos)) {
             smallWeChatDto = new SmallWeChatDto();
             smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
             smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
@@ -359,7 +435,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
     }
 
     private void doSaveOnlinePay(SmallWeChatDto smallWeChatDto, String openId, String orderId, String feeName,
-                                 double money, String state, String message,String ppId) {
+                                 double money, String state, String message, String ppId) {
         OnlinePayPo onlinePayPo = new OnlinePayPo();
         onlinePayPo.setAppId(smallWeChatDto.getAppId());
         onlinePayPo.setMchId(smallWeChatDto.getMchId());

+ 18 - 1
service-acct/src/main/java/com/java110/acct/payment/business/payFee/PayFeePaymentBusiness.java

@@ -1,15 +1,18 @@
 package com.java110.acct.payment.business.payFee;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.integral.IComputeGiftIntegral;
 import com.java110.acct.payment.IPaymentBusiness;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.factory.CallApiServiceFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.dto.fee.FeeDto;
+import com.java110.dto.integral.GiftIntegralDto;
 import com.java110.dto.payment.PaymentOrderDto;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.util.MoneyUtil;
 import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -25,6 +28,10 @@ public class PayFeePaymentBusiness implements IPaymentBusiness {
     private final static Logger logger = LoggerFactory.getLogger(PayFeePaymentBusiness.class);
 
 
+    @Autowired
+    private IComputeGiftIntegral computeGiftIntegralImpl;
+
+
     @Override
     public PaymentOrderDto unified(ICmdDataFlowContext context, JSONObject reqJson) {
 
@@ -35,14 +42,24 @@ public class PayFeePaymentBusiness implements IPaymentBusiness {
         String feeName = orderInfo.getString("feeName");
         double money = Double.parseDouble(orderInfo.getString("receivedAmount"));
 
+        GiftIntegralDto giftIntegralDto = computeGiftIntegralImpl.gift(money, reqJson.getIntValue("cycles"), reqJson.getString("communityId"));
+
         //这里防止 小数点不是 2位 比如 3位之类的 微信平台不支持
-        money = MoneyUtil.computePriceScale(money,"1",2);
+        money = MoneyUtil.computePriceScale(money, "1", 2);
 
 
         PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
         paymentOrderDto.setOrderId(orderId);
         paymentOrderDto.setMoney(money);
         paymentOrderDto.setName(feeName);
+
+        if (giftIntegralDto != null && giftIntegralDto.getMoney() > 0) {
+            paymentOrderDto.setIsShare("Y");
+            giftIntegralDto.setUserId(userId);
+            paymentOrderDto.setGiftIntegralDto(giftIntegralDto);
+        }
+
+
         return paymentOrderDto;
     }
 

+ 0 - 323
service-job/src/main/java/com/java110/job/adapt/payment/integral/PayFeeGiftIntegralAdapt.java

@@ -1,323 +0,0 @@
-package com.java110.job.adapt.payment.integral;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.core.log.LoggerFactory;
-import com.java110.core.smo.IComputeFeeSMO;
-import com.java110.dto.room.RoomDto;
-import com.java110.dto.account.AccountDto;
-import com.java110.dto.fee.FeeAttrDto;
-import com.java110.dto.fee.FeeDetailDto;
-import com.java110.dto.fee.FeeDto;
-import com.java110.dto.integral.IntegralRuleConfigDto;
-import com.java110.dto.integral.IntegralRuleFeeDto;
-import com.java110.dto.log.LogSystemErrorDto;
-import com.java110.dto.owner.OwnerDto;
-import com.java110.dto.system.Business;
-import com.java110.intf.acct.*;
-import com.java110.intf.community.ICommunityInnerServiceSMO;
-import com.java110.intf.community.IRoomV1InnerServiceSMO;
-import com.java110.intf.fee.IFeeAttrInnerServiceSMO;
-import com.java110.intf.fee.IFeeDetailInnerServiceSMO;
-import com.java110.intf.fee.IFeeInnerServiceSMO;
-import com.java110.intf.user.IOwnerV1InnerServiceSMO;
-import com.java110.job.adapt.DatabusAdaptImpl;
-import com.java110.po.account.AccountPo;
-import com.java110.po.account.AccountDetailPo;
-import com.java110.po.fee.PayFeeDetailPo;
-import com.java110.po.integral.IntegralGiftDetailPo;
-import com.java110.po.log.LogSystemErrorPo;
-import com.java110.service.smo.ISaveSystemErrorSMO;
-import com.java110.utils.exception.CmdException;
-import com.java110.utils.lock.DistributedLock;
-import com.java110.utils.util.*;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 缴费 赠送 积分
- *
- * @author fqz
- * @date 2020-12-11  18:54
- */
-@Component(value = "payFeeGiftIntegralAdapt")
-public class PayFeeGiftIntegralAdapt extends DatabusAdaptImpl {
-
-    private static Logger logger = LoggerFactory.getLogger(PayFeeGiftIntegralAdapt.class);
-
-    @Autowired
-    private ICommunityInnerServiceSMO communityInnerServiceSMO;
-
-    @Autowired
-    private ISaveSystemErrorSMO saveSystemErrorSMOImpl;
-
-    @Autowired
-    private IRoomV1InnerServiceSMO roomV1InnerServiceSMOImpl;
-
-
-    @Autowired
-    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
-
-    @Autowired
-    private IFeeAttrInnerServiceSMO feeAttrInnerServiceSMOImpl;
-
-    @Autowired
-    private IFeeDetailInnerServiceSMO feeDetailInnerServiceSMOImpl;
-
-    @Autowired
-    private IIntegralRuleFeeV1InnerServiceSMO integralRuleFeeV1InnerServiceSMOImpl;
-
-    @Autowired
-    private IIntegralRuleConfigV1InnerServiceSMO integralRuleConfigV1InnerServiceSMOImpl;
-
-    @Autowired
-    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
-
-    @Autowired
-    private IOwnerV1InnerServiceSMO ownerInnerServiceSMOImpl;
-
-
-    @Autowired
-    private IIntegralGiftDetailV1InnerServiceSMO integralGiftDetailV1InnerServiceSMOImpl;
-
-
-    @Autowired
-    private IComputeFeeSMO computeFeeSMOImpl;
-
-    //模板信息推送地址
-    private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
-
-    @Override
-    public void execute(Business business, List<Business> businesses) {
-        JSONObject data = business.getData();
-
-        if (data != null) {
-            logger.debug("请求日志:{}", data);
-        }
-        JSONArray businessPayFeeDetails = null;
-        if (data == null) {
-            FeeDetailDto feeDetailDto = new FeeDetailDto();
-            feeDetailDto.setbId(business.getbId());
-            List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto);
-            Assert.listOnlyOne(feeDetailDtos, "未查询到缴费记录");
-            businessPayFeeDetails = JSONArray.parseArray(JSONArray.toJSONString(feeDetailDtos, SerializerFeature.WriteDateUseDateFormat));
-        } else if (data.containsKey(PayFeeDetailPo.class.getSimpleName())) {
-            Object bObj = data.get(PayFeeDetailPo.class.getSimpleName());
-            if (bObj instanceof JSONObject) {
-                businessPayFeeDetails = new JSONArray();
-                businessPayFeeDetails.add(bObj);
-            } else if (bObj instanceof Map) {
-                businessPayFeeDetails = new JSONArray();
-                businessPayFeeDetails.add(JSONObject.parseObject(JSONObject.toJSONString(bObj)));
-            } else if (bObj instanceof List) {
-                businessPayFeeDetails = JSONArray.parseArray(JSONObject.toJSONString(bObj));
-            } else {
-                businessPayFeeDetails = (JSONArray) bObj;
-            }
-        } else {
-            if (data instanceof JSONObject) {
-                businessPayFeeDetails = new JSONArray();
-                businessPayFeeDetails.add(data);
-            }
-        }
-
-        if (businessPayFeeDetails == null) {
-            return;
-        }
-        for (int bPayFeeDetailIndex = 0; bPayFeeDetailIndex < businessPayFeeDetails.size(); bPayFeeDetailIndex++) {
-            JSONObject businessPayFeeDetail = businessPayFeeDetails.getJSONObject(bPayFeeDetailIndex);
-            doPayFeeDetail(business, businessPayFeeDetail);
-        }
-    }
-
-    private void doPayFeeDetail(Business business, JSONObject businessPayFeeDetail) {
-        try {
-            //查询缴费明细
-            PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(businessPayFeeDetail, PayFeeDetailPo.class);
-            FeeDto feeDto = new FeeDto();
-            feeDto.setFeeId(payFeeDetailPo.getFeeId());
-            feeDto.setCommunityId(payFeeDetailPo.getCommunityId());
-            List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
-
-            Assert.listOnlyOne(feeDtos, "未查询到费用信息");
-
-            if(businessPayFeeDetail.containsKey("receivedAmount")
-                    && businessPayFeeDetail.getDoubleValue("receivedAmount")<0){
-                return ;
-            }
-
-            IntegralRuleFeeDto integralRuleFeeDto = new IntegralRuleFeeDto();
-            integralRuleFeeDto.setFeeConfigId(feeDtos.get(0).getConfigId());
-            integralRuleFeeDto.setCurTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
-            integralRuleFeeDto.setCommunityId(payFeeDetailPo.getCommunityId());
-            integralRuleFeeDto.setCycle(payFeeDetailPo.getCycles());
-            List<IntegralRuleFeeDto> integralRuleFeeDtos = integralRuleFeeV1InnerServiceSMOImpl.queryIntegralRuleFees(integralRuleFeeDto);
-
-            if (integralRuleFeeDtos == null || integralRuleFeeDtos.size() < 1) {
-                return;
-            }
-
-            List<String> ruleIds = new ArrayList<>();
-            for (IntegralRuleFeeDto tmpCouponRuleFeeDto : integralRuleFeeDtos) {
-                ruleIds.add(tmpCouponRuleFeeDto.getRuleId());
-            }
-
-            IntegralRuleConfigDto integralRuleConfigDto = new IntegralRuleConfigDto();
-            integralRuleConfigDto.setRuleIds(ruleIds.toArray(new String[ruleIds.size()]));
-            List<IntegralRuleConfigDto> integralRuleConfigDtos = integralRuleConfigV1InnerServiceSMOImpl.queryIntegralRuleConfigs(integralRuleConfigDto);
-
-            if (integralRuleConfigDtos == null || integralRuleConfigDtos.size() < 1) {
-                return;
-            }
-
-            // 计算赠送 积分公式
-            long quantity = computeIntegralQuantity(integralRuleConfigDtos, feeDtos.get(0), payFeeDetailPo.getReceivedAmount());
-
-            if (quantity <= 0) {
-                return;
-            }
-            //赠送优惠券
-            giftIntegral(integralRuleConfigDtos, feeDtos.get(0), payFeeDetailPo, quantity);
-        } catch (Exception e) {
-            LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo();
-            logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId));
-            logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_COUPON);
-            logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e));
-            saveSystemErrorSMOImpl.saveLog(logSystemErrorPo);
-            logger.error("通知异常", e);
-        }
-    }
-
-    private long computeIntegralQuantity(List<IntegralRuleConfigDto> integralRuleConfigDtos, FeeDto feeDto, String receivedAmount) {
-        JSONObject reqJson = new JSONObject();
-        reqJson.put("amount", receivedAmount);
-        reqJson.put("area", "1");
-        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) {
-            RoomDto roomDto = new RoomDto();
-            roomDto.setRoomId(feeDto.getPayerObjId());
-            List<RoomDto> roomDtos = roomV1InnerServiceSMOImpl.queryRooms(roomDto);
-            Assert.listOnlyOne(roomDtos, "房屋不存在");
-            reqJson.put("area", roomDtos.get(0).getBuiltUpArea());
-        }
-
-        long quantity = 0;
-        for (IntegralRuleConfigDto integralRuleConfigDto : integralRuleConfigDtos) {
-            quantity += computeFeeSMOImpl.computeOneIntegralQuantity(integralRuleConfigDto, reqJson);
-        }
-        return quantity;
-    }
-
-    /**
-     * 赠送积分
-     *
-     * @param integralRuleConfigDtos
-     * @param feeDto
-     * @param payFeeDetailPo
-     */
-    private void giftIntegral(List<IntegralRuleConfigDto> integralRuleConfigDtos, FeeDto feeDto, PayFeeDetailPo payFeeDetailPo, long quantity) {
-
-
-        String ownerId = FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_ID);
-
-        if (StringUtil.isEmpty(ownerId)) {
-            return;
-        }
-
-        //向积分账户中充值积分
-        AccountDto accountDto = new AccountDto();
-        accountDto.setObjId(ownerId);
-        accountDto.setAcctType(AccountDto.ACCT_TYPE_INTEGRAL);
-        List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
-
-        if (accountDtos == null || accountDtos.size() < 1) {
-            accountDtos = addAccountDto(accountDto,payFeeDetailPo);
-        }
-
-        AccountDetailPo accountDetailPo = new AccountDetailPo();
-        accountDetailPo.setAcctId(accountDtos.get(0).getAcctId());
-        accountDetailPo.setObjId(accountDtos.get(0).getObjId());
-        accountDetailPo.setObjType(accountDtos.get(0).getObjType());
-        accountDetailPo.setAmount(quantity + "");
-        int flag = accountInnerServiceSMOImpl.prestoreAccount(accountDetailPo);
-
-        if (flag < 1) {
-            throw new CmdException("扣款失败");
-        }
-
-        for (IntegralRuleConfigDto integralRuleConfigDto : integralRuleConfigDtos) {
-            try {
-                doGiftIntegral(integralRuleConfigDto, feeDto,accountDtos.get(0));
-            } catch (Exception e) {
-                LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo();
-                logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId));
-                logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_INTEGRAL);
-                logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e));
-                saveSystemErrorSMOImpl.saveLog(logSystemErrorPo);
-                logger.error("通知异常", e);
-            }
-        }
-
-    }
-
-    private List<AccountDto> addAccountDto(AccountDto accountDto, PayFeeDetailPo payFeeDetailPo) {
-        if (StringUtil.isEmpty(accountDto.getObjId())) {
-            return new ArrayList<>();
-        }
-        //开始锁代码
-        String requestId = DistributedLock.getLockUUID();
-        String key = this.getClass().getSimpleName() + "AddCountDto" + accountDto.getObjId();
-        try {
-            DistributedLock.waitGetDistributedLock(key, requestId);
-
-            AccountPo accountPo = new AccountPo();
-            accountPo.setAmount("0");
-            accountPo.setAcctId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_acctId));
-            accountPo.setObjId(accountDto.getObjId());
-            accountPo.setObjType(AccountDto.OBJ_TYPE_PERSON);
-            accountPo.setAcctType(AccountDto.ACCT_TYPE_INTEGRAL);
-            OwnerDto tmpOwnerDto = new OwnerDto();
-            tmpOwnerDto.setMemberId(accountDto.getObjId());
-            tmpOwnerDto.setCommunityId(payFeeDetailPo.getCommunityId());
-            List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(tmpOwnerDto);
-            Assert.listOnlyOne(ownerDtos, "业主不存在");
-            accountPo.setAcctName(ownerDtos.get(0).getName());
-            accountPo.setPartId(ownerDtos.get(0).getCommunityId());
-            accountPo.setLink(ownerDtos.get(0).getLink());
-            accountInnerServiceSMOImpl.saveAccount(accountPo);
-            List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
-            return accountDtos;
-        } finally {
-            DistributedLock.releaseDistributedLock(requestId, key);
-        }
-    }
-
-    private void doGiftIntegral(IntegralRuleConfigDto integralRuleConfigDto, FeeDto feeDto,AccountDto accountDto) {
-
-        //先加明细
-        IntegralGiftDetailPo integralGiftDetailPo = new IntegralGiftDetailPo();
-        integralGiftDetailPo.setCommunityId(integralRuleConfigDto.getCommunityId());
-        integralGiftDetailPo.setAcctId(accountDto.getAcctId());
-        integralGiftDetailPo.setAcctName(accountDto.getAcctName());
-        integralGiftDetailPo.setAcctDetailId("-1");
-        integralGiftDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId("11"));
-        integralGiftDetailPo.setConfigId(integralRuleConfigDto.getConfigId());
-        integralGiftDetailPo.setConfigName(integralRuleConfigDto.getConfigName());
-        integralGiftDetailPo.setRuleId(integralRuleConfigDto.getRuleId());
-        integralGiftDetailPo.setRuleName(integralRuleConfigDto.getRuleName());
-        integralGiftDetailPo.setQuantity(integralRuleConfigDto.getQuantity());
-        integralGiftDetailPo.setCreateUserId(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_ID));
-        integralGiftDetailPo.setUserName(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_NAME));
-        integralGiftDetailPo.setTel(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_LINK));
-        integralGiftDetailV1InnerServiceSMOImpl.saveIntegralGiftDetail(integralGiftDetailPo);
-
-    }
-
-
-}

+ 0 - 5
service-job/src/main/java/com/java110/job/adapt/payment/integral/package-info.java

@@ -1,5 +0,0 @@
-/**
- * 该包处理
- * 缴费赠送 积分给业主
- */
-package com.java110.job.adapt.payment.integral;

+ 23 - 3
service-job/src/main/java/com/java110/job/smo/impl/MallInnerServiceSMOImpl.java

@@ -41,7 +41,7 @@ public class MallInnerServiceSMOImpl extends BaseServiceSMO implements IMallInne
         String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
 
         if (!"ON".equals(mallSwitch)) {
-            return new ResultVo(ResultVo.CODE_OK,ResultVo.MSG_OK);
+            return new ResultVo(ResultVo.CODE_OK, ResultVo.MSG_OK);
         }
 
         ResultVo resultVo = sendMallImpl.post("/mall/api/common.openCommonApi", paramIn);
@@ -54,7 +54,7 @@ public class MallInnerServiceSMOImpl extends BaseServiceSMO implements IMallInne
         String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
 
         if (!"ON".equals(mallSwitch)) {
-            return new ResultVo(ResultVo.CODE_OK,ResultVo.MSG_OK);
+            return new ResultVo(ResultVo.CODE_OK, ResultVo.MSG_OK);
         }
 
 
@@ -95,7 +95,7 @@ public class MallInnerServiceSMOImpl extends BaseServiceSMO implements IMallInne
         String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
 
         if (!"ON".equals(mallSwitch)) {
-           return new ResultVo(ResultVo.CODE_OK,ResultVo.MSG_OK);
+            return new ResultVo(ResultVo.CODE_OK, ResultVo.MSG_OK);
         }
 
         JSONObject paramIn = new JSONObject();
@@ -110,4 +110,24 @@ public class MallInnerServiceSMOImpl extends BaseServiceSMO implements IMallInne
         return resultVo;
     }
 
+    @Override
+    public double computeIntegralMoney(@RequestBody int quantity) {
+
+        String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
+
+        if (!"ON".equals(mallSwitch)) {
+            return 0;
+        }
+
+
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("quantity", quantity);
+        paramIn.put("mallApiCode", "computeIntegralMoneyBmoImpl");
+        ResultVo resultVo = sendMallImpl.post("/mall/api/common.openCommonApi", paramIn);
+        if (resultVo.getCode() != ResultVo.CODE_OK) {
+            throw new IllegalArgumentException(resultVo.getMsg());
+        }
+        return Double.parseDouble(resultVo.getData().toString());
+    }
+
 }