浏览代码

费用明细区分白天和夜间停车费

lzm 3 年之前
父节点
当前提交
300b343f88

+ 25 - 1
sp-admin/sa-view/tb-fee-statistics/tb-fee-details-list.html

@@ -14,6 +14,23 @@
 		<script src="../../static/kj/layer/layer.js"></script>
 		<script src="../../static/sa.js"></script>
 	</head>
+	<style>
+		.keyButton.el-button{
+			width: 100%;
+			overflow:hidden;
+			text-align: left;
+			text-overflow:ellipsis;
+			white-space:nowrap;
+			border: 0 !important;
+			background: transparent;
+			padding: 0 !important;
+		}
+		.keyButton.el-button:hover {
+			border: 0 !important;
+			background: transparent;
+			padding: 0 !important;
+		}
+	</style>
 	<body>
 		<div class="vue-box" style="display: none;" :style="'display: block;'">
 			<div class="c-panel">
@@ -96,7 +113,14 @@
 							<span v-else>{{s.row.businessCarNo}}</span>
 						</template>
 					</el-table-column>
-					<sa-td name="订单编号" prop="transactionId" width="220px" ></sa-td>
+<!--					<sa-td name="订单编号" prop="transactionId" width="220px" ></sa-td>-->
+					<el-table-column label="订单编号" width="220px">
+						<template slot-scope="s">
+							<el-tooltip :content="s.row.transactionId"placement="bottom"effect="light">
+								<el-button class="keyButton">{{ s.row.transactionId }}</el-button>
+							</el-tooltip>
+						</template>
+					</el-table-column>
 					<sa-td name="作业编号" prop="businessItemNo" width="145px" ></sa-td>
 					<sa-td name="企业名称" prop="pickCustomerName" ></sa-td>
 					<sa-td name="发票号" prop="" ></sa-td>

+ 1 - 1
sp-server/src/main/java/com/pj/api/wx/service/WxService.java

@@ -209,7 +209,7 @@ public class WxService {
                     tbBusinessService.updateById(business);
                 }
             }
-            tbFeeDetailsService.chargeParkFee(cars, transactionId,outTradeNo);//添加cars的收费明细
+            tbFeeDetailsService.chargeParkFee(cars, transactionId);//添加cars的收费明细
             String businessId = attach.getB();
             if (StrUtil.isNotEmpty(businessId)) {
                 List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);

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

@@ -131,46 +131,81 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         return list(qw);
     }
 
+    public TbFeeDetails findBuCarIdAndCarNoAndFeeTypeAndItemTypeName(String businessCarId, String carNo, Integer feeType, String itemTypeName){
+        QueryWrapper<TbFeeDetails> qw = new QueryWrapper<>();
+        qw.eq("business_car_id", businessCarId);
+        qw.eq("car_no", carNo);
+        qw.eq("fee_type", feeType);
+        qw.eq("item_type_name", itemTypeName);
+        return getOne(qw);
+    }
 
