| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | 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.pay.wx.WxFastPayService; |
| | | import com.sandu.ximon.admin.service.C3ChargingService; |
| | | 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 org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Map; |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.SortedMap; |
| | | |
| | | /** |
| | | * @Author liuhaonan |
| | | * @Date 2022/3/22 14:10 |
| | | * @Version 1.0 |
| | | */ |
| | | @RestController |
| | |
| | | public class C3mOrderController { |
| | | |
| | | private final C3mOrderService c3mOrderService; |
| | | private final C3ChargingService c3mService; |
| | | private final UsrAlipayConfigService alipayConfigService; |
| | | private final WxFastPayService wxPayService; |
| | | private final C3mChargingChargeService c3mChargingChargeService; |
| | | |
| | | |
| | | /** |
| | | * 退款 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @PostMapping("/refond") |
| | | public ResponseVO<Object> refond(@RequestBody Map params) { |
| | | // c3mOrderService.orderRefund( (String)params.get("outTradeNo"), |
| | | // (Double)params.get("refundAmount")); |
| | | return ResponseUtil.success(c3mOrderService.orderRefund((String) params.get("outTradeNo"), |
| | | (Double) params.get("refundAmount"))); |
| | | public ResponseVO<Object> refond(@RequestBody PayParam params) { |
| | | |
| | | if (params.getOutTradeNo().isEmpty() || params.getRefundAmount() == null) { |
| | | throw new BusinessException("退款参数不能为空"); |
| | | } |
| | | return ResponseUtil.success(c3mOrderService.orderRefund(params.getOutTradeNo(), |
| | | params.getRefundAmount())); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 预付款,生成订单(或直接从redis中获取当前未过期的订单) |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) { |
| | | if (param.getTotalAmount() < 0) { |
| | | throw new BusinessException("金额必须大于0"); |
| | | } |
| | | // C3充电桩实体 |
| | | C3mCharging c3m = c3mService.getC3mByPoleId(param.getPoleId()); |
| | | if (null == c3m) { |
| | | throw new BusinessException("未找到当前充电桩"); |
| | | } |
| | | //获取预付金额 |
| | | 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("该充电桩正被使用!"); |
| | | } |
| | | |
| | | 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()); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单状态查询 微信支付 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @RequestMapping("/queryOrder") |
| | | public ResponseVO<Object> queryOrder(@RequestBody PayParam param) { |
| | | if (param.getOrderId() == null) { |
| | | throw new BusinessException("请输入正确的订单id"); |
| | | } |
| | | C3mOrder order = c3mOrderService.getById(param.getOrderId()); |
| | | if (order == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | if ((OrderType.ALIPAY.getCode()).equals(order.getOrderType())) { |
| | | return ResponseUtil.success(AliPayUtils.alipayQuery(order.getOutTradeNo(), param.getPoleId())); |
| | | } else if ((OrderType.WXPAY.getCode()).equals(order.getOrderType())) { |
| | | return ResponseUtil.success(wxPayService.WxOrderQuery(param.getPoleId(), order.getOutTradeNo())); |
| | | } else { |
| | | return ResponseUtil.success("支付方式异常"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 订单列表 |
| | | */ |
| | | @GetMapping("/list") |
| | | public ResponseVO<Object> list(BaseConditionVO baseConditionVO) { |
| | | List<C3mOrderBo> list = c3mOrderService.orderList(baseConditionVO); |
| | | return ResponseUtil.successPage(list); |
| | | } |
| | | |
| | | } |