Explorar o código

修改支付逻辑

huangpeifeng %!s(int64=2) %!d(string=hai) anos
pai
achega
e6429755b4

+ 14 - 3
sp-admin/sa-view/tb-deduction-record/tb-deduction-record-list.html

@@ -76,9 +76,9 @@
 					<sa-td type="selection"></sa-td>
 					<sa-td name="主键" prop="id" v-if="false"></sa-td>
 					<sa-td name="业务id" prop="businessId" v-if="false"></sa-td>
-					<sa-td name="客户id" prop="customerId" ></sa-td>
+					<sa-td name="客户id" prop="customerId" v-if="false" ></sa-td>
 					<sa-td name="客户名称" prop="customerName" ></sa-td>
-					<sa-td name="合作伙伴" prop="partner" ></sa-td>
+					<sa-td name="合作伙伴" prop="pickCustomerName" ></sa-td>
 					<sa-td name="业务单号" prop="businessNo" ></sa-td>
 					<sa-td name="车牌号" prop="carNo" ></sa-td>
 					<sa-td name="收费项目" prop="feeType" type="enum"
@@ -96,7 +96,18 @@
 						<span>{{s.row.taxRate * 100}}</span>
 						</template>
 					</sa-td>
-
+					<el-table-column label="税额(元)">
+						<template slot-scope="s">
+							<span>{{Number(s.row.taxPrice).toFixed(2)}}</span>
+						</template>
+					</el-table-column>
+					<el-table-column label="不含税金额(元)">
+						<template slot-scope="s">
+							<span>{{Number(s.row.noTaxPrice).toFixed(2)}}</span>
+						</template>
+					</el-table-column>
+					<sa-td name="生成时间" prop="createTime" width="150px"></sa-td>
+					<sa-td name="付款时间" prop="payTime" width="150px"></sa-td>
 					<el-table-column label="操作" fixed="right"  width="240px">
 						<template slot-scope="s">
 							<el-button class="c-btn" type="primary" icon="el-icon-edit"

+ 2 - 2
sp-admin/sa-view/tb-invoice-order/tb-invoice-order-info.html

