wuxw hai 1 ano
pai
achega
e1013e581f

+ 31 - 0
java110-bean/src/main/java/com/java110/dto/integral/DeductionIntegralDto.java

@@ -0,0 +1,31 @@
+package com.java110.dto.integral;
+
+import java.io.Serializable;
+
+public class DeductionIntegralDto implements Serializable {
+
+    private int integral;
+
+    private double money;
+
+    public DeductionIntegralDto(int integral, double money) {
+        this.integral = integral;
+        this.money = money;
+    }
+
+    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;
+    }
+}

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

@@ -32,6 +32,8 @@ public class PaymentOrderDto implements Serializable{
 
     private String cycles;
 
+    private String useIntegral;
+
     private GiftIntegralDto giftIntegralDto;
 
 
@@ -126,4 +128,12 @@ public class PaymentOrderDto implements Serializable{
     public void setCycles(String cycles) {
         this.cycles = cycles;
     }
+
+    public String getUseIntegral() {
+        return useIntegral;
+    }
+
+    public void setUseIntegral(String useIntegral) {
+        this.useIntegral = useIntegral;
+    }
 }

+ 14 - 0
service-acct/src/main/java/com/java110/acct/integral/IComputeDeductionIntegral.java

@@ -0,0 +1,14 @@
+package com.java110.acct.integral;
+
+import com.java110.dto.integral.DeductionIntegralDto;
+import com.java110.dto.integral.GiftIntegralDto;
+
+public interface IComputeDeductionIntegral {
+    /**
+     * 抵扣积分和金额计算
+     *
+     * @param communityId
+     * @return
+     */
+    DeductionIntegralDto deduction(String userId,String orderId, String communityId);
+}

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

@@ -0,0 +1,8 @@
+package com.java110.acct.integral;
+
+import com.java110.dto.integral.DeductionIntegralDto;
+
+public interface IDeductionIntegral {
+
+    int deduction(String orderId);
+}

+ 65 - 0
service-acct/src/main/java/com/java110/acct/integral/impl/ComputeDeductionIntegralImpl.java

@@ -0,0 +1,65 @@
+package com.java110.acct.integral.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.integral.IComputeDeductionIntegral;
+import com.java110.dto.MallDataDto;
+import com.java110.dto.integral.DeductionIntegralDto;
+import com.java110.dto.integral.GiftIntegralDto;
+import com.java110.dto.user.UserDto;
+import com.java110.intf.job.IMallInnerServiceSMO;
+import com.java110.intf.user.IUserV1InnerServiceSMO;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.cache.MappingCache;
+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.util.List;
+
+@Service
+public class ComputeDeductionIntegralImpl implements IComputeDeductionIntegral {
+
+    private static final String MALL_DOMAIN = "MALL";
+
+    @Autowired
+    private IMallInnerServiceSMO mallInnerServiceSMOImpl;
+
+    @Autowired
+    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
+
+    @Override
+    public DeductionIntegralDto deduction(String userId,String orderId, String communityId) {
+
+        String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
+
+        if (!"ON".equals(mallSwitch)) {
+            return new DeductionIntegralDto(0, 0);
+        }
+
+        UserDto userDto = new UserDto();
+        userDto.setUserId(userId);
+        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
+
+        if (ListUtil.isNull(userDtos)) {
+            return new DeductionIntegralDto(0, 0);
+        }
+
+
+        JSONObject reqJson = new JSONObject();
+        reqJson.put("link", userDtos.get(0).getTel());
+        ResultVo resultVo = mallInnerServiceSMOImpl.postMallData(new MallDataDto("queryAppUserIntegralBmoImpl", reqJson));
+
+        if (resultVo.getCode() != ResultVo.CODE_OK) {
+            return new DeductionIntegralDto(0, 0);
+        }
+
+
+        JSONObject data = reqJson.getJSONObject("data");
+
+
+       DeductionIntegralDto deductionIntegralDto =  new DeductionIntegralDto(data.getIntValue("integral"), data.getDoubleValue("integralMoney"));
+        CommonCache.setValue("integral_deduction_" + orderId, JSONObject.toJSONString(deductionIntegralDto), CommonCache.PAY_DEFAULT_EXPIRE_TIME);
+        return deductionIntegralDto;
+    }
+}

+ 27 - 0
service-acct/src/main/java/com/java110/acct/integral/impl/DeductionIntegralImpl.java

@@ -0,0 +1,27 @@
+package com.java110.acct.integral.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.integral.IDeductionIntegral;
+import com.java110.dto.integral.DeductionIntegralDto;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.util.StringUtil;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DeductionIntegralImpl implements IDeductionIntegral {
+    @Override
+    public int deduction(String orderId) {
+
+        String deductionIntegralDtoStr = CommonCache.getAndRemoveValue("integral_deduction_" + orderId);
+
+        if (StringUtil.isEmpty(deductionIntegralDtoStr)) {
+            return 0;
+
+        }
+        DeductionIntegralDto deductionIntegralDto = JSONObject.parseObject(deductionIntegralDtoStr, DeductionIntegralDto.class);
+        if (deductionIntegralDto == null) {
+            return 0;
+        }
+        return 0;
+    }
+}

+ 29 - 5
service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java

@@ -2,7 +2,9 @@ package com.java110.acct.payment.adapt.wechat;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.integral.IComputeDeductionIntegral;
 import com.java110.acct.integral.IComputeGiftIntegral;
+import com.java110.acct.integral.IDeductionIntegral;
 import com.java110.acct.payment.IPaymentFactoryAdapt;
 import com.java110.core.client.RestTemplate;
 import com.java110.core.context.ICmdDataFlowContext;
@@ -10,6 +12,7 @@ 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.DeductionIntegralDto;
 import com.java110.dto.integral.GiftIntegralDto;
 import com.java110.dto.paymentPool.PaymentPoolDto;
 import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
@@ -97,6 +100,12 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
     @Autowired
     private IComputeGiftIntegral computeGiftIntegralImpl;
 
+    @Autowired
+    private IComputeDeductionIntegral computeDeductionIntegralImpl;
+
+    @Autowired
+    private IDeductionIntegral deductionIntegralImpl;
+
 
     @Override
     public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception {
@@ -104,6 +113,8 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson);
 
         String paymentPoolId = reqJson.getString("paymentPoolId");
+        String useIntegral = reqJson.getString("useIntegral");
+        paymentOrderDto.setUseIntegral(useIntegral);
 
 
         String appId = context.getReqHeaders().get("app-id");
@@ -152,7 +163,6 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
 
         Map<String, String> resMap = null;
         resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
-                paymentOrderDto.getOrderId(),
                 tradeType,
                 payAmount,
                 openId,
@@ -197,7 +207,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
     }
 
 
