Преглед на файлове

充值修改,用户订单列表

skyline преди 1 година
родител
ревизия
5105e48784

+ 1 - 1
car-wash-entity/src/main/java/com/kym/entity/common/PageParams.java

@@ -9,6 +9,6 @@ import lombok.Data;
  */
 @Data
 public class PageParams {
-    private int PageNum = 1;
+    private int pageNum = 1;
     private int pageSize = 10;
 }

+ 122 - 0
car-wash-entity/src/main/java/com/kym/entity/miniapp/vo/WashOrderVo.java

@@ -0,0 +1,122 @@
+package com.kym.entity.miniapp.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.kym.entity.BaseEntity;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+/**
+ * 洗车订单
+ */
+@Data
+@Accessors(chain = true)
+public class WashOrderVo extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long userId;
+
+    private String stationId;
+
+    /**
+     * 产品key
+     */
+    private String productKey;
+
+    /**
+     * 设备名称
+     */
+    private String deviceName;
+
+
+    /**
+     * 订单号,和开机命令的order_id相同,如果使用按钮快速开机,order_id是空字符串
+     */
+    private String orderId;
+
+    /**
+     * 会员折扣比例(0-100,100表示不享受折扣,95表示9.5折优惠)
+     */
+    private Integer memberDiscount;
+
+    /**
+     * 消费总额,等于各单项费用之和(单位分)
+     */
+    private Integer amount;
+
+    /**
+     * 应收金额,如果大于预付金额,则限制为预付金额并关机,否则等于消费总金额(单位分)
+     */
+    private Integer amountReceivable;
+
+    /**
+     * 实收金额等于应收金额乘会员折扣(单位分)
+     */
+    private Integer amountReceived;
+
+    /**
+     * 优惠金额等于消费总额减去实收金额(单位分)
+     */
+    private Integer discountMoney;
+
+    /**
+     * 订单操作剩余操作时间(单位秒),开机后从operation_timeout开始每秒减1,减到0关机,关机原因close_type=operation_timeout
+     */
+    private Integer operationRemainTime;
+
+    /**
+     * 设备空闲关机倒计时剩余时间(单位秒),开机后从idle_timeout开始每秒减1,见到0关机,关机原因close_type=idle_time(递减过程中按任意功能键,重新开始从idle_timeout递减)
+     */
+    private Integer idleRemainTime;
+
+    /**
+     * 费用明细:name 名称 price 单价(单位分) seconds 时长(单位秒) amount 费用(单位分) space⻋位或场地,water清水,foam泡沫,cleaner吸尘,tap水龙头,user_ext用户扩展,消毒或吹干等功能,coat镀膜,blow吹气
+     */
+    private String detail;
+
+    /**
+     * 开始时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private LocalDateTime startTime;
+
+    /**
+     * 结束时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private LocalDateTime endTime;
+
+    /**
+     * 优惠方式
+     */
+    private String discountType;
+
+    /**
+     * 优惠金额(分)
+     */
+    private Integer discountAmount;
+
+    /**
+     * 订单状态:0:未知,1:成功,2:失败,3:取消
+     */
+    private Integer orderStatus;
+
+    /**
+     * 支付状态:0:未支付,1:已支付
+     */
+    private Integer payStatus;
+
+    private String stopReason;
+
+    /**
+     * 发票状态:0-待开票 1-已开票 2-已作废(用不上) 3-开票中
+     */
+    private Integer invoiceStatus;
+
+    /**
+     * 发票id
+     */
+    private Long invoiceId;
+}

+ 6 - 0
car-wash-miniapp/src/main/java/com/kym/miniapp/controller/AccountController.java

@@ -42,6 +42,12 @@ public class AccountController {
         return R.success(walletDetailService.listWalletDetail(type));
     }
 
