From 75cbaa2d0ce62ea8f6752a917627591ab918ab22 Mon Sep 17 00:00:00 2001
From: xiaogang <905166056@qq.com>
Date: 星期一, 20 六月 2022 17:36:02 +0800
Subject: [PATCH] 1、缴费积分抵扣从小区设置里面配置并且进行抵扣2、抵扣明细3、超时相关bug

---
 service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java |  158 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 2 deletions(-)

diff --git a/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java b/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java
index 0dcd98c..d605809 100644
--- a/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java
+++ b/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java
@@ -8,10 +8,17 @@
 import com.java110.api.smo.payment.adapt.IPayAdapt;
 import com.java110.core.context.IPageData;
 import com.java110.core.context.PageData;
+import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.dto.app.AppDto;
 import com.java110.dto.owner.OwnerAppUserDto;
 import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.intf.acct.IAccountDetailInnerServiceSMO;
+import com.java110.intf.acct.IAccountInnerServiceSMO;
+import com.java110.intf.feeAccountDetail.IFeeAccountDetailServiceSMO;
+import com.java110.po.account.AccountPo;
+import com.java110.po.accountDetail.AccountDetailPo;
+import com.java110.po.feeAccountDetail.FeeAccountDetailPo;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.WechatConstant;
@@ -29,6 +36,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -45,9 +53,17 @@
     @Autowired
     private RestTemplate outRestTemplate;
 
-
     @Autowired
     private WechatAuthProperties wechatAuthProperties;