-    public void chargeParkFee(List<PriceBO> cars, String transactionId,String outTradeNo) {
-        Date now = new Date();
-        String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
-        String toDay = DateUtil.format(now, "yyyy-MM-dd");
+
+    public void chargeParkFee(List<PriceBO> cars, String transactionId) {
         for (PriceBO bo1 : cars) {
             if(bo1.getP().compareTo(BigDecimal.valueOf(0)) == 0){
                 continue;
             }
             TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
             TbBusiness business = tbBusinessService.getById(car.getBusinessId());
-            String carNo = car.getCarNo();
-            TbFeeDetails parkFee = null;
-//            if(business != null){
-//                parkFee = getByBusinessIdAndCarNoAndFeeType(car.getBusinessId(), carNo, TbFeeDetails.fee.PARK_FEE.getCode());
-//            } else {
-//                parkFee = getByBusinessCarIdAndCarNoAndFeeType(car.getId(), carNo, TbFeeDetails.fee.PARK_FEE.getCode());
-//            }
-            if(parkFee == null){
-                parkFee = new TbFeeDetails();
-                parkFee.setTaxRate(partConfig.getTaxRate());
+            BigDecimal paidMoney  = car.getMoney();
+
+            List<TbFeeDetails> oldFeeList = getByBusinessCarIdAndCarNoAndFeeType(car.getId(), car.getCarNo(), TbFeeDetails.fee.PARK_FEE.getCode());
+            TbFeeDetails nightParkFee = new TbFeeDetails();
+            TbFeeDetails dayParkFee = new TbFeeDetails();
+            String transactionIdStr = "";
+            for (TbFeeDetails oldFee : oldFeeList) {
+                if(!StrUtil.isEmpty(oldFee.getTransactionId())){
+                    transactionIdStr = oldFee.getTransactionId();
+                }
+                if(StrUtil.equals(oldFee.getItemTypeName(), "白天停车")){
+                    dayParkFee = oldFee;
+                }
+                if(StrUtil.equals(oldFee.getItemTypeName(), "夜间停车")){
+                    nightParkFee = oldFee;
+                }
+            }
+            transactionIdStr = transactionIdStr.equals("") ? transactionId : transactionIdStr + "," + transactionId;
+            BigDecimal baseNightPrice = partConfig.getBasePrice().add(partConfig.getExtraPrice());
+            BigDecimal[] qr = paidMoney.divideAndRemainder(baseNightPrice);//商和余数的数组,商为夜间停车次数,余数为白天停车费用。
+            BigDecimal nightFeeNum = qr[0];
+            if(nightFeeNum.compareTo(BigDecimal.valueOf(0)) > 0){
+                nightParkFee.setNum(nightFeeNum.intValue()).setItemTypeName("夜间停车")
+                .setUnitPrice(baseNightPrice).setItemPrice(baseNightPrice.multiply(nightFeeNum));
+                setFee(nightParkFee, car, business, transactionIdStr);
+                saveOrUpdate(nightParkFee);
+                if(qr[1].compareTo(BigDecimal.valueOf(0)) == 0 && dayParkFee.getId() != null){
+                    delete(Long.valueOf(dayParkFee.getId()));
+                }
             }
-            BigDecimal taxPrice = bo1.getP().divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP).multiply(parkFee.getTaxRate());
-            BigDecimal noTaxPrice = bo1.getP().subtract(taxPrice);
-            parkFee.setBusinessId(car.getBusinessId()).setBusinessCarId(car.getId())
-                    .setCarNo(car.getCarNo()).setOutTradeNo(outTradeNo)
-                    .setItemPrice(bo1.getP()).setUnitPrice(bo1.getP()).setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
-                    .setFeeType(TbFeeDetails.fee.PARK_FEE.getCode()).setItemTypeName("停车业务")
-                    .setPayDay(toDay).setPayType(3).setCreateTime(now)
-                    .setNum(1).setIsSettle(1).setPayMode(1).setPayTime(nowStr)
-                    .setTransactionId(transactionId)
-                    .setBusinessCarNo(car.getNo());
-            if (business!=null){
-                parkFee.setWeight(business.getNetWeight()).setBusinessNo(business.getNo());
+            if(qr[1].compareTo(BigDecimal.valueOf(0)) > 0){
+                dayParkFee.setNum(1).setItemTypeName("白天停车").setUnitPrice(qr[1]).setItemPrice(qr[1]);
+                setFee(dayParkFee, car, business, transactionIdStr);
+                saveOrUpdate(dayParkFee);
             }
-            saveOrUpdate(parkFee);
+
         }
     }
 
-
+    private void setFee(TbFeeDetails parkFee, TbBusinessCar car, TbBusiness business, String transactionId){
+        Date now = new Date();
+        String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
+        String toDay = DateUtil.format(now, "yyyy-MM-dd");
+        parkFee.setTaxRate(partConfig.getTaxRate());
+        BigDecimal taxPrice = parkFee.getItemPrice().divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP).multiply(parkFee.getTaxRate());
+        BigDecimal noTaxPrice = parkFee.getItemPrice().subtract(taxPrice);
+        parkFee.setBusinessId(car.getBusinessId()).setBusinessCarId(car.getId())
+                .setCarNo(car.getCarNo())
+                .setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
+                .setFeeType(TbFeeDetails.fee.PARK_FEE.getCode())
+                .setPayDay(toDay).setPayType(3).setCreateTime(now)
+                .setIsSettle(1).setPayMode(1).setPayTime(nowStr)
+                .setTransactionId(transactionId)
+                .setBusinessCarNo(car.getNo());
+        if (business!=null){
+            parkFee.setWeight(business.getNetWeight()).setBusinessNo(business.getNo());
+        }
+    }
 
     public String export(SoMap so) throws Exception{
         Date now = new Date();

+ 20 - 5
sp-server/src/main/java/com/pj/project/tb_fee_statistics/TbFeeStatisticsService.java

@@ -150,15 +150,14 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
         }
         BigDecimal totalPrice = BigDecimal.valueOf(0);
         Integer totalNum = parkFee.getNum();
+
         for (PriceBO bo1 : cars) {
             BigDecimal price = bo1.getP();
             if(price.compareTo(BigDecimal.valueOf(0)) != 0){
                 totalPrice = totalPrice.add(price);
-//                TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
-//                if(car.getMoney().compareTo(BigDecimal.valueOf(0)) == 0){
-//                    totalNum++;
-//                }
-                totalNum++;
+                TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
+                Integer addNum = calcuAddNum(car.getMoney(), price);
+                totalNum += addNum;
             }
         }
         if(totalPrice.compareTo(BigDecimal.valueOf(0)) == 0){
@@ -177,6 +176,22 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
         this.saveOrUpdate(parkFee);
     }
 
+    public Integer calcuAddNum(BigDecimal money, BigDecimal p){
+        BigDecimal baseNightPrice = partConfig.getBasePrice().add(partConfig.getExtraPrice());
+        BigDecimal[] qrOld = money.divideAndRemainder(baseNightPrice);
+        Integer oldNightNum = qrOld[0].intValue();
+        if(qrOld[1].compareTo(BigDecimal.valueOf(0)) > 0){
+            oldNightNum++;
+        }
+        BigDecimal newMoney = money.add(p);
+        BigDecimal[] qrNew = newMoney.divideAndRemainder(baseNightPrice);
+        Integer newNightNum = qrNew[0].intValue();
+        if(qrNew[1].compareTo(BigDecimal.valueOf(0)) > 0){
+            newNightNum++;
+        }
+        return newNightNum-oldNightNum;
+    }
+
     //@Async
     public void countBusinessFee(List<TbBusinessItem> items, String transactionId) {
         Date now = new Date();