1098226878@qq.com %!s(int64=4) %!d(string=hai) anos
pai
achega
68d032d3c5

+ 40 - 12
service-api/src/main/java/com/java110/api/smo/payment/impl/ToPayTempCarFeeSMOImpl.java

@@ -16,6 +16,7 @@ import com.java110.intf.user.IOwnerCarOpenUserV1InnerServiceSMO;
 import com.java110.po.ownerCarOpenUser.OwnerCarOpenUserPo;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.WechatConstant;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.util.Assert;
@@ -31,7 +32,10 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
+import java.util.Date;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 @Service("toPayTempCarFeeSMOImpl")
 public class ToPayTempCarFeeSMOImpl extends AppAbstractComponentSMO implements IToPayTempCarFeeSMO {
@@ -98,8 +102,25 @@ public class ToPayTempCarFeeSMOImpl extends AppAbstractComponentSMO implements I
         }
         JSONObject fee = orderInfo.getJSONObject("data");
 
-        double money = fee.getDouble("payCharge");
-        String orderId = GenerateCodeFactory.getOId();
+        double money = fee.getDouble("receivedAmount");
+
+        String orderId = fee.getString("oId");
+        //需要判断金额是否 == 0 等于0 直接掉缴费通知接口
+        if (money <= 0) {
+            JSONObject paramOut = new JSONObject();
+            paramOut.put("oId", orderId);
+            String urlOut = "tempCarFee.notifyTempCarFeeOrder";
+            responseEntity = this.callCenterService(getHeaders("-1", pd.getAppId()), paramOut.toJSONString(), urlOut, HttpMethod.POST);
+            JSONObject param = new JSONObject();
+            if (responseEntity.getStatusCode() != HttpStatus.OK) {
+                param.put("code", "101");
+                param.put("msg", "扣费为0回调失败");
+                return new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK);
+            }
+            param.put("code", "100");
+            param.put("msg", "扣费为0回调成功");
+            return new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK);
+        }
         String openId = paramIn.getString("openId");
         String payAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_ADAPT);
         payAdapt = StringUtil.isEmpty(payAdapt) ? DEFAULT_PAY_ADAPT : payAdapt;
@@ -111,15 +132,14 @@ public class ToPayTempCarFeeSMOImpl extends AppAbstractComponentSMO implements I
         if (!"0".equals(result.get("code"))) {
             return responseEntity;
         }
-        JSONObject saveFees = new JSONObject();
-        saveFees.put("orderId", paramIn.getString("inoutId"));
-        saveFees.put("carNum", paramIn.getString("carNum"));
-        saveFees.put("amount", money);
-        saveFees.put("paId", paramIn.getString("paId"));
-        saveFees.put("payTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
-        saveFees.put("payType", "2");
-        CommonCache.setValue(FeeDto.REDIS_PAY_TEMP_CAR_FEE + orderId, saveFees.toJSONString(), CommonCache.PAY_DEFAULT_EXPIRE_TIME);
-
+//        JSONObject saveFees = new JSONObject();
+//        saveFees.put("orderId", paramIn.getString("inoutId"));
+//        saveFees.put("carNum", paramIn.getString("carNum"));
+//        saveFees.put("amount", money);
+//        saveFees.put("paId", paramIn.getString("paId"));
+//        saveFees.put("payTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+//        saveFees.put("payType", "2");
+//        CommonCache.setValue(FeeDto.REDIS_PAY_TEMP_CAR_FEE + orderId, saveFees.toJSONString(), CommonCache.PAY_DEFAULT_EXPIRE_TIME);
         //记录openId 和车辆关系 以免每次 输入 车牌号麻烦
         OwnerCarOpenUserPo ownerCarOpenUserPo = new OwnerCarOpenUserPo();
         ownerCarOpenUserPo.setCarNum(paramIn.getString("carNum"));
@@ -132,7 +152,15 @@ public class ToPayTempCarFeeSMOImpl extends AppAbstractComponentSMO implements I
         return responseEntity;
     }
 
