| | |
| | | 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.pay.wx.WxFastPayService; |
| | | import com.sandu.ximon.admin.security.PermissionConfig; |
| | | 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.dao.domain.C3mCharging; |
| | | import com.sandu.ximon.dao.domain.C3mOrder; |
| | | import com.sandu.ximon.dao.enums.MenuEnum; |
| | | 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 me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | 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; |
| | | private final PermissionConfig permissionConfig; |
| | | |
| | | |
| | | /** |
| | | * 退款 |
| | | * |
| | | * @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"))); |
| | | |
| | | @PostMapping("/refund") |
| | | public ResponseVO<Object> refund(@RequestBody PayParam params) { |
| | | if (!permissionConfig.check(MenuEnum.C3_REFUND.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (params.getOutTradeNo().isEmpty() || params.getOutTradeNo() == null) { |
| | | throw new BusinessException("退款参数不能为空"); |
| | | } |
| | | return ResponseUtil.success(c3mOrderService.orderRefund(params.getOutTradeNo())); |
| | | } |
| | | |
| | | /** |
| | | * 预付款,生成订单(或直接从redis中获取当前未过期的订单) |
| | | * |
| | | * @return |
| | | */ |
| | | @AnonymousAccess |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(HttpServletRequest request, @RequestBody PayParam param) throws WxErrorException, InterruptedException { |
| | | 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()); |
| | | 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(), param.getOpenId()); |
| | | |
| | | 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, |
| | | @RequestParam(value = "keyword", required = false) String keyword, |
| | | @RequestParam(value = "orderStatus", required = false) Integer orderStatus, |
| | | @RequestParam(value = "timeType", required = false) Integer timeType) { |
| | | if (!permissionConfig.check(MenuEnum.ORDER_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | 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()); |
| | | } |
| | | |
| | | } |