Browse Source

新增退款功能

fulonglong 3 năm trước cách đây
mục cha
commit
a7065a319c

+ 2 - 0
src/main/java/com/charging/chargingparking/constant/ParkingConstant.java

@@ -16,4 +16,6 @@ public class ParkingConstant {
     public static final String INMESSAGE = "欢迎光临";
 
     public static final String NEEDPAY = "请付款";
+
+    public static final String COMMON = "减速慢行 自动识别 礼让行人 请勿跟车";
 }

+ 19 - 7
src/main/java/com/charging/chargingparking/modules/pay/alipay/AlipayController.java

@@ -18,13 +18,12 @@ import com.charging.chargingparking.dto.MessageResult;
 import com.charging.chargingparking.dto.ParkingCostDTO;
 import com.charging.chargingparking.dto.UserInfo;
 import com.charging.chargingparking.entity.ParkingInfo;
+import com.charging.chargingparking.entity.ParkingMerchant;
 import com.charging.chargingparking.entity.ParkingPay;
 import com.charging.chargingparking.entity.ParkingRecord;
 import com.charging.chargingparking.modules.pay.properties.AliPayProperties;
 import com.charging.chargingparking.modules.pay.properties.WxPayProperties;
-import com.charging.chargingparking.service.ParkingFeeService;
-import com.charging.chargingparking.service.ParkingPayService;
-import com.charging.chargingparking.service.ParkingRecordService;
+import com.charging.chargingparking.service.*;
 import com.charging.chargingparking.utils.StringUtils;
 import com.ijpay.alipay.AliPayApi;
 import lombok.extern.slf4j.Slf4j;