@@ -138,8 +138,8 @@
                         this.feeDetails = res.data;
                     }.bind(this))
                 }else {
-                    if(this.m.businessId){
-                        sa.ajax('/TbInvoiceOrder/getDetailsByBusinessId?businessId=' + this.m.businessId, function (res) {
+                    if(this.m.preOrderNum){
+                        sa.ajax('/TbInvoiceOrder/getDetailsByBusinessId?preOrderNum=' + this.m.preOrderNum, function (res) {
                             this.feeDetails = res.data;
                         }.bind(this))
                     }

+ 0 - 2
sp-server/src/main/java/com/pj/api/open/service/OpenService.java

@@ -214,7 +214,6 @@ public class OpenService {
                     if (dif > 0) {
                         RedisUtil.setByMINUTES(channel, carNo, 1);
                         log.error("请求返回:请缴停车费:{},{}元", carNo, dif);
-                        automaticPay.run(null,tbBusinessCar.getCarNo(),1);
                         return ResultJson.error("请缴停车费" + dif + "元");
                     }
                 }
@@ -228,7 +227,6 @@ public class OpenService {
                     if (dif > 0) {
                         RedisUtil.setByMINUTES(channel, carNo, 1);
                         log.error("请求返回:请缴停车费:{},{}元", carNo, dif);
-                        automaticPay.run(null,tbBusinessCar.getCarNo(),1);
                         return ResultJson.error("请缴停车费" + dif + "元");
                     }
                 }

+ 50 - 23
sp-server/src/main/java/com/pj/project/tb_account/AutomaticPay.java

@@ -131,12 +131,13 @@ public class AutomaticPay {
             StaticLog.info("未获取到收费总金额或收费总金额非法,退出收费程序:{}" , businessId);
             return;
         }
-        if(!deductionBindService.checkBind(tbBusiness.getCustomerId(),plate)){
+        if(!deductionBindService.isBindCarByPlate(plate)){
             StaticLog.info("业务车辆未绑定指定客户的预存款账户,退出收费程序:{}{}",businessId,tbBusiness.getCustomerName());
             return;
         }
         List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
-        TbAccount tbAccount = tbAccountService.getByCustomerId(tbBusiness.getCustomerId());
+        TbDeductionBind bind = deductionBindService.getBindCarByPlate(plate);
+        TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
         String key = AesUtil.reverse(tbAccount.getAccSalt());
         String totalMoney = tbAccount.getTotalMoney();
         BigDecimal parkingMoneyBig = new BigDecimal(0);
@@ -150,7 +151,7 @@ public class AutomaticPay {
         }
         if(balance.doubleValue()<0){
             StaticLog.info("支付账户余额不足!,退出收费程序:{}" , businessId);
-            deductionBindService.setFeeFailRecord(tbBusiness.getCustomerId(),plate,
+            deductionBindService.setFeeFailRecord(bind.getCustomerId(),plate,
                     AesUtil.toStr(tbBusiness.getGoodsName())+":因支付账户余额不足,自动缴费失败。。");
             return;
         }
@@ -174,19 +175,20 @@ public class AutomaticPay {
         //更新账户余额
         tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(),key));
         tbAccount.updateById();
-        deductionBindService.setDeductMoney(tbBusiness.getCustomerId(),plate,tbBusiness.getItemPrice());
+        deductionBindService.setDeductMoney(bind.getCustomerId(),plate,tbBusiness.getItemPrice());
         //生成收费明细
         List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.autoChargeBusinessFee(
                 businessItems,null,null,now);
         //生成扣费记录
-        createTbDeductionRecord(tbFeeDetailsList,tbAccount, totalMoneyBig,plate);
+        createTbDeductionRecord(tbFeeDetailsList,tbAccount, totalMoneyBig,plate,bind.getCustomerName(),no);
         //生成开票信息
-        createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate,isOut);
+        createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate,bind.getCustomerId(),no,isOut);
         if(isOut){
-            deductionBindService.setDeductMoney(tbBusiness.getCustomerId(),plate,parkingMoneyBig);
+            deductionBindService.setDeductMoney(bind.getCustomerId(),plate,parkingMoneyBig);
             List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
                     cars,null,null,now);
-            createTbDeductionRecord(parkFeeDetailsList,tbAccount, totalMoneyBig.subtract(tbBusiness.getItemPrice()),plate);
+            createTbDeductionRecord(parkFeeDetailsList,tbAccount,
+                    totalMoneyBig.subtract(tbBusiness.getItemPrice()),plate,bind.getCustomerName(),no);
             deductionBindService.autoUnbindCar(cars);
         }
         StaticLog.info("预充值自动缴费成功!,退出收费程序:{}{}" , businessId,tbAccount.getCustomerId());
@@ -230,41 +232,50 @@ public class AutomaticPay {
             return;
         }
         StaticLog.info("开始自动缴纳停车费:{}" , car.getCarNo());
-        if(car.getPay()==1 || car.getPayTime()!=null){
-            StaticLog.info("该车辆已缴纳过停车费!,退出收费程序:{}" , car.getCarNo());
-            return;
-        }
+//        if(car.getPay()==1 || car.getPayTime()!=null){
+//            StaticLog.info("该车辆已缴纳过停车费!,退出收费程序:{}" , car.getCarNo());
+//            return;
+//        }
         TbAccount account = tbAccountService.getTbAccountByPlate(car.getCarNo());
         if (account==null){
             StaticLog.info("该车辆还未绑定客户预存款账户!,退出收费程序:{}" , car.getCarNo());
             return;
         }
-        BigDecimal totalBig = new BigDecimal("0");
-        String key = null;
-        if(!NumberUtil.isNumber(account.getTotalMoney())){
-            key = AesUtil.reverse(account.getAccSalt());
-            totalBig = new BigDecimal(AesUtil.decryptECB(account.getTotalMoney(),key));
-        }
         BigDecimal parkFeeBig = null;
         if(parkingFee>0){
             parkFeeBig = new BigDecimal(String.valueOf(parkingFee));
         }else {
             parkFeeBig = caulatePrice(car, new Date());
         }
+        if(parkFeeBig==null ||parkFeeBig.doubleValue()<=0){
+            StaticLog.info("该车辆无需缴纳停车费!,退出收费程序:{}" , car.getCarNo());
+            return;
+        }
+        TbDeductionBind bind = deductionBindService.getBindCarByPlate(plate);
+        BigDecimal totalBig = new BigDecimal("0");
+        String key = null;
+        if(!NumberUtil.isNumber(account.getTotalMoney())){
+            key = AesUtil.reverse(account.getAccSalt());
+            totalBig = new BigDecimal(AesUtil.decryptECB(account.getTotalMoney(),key));
+        }
+
         BigDecimal balance = totalBig.subtract(parkFeeBig);
         if(balance.doubleValue()<0){
             StaticLog.info("支付账户余额不足!,退出收费程序:{}" , car.getCarNo());
             return;
         }
+        String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
         car.setMoney(parkFeeBig);
         updateTbBusinessCar(car);
         account.setTotalMoney(AesUtil.encryptECB(balance.toString(),key));
         account.updateById();
+        deductionBindService.setDeductMoney(bind.getCustomerId(),plate,parkFeeBig);
         List<TbBusinessCar> cars = new ArrayList<TbBusinessCar>();
         cars.add(car);
         List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
                 cars,null,null,new Date());
-        createTbDeductionRecord(parkFeeDetailsList,account, totalBig,plate);
+        createTbDeductionRecord(parkFeeDetailsList,account, totalBig,plate,bind.getCustomerName(),no);
+        createTbInvoiceOrderPark(car,account.getCustomerId(),no);
         deductionBindService.autoUnbindCar(cars);
         StaticLog.info("停车费自动缴费成功!,退出收费程序:{}" , car.getCarNo());
     }
