|
@@ -1,6 +1,7 @@
|
|
|
package com.pj.api.wx.service;
|
|
|
|
|
|
import cn.hutool.core.net.URLDecoder;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.XmlUtil;
|
|
@@ -35,6 +36,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
@@ -81,7 +83,7 @@ public class WxService {
|
|
|
params.put("body", "支付中心-业务订单支付");
|
|
|
params.put("out_trade_no", out_trade_no);
|
|
|
params.put("attach", JSONUtil.toJsonStr(atchMap));
|
|
|
- String total_free = Integer.parseInt(money) * 100 + "";
|
|
|
+ String total_free = NumberUtil.mul(money, 100 + "").intValue() + "";
|
|
|
// String total_free = "1";
|
|
|
log.info("pay free:{}", total_free);
|
|
|
params.put("total_fee", total_free);
|
|
@@ -150,7 +152,7 @@ public class WxService {
|
|
|
String total_fee = notifyBO.getTotalFee();
|
|
|
BigDecimal money = new BigDecimal(total_fee).divide(new BigDecimal(100), 2, BigDecimal.ROUND_UP);
|
|
|
log.info("wx pay notify;{}", JSONUtil.toJsonStr(notifyBO));
|
|
|
- String tradeNo =notifyBO.getOutTradeNo();
|
|
|
+ String tradeNo = notifyBO.getOutTradeNo();
|
|
|
tradeNo = StrUtil.subBefore(tradeNo, "_", true);
|
|
|
String attachStr = notifyBO.getAttach();
|
|
|
String transactionId = notifyBO.getTransactionId();
|
|
@@ -160,19 +162,25 @@ public class WxService {
|
|
|
List<PriceBO> cars = JSONUtil.toList(attach.getC(), PriceBO.class);
|
|
|
for (PriceBO bo1 : cars) {
|
|
|
TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
|
|
|
- car.setPay(1).setMoney(car.getMoney().add(bo1.getP()));
|
|
|
+ BigDecimal price = bo1.getP();
|
|
|
+ car.setPay(1).setMoney(car.getMoney().add(price));
|
|
|
tbBusinessCarService.updateById(car);
|
|
|
+ TbBusiness business = tbBusinessService.getById(car.getBusinessId());
|
|
|
+ business.setPayMoney(business.getPayMoney().add(price));
|
|
|
+ business.setPayStatus(business.getPayMoney().add(price).equals(business.getTotalMoney()) ? 3 : 4);
|
|
|
+ tbBusinessService.updateById(business);
|
|
|
}
|
|
|
String businessId = attach.getB();
|
|
|
-
|
|
|
if (StrUtil.isNotEmpty(businessId)) {
|
|
|
- List<TbBusinessItem>items=tbBusinessItemService.findByBusinessId(businessId);
|
|
|
+ List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
|
|
|
items.forEach(tbBusinessItem -> tbBusinessItem.setPayStatus(1).setPayTime(now));
|
|
|
+ double sum = items.stream().collect(Collectors.summarizingDouble(item -> item.getItemPrice().doubleValue())).getSum();
|
|
|
+ BigDecimal itemPrice=new BigDecimal(sum);
|
|
|
tbBusinessItemService.updateBatchById(items);
|
|
|
TbBusiness tbBusiness = tbBusinessService.getById(businessId);
|
|
|
- tbBusiness.setPayStatus(tbBusiness.getPayMoney().add(money).equals(tbBusiness.getTotalMoney()) ? 3 : 4);
|
|
|
+ tbBusiness.setPayStatus(tbBusiness.getPayMoney().add(itemPrice).equals(tbBusiness.getTotalMoney()) ? 3 : 4);
|
|
|
tbBusiness.setPayTime(now).setPayType(3).setConfirmInput(1).setConfirmInputTime(now)
|
|
|
- .setPayMoney(tbBusiness.getPayMoney().add(money))
|
|
|
+ .setPayMoney(tbBusiness.getPayMoney().add(itemPrice))
|
|
|
.setPayNo(transactionId);
|
|
|
tbBusinessService.updateById(tbBusiness);
|
|
|
TbPayRecord payRecord = new TbPayRecord();
|
|
@@ -218,8 +226,8 @@ public class WxService {
|
|
|
params.put("jsapi_ticket", jsTicket);
|
|
|
params.put("timestamp", nowTime);
|
|
|
params.put("url", url);
|
|
|
- String sign= SecureUtil.sha1(params.toString().substring(1, params.toString().lastIndexOf("}")).replaceAll(", ", "&"));
|
|
|
- params.put("sign",sign);
|
|
|
+ String sign = SecureUtil.sha1(params.toString().substring(1, params.toString().lastIndexOf("}")).replaceAll(", ", "&"));
|
|
|
+ params.put("sign", sign);
|
|
|
params.put("appId", wxConfig.getAppId());
|
|
|
return params;
|
|
|
}
|