| | |
| | | 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.common.security.annotation.AnonymousAccess; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.param.PayParam; |
| | | import com.sandu.ximon.admin.pay.alipay.UsrAlipayConfigService; |
| | |
| | | import com.sandu.ximon.admin.service.C3mChargingChargeService; |
| | | import com.sandu.ximon.admin.service.C3mOrderService; |
| | | import com.sandu.ximon.admin.utils.AliPayUtils; |
| | | import com.sandu.ximon.dao.bo.C3mOrderBo; |
| | | import com.sandu.ximon.dao.domain.C3mCharging; |
| | | 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 javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.SortedMap; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/refond") |
| | | public ResponseVO<Object> refond(@RequestBody PayParam params) { |
| | | |
| | | if (params.getOutTradeNo().isEmpty() || params.getRefundAmount() == null) { |
| | | if (params.getOutTradeNo().isEmpty() || params.getOutTradeNo() == null) { |
| | | throw new BusinessException("退款参数不能为空"); |
| | | } |
| | | return ResponseUtil.success(c3mOrderService.orderRefund(params.getOutTradeNo(), |
| | | params.getRefundAmount())); |
| | | |
| | | return ResponseUtil.success(c3mOrderService.orderRefund(params.getOutTradeNo())); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | @AnonymousAccess |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) { |
| | | if (param.getTotalAmount() < 0) { |
| | | throw new BusinessException("金额必须大于0"); |
| | | public ResponseVO<Object> advancePayOrder(HttpServletRequest request, @RequestBody PayParam param) throws WxErrorException { |
| | | if (param.getOpenId().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()); |
| | | if (null == c3mOrderEntity) { |
| | | throw new BusinessException("该充电桩正被使用!"); |
| | | } |
| | | , totalAmount, param.getSubscribeChargingCapacity(), param.getOpenId()); |
| | | |
| | | 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()); |
| | | String s = WxFastPayService.parseWxAmount(c3mOrderEntity.getTotalAmount().toString()); |
| | | //生成微信预付订单 |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay(request,"扫码充电支付(C3充电桩)", c3mOrderEntity.getOutTradeNo(), Integer.valueOf(s), param.getPoleId(), param.getOpenId()); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 订单列表 |
| | | * |
| | | * @param baseConditionVO |
| | | * @param keyword 灯杆名称 |
| | | * @param orderStatus 订单状态:// 未支付(0) 已支付(1),退款中(2),已退款(3),订单完成(4),退款失败5) |
| | | * @param timeType 时间 1:一个月 2:三个月 3:六个月 |
| | | * @return |
| | | */ |
| | | @GetMapping("/list") |
| | | public ResponseVO<Object> list(BaseConditionVO baseConditionVO) { |
| | | List<C3mOrderBo> list = c3mOrderService.orderList(baseConditionVO); |
| | | return ResponseUtil.successPage(list); |
| | | public ResponseVO<Object> list(BaseConditionVO baseConditionVO, |
| | | @RequestParam(value = "keyword", required = false) String keyword, |
| | | @RequestParam(value = "orderStatus", required = false) Integer orderStatus, |
| | | @RequestParam(value = "timeType", required = false) Integer timeType) { |
| | | return ResponseUtil.successPage(c3mOrderService.orderList(baseConditionVO, keyword, orderStatus, timeType)); |
| | | } |
| | | |
| | | /** |
| | | * 获取wx的openid |
| | | */ |
| | | @AnonymousAccess |
| | | @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()); |
| | | } |
| | | |
| | | } |