admin
2024-06-30 b6fdf185c7e8fb1f06da0e609e39aecaef6b66f5
src/main/java/com/taoke/autopay/controller/client/OrderController.java
@@ -8,13 +8,15 @@
import com.google.gson.stream.JsonWriter;
import com.taoke.autopay.dao.KeyOrderMapper;
import com.taoke.autopay.dto.DYOrderDto;
import com.taoke.autopay.entity.ClientInfo;
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.entity.*;
import com.taoke.autopay.exception.KeyOrderException;
import com.taoke.autopay.exception.WxOrderCountException;
import com.taoke.autopay.factory.OrderFactory;
import com.taoke.autopay.service.ClientInfoService;
import com.taoke.autopay.service.KeyOrderService;
import com.taoke.autopay.service.WxUserOrderCountService;
import com.taoke.autopay.service.WxUserSettingService;
import com.taoke.autopay.utils.JsonUtil;
import com.taoke.autopay.utils.StringUtil;
import com.taoke.autopay.utils.TimeUtil;
@@ -53,8 +55,9 @@
                // 判断是否是同一天
                desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
                out.value(desc);
            } else
            } else {
                out.value("");
            }
        }
        @Override
@@ -68,6 +71,13 @@
    @Resource
    private ClientInfoService clientInfoService;
    @Resource
    private WxUserOrderCountService wxUserOrderCountService;
    @Resource
    private WxUserSettingService wxUserSettingService;
    @ResponseBody
    @RequestMapping("listOrder")
@@ -147,14 +157,14 @@
    }
    /**
     * @author hxh
     * @return java.lang.String 返回是否可以去支付
     * @author hxh
     * @description 设置订单号
     * @date 23:08 2024/6/24
     * @param: acceptData
     * @param: id 订单ID
     * @param: orderNo 订单号
     * @param: orderStatus 订单状态:订单已取消/已支付
     * @return java.lang.String
     **/
    @ResponseBody
    @RequestMapping("setOrderNo")
@@ -181,6 +191,9 @@
        }
        try {
            if (!StringUtil.isNullOrEmpty(orderStatus)) {
                throw new KeyOrderException(orderStatus);
            }
            DYOrderDto dto = DYOrderApi.getOrderDetail(orderNo);
//            dto.setOrder_status(1);
            if (dto.getOrder_status() != DYOrderDto.ORDER_STATUS_NOT_PAY) {
@@ -191,7 +204,7 @@
                orderUpdate.setOrderType(1);
                orderUpdate.setOrderNo(orderNo);
                if (order.getState() == KeyOrder.STATE_NOT_PROCESS) {
                     if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) {
                    if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) {
                        orderUpdate.setState(KeyOrder.STATE_PAY);
                        orderUpdate.setStateDesc(dto.getOrder_status_desc());
                    } else {
@@ -206,12 +219,24 @@
                    throw new Exception("订单已支付");
                }
            }
            if (order.getUid() != null) {
                WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
                if (countInfo != null) {
                    WxUserSettings settings = wxUserSettingService.selectByUid(order.getUid());
                    if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) {
                        throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay());
                    }
                }
            }
            // 设置进入
            KeyOrder orderUpdate = new KeyOrder();
            orderUpdate.setId(id);
            orderUpdate.setOrderType(1);
            orderUpdate.setOrderState(dto.getOrder_status());
            orderUpdate.setOrderNo(orderNo);
            orderUpdate.setExcutePayTime(new Date());
            keyOrderService.update(orderUpdate);
            order = keyOrderService.selectById(id);
            return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order)));
@@ -222,6 +247,9 @@
            orderUpdate.setOrderState(0);
            orderUpdate.setOrderNo(orderNo);
            orderUpdate.setState(KeyOrder.STATE_REJECT_PAY);
            if (order.getExcutePayTime() == null) {
                orderUpdate.setExcutePayTime(new Date());
            }
            orderUpdate.setStateDesc(e.getMessage());
            keyOrderService.update(orderUpdate);
            return JsonUtil.loadFalseResult(e.getMessage());
@@ -246,7 +274,7 @@
            return JsonUtil.loadFalseResult("没有匹配到订单号");
        }
        if(order.getState()==KeyOrder.STATE_NOT_PROCESS) {
        if (order.getState() == KeyOrder.STATE_NOT_PROCESS) {
            if (!paySuccess) {
                // 支付失败
                KeyOrder orderUpdate = new KeyOrder();
@@ -258,8 +286,16 @@
                KeyOrder orderUpdate = new KeyOrder();
                orderUpdate.setId(id);
                orderUpdate.setState(KeyOrder.STATE_PAY);
                if (order.getPayTime() == null) {
                    orderUpdate.setPayTime(new Date());
                }
                orderUpdate.setStateDesc("支付成功");
                keyOrderService.update(orderUpdate);
                try {
                    keyOrderService.paySuccess(id, "支付成功", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
                } catch (WxOrderCountException e) {
                    e.printStackTrace();
                    return JsonUtil.loadFalseResult(e.getMessage());
                }
            }
        }
        return JsonUtil.loadTrueResult("");
@@ -294,16 +330,16 @@
    @ResponseBody
    @RequestMapping("deleteAll")
    public String deleteAll(AcceptData acceptData,Long uid) {
    public String deleteAll(AcceptData acceptData, Long uid) {
     ClientInfo user=   clientInfoService.selectByPrimaryKey(uid);
     if(user==null){
         return JsonUtil.loadFalseResult("用户不存在");
     }
        ClientInfo user = clientInfoService.selectByPrimaryKey(uid);
        if (user == null) {
            return JsonUtil.loadFalseResult("用户不存在");
        }
     if(user.getRule() != ClientInfo.RULE_ADMIN){
         return JsonUtil.loadFalseResult("只有管理员才能删除");
     }
        if (user.getRule() != ClientInfo.RULE_ADMIN) {
            return JsonUtil.loadFalseResult("只有管理员才能删除");
        }
        // 删除24小时之前的数据
//        keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24*60*60*1000L));