| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import cn.hutool.core.map.MapUtil; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | |
| | | import com.sandu.ximon.dao.domain.C3mOrder; |
| | | import com.sandu.ximon.dao.enums.OrderType; |
| | | import lombok.AllArgsConstructor; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | * @return |
| | | */ |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) { |
| | | if (param.getTotalAmount() < 0) { |
| | | throw new BusinessException("金额必须大于0"); |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) throws WxErrorException { |
| | | if (param.getWxCode().isEmpty()) { |
| | | throw new BusinessException("微信code不能为空"); |
| | | } |
| | | if (param.getPoleId() == null || param.getSubscribeChargingCapacity() == null) { |
| | | throw new BusinessException("充电桩id或充电容量不能为空"); |
| | | } |
| | | if (param.getSubscribeChargingCapacity() < 1) { |
| | | throw new BusinessException("充电容量不能小于1Kw/h"); |
| | | } |
| | | // C3充电桩实体 |
| | | C3mCharging c3m = c3mService.getC3mByPoleId(param.getPoleId()); |
| | |
| | | BigDecimal TotalAmount = c3mChargingChargeService.getCostByC3id(c3m.getC3Id(), param.getSubscribeChargingCapacity()); |
| | | //转换为double类型 |
| | | double totalAmount = TotalAmount.doubleValue(); |
| | | //生成订单 |
| | | C3mOrder c3mOrderEntity = c3mOrderService.advancePayOrder(param.getPoleId(), c3m, "wxpay" |
| | | , totalAmount, param.getSubscribeChargingCapacity()); |
| | | , totalAmount, param.getSubscribeChargingCapacity(), param.getWxCode()); |
| | | if (null == c3mOrderEntity) { |
| | | throw new BusinessException("该充电桩正被使用!"); |
| | | } |
| | |
| | | param.setOutTradeNo(c3mOrderEntity.getOutTradeNo()); |
| | | param.setTotalAmount(c3mOrderEntity.getTotalAmount()); |
| | | String s = WxFastPayService.parseWxAmount(param.getTotalAmount().toString()); |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay("扫码充电支付(C3充电桩)", param.getOutTradeNo(), Integer.valueOf(s), param.getPoleId()); |
| | | //生成微信预付订单 |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay("扫码充电支付(C3充电桩)", param.getOutTradeNo(), Integer.valueOf(s), param.getPoleId(), param.getWxCode()); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | |
| | | return ResponseUtil.successPage(list); |
| | | } |
| | | |
| | | /** |
| | | * 获取wx的openid |
| | | */ |
| | | @PostMapping("/getWxOpenId") |
| | | public ResponseVO<Object> getWxOpenId(@RequestBody PayParam param) throws WxErrorException { |
| | | if (param.getWxCode() == null || param.getPoleId() == null || param.getWxCode().isEmpty()) { |
| | | throw new BusinessException("参数不能为空"); |
| | | } |
| | | String openId = wxPayService.getOpenId(param.getPoleId(), param.getWxCode()); |
| | | return ResponseUtil.success(MapUtil.builder().put("openId", openId).build()); |
| | | } |
| | | |
| | | } |