+    /**
+     * 退款记录
+     *
+     * @param params
+     * @return
+     */
     @PostMapping("/listRefund")
     public R<?> listRefund(@RequestBody CommonQueryParam params) {
         return R.success(refundLogService.listRefundLogForApp(params));

+ 12 - 3
car-wash-miniapp/src/main/java/com/kym/miniapp/controller/PaymentController.java

@@ -8,7 +8,10 @@ import jakarta.servlet.http.HttpServletRequest;
 import lombok.SneakyThrows;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
+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.ResponseBody;
 
 
 /**
@@ -25,11 +28,17 @@ public class PaymentController {
         this.wxPayService = wxPayService;
     }
 
+    /**
+     * 充值
+     *
+     * @param rechargeConfigId
+     * @return
+     */
     @ApiLog("微信支付")
     @PostMapping("/wxPay")
     @ResponseBody
-    R<?> prepay(@RequestBody JSONObject params) {
-        return R.success(wxPayService.wxPay(params));
+    R<?> prepay(@RequestBody Long rechargeConfigId) {
+        return R.success(wxPayService.wxPay(rechargeConfigId));
     }
 
     @ApiLog(value = "微信回调", ignoreParams = true)

+ 23 - 0
car-wash-miniapp/src/main/java/com/kym/miniapp/controller/WashOrderController.java

@@ -1,6 +1,11 @@
 package com.kym.miniapp.controller;
 
+import com.kym.common.R;
 import com.kym.common.controller.IController;
+import com.kym.entity.common.PageParams;
+import com.kym.service.miniapp.WashOrderService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -16,4 +21,22 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/wash-order")
 public class WashOrderController extends IController {
 
+    private final WashOrderService washOrderService;
+
+    public WashOrderController(WashOrderService washOrderService) {
+        this.washOrderService = washOrderService;
+    }
+
+
+    /**
+     * 获取当前用户订单列表
+     *
+     * @param params
+     * @return
+     */
+    @GetMapping(value = "/listMyWashOrder")
+    R<?> listMyWashOrder(@ModelAttribute PageParams params) {
+        return resp(() -> washOrderService.listMyWashOrder(params));
+    }
+
 }

+ 5 - 0
car-wash-service/src/main/java/com/kym/service/miniapp/WashOrderService.java

@@ -1,8 +1,11 @@
 package com.kym.service.miniapp;
 
+import com.kym.entity.common.PageBean;
+import com.kym.entity.common.PageParams;
 import com.kym.entity.miniapp.WashOrder;
 import com.kym.entity.miniapp.queryParams.DeviceQueryParams;
 import com.kym.entity.miniapp.queryParams.WashOrderQueryParams;
+import com.kym.entity.miniapp.vo.WashOrderVo;
 import com.kym.service.mybatisplus.MyBaseService;
 
 /**
@@ -20,4 +23,6 @@ public interface WashOrderService extends MyBaseService<WashOrder> {
     void closeOrder(DeviceQueryParams params);
 
     WashOrder queryOrder(WashOrderQueryParams params);
+
+    PageBean<WashOrderVo> listMyWashOrder(PageParams params);
 }

+ 25 - 0
car-wash-service/src/main/java/com/kym/service/miniapp/impl/WashOrderServiceImpl.java

@@ -1,18 +1,23 @@
 package com.kym.service.miniapp.impl;
 
 import cn.dev33.satoken.stp.StpUtil;
+import com.github.pagehelper.PageHelper;
 import com.kym.common.exception.BusinessException;
 import com.kym.common.utils.OrderUtils;
+import com.kym.entity.common.PageBean;
+import com.kym.entity.common.PageParams;
 import com.kym.entity.miniapp.Account;
 import com.kym.entity.miniapp.User;
 import com.kym.entity.miniapp.WashOrder;
 import com.kym.entity.miniapp.queryParams.DeviceQueryParams;
 import com.kym.entity.miniapp.queryParams.WashOrderQueryParams;
+import com.kym.entity.miniapp.vo.WashOrderVo;
 import com.kym.mapper.miniapp.WashOrderMapper;
 import com.kym.service.awoara.AwoaraService;
 import com.kym.service.miniapp.AccountService;
 import com.kym.service.miniapp.WashOrderService;
 import com.kym.service.mybatisplus.MyBaseServiceImpl;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
@@ -115,4 +120,24 @@ public class WashOrderServiceImpl extends MyBaseServiceImpl<WashOrderMapper, Was
                 .eq(WashOrder::getOrderId, params.getOrderId())
                 .one();
     }
+
+    /**
+     * 当前用户订单列表
+     * @param params
+     * @return
+     */
+    @Override
+    public PageBean<WashOrderVo> listMyWashOrder(PageParams params){
+        PageHelper.startPage(params.getPageNum(), params.getPageSize());
+        var res = lambdaQuery()
+                .eq(WashOrder::getUserId, StpUtil.getLoginIdAsLong())
+                .orderByDesc(WashOrder::getId)
+                .list();
+        var voList = res.stream().map(order -> {
+            var vo = new WashOrderVo();
+            BeanUtils.copyProperties(order, vo);
+            return vo;
+        }).toList();
+        return new PageBean<>(voList);
+    }
 }

+ 1 - 2
car-wash-service/src/main/java/com/kym/service/wechat/WxPayService.java

@@ -1,6 +1,5 @@
 package com.kym.service.wechat;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.kym.entity.miniapp.Invoice;
 import com.kym.entity.wechat.*;
 import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
@@ -27,7 +26,7 @@ public interface WxPayService {
     @SneakyThrows
     ResponseEntity<Object> wxRefundNotify(HttpServletRequest request);
 
-    PrepayWithRequestPaymentResponse wxPay(JSONObject rechargeAmount);
+    PrepayWithRequestPaymentResponse wxPay(Long rechargeConfigId);
 
     ResponseEntity<Object> wxNotify(HttpServletRequest request) throws IOException;
 

+ 17 - 13
car-wash-service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -82,7 +82,6 @@ public class WxPayServiceImpl implements WxPayService {
     public static RefundService refundService;
 
     public static Config config;
-
     private final WxPayConfig conf;
 
     private final WxFapiaoConfig fapiaoConfig;
@@ -108,6 +107,7 @@ public class WxPayServiceImpl implements WxPayService {
     private final UserRechargeRightsService userRechargeRightsService;
 
     private final InvoiceDetailService invoiceDetailService;
+    private final RechargeConfigService rechargeConfigService;
 
 
     /**
@@ -119,7 +119,8 @@ public class WxPayServiceImpl implements WxPayService {
     public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService,
                             PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService,
                             RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService,
-                            EnPlusService enPlusService, ActivityService activityService, UserRechargeRightsService userRechargeRightsService, InvoiceDetailService invoiceDetailService) {
+                            EnPlusService enPlusService, ActivityService activityService, UserRechargeRightsService userRechargeRightsService,
+                            InvoiceDetailService invoiceDetailService, RechargeConfigService rechargeConfigService) {
         this.conf = conf;
         this.fapiaoConfig = fapiaoConfig;
         this.walletDetailService = walletDetailService;
@@ -133,6 +134,7 @@ public class WxPayServiceImpl implements WxPayService {
         this.activityService = activityService;
         this.userRechargeRightsService = userRechargeRightsService;
         this.invoiceDetailService = invoiceDetailService;
+        this.rechargeConfigService = rechargeConfigService;
     }
 
     /**
@@ -198,7 +200,7 @@ public class WxPayServiceImpl implements WxPayService {
             throw new BusinessException("接收到签名探测流量");
         }
 
-        LOGGER.info("微信支付回调{}:\n Request参数:\n signature:{},serial:{},nonce:{},timestamp:{},signatureType:{}", no, signature, serial, nonce, timestamp, signatureType);
+        LOGGER.info("微信支付回调{}: Request参数: signature:{},serial:{},nonce:{},timestamp:{},signatureType:{}", no, signature, serial, nonce, timestamp, signatureType);
 
         ServletInputStream inputStream = request.getInputStream();
         ByteArrayOutputStream result = new ByteArrayOutputStream();
@@ -230,11 +232,16 @@ public class WxPayServiceImpl implements WxPayService {
      * JSAPI支付下单
      */
     @Override
-    public PrepayWithRequestPaymentResponse wxPay(JSONObject params) {
-        if (!params.containsKey("amount") || params.getInteger("amount") == null || !(params.get("amount") instanceof Integer)) {
+    @Transactional
+    public PrepayWithRequestPaymentResponse wxPay(Long rechargeConfigId) {
+        // 充值配置
+        var rechargeConfig = rechargeConfigService.getById(rechargeConfigId);
+
+        if ((rechargeConfig == null) || rechargeConfig.getRechargeAmount() <= 0) {
             throw new BusinessException(ResponseEnum.WX_PAY_AMOUNT_ERROR);
         }
-        var rechargeAmount = params.getInteger("amount");
+
+        var rechargeAmount = rechargeConfig.getRechargeAmount();
         var openid = StpUtil.getSession().getString("openid");
         var userId = StpUtil.getLoginIdAsLong();
         // 生成订单号
@@ -251,7 +258,8 @@ public class WxPayServiceImpl implements WxPayService {
         // request.setXxx(val)设置所需参数,具体参数可见Request定义
         PrepayRequest request = new PrepayRequest();
         Amount amount = new Amount();
-        amount.setTotal(rechargeAmount); // 传入金额单位为分
+        // 传入金额单位为分
+        amount.setTotal(rechargeAmount);
         request.setAmount(amount);
         request.setAppid(conf.getAppid());
         request.setMchid(conf.getMchid());
@@ -302,12 +310,11 @@ public class WxPayServiceImpl implements WxPayService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public ResponseEntity<Object> wxNotify(HttpServletRequest request) {
-
         try {
             var notifyRes = handleWxNotify(request);
             // 以支付通知回调为例,验签、解密并转换成 Transaction
             Transaction transaction = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], Transaction.class);
-            LOGGER.info("微信支付回调{}:验签解密完毕,数据:\n{}", notifyRes[2], transaction);
+            LOGGER.info("微信支付回调{}:验签解密完毕,数据:{}", notifyRes[2], transaction);
             // 判断是否已经接收处理过通知
             if (payLogService.lambdaQuery().eq(PayLog::getOutTradeNo, transaction.getOutTradeNo()).one() != null) {
                 return ResponseEntity.status(HttpStatus.OK).build();
@@ -316,14 +323,13 @@ public class WxPayServiceImpl implements WxPayService {
             DateTime dt = DateUtil.parse(transaction.getSuccessTime());
             LocalDateTime successTime = LocalDateTimeUtil.of(dt);
 
-
             // 钱包流水
             var walletDetail = walletDetailService.getWalletDetailByOrderNo(transaction.getOutTradeNo(), WalletDetail.TYPE_充值);
             if (walletDetail != null) {
 
                 // 更新余额
                 var account = accountService.getAccountByUserId(walletDetail.getUserId());
-                accountService.lambdaUpdate().setSql("balance = (balance+%d)".formatted(transaction.getAmount().getTotal()))
+                accountService.lambdaUpdate().setSql("balance = (balance + %d)".formatted(transaction.getAmount().getTotal()))
                         .eq(Account::getUserId, walletDetail.getUserId()).update();
 
                 walletDetail.setStatus(WalletDetail.STATUS_已确认);  //已确认
@@ -334,7 +340,6 @@ public class WxPayServiceImpl implements WxPayService {
                 walletDetail.setTransactionTime(successTime);
                 walletDetailService.updateById(walletDetail);
 
-
                 // 异步处理充值服务费打折权益活动相关逻辑
                 activityService.handleRechargeActivity(walletDetail.getUserId(), transaction.getAmount().getTotal());
 
@@ -360,7 +365,6 @@ public class WxPayServiceImpl implements WxPayService {
                 // 如果存在进行中的订单,则向en+更新用户余额
                 var chargingOrder = chargeOrderService.getChargingOrderByUserId(walletDetail.getUserId());
                 if (chargingOrder != null) {
-                    // TODO: 2023-11-30 快充这里考虑过充的金额要提高
                     var res = enPlusService.updateBalanceByQueryEquipChargeStatus(chargingOrder.getStartChargeSeq(), account.getBalance() - 50);
                     LOGGER.info("用户:{}充电过程中充值,已更新en+充电金额,en+返回数据:{}", account.getUserId(), res);
                 }