-
+    private Map<String, String> getHeaders(String userId,String APP_ID) {
+        Map<String, String> headers = new HashMap<>();
+        headers.put(CommonConstant.HTTP_APP_ID.toLowerCase(), APP_ID);
+        headers.put(CommonConstant.HTTP_USER_ID.toLowerCase(), userId);
+        headers.put(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), UUID.randomUUID().toString());
+        headers.put(CommonConstant.HTTP_REQ_TIME.toLowerCase(), DateUtil.getDefaultFormateTimeString(new Date()));
+        headers.put(CommonConstant.HTTP_SIGN.toLowerCase(), "");
+        return headers;
+    }
     private SmallWeChatDto getSmallWechat(IPageData pd, JSONObject paramIn) {
 
         ResponseEntity responseEntity = null;

+ 75 - 3
service-fee/src/main/java/com/java110/fee/cmd/tempCarFee/GetTempCarFeeOrderCmd.java

@@ -1,17 +1,29 @@
 package com.java110.fee.cmd.tempCarFee;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.AbstractServiceCmdListener;
 import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.couponUser.CouponUserDto;
 import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
 import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
+import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.utils.cache.CommonCache;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * 类表述:删除
  * 服务编码:feePrintPage.deleteFeePrintPage
@@ -24,9 +36,11 @@ import org.springframework.http.ResponseEntity;
  */
 @Java110Cmd(serviceCode = "tempCarFee.getTempCarFeeOrder")
 public class GetTempCarFeeOrderCmd extends AbstractServiceCmdListener {
-
+    @Autowired
+    private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
     @Autowired
     private IGetTempCarFeeRules getTempCarFeeRulesImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
 
@@ -40,7 +54,65 @@ public class GetTempCarFeeOrderCmd extends AbstractServiceCmdListener {
         TempCarPayOrderDto tempCarPayOrderDto = new TempCarPayOrderDto();
         tempCarPayOrderDto.setPaId(reqJson.getString("paId"));
         tempCarPayOrderDto.setCarNum(reqJson.getString("carNum"));
-       ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.getTempCarFeeOrder(tempCarPayOrderDto);
-       cmdDataFlowContext.setResponseEntity(responseEntity);
+        ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.getTempCarFeeOrder(tempCarPayOrderDto);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            cmdDataFlowContext.setResponseEntity(responseEntity);
+            return;
+        }
+        JSONObject orderInfo = JSONObject.parseObject(responseEntity.getBody().toString());
+        if (orderInfo.getIntValue("code") != 0) {
+            cmdDataFlowContext.setResponseEntity(responseEntity);
+            return;
+        }
+
+        JSONObject fee = orderInfo.getJSONObject("data");
+        //double money = fee.getDouble("payCharge");
+        BigDecimal money = new BigDecimal(fee.getDouble("payCharge"));
+        //3.0 考虑优惠卷
+        double couponPrice = checkCouponUser(reqJson);
+        money = money.subtract(new BigDecimal(couponPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+
+        double receivedAmount = money.doubleValue();
+        //所有 优惠折扣计算完后,如果总金额小于等于0,则返回总扣款为0
+        if (receivedAmount <= 0) {
+            receivedAmount = 0.0;
+        }
+        fee.put("receivedAmount", receivedAmount);
+        fee.put("oId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oId));
+        fee.putAll(reqJson);
+        CommonCache.setValue("getTempCarFeeOrder" + fee.getString("oId"), fee.toJSONString(), 24 * 60 * 60);
+        cmdDataFlowContext.setResponseEntity(responseEntity);
+    }
+
+    private double checkCouponUser(JSONObject paramObj) {
+        JSONArray couponList = paramObj.getJSONArray("couponList");
+        BigDecimal couponPrice = new BigDecimal(0.0);
+        List<String> couponIds = new ArrayList<String>();
+
+        if (couponList == null || couponList.size() < 1) {
+            paramObj.put("couponPrice", couponPrice.doubleValue());
+            paramObj.put("couponUserDtos", new JSONArray()); //这里考虑空
+            return couponPrice.doubleValue();
+        }
+        for (int couponIndex = 0; couponIndex < couponList.size(); couponIndex++) {
+            couponIds.add(couponList.getJSONObject(couponIndex).getString("couponId"));
+        }
+        CouponUserDto couponUserDto = new CouponUserDto();
+        couponUserDto.setCouponIds(couponIds.toArray(new String[couponIds.size()]));
+        List<CouponUserDto> couponUserDtos = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
+        if (couponUserDtos == null || couponUserDtos.size() < 1) {
+            paramObj.put("couponPrice", couponPrice.doubleValue());
+            return couponPrice.doubleValue();
+        }
+        for (CouponUserDto couponUser : couponUserDtos) {
+            //不计算已过期购物券金额
+            if (couponUser.getEndTime().compareTo(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B)) >= 0) {
+                couponPrice = couponPrice.add(new BigDecimal(Double.parseDouble(couponUser.getActualPrice())));
+            }
+        }
+        paramObj.put("couponPrice", couponPrice.doubleValue());
+        paramObj.put("couponUserDtos", BeanConvertUtil.beanCovertJSONArray(couponUserDtos));
+        return couponPrice.doubleValue();
     }
 }

+ 61 - 1
service-fee/src/main/java/com/java110/fee/cmd/tempCarFee/NotifyTempCarFeeOrderCmd.java

@@ -1,17 +1,27 @@
 package com.java110.fee.cmd.tempCarFee;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.AbstractServiceCmdListener;
 import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.couponUser.CouponUserDto;
 import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
 import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
+import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
+import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.po.couponUser.CouponUserPo;
+import com.java110.po.couponUserDetail.CouponUserDetailPo;
+import com.java110.utils.cache.CommonCache;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.BeanConvertUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 
+import java.util.List;
+
 /**
  * 类表述:通知
  * 服务编码:tempCarFee.notifyTempCarFeeOrder
@@ -27,7 +37,10 @@ public class NotifyTempCarFeeOrderCmd extends AbstractServiceCmdListener {
 
     @Autowired
     private IGetTempCarFeeRules getTempCarFeeRulesImpl;
-
+    @Autowired
+    private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
+    @Autowired
+    private ICouponUserDetailV1InnerServiceSMO couponUserDetailV1InnerServiceSMOImpl;
     //{"amount":20.0,"payType":"2","orderId":"19c4321c-b5d5-405f-b2ff-20e86a2e7f3e",
     // "payTime":"2021-10-17 17:29:54","paId":"102021101160020175","carNum":"青A88888","oId":"102021101724760012"}
     @Override
@@ -37,8 +50,55 @@ public class NotifyTempCarFeeOrderCmd extends AbstractServiceCmdListener {
 
     @Override
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
+        String paramIn = CommonCache.getAndRemoveValue("getTempCarFeeOrder" + reqJson.getString("oId"));
+        JSONObject paramObj = JSONObject.parseObject(paramIn);
+        System.out.println("获取到内存中的数据了++++++++++++==》"+paramObj.toJSONString());
+        modifyCouponUser(paramObj);
         TempCarPayOrderDto tempCarPayOrderDto = BeanConvertUtil.covertBean(reqJson, TempCarPayOrderDto.class);
         ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.notifyTempCarFeeOrder(tempCarPayOrderDto);
         cmdDataFlowContext.setResponseEntity(responseEntity);
     }
+
+    private void modifyCouponUser(JSONObject paramObj) {
+        if (!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice") <= 0) {
+            return;
+        }
+        //FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
+        CouponUserDto couponUserDto = null;
+        JSONArray couponUserDtos = paramObj.getJSONArray("couponUserDtos");
+        CouponUserDto couponUser = null;
+        for (int accountIndex = 0; accountIndex < couponUserDtos.size(); accountIndex++) {
+            couponUser = BeanConvertUtil.covertBean(couponUserDtos.getJSONObject(accountIndex), CouponUserDto.class);
+            couponUserDto = new CouponUserDto();
+            couponUserDto.setCouponId(couponUser.getCouponId());
+            couponUserDto.setState(CouponUserDto.COUPON_STATE_RUN);
+            List<CouponUserDto> couponUserDtos1 = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
+            if (couponUserDtos1 == null || couponUserDtos1.size() < 1) {
+                throw new CmdException("优惠券被使用");
+            }
+            CouponUserPo couponUserPo = new CouponUserPo();
+            couponUserPo.setState(CouponUserDto.COUPON_STATE_STOP);
+            couponUserPo.setCouponId(couponUser.getCouponId());
+            int fage = couponUserV1InnerServiceSMOImpl.updateCouponUser(couponUserPo);
+            if (fage < 1) {
+                throw new CmdException("更新优惠卷信息失败");
+            }
+            CouponUserDetailPo couponUserDetailPo = new CouponUserDetailPo();
+            couponUserDetailPo.setUoId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_usId));
+            couponUserDetailPo.setCouponId(couponUser.getCouponId());
+            couponUserDetailPo.setUserId(couponUser.getUserId());
+            couponUserDetailPo.setCouponName(couponUser.getCouponName());
+            couponUserDetailPo.setUserName(couponUser.getUserName());
+            couponUserDetailPo.setObjId(paramObj.getString("feeId"));
+            couponUserDetailPo.setObjType(paramObj.getString("feeTypeCd"));
+            couponUserDetailPo.setOrderId(paramObj.getString("oId"));
+            fage = couponUserDetailV1InnerServiceSMOImpl.saveCouponUserDetail(couponUserDetailPo);
+            if (fage < 1) {
+                throw new CmdException("新增优惠卷使用记录信息失败");
+            }
+        }
+
+        paramObj.put("remark", paramObj.getString("remark") + "-优惠劵抵扣" + paramObj.getDouble("couponPrice") + "元");
+
+    }
 }