@@ -276,11 +287,11 @@ public class AutomaticPay {
      * @param totalMoneyBig
      */
     private void createTbDeductionRecord(List<TbFeeDetails> tbFeeDetailsList,TbAccount tbAccount,
-                                         BigDecimal totalMoneyBig,String plate){
+                                         BigDecimal totalMoneyBig,String plate,String customerName,String no ){
         if(tbFeeDetailsList==null)return;
         int i = 0;
         String tempMoney = null;
-        String bindIdStr = deductionBindService.getBindId(tbAccount.getCustomerId(),plate);
+        String bindIdStr = deductionBindService.getBindId(plate);
         for (TbFeeDetails feeDetails : tbFeeDetailsList){
             TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails,TbDeductionRecord.class);
             String totalStr = null;
@@ -294,15 +305,19 @@ public class AutomaticPay {
             deductionRecord.setId(null);
             deductionRecord.setDeductionBindId(bindIdStr);
             deductionRecord.setCustomerId(tbAccount.getCustomerId());
+            deductionRecord.setCustomerName(customerName);
             deductionRecord.setFeeDetailsId(feeDetails.getId());
             deductionRecord.setOriginalMoney(totalMoneyBig.toString());
             deductionRecord.setDeductMoney(feeDetails.getItemPrice());
             deductionRecord.setTotalMoney(totalStr);
             deductionRecord.setReviewStatus(0);
             deductionRecord.setCarNo(plate);
+            deductionRecord.setPreOrderNum(no);
             deductionRecord.insert();
             feeDetails.setCarNo(plate);
+            feeDetails.setPreOrderNum(no);
             feeDetails.setCustomerId(tbAccount.getCustomerId());
+            feeDetails.setCustomerName(customerName);
             tbFeeDetailsService.updateById(feeDetails);
             i++;
         }
@@ -332,7 +347,7 @@ public class AutomaticPay {
      * @param tbBusiness
      */
     private void createTbInvoiceOrder(TbBusiness tbBusiness,List<TbBusinessCar> cars, BigDecimal parkingFee,
-                                      String plate,boolean isOut){
+                                      String plate, String customerId, String no, boolean isOut){
         TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
         List<String> businessNameList = new ArrayList<>();
         List<String> businessNoList = new ArrayList<>();
@@ -371,7 +386,19 @@ public class AutomaticPay {
         }
         invoiceOrder.setBusinessName(businessNameStr).setBusinessNo(businessNoStr).setCarNo(carNoStr)
                     .setTransactionId(null).setBillMoney(billMoney).setBusinessId(tbBusiness.getId())
-                    .setStatus(0).setCreateTime(new Date()).setCustomerId(tbBusiness.getCustomerId());
+                    .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
+        invoiceOrderService.save(invoiceOrder);
+    }
+
+    /**
+     * 无业务车辆收停车费生成发票信息
+     */
+    private void createTbInvoiceOrderPark(TbBusinessCar car, String customerId,String no){
+        TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
+
+        invoiceOrder.setBusinessName("停车费").setBusinessNo(car.getNo()).setCarNo(car.getCarNo())
+                .setTransactionId(null).setBillMoney(car.getMoney()).setBusinessId(null)
+                .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
         invoiceOrderService.save(invoiceOrder);
     }
 

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_account/TbAccountMapper.xml

@@ -140,7 +140,7 @@
     <select id="getAccountByPlate" resultType="com.pj.project.tb_account.TbAccount">
         select a.* from tb_deduction_bind b left join tb_account a on a.customer_id=b.customer_id
         <where>
-            and a.status=1 and b.update_time is null
+            and a.status=1 and b.unbind_time is null
             and b.bind_car = #{plate} 
         </where>
     </select>

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_business_item/PayTask.java

@@ -310,7 +310,7 @@ public class PayTask extends Task {
         for (TbFeeDetails feeDetails : tbFeeDetailsList){
             TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails,TbDeductionRecord.class);
             if(TbGoods.DeductionTypeEnum.BUSINESS_OK.getCode()==tbBusiness.getAutoDeductionType()){
-                String bindIdStr = deductionBindService.getBindId(tbAccount.getCustomerId(),plate);
+                String bindIdStr = deductionBindService.getBindId(plate);
                 deductionRecord.setDeductionBindId(bindIdStr);
             }
             String totalStr = null;

+ 17 - 10
sp-server/src/main/java/com/pj/project/tb_deduction_bind/TbDeductionBindService.java

@@ -124,15 +124,13 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
 
     /**
      * 根据条件解绑
-     * @param customerId
      * @param plate
      * @return
      */
-    public boolean autoUnbindCar(String customerId,String plate){
-        if(NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
+    public boolean autoUnbindCar(String plate){
+        if(NbUtil.isNull(plate)) return false;
 
         TbDeductionBind bind = tbDeductionBindMapper.selectOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                        true,TbDeductionBind::getCustomerId,customerId).eq(
                         true,TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
         if(bind==null)return false;
         bind.setUpdateBy("预充值自动缴费解绑");
@@ -148,7 +146,7 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
     public void autoUnbindCar(List<TbBusinessCar> cars){
         if(cars==null) return;
         for (TbBusinessCar car:cars){
-            this.autoUnbindCar(car.getCustomerId(),car.getCarNo());
+            this.autoUnbindCar(car.getCarNo());
         }
     }
     /**
@@ -211,6 +209,17 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
     }
 
     /**
+     *  根据车牌号获取车辆绑定对象
+     * @param plate
+     * @return
+     */
+    public TbDeductionBind getBindCarByPlate(String plate){
+        if(NbUtil.isNull(plate)) return null;
+        return tbDeductionBindMapper.selectOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
+                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
+    }
+
+    /**
      * 判断是否已解绑
      * @param id
      * @return
@@ -222,16 +231,14 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
     }
 
     /**
-     * 根据客户Id和车牌,获取已绑定成功的主键Id
-     * @param customerId
+     * 根据车牌,获取已绑定成功的主键Id
      * @param plate
      * @return
      */
-    public String getBindId(String customerId,String plate){
-        if(NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return null;
+    public String getBindId(String plate){
+        if(NbUtil.isNull(plate)) return null;
         Map idMap =  this.getMap(new LambdaQueryWrapper<TbDeductionBind>().select(
                 TbDeductionBind::getId).eq(
-                TbDeductionBind::getCustomerId,customerId).eq(
                 TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
         return ObjectUtil.isNotEmpty(idMap)? AesUtil.toStr(idMap.get("id")):null;
     }

+ 5 - 0
sp-server/src/main/java/com/pj/project/tb_deduction_record/TbDeductionRecord.java

@@ -248,4 +248,9 @@ public class TbDeductionRecord extends Model<TbDeductionRecord> implements Seria
      * 绑定表Id
      */
     public String deductionBindId;
+
+    /**
+     * 预存款自动收费订单号
+     */
+    private String preOrderNum;
 }

+ 4 - 0
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetails.java

@@ -214,6 +214,10 @@ public class TbFeeDetails implements Serializable {
      * tbDeductionBindId
      */
     public String deductionBindId;
+    /**
+     * 预存款自动收费订单号
+     */
+    private String preOrderNum;
 
     @Getter
     @AllArgsConstructor

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsService.java

@@ -936,7 +936,7 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         for (TbBusinessCar car : cars) {
 
             //TbBusinessCar car = bo1;
-            String bindIdStr = tbDeductionBindService.getBindId(car.getCustomerId(),car.getCarNo());
+            String bindIdStr = tbDeductionBindService.getBindId(car.getCarNo());
             //thisCarAllFeeList是当前放行记录的车辆的所有日期的白天停车和夜间停车明细
             List<TbFeeDetails> thisCarAllFeeList = getByBusinessCarIdAndCarNoAndFeeType(car.getId(), car.getCarNo(), TbFeeDetails.fee.PARK_FEE.getCode());
             //不是当前日期,当前放行记录的车辆在之前的日期付的钱

+ 4 - 0
sp-server/src/main/java/com/pj/project/tb_invoice_order/TbInvoiceOrder.java

@@ -105,5 +105,9 @@ public class TbInvoiceOrder implements Serializable {
      */
     public String infoNo;
 
+    /**
+     * 预存款自动收费订单号
+     */
+    private String preOrderNum;
 
 }

+ 2 - 2
sp-server/src/main/java/com/pj/project/tb_invoice_order/TbInvoiceOrderController.java

@@ -108,8 +108,8 @@ public class TbInvoiceOrderController {
     }
 
     @RequestMapping("getDetailsByBusinessId")
-    public AjaxJson getDetailsByBusinessId(String businessId) {
-        List<TbFeeDetails> details = tbInvoiceOrderService.getDetailsByBusinessId(businessId);
+    public AjaxJson getDetailsByBusinessId(String preOrderNum) {
+        List<TbFeeDetails> details = tbInvoiceOrderService.getDetailsByBusinessId(preOrderNum);
         return AjaxJson.getSuccessData(details);
     }
 

+ 5 - 3
sp-server/src/main/java/com/pj/project/tb_invoice_order/TbInvoiceOrderMapper.xml

@@ -5,9 +5,9 @@
     <!-- 增 [G] -->
     <insert id="add">
         insert into tb_invoice_order (id, customer_id, business_id, business_name, business_no, car_no, transaction_id,
-                                      bill_money, bill_image, status, invoice_time, create_time, info_id, info_no)
+                                      bill_money, bill_image, status, invoice_time, create_time, info_id, info_no,pre_order_num)
         values (#{id}, #{customerId}, #{businessId}, #{businessName}, #{businessNo}, #{carNo}, #{transactionId},
-                #{billMoney}, #{billImage}, #{status}, #{invoiceTime}, #{createTime}, #{infoId}, #{infoNo})
+                #{billMoney}, #{billImage}, #{status}, #{invoiceTime}, #{createTime}, #{infoId}, #{infoNo},#{preOrderNum})
     </insert>
 
     <!-- 删 -->
@@ -32,7 +32,8 @@
             invoice_time   = #{invoiceTime},
             create_time    = #{createTime},
             info_id        = #{infoId},
-            info_no        = #{infoNo}
+            info_no        = #{infoNo},
+            pre_order_num   = #{preOrderNum}
         where id = #{id}
     </update>
 
@@ -56,6 +57,7 @@
         <result property="createTime" column="create_time"/>
         <result property="infoId" column="info_id"/>
         <result property="infoNo" column="info_no"/>
+        <result property="preOrderNum" column="pre_order_num"/>
     </resultMap>
 
     <!-- 公共查询sql片段 -->

+ 3 - 3
sp-server/src/main/java/com/pj/project/tb_invoice_order/TbInvoiceOrderService.java

@@ -310,10 +310,10 @@ public class TbInvoiceOrderService extends ServiceImpl<TbInvoiceOrderMapper, TbI
         return detailsList;
     }
 
-    public List<TbFeeDetails> getDetailsByBusinessId(String businessId) {
-        if(NbUtil.isNullStr(businessId))return null;
+    public List<TbFeeDetails> getDetailsByBusinessId(String preOrderNum) {
+        if(NbUtil.isNullStr(preOrderNum))return null;
         List<TbFeeDetails> detailsList = tbFeeDetailsService.list(new LambdaQueryWrapper<TbFeeDetails>()
-                .eq(TbFeeDetails::getBusinessId,businessId));
+                .eq(TbFeeDetails::getPreOrderNum,preOrderNum));
         return detailsList;
     }
 }

+ 2 - 0
sp-server/src/main/java/com/pj/utils/AesUtil.java

@@ -19,6 +19,8 @@ public class AesUtil {
     private static final String KEY = "h!f78tr#L3D$2Z0q";
     private static final String PADDING = "PKCS7Padding";
 
+    { AES oneAes = new AES(Mode.ECB.name(), PADDING, KEY.getBytes(StandardCharsets.UTF_8));}
+
     /**
      * AES加密,ECB模式
      * @param content 待加密内容