@@ -54,6 +53,12 @@ public class AlipayController {
     @Autowired
     private ParkingRecordService parkingRecordService;
 
+    @Autowired
+    private ParkingInfoService parkingInfoService;
+
+    @Autowired
+    private ParkingMerchantService parkingMerchantService;
+
     @Autowired
     private ParkingFeeService parkingFeeService;
 
@@ -148,7 +153,15 @@ public class AlipayController {
 
             ParkingRecord parkingRecord = parkingRecordService.getById(id);
             if (parkingRecord == null) {
-                throw new Exception("订单不存在");
+                throw new Exception("停车场记录不存在");
+            }
+
+            //停车场
+            ParkingInfo parkingInfo = parkingInfoService.getById(parkingRecord.getParkId());
+            //商户
+            ParkingMerchant parkingMerchant = parkingMerchantService.getById(parkingInfo.getMerchantId());
+            if (parkingMerchant == null || StrUtil.isBlank(parkingMerchant.getAppAuthToken())){
+                throw new Exception("商户信息错误");
             }
 
 
@@ -187,7 +200,7 @@ public class AlipayController {
 
             extendParams.put("sys_service_provider_id", aliPayProperties.getMchId());
             maps.put("extend_params", extendParams);
-            request.putOtherTextParam("app_auth_token", aliPayProperties.getAppAuthToken());
+            request.putOtherTextParam("app_auth_token", parkingMerchant.getAppAuthToken());
             //把订单信息转换为json对象的字符串
             String postdata = JSONObject.toJSONString(maps);
             request.setBizContent(postdata);
@@ -200,8 +213,7 @@ public class AlipayController {
                 result.setData(resultMap);
                 result.setResult(true);
             } else {
-                result.setResult(false);
-                result.setData("");
+                throw new Exception(response.getSubMsg());
             }
         } catch (Exception e) {
             e.printStackTrace();

+ 22 - 7
src/main/java/com/charging/chargingparking/modules/pay/wechat/WxPayController.java

@@ -9,6 +9,7 @@ import com.charging.chargingparking.dto.AccessToken;
 import com.charging.chargingparking.dto.MessageResult;
 import com.charging.chargingparking.dto.ParkingCostDTO;
 import com.charging.chargingparking.dto.UserInfo;
+import com.charging.chargingparking.entity.ParkingInfo;
 import com.charging.chargingparking.entity.ParkingMerchant;
 import com.charging.chargingparking.entity.ParkingPay;
 import com.charging.chargingparking.entity.ParkingRecord;
@@ -57,6 +58,9 @@ public class WxPayController {
     @Autowired
     private WxPayProperties wxPayProperties;
 
+    @Autowired
+    private ParkingInfoService parkingInfoService;
+
     @Autowired
     private ParkingPayService parkingPayService;
 
@@ -91,6 +95,14 @@ public class WxPayController {
                 throw new Exception("记录不存在");
             }
 
+            //停车场
+            ParkingInfo parkingInfo = parkingInfoService.getById(parkingRecord.getParkId());
+            //商户
+            ParkingMerchant parkingMerchant = parkingMerchantService.getById(parkingInfo.getMerchantId());
+            if (parkingMerchant == null || StrUtil.isBlank(parkingMerchant.getSubMchId())){
+                throw new Exception("商户信息错误");
+            }
+
 
             //记录总应缴
             ParkingCostDTO parkingCostDTO = parkingFeeService.parkingCost(parkingRecord);
@@ -104,6 +116,8 @@ public class WxPayController {
                 throw new Exception("请直接离场");
             }
 
+
+
             //金额处理
             int wxTotalTee = parkCost.subtract(parkingRecord.getPayAmount()).multiply(new BigDecimal(100)).intValue();
 
@@ -116,7 +130,7 @@ public class WxPayController {
             parkingPay.setCodePayType(codePayType);
             parkingPayService.save(parkingPay);
 
-            ProfitVo profitVo = parkingPayProfitService.getProfitVo(parkingPay);
+            ProfitVo profitVo = parkingPayProfitService.getProfitVo(parkingPay,parkCost.subtract(parkingRecord.getPayAmount()));
             String profitSharing = "N";
             if (profitVo.getProfitFlag()){
                 parkingPay.setProfitNeedFlag(true);
@@ -130,7 +144,7 @@ public class WxPayController {
                     //       .appid(companyPaymentInfo.getSubAppId())
                     //      .mch_id(companyPaymentInfo.getSubMchId())
                     .mch_id(wxPayProperties.getMchId())
-                    .sub_mch_id(wxPayProperties.getSubMchId())
+                    .sub_mch_id(profitVo.getSubMchId())
                     //      .sub_appid(companyPaymentInfo.getSubAppId())
                     .nonce_str(WxPayKit.generateStr())
                     .body(parkingRecord.getProductTheme())
@@ -342,7 +356,7 @@ public class WxPayController {
                     .out_refund_no(WxPayKit.generateStr())
                     .total_fee(totalFee)
                     .refund_fee(totalFee)
-                    .notify_url(wxPayProperties.getRefundUrl())
+              //      .notify_url(wxPayProperties.getRefundUrl())
                     .build()
                     .createSign(wxPayProperties.getMchKey(), SignType.HMACSHA256);
             String result = WxPayApi.orderRefund(false, params, wxPayProperties.getCertPath(), wxPayProperties.getMchId());
@@ -369,13 +383,14 @@ public class WxPayController {
 
     @RequestMapping(value = "/wxJsapiRefundNotify", method = {RequestMethod.POST, RequestMethod.GET})
     @ResponseBody
-    public MessageResult wxJsapiRefundNotify(HttpServletRequest request){
-        MessageResult msgResult = new MessageResult<>();
+    public String wxJsapiRefundNotify(HttpServletRequest request){
 
         String xmlMsg = HttpKit.readData(request);
         log.warn("微信退款回调:"+xmlMsg);
-
-        return msgResult;
+        Map<String,String> resultMap = new HashMap<>();
+        resultMap.put("code","SUCCESS");
+        resultMap.put("message","成功");
+        return WxPayKit.toXml(resultMap);
     }
 
 

+ 2 - 0
src/main/java/com/charging/chargingparking/modules/vo/ProfitVo.java

@@ -14,6 +14,8 @@ public class ProfitVo {
     //分账出资账户
     private String subMchId;
 
+    private String appAuthToken;
+
     //出资商户
     private String merchantName;
 

+ 3 - 1
src/main/java/com/charging/chargingparking/service/ParkingPayProfitService.java

@@ -5,12 +5,14 @@ import com.charging.chargingparking.entity.ParkingPayProfit;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.charging.chargingparking.modules.vo.ProfitVo;
 
+import java.math.BigDecimal;
+
 /**
  *
  */
 public interface ParkingPayProfitService extends IService<ParkingPayProfit> {
 
-    ProfitVo getProfitVo(ParkingPay parkingPay);
+    ProfitVo getProfitVo(ParkingPay parkingPay, BigDecimal amount);
 
     void profitPay(ParkingPay parkingPay);
 }

+ 5 - 0
src/main/java/com/charging/chargingparking/service/impl/ParkingChannelServiceImpl.java

@@ -143,6 +143,11 @@ public class ParkingChannelServiceImpl extends ServiceImpl<ParkingChannelMapper,
             log.warn(StrUtil.format("通道:{},轮训发送数据:{}", parkingChannel.getChannelName(), JSONObject.parseObject(JSONObject.toJSONString(map))));
         }
 
+        //屏幕常显示内容
+        if (responseAlarmInfoPlate.getSerialData().size() == 0) {
+            responseAlarmInfoPlate.setSerialData(stringUtils.getSerialData(ParkingConstant.COMMON, null, null,true,false));
+        }
+
         return map;
     }
 }

+ 1 - 1
src/main/java/com/charging/chargingparking/service/impl/ParkingMemberServiceImpl.java

@@ -147,7 +147,7 @@ public class ParkingMemberServiceImpl extends ServiceImpl<ParkingMemberMapper, P
             if (StrUtil.isNotBlank(addParkingMember.getId())){
                 ParkingMember parkingMember = getById(addParkingMember.getId());
                 if (parkingMember == null){
-                    throw new Exception("记录不存");
+                    throw new Exception("记录不存");
                 }
                 parkingMember.setMemberStartTime(addParkingMember.getMemberStartTime());
                 parkingMember.setMemberEndTime(addParkingMember.getMemberEndTime());

+ 13 - 9
src/main/java/com/charging/chargingparking/service/impl/ParkingPayProfitServiceImpl.java

@@ -50,28 +50,32 @@ public class ParkingPayProfitServiceImpl extends ServiceImpl<ParkingPayProfitMap
     private ParkingMerchantService parkingMerchantService;
 
     @Override
-    public ProfitVo getProfitVo(ParkingPay parkingPay) {
+    public ProfitVo getProfitVo(ParkingPay parkingPay,BigDecimal amount) {
 
         ProfitVo profitVo = new ProfitVo();
         profitVo.setProfitFlag(false);
+        ParkingRecord parkingRecord = parkingRecordService.getById(parkingPay.getParkingRecordId());
+        //停车场
+        ParkingInfo parkingInfo = parkingInfoService.getById(parkingRecord.getParkId());
+        //商户
+        ParkingMerchant parkingMerchant = parkingMerchantService.getById(parkingInfo.getMerchantId());
 
+
+        profitVo.setSubMchId(parkingMerchant.getSubMchId());
+        profitVo.setAppAuthToken(parkingMerchant.getAppAuthToken());
         try {
-            ParkingRecord parkingRecord = parkingRecordService.getById(parkingPay.getParkingRecordId());
-            //停车场
-            ParkingInfo parkingInfo = parkingInfoService.getById(parkingRecord.getParkId());
-            //商户
-            ParkingMerchant parkingMerchant = parkingMerchantService.getById(parkingInfo.getMerchantId());
+
             if (parkingMerchant.getProfitFlag()) {
 
                 //待分账金额
-                BigDecimal waitProfitAmount = parkingPay.getPayAmount().multiply(parkingMerchant.getProfitScale()).setScale(2, RoundingMode.DOWN);
+                BigDecimal waitProfitAmount = amount.multiply(parkingMerchant.getProfitScale()).setScale(2, RoundingMode.DOWN);
 
                 //分账金额大于0才有分账意义
                 if (waitProfitAmount.compareTo(BigDecimal.ZERO) > 0) {
                     profitVo.setProfitFlag(true);
                     profitVo.setProfitScale(parkingMerchant.getProfitScale());
                     if (parkingPay.getPayStatus() == 20) {
-                        profitVo.setSubMchId(parkingMerchant.getSubMchId());
+
                         profitVo.setProfitAmount(waitProfitAmount);
                         profitVo.setTransactionId(parkingPay.getTransactionNo());
                         profitVo.setOutOrderNo(parkingPay.getOutOrderNo());
@@ -94,7 +98,7 @@ public class ParkingPayProfitServiceImpl extends ServiceImpl<ParkingPayProfitMap
         try {
 
             if (parkingPay.getProfitNeedFlag()) {
-                ProfitVo profitVo = getProfitVo(parkingPay);
+                ProfitVo profitVo = getProfitVo(parkingPay,parkingPay.getPayAmount());
                 List<ReceiverModel> list = new ArrayList<>();
 
                 //测试使用个人用户分账

+ 5 - 2
src/main/java/com/charging/chargingparking/service/impl/ParkingPayServiceImpl.java

@@ -64,8 +64,11 @@ public class ParkingPayServiceImpl extends ServiceImpl<ParkingPayMapper, Parking
         parkingRecord.setPayAmount(parkingRecord.getPayAmount().add(buyerPayAmount));
         parkingRecordService.updateById(parkingRecord);
 
-        //分账
-        parkingPayProfitService.profitPay(parkingPay);
+        //微信分账
+        if ("wechat".equals(parkingPay.getPayName())){
+            parkingPayProfitService.profitPay(parkingPay);
+        }
+
 
 
     }

+ 1 - 1
src/main/resources/application-production.yml

@@ -44,7 +44,7 @@ wx:
     notifyUrl: https://51team.xiaoxinda.com/charging-parking/wxPay/parkingWxPayNotify
     refundUrl: https://51team.xiaoxinda.com/charging-parking/wxPay/wxJsapiRefundNotify
     ip: 47.92.161.104
-    certPath: /opt/app/cert/xiaoxinda/apiclient_cert.p12
+    certPath: /opt/parking/cert/xiaoxinda/apiclient_cert.p12
     temporaryUrl: https://charging.xiaoxinda.com/charging-station-server/wxPay/wxJsapiPayTemporaryNotify
     urlKey: F3