+
+    @Autowired
+    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+    @Autowired
+    private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
+
+    @Autowired
+    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
 
     @Override
     public ResponseEntity<String> toPay(IPageData pd) {
@@ -93,7 +109,7 @@
         String orderId = orderInfo.getString("oId");
         String feeName = orderInfo.getString("feeName");
         double money = Double.parseDouble(orderInfo.getString("receivedAmount"));
-        //闇�瑕佸垽鏂噾棰濇槸鍚� == 0 绛変簬0 鐩存帴鎺夌即璐归�氱煡鎺ュ彛
+        //闇�瑕佸垽鏂噾棰濇槸鍚� == 0 绛変簬0 鐩存帴璋冪即璐归�氱煡鎺ュ彛
         if (money <= 0) {
             JSONObject paramOut = new JSONObject();
             paramOut.put("oId", orderId);
@@ -109,6 +125,144 @@
             if (ResultVo.CODE_OK != result.getInteger("code")) {
                 return responseEntity;
             }
+            if (paramIn.containsKey("selectUserAccount") && !StringUtil.isEmpty(paramIn.getString("selectUserAccount"))) {
+                String selectUserAccount = paramIn.getString("selectUserAccount");
+                JSONArray params = JSONArray.parseArray(selectUserAccount);
+                for (int paramIndex = 0; paramIndex < params.size(); paramIndex++) {
+                    JSONObject paramObj = params.getJSONObject(paramIndex);
+                    if (!StringUtil.isEmpty(paramObj.getString("acctType")) && paramObj.getString("acctType").equals("2004")) { //绉垎璐︽埛
+                        //璐︽埛閲戦
+                        BigDecimal amount = new BigDecimal(paramObj.getString("amount"));
+                        //鑾峰彇鏈�澶ф姷鎵gН鍒�
+                        BigDecimal maximumNumber = new BigDecimal(paramObj.getString("maximumNumber"));
+                        //鑾峰彇绉垎鎶垫墸姣斾緥
+                        BigDecimal deductionProportion = new BigDecimal(paramObj.getString("deductionProportion"));
+                        int flag = amount.compareTo(maximumNumber);
+                        BigDecimal redepositAmount = new BigDecimal("0.00");
+                        BigDecimal integralAmount = new BigDecimal("0.00");
+                        if (flag == 1) { //璐︽埛绉垎澶т簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                            redepositAmount = maximumNumber;
+                            integralAmount = amount.subtract(maximumNumber);
+                        }
+                        if (flag > -1) { //璐︽埛绉垎澶т簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                            redepositAmount = maximumNumber;
+                            integralAmount = amount.subtract(maximumNumber);
+                        }
+                        if (flag == -1) { //璐︽埛绉垎灏忎簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                            redepositAmount = amount;
+                        }
+                        if (flag < 1) { //璐︽埛绉垎灏忎簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                            redepositAmount = amount;
+                        }
+                        if (flag == 0) { //璐︽埛绉垎绛変簬鏈�澶т娇鐢ㄧН鍒�
+                            redepositAmount = amount;
+                        }
+                        //鏇存柊璐︽埛淇℃伅
+                        AccountPo accountPo = new AccountPo();
+                        accountPo.setAcctId(paramObj.getString("acctId"));
+                        accountPo.setAmount(integralAmount.toString());
+                        accountInnerServiceSMOImpl.updateAccount(accountPo);
+                        //鐢熸垚璐︽埛璇︽儏
+                        AccountDetailPo accountDetailPo = new AccountDetailPo();
+                        accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+                        accountDetailPo.setAcctId(paramObj.getString("acctId"));
+                        accountDetailPo.setDetailType("2002"); //1001 杞叆 2002 杞嚭
+                        accountDetailPo.setRelAcctId("-1");
+                        accountDetailPo.setAmount(redepositAmount.toString());
+                        accountDetailPo.setObjType("6006"); //6006 涓汉 7007 鍟嗘埛
+                        accountDetailPo.setObjId(paramObj.getString("objId"));
+                        accountDetailPo.setOrderId("-1");
+                        accountDetailPo.setbId("-1");
+                        accountDetailPo.setRemark("鎵嬫満绔Н鍒嗘姷鎵�");
+                        accountDetailPo.setCreateTime(new Date());
+                        accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
+                        //璁$畻绉垎鎹㈢畻鐨勯噾棰�
+                        BigDecimal divide = redepositAmount.divide(deductionProportion);
+                        BigDecimal deductionAmount = new BigDecimal(paramIn.getString("deductionAmount"));
+                        //璁$畻瀹炰粯閲戦
+                        int flag2 = divide.compareTo(deductionAmount);
+                        BigDecimal subtract = new BigDecimal("0.00");
+                        //鐢熸垚鎶垫墸鏄庣粏璁板綍
+                        FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                        if (flag2 == -1) { //绉垎鎹㈢畻閲戦灏忎簬搴斾粯閲戦
+                            subtract = deductionAmount.subtract(divide);
+                            BigDecimal multiply = divide.multiply(deductionProportion);
+                            feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+                        } else if (flag < 1) { //绉垎鎹㈢畻閲戦灏忎簬绛変簬搴斾粯閲戦
+                            subtract = deductionAmount.subtract(divide);
+                            BigDecimal multiply = divide.multiply(deductionProportion);
+                            feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+                        } else {
+                            BigDecimal multiply = deductionAmount.multiply(deductionProportion);
+                            feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+                        }
+                        paramIn.put("receivedMoney", subtract);
+//                    payFeeDetailPo.setReceivedAmount(subtract.toString());
+                        feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                        feeAccountDetailPo.setDetailId(accountDetailPo.getDetailId());
+                        feeAccountDetailPo.setCommunityId(paramObj.getString("communityId"));
+                        feeAccountDetailPo.setState("1003"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                        feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                    } else if (!StringUtil.isEmpty(paramObj.getString("acctType")) && paramObj.getString("acctType").equals("2003")) { //鐜伴噾璐︽埛
+                        //璐︽埛閲戦
+                        BigDecimal amount = new BigDecimal(paramObj.getString("amount"));
+                        //鑾峰彇搴旀敹閲戦
+                        BigDecimal deductionAmount = new BigDecimal("0.00");
+                        if (paramIn.containsKey("receivedMoney") && !StringUtil.isEmpty(paramIn.getString("receivedMoney"))) {
+                            deductionAmount = new BigDecimal(paramIn.getString("receivedMoney"));
+                        } else {
+                            deductionAmount = new BigDecimal(paramIn.getString("deductionAmount"));
+                        }
+                        int flag = amount.compareTo(deductionAmount);
+                        BigDecimal redepositAmount = new BigDecimal("0.00");
+                        BigDecimal integralAmount = new BigDecimal("0.00");
+                        if (flag == 1) { //鐜伴噾璐︽埛澶т簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+                            redepositAmount = deductionAmount;
+                            integralAmount = amount.subtract(deductionAmount);
+                        }
+                        if (flag > -1) { //鐜伴噾璐︽埛澶т簬绛変簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+                            redepositAmount = deductionAmount;
+                            integralAmount = amount.subtract(deductionAmount);
+                        }
+                        if (flag == -1) { //鐜伴噾璐︽埛灏忎簬瀹炴敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+                            redepositAmount = amount;
+                        }
+                        if (flag < 1) { //鐜伴噾璐︽埛灏忎簬绛変簬搴旀敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+                            redepositAmount = amount;
+                        }
+                        if (flag == 0) { //鐜伴噾璐︽埛绛変簬搴旀敹閲戦
+                            redepositAmount = amount;
+                        }
+                        //鏇存柊璐︽埛淇℃伅
+                        AccountPo accountPo = new AccountPo();
+                        accountPo.setAcctId(paramObj.getString("acctId"));
+                        accountPo.setAmount(integralAmount.toString());
+                        accountInnerServiceSMOImpl.updateAccount(accountPo);
+                        //鐢熸垚璐︽埛璇︽儏
+                        AccountDetailPo accountDetailPo = new AccountDetailPo();
+                        accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+                        accountDetailPo.setAcctId(paramObj.getString("acctId"));
+                        accountDetailPo.setDetailType("2002"); //1001 杞叆 2002 杞嚭
+                        accountDetailPo.setRelAcctId("-1");
+                        accountDetailPo.setAmount(redepositAmount.toString());
+                        accountDetailPo.setObjType("6006"); //6006 涓汉 7007 鍟嗘埛
+                        accountDetailPo.setObjId(paramObj.getString("objId"));
+                        accountDetailPo.setOrderId("-1");
+                        accountDetailPo.setbId("-1");
+                        accountDetailPo.setRemark("鎵嬫満绔幇閲戣处鎴锋姷鎵�");
+                        accountDetailPo.setCreateTime(new Date());
+                        accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
+                        //鐢熸垚鎶垫墸鏄庣粏璁板綍
+                        FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                        feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                        feeAccountDetailPo.setDetailId(accountDetailPo.getDetailId());
+                        feeAccountDetailPo.setCommunityId(paramIn.getString("communityId"));
+                        feeAccountDetailPo.setState("1002"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                        feeAccountDetailPo.setAmount(redepositAmount.toString()); //绉垎鎶垫墸閲戦
+                        feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                    }
+                }
+            }
             param.put("code", "100");
             param.put("msg", "鎵h垂涓�0鍥炶皟鎴愬姛");
             return new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK);

--
Gitblit v1.8.0