-    private Map<String, String> java110UnifieldOrder(String feeName, String orderNum,
+    private Map<String, String> java110UnifieldOrder(String feeName,
                                                      String tradeType, double payAmount, String openid,
                                                      SmallWeChatDto smallWeChatDto,
                                                      List<PaymentPoolValueDto> paymentPoolValueDtos,
@@ -217,11 +227,18 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
             paymentOrderDto.setGiftIntegralDto(giftIntegralDto);
         }
 
+        //todo 计算 积分抵扣
+        if ("Y".equals(paymentOrderDto.getUseIntegral())) {
+            DeductionIntegralDto deductionIntegralDto = computeDeductionIntegralImpl.deduction(paymentOrderDto.getUserId(),
+                    paymentOrderDto.getOrderId(),
+                    paymentPoolValueDtos.get(0).getCommunityId());
+            payAmount = payAmount - deductionIntegralDto.getMoney();
+        }
+
         //这里防止 小数点不是 2位 比如 3位之类的 微信平台不支持
         payAmount = MoneyUtil.computePriceScale(payAmount, "1", 2);
 
 
-
         String mchId = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_MCHID");
         String key = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "WECHAT_KEY");
 
@@ -234,7 +251,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         paramMap.put("mch_id", mchId);
         paramMap.put("nonce_str", PayUtil.makeUUID(32));
         paramMap.put("body", feeName);
-        paramMap.put("out_trade_no", orderNum);
+        paramMap.put("out_trade_no", paymentOrderDto.getOrderId());
         paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount));
         paramMap.put("spbill_create_ip", PayUtil.getLocalIp());
         paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
@@ -275,7 +292,7 @@ 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, paymentOrderDto.getOrderId(), feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付", paymentPoolValueDtos.get(0).getPpId());
         return PayUtil.xmlStrToMap(responseEntity.getBody());
     }
 
@@ -380,6 +397,12 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
 
         doUpdateOnlinePay(outTradeNo, OnlinePayDto.STATE_COMPILE, "支付成功");
 
+        //todo 将抵扣积分转给物业
+        deductionIntegralImpl.deduction(paymentOrderDto.getOrderId());
+
+
+
+
         String giftIntegralDtoStr = CommonCache.getAndRemoveValue("integral_share_acct_" + paymentOrderDto.getOrderId());
 
         if (StringUtil.isEmpty(giftIntegralDtoStr)) {
@@ -413,6 +436,7 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
         // todo 给用户赠送积分
         wechatIntegralShareAcct.sendIntegral(giftIntegralDto);
 
+
         return 1;
     }
 

+ 3 - 0
service-acct/src/main/java/com/java110/acct/payment/business/account/PreStoreOnlinePaymentBusiness.java

@@ -102,6 +102,7 @@ public class PreStoreOnlinePaymentBusiness implements IPaymentBusiness {
      */
     @Override
     public PaymentOrderDto unified(ICmdDataFlowContext context, JSONObject reqJson) {
+        String userId = context.getReqHeaders().get("user-id");
 
         //Assert.hasKeyAndValue(reqJson, "spaceId", "请求报文中未包含spaceId");
         Assert.hasKeyAndValue(reqJson, "acctId", "请求报文中未包含acctId");
@@ -118,6 +119,8 @@ public class PreStoreOnlinePaymentBusiness implements IPaymentBusiness {
         paymentOrderDto.setOrderId(GenerateCodeFactory.getOId());
         paymentOrderDto.setMoney(reqJson.getDoubleValue("receivedAmount"));
         paymentOrderDto.setName("账户充值");
+        paymentOrderDto.setUserId(userId);
+        paymentOrderDto.setCycles("1");
 
         reqJson.put("receivableAmount", reqJson.getDoubleValue("receivedAmount"));
         reqJson.put("receivedAmount", reqJson.getDoubleValue("receivedAmount"));

+ 3 - 0
service-acct/src/main/java/com/java110/acct/payment/business/chargeCard/PreStoreChargeCardBusiness.java

@@ -101,6 +101,7 @@ public class PreStoreChargeCardBusiness implements IPaymentBusiness {
      */
     @Override
     public PaymentOrderDto unified(ICmdDataFlowContext context, JSONObject reqJson) {
+        String userId = context.getReqHeaders().get("user-id");
 
         //Assert.hasKeyAndValue(reqJson, "spaceId", "请求报文中未包含spaceId");
         Assert.hasKeyAndValue(reqJson, "cardId", "请求报文中未包含cardId");
@@ -118,6 +119,8 @@ public class PreStoreChargeCardBusiness implements IPaymentBusiness {
         paymentOrderDto.setOrderId(GenerateCodeFactory.getOId());
         paymentOrderDto.setMoney(Double.parseDouble(chargeMonthCardDtos.get(0).getCardPrice()));
         paymentOrderDto.setName("购买充电月卡");
+        paymentOrderDto.setUserId(userId);
+        paymentOrderDto.setCycles("1");
 
         reqJson.put("receivableAmount", paymentOrderDto.getMoney());
         reqJson.put("receivedAmount", paymentOrderDto.getMoney());

+ 3 - 0
service-acct/src/main/java/com/java110/acct/payment/business/meter/PreStoreMeterPaymentBusiness.java

@@ -110,6 +110,7 @@ public class PreStoreMeterPaymentBusiness implements IPaymentBusiness {
         } else {
             typeCdName = "煤气充值";
         }
+        String userId = context.getReqHeaders().get("user-id");
 
         FeeConfigDto feeConfigDto = new FeeConfigDto();
         feeConfigDto.setCommunityId(reqJson.getString("communityId"));
@@ -124,6 +125,8 @@ public class PreStoreMeterPaymentBusiness implements IPaymentBusiness {
         paymentOrderDto.setOrderId(GenerateCodeFactory.getOId());
         paymentOrderDto.setMoney(reqJson.getDoubleValue("receivedAmount"));
         paymentOrderDto.setName(typeCdName);
+        paymentOrderDto.setUserId(userId);
+        paymentOrderDto.setCycles("1");
 
         reqJson.put("receivableAmount", reqJson.getDoubleValue("receivedAmount"));
         reqJson.put("receivedAmount", reqJson.getDoubleValue("receivedAmount"));

+ 3 - 1
service-acct/src/main/java/com/java110/acct/payment/business/monthCard/BuyCarMonthCardPaymentBusiness.java

@@ -135,15 +135,17 @@ public class BuyCarMonthCardPaymentBusiness implements IPaymentBusiness {
 
         String typeCdName = reqJson.getString("carNum") + "购买月卡";
 
+        String userId = context.getReqHeaders().get("user-id");
 
         PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
         paymentOrderDto.setOrderId(GenerateCodeFactory.getOId());
         paymentOrderDto.setMoney(carMonthCardDtos.getJSONObject(0).getDoubleValue("cardPrice"));
         paymentOrderDto.setName(typeCdName);
+        paymentOrderDto.setUserId(userId);
+        paymentOrderDto.setCycles("1");
 
         reqJson.put("receivableAmount", carMonthCardDtos.getJSONObject(0).getString("cardPrice"));
         reqJson.put("receivedAmount", carMonthCardDtos.getJSONObject(0).getString("cardPrice"));
-        String userId = context.getReqHeaders().get("user-id");
 
         reqJson.put("cardMonth", carMonthCardDtos.getJSONObject(0).getString("cardMonth"));
         reqJson.put("carMemberId", ownerCarDtos.get(0).getMemberId());

+ 3 - 0
service-acct/src/main/java/com/java110/acct/payment/business/oweFee/OweFeePaymentBusiness.java

@@ -146,6 +146,9 @@ public class OweFeePaymentBusiness implements IPaymentBusiness {
         paymentOrderDto.setOrderId(orderId);
         paymentOrderDto.setMoney(money);
         paymentOrderDto.setName(feeName + "欠费费用");
+        paymentOrderDto.setUserId(userId);
+        paymentOrderDto.setCycles("1");
+
 
         JSONObject saveFees = new JSONObject();
         saveFees.put("orderId", orderId);