Просмотр исходного кода

骑手二维码收单、接单、完成订单优化

codingliang 1 год назад
Родитель
Сommit
4cd8a9251d

+ 5 - 0
src/main/java/com/sqx/common/constant/RedisKey.java

@@ -69,6 +69,11 @@ public interface RedisKey {
     String COMMON_INFO_CACHE_KEY = "wm:data:common:%s";
 
     /**
+     * 用户信息缓存key
+     */
+    String USER_INFO_CACHE_KEY = "wm:data:user:%s";
+
+    /**
      * 店铺缓存信息
      */
     String SHOP_INFO_CACHE_KEY = "wm:data:shop:%s";

+ 28 - 24
src/main/java/com/sqx/modules/app/service/impl/UserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sqx.modules.app.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONException;
 import com.alibaba.fastjson.JSONObject;
@@ -31,31 +32,36 @@ import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
 import com.github.qcloudsms.SmsSingleSender;
 import com.github.qcloudsms.SmsSingleSenderResult;
 import com.github.qcloudsms.httpclient.HTTPException;
+import com.sqx.common.constant.RedisKey;
 import com.sqx.common.utils.PageUtils;
+import com.sqx.common.utils.RedisUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.dao.MsgDao;
 import com.sqx.modules.app.dao.UserDao;
 import com.sqx.modules.app.dao.UserMoneyDao;
-import com.sqx.modules.app.entity.*;
+import com.sqx.modules.app.entity.AppUserInfo;
+import com.sqx.modules.app.entity.Msg;
+import com.sqx.modules.app.entity.UserEntity;
+import com.sqx.modules.app.entity.UserMoney;
+import com.sqx.modules.app.entity.queryRiderVo;
+import com.sqx.modules.app.entity.queryRidersVo;
 import com.sqx.modules.app.service.UserService;
 import com.sqx.modules.app.utils.JwtUtils;
 import com.sqx.modules.app.utils.UserConstantInterface;
 import com.sqx.modules.common.entity.CommonInfo;
 import com.sqx.modules.common.service.CommonInfoService;
 import com.sqx.modules.errand.entity.Feedback;
-import com.sqx.modules.errand.vo.queryOrderInfoVo;
 import com.sqx.modules.file.utils.Md5Utils;
 import com.sqx.modules.integral.dao.UserIntegralDao;
 import com.sqx.modules.integral.entity.UserIntegral;
-import com.sqx.modules.invite.service.InviteService;
 import com.sqx.modules.message.entity.MessageInfo;
 import com.sqx.modules.message.service.MessageService;
 import com.sqx.modules.utils.HttpClientUtil;
 import com.sqx.modules.utils.InvitationCodeUtil;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import weixin.popular.api.SnsAPI;
 import weixin.popular.util.JsonUtil;
@@ -74,28 +80,19 @@ import java.util.Map;
  * @author fang
  * @date 2021/2/27
  */
-
-@Service("userService")
 @Slf4j
+@Service("userService")
+@RequiredArgsConstructor
 public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
 
-    @Autowired
-    private CommonInfoService commonInfoService;
-    @Autowired
-    private MsgDao msgDao;
-    @Autowired
-    private JwtUtils jwtUtils;
-    private int number = 1;
-    @Autowired
-    private InviteService inviteService;
-    @Autowired
-    private MessageService messageService;
-    @Autowired
-    private UserDao userDao;
-    @Autowired
-    private UserMoneyDao userMoneyDao;
-    @Autowired
-    private UserIntegralDao userIntegralDao;
+    private final CommonInfoService commonInfoService;
+    private final MsgDao msgDao;
+    private final JwtUtils jwtUtils;
+    private final MessageService messageService;
+    private final UserDao userDao;
+    private final UserMoneyDao userMoneyDao;
+    private final UserIntegralDao userIntegralDao;
+    private final RedisUtils redisUtils;
 
     @Override
     public queryRiderVo queryRider(Long userId) {
@@ -1022,7 +1019,14 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 
     @Override
     public UserEntity selectUserById(Long userId) {
-        return baseMapper.selectById(userId);
+        String key = String.format(RedisKey.USER_INFO_CACHE_KEY, userId);
+        UserEntity userEntity = (UserEntity) redisUtils.get(key);
+        if (ObjectUtil.isNull(userEntity)) {
+            userEntity = baseMapper.selectById(userId);
+
+            redisUtils.set(key, userEntity, RedisUtils.TEN_MINUTE_ONE_EXPIRE);
+        }
+        return userEntity;
     }
 
     @Override

+ 55 - 23
src/main/java/com/sqx/modules/errand/controller/app/AppTbIndentController.java

@@ -1,6 +1,6 @@
 package com.sqx.modules.errand.controller.app;
 
-import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -12,27 +12,46 @@ import com.sqx.modules.app.entity.UserEntity;
 import com.sqx.modules.app.entity.queryRiderVo;
 import com.sqx.modules.app.service.UserService;
 import com.sqx.modules.common.service.CommonInfoService;
-import com.sqx.modules.errand.dto.*;
-import com.sqx.modules.errand.entity.*;
+import com.sqx.modules.errand.dto.OrderRiderDeliveryDTO;
+import com.sqx.modules.errand.dto.RiderDeliveryDTO;
+import com.sqx.modules.errand.dto.RiderTransferByOrderIdDTO;
+import com.sqx.modules.errand.dto.RiderTransferOrderDTO;
+import com.sqx.modules.errand.dto.RiderTransferOrdersDTO;
+import com.sqx.modules.errand.dto.WaitForAcceptOrderQueryDTO;
+import com.sqx.modules.errand.entity.ErrandAddress;
+import com.sqx.modules.errand.entity.ErrandComplaint;
+import com.sqx.modules.errand.entity.ErrandEvaluate;
+import com.sqx.modules.errand.entity.ErrandRedPacket;
+import com.sqx.modules.errand.entity.TbIndent;
+import com.sqx.modules.errand.entity.TransferRecordEntity;
 import com.sqx.modules.errand.service.ErrandComplaintService;
 import com.sqx.modules.errand.service.TbIndentService;
 import com.sqx.modules.errand.service.TransferRecordService;
-import com.sqx.modules.errand.service.impl.TransferRecordServiceImpl;
 import com.sqx.modules.errand.vo.queryOrderInfoVo;
-import com.sqx.modules.printInfo.entity.PrintInfo;
 import icu.xuyijie.secureapi.annotation.DecryptParam;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
-import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/app/tbindent")
@@ -446,29 +465,39 @@ public class AppTbIndentController {
         return Result.success().put("data", data);
     }
 
-    private void checkTransferOrderParam(RiderTransferOrderDTO transferOrderDTO) {
-        if (StringUtils.isBlank(transferOrderDTO.getPhone()) && StringUtils.isBlank(transferOrderDTO.getRealName())) {
-            throw new SqxException("待分配骑手手机号和待分配骑手真实姓名不能同时为空");
-        }
+    @GetMapping("get-by-code/{code}")
+    @ApiOperation("根据收单码查询订单")
+    public Result getByCode(@PathVariable String code) {
+        TbIndent indent = tbIndentService.getByOrderId(code);
+        return Result.success().put("data", indent);
+    }
+
+    @Login
+    @PutMapping(value = "receive/{code}")
+    @ApiOperation("根据扫码或收单码接单")
+    public Result receiveOrder(@RequestAttribute Long userId, @PathVariable String code) {
+        return tbIndentService.orderIndentReceiving(userId, code);
     }
 
+    @Login
+    @PostMapping(value = "finish-order")
+    @ApiOperation("骑手完成订单")
+    public Result riderFinishOrder(@RequestAttribute Long userId, @Valid @RequestBody OrderRiderDeliveryDTO orderRiderDeliveryDTO) {
+        return tbIndentService.orderRiderDelivery(userId, orderRiderDeliveryDTO);
+    }
 
     //region 2024-09-12 A-jax 添加接口
     //region 1、根据订单id查询跑腿订单的信息;
+    // TODO 以下三个接口待删除
     @Login
     @GetMapping("selectTbIndentPage")
     @ApiOperation("扫码或收单码查询跑腿订单列表(带分页")
     public Result selectMemberPage(@RequestAttribute Long userId, Integer page, Integer limit, String acquireCode) {
+        if (StrUtil.isBlank(acquireCode)) {
+            throw new SqxException("请输入正确的扫码或收单码");
+        }
         //如果只有一条数据就看看数据是否能被当前骑手接
         PageUtils datas = tbIndentService.selectIndentPage(page, limit, acquireCode, userId);
-        if (datas.getTotalCount() == 1) {
-            //校验当前骑手是否能接单
-            Result checkData = tbIndentService.checkIndent(userId, acquireCode);
-            if ((int) checkData.get("code") != 0) {
-                return checkData;//Result.error("当前订单无法接单");
-            }
-        }
-
         return Result.success().put("data", datas);
     }
     //endregion
@@ -478,7 +507,6 @@ public class AppTbIndentController {
     @PostMapping(value = "orderIndentReceiving")
     @ApiOperation("骑手根据扫码或收单码接单")
     public Result orderIndentReceiving(@RequestAttribute Long userId, String acquireCode) {
-
         return tbIndentService.orderIndentReceiving(userId, acquireCode);
     }
     //endregion
@@ -488,7 +516,6 @@ public class AppTbIndentController {
     @PostMapping(value = "orderRiderDelivery")
     @ApiOperation("骑手根据扫码或收单码完成订单")
     public Result orderRiderDelivery(@RequestAttribute Long userId, @Valid @RequestBody OrderRiderDeliveryDTO orderRiderDeliveryDTO) {
-
         return tbIndentService.orderRiderDelivery(userId, orderRiderDeliveryDTO);
     }
     //endregion
@@ -511,7 +538,12 @@ public class AppTbIndentController {
             throw new SqxException("待分配骑手手机号和待分配骑手真实姓名不能同时为空");
         }
     }
+
+    private void checkTransferOrderParam(RiderTransferOrderDTO transferOrderDTO) {
+        if (StringUtils.isBlank(transferOrderDTO.getPhone()) && StringUtils.isBlank(transferOrderDTO.getRealName())) {
+            throw new SqxException("待分配骑手手机号和待分配骑手真实姓名不能同时为空");
+        }
+    }
     //endregion
     //endregion
-
 }

+ 2 - 0
src/main/java/com/sqx/modules/errand/service/TbIndentService.java

@@ -152,4 +152,6 @@ public interface TbIndentService extends IService<TbIndent> {
      * @param imgs         图片地址
      */
     void riderUploadDeliveryImg(Long userId, String indentNumber, String imgs);
+
+    TbIndent getByOrderId(String orderId);
 }

+ 162 - 184
src/main/java/com/sqx/modules/errand/service/impl/TbIndentServiceImpl.java

@@ -821,130 +821,138 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         return Result.success();
     }
 
+    public void checkRider(Long riderUserId) {
+        // 判断骑手状态是否被封号
+        UserEntity riderUser = userService.selectUserById(riderUserId);
+        if (riderUser.getStatus() != 1) {
+            throw new SqxException("骑手的帐号已被封禁,请联系客服解封!");
+        }
+
+        // 判断骑手保证金是否大于可接单金额
+        CommonInfo one1 = commonInfoService.findOne(273);
+        Double cashDeposit = Double.valueOf(one1.getValue());
+        if (riderUser.getCashDeposit().compareTo(BigDecimal.valueOf(cashDeposit)) < 0) {
+            throw new SqxException("骑手的保证金不足,请缴纳保证金后再接单");
+        }
+
+        // 判断骑手是否超过最大接单数量
+        String maxNumStr = commonInfoService.findOne(342).getValue();
+        Integer maxNum = Integer.parseInt(maxNumStr);
+        if (tbIndentDao.selectIndentByRiderUserCount(riderUserId) >= maxNum) {
+            throw new SqxException("您已达最大接单数量,请先完成订单后再进行接单");
+        }
+    }
+
     @Override
-    public Result orderIndentReceiving(Long userId, String acquireCode) {
+    public Result orderIndentReceiving(Long riderUserId, String acquireCode) {
+        // 检查骑手
+        checkRider(riderUserId);
+
+        // 根据收单码查询订单
+        TbIndent tbIndent = getByOrderId(acquireCode);
+
+        String receiveTimeStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+        UserEntity riderUser = userService.selectUserById(riderUserId);
+
+        RLock lock = redissonClient.getLock(String.format(RedisKey.UPDATE_INDENT_LOCK, tbIndent.getIndentNumber()));
+        lock.lock();
         try {
-            //判断骑手状态是否被封号
-            UserEntity userEntity1 = userService.selectUserById(userId);
-            if (userEntity1.getStatus() != 1) {
-                return Result.error("您的帐号已被封禁,请联系客服解封!");
+            // 再次查询订单
+            tbIndent = getById(tbIndent.getIndentId());
+            if (!"2".equals(tbIndent.getIndentState())) {
+                throw new SqxException("订单已被抢走!");
             }
-            //判断骑手保证金是否大于可接单金额
-            UserEntity userMessage = userService.selectUserById(userId);
-            String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
-            CommonInfo one1 = commonInfoService.findOne(273);
-            Double cashDeposit = Double.valueOf(one1.getValue());
-            if (userMessage.getCashDeposit().compareTo(BigDecimal.valueOf(cashDeposit)) > 0 || userMessage.getCashDeposit().compareTo(BigDecimal.valueOf(cashDeposit)) == 0) {
-                //  tbIndentDao.indentReceiving(userId, indentNumber, format);
-                //判断骑手是否超过最大接单数量
-                String maxNumStr = commonInfoService.findOne(342).getValue();
-                Integer maxNum = Integer.parseInt(maxNumStr);
-                int i = tbIndentDao.selectIndentByRiderUserCount(userId);
-                if (i >= maxNum) {
-                    return Result.error("您已达最大接单数量,请先完成订单后再进行接单");
-                }
-                TbIndent tbIndent = tbIndentDao.findIndentByOrderId(acquireCode);
-                log.error("抢单:" + userId + "     " + tbIndent.getIndentState());
-                RLock lock = redissonClient.getLock(String.format(RedisKey.UPDATE_INDENT_LOCK, tbIndent.getIndentNumber()));
-                lock.lock();
-                try {
-//                if(!"2".equals(tbIndent.getIndentState())){
-//                    return Result.error("订单已被抢走!");
-//                }
-                    if ("5".equals(tbIndent.getIndentType())) {
-                        if ("2".equals(tbIndent.getIndentState()) || "3".equals(tbIndent.getIndentState())) {
-                            tbIndentDao.orderIndentReceiv(userId, acquireCode, format, "4");
-
-                            TransferRecordEntity tr = new TransferRecordEntity();
-                            tr.setUserId(userEntity1.getUserId());
-                            tr.setUserName(userEntity1.getUserName());
-                            tr.setUserPhone(userEntity1.getPhone());
-                            tr.setOrderId(tbIndent.getOrderId());
-                            tr.setReceveTime(format);
-                            //获取站点内容
-                            RiderStation station = riderStationService.stationById(userEntity1.getRiderStationId());
-                            if(station != null){
-                                tr.setStationName(station.getStationName());
-                            }
-                            tr.setDeleteFlag(0);
-                            transferRecordDao.insert(tr);
-                        }
-                    }
 
-                } finally {
-                    lock.unlock();
-                }
+            // 更改订单状态
+            TbIndent newIndent = new TbIndent();
+            newIndent.setIndentId(tbIndent.getIndentId());
+            newIndent.setIndentState("4"); // 4:骑手已取货/购买
+            newIndent.setRiderUserId(riderUserId);
+            newIndent.setReceivingTime(receiveTimeStr);
+            updateById(newIndent);
+
+            // 插入转单记录记录
+            TransferRecordEntity tr = new TransferRecordEntity();
+            tr.setUserId(riderUserId);
+            tr.setUserName(riderUser.getUserName());
+            tr.setUserPhone(riderUser.getPhone());
+            tr.setOrderId(tbIndent.getOrderId());
+            tr.setReceveTime(receiveTimeStr);
+            RiderStation station = riderStationService.stationById(riderUser.getRiderStationId());  // 获取站点内容
+            if(station != null){
+                tr.setStationName(station.getStationName());
+            }
+            tr.setDeleteFlag(0);
+            transferRecordDao.insert(tr);
+        } finally {
+            lock.unlock();
+        }
 
-                MyGlobalThreadPool.execute(() -> {
-                    try {
-                        // 消息推送(以前写的在下面放着)
-                        List<String> msgList = new ArrayList<>();
-                        msgList.add("接单项目");
-                        msgList.add(userEntity1.getNickName());
-                        msgList.add(format);
-                        msgList.add("接单成功,请及时取货!");
-                        CommonInfo five = commonInfoService.findOne(310);
-                        userService.pushToSingleRider("接单成功", "您已接单成功,请及时派送", userEntity1.getRiderClientid());
-                        SenInfoCheckUtil.sendRiderMsg(userEntity1.getRiderOpenId(), five.getValue(), msgList, 4);
-
-                        MessageInfo messageInfo = new MessageInfo();
-                        messageInfo.setContent("骑手已接单");
-                        messageInfo.setTitle("订单状态通知");
-                        messageInfo.setState(String.valueOf(5));
-                        messageInfo.setCreateAt(DateUtils.format(new Date()));
-                        messageInfo.setIsSee("0");
-                        UserEntity userEntity = userService.selectUserById(tbIndent.getUserId());
-                        messageInfo.setUserName(userEntity.getUserName());
-                        messageInfo.setUserId(String.valueOf(userEntity.getUserId()));
-                        messageService.saveBody(messageInfo);
-
-                        List<String> msgListUser = new ArrayList<>();
-                        String value = commonInfoService.findOne(12).getValue();
-                        if (tbIndent.getOrderId() != null) {
-                            TbOrder order = appOrderService.getById(tbIndent.getOrderId());
-                            if (order != null) {
-                                Long shopId = order.getShopId();
-                                GoodsShop goodsShop = goodsShopDao.selectById(shopId);
-                                msgListUser.add(goodsShop.getShopName());
-                            } else {
-                                msgListUser.add(value);
-                            }
-                        } else {
-                            msgListUser.add(value);
-                        }
-                        msgListUser.add("骑手已接单");
-                        msgListUser.add(tbIndent.getIndentNumber());
-                        msgListUser.add(DateUtils.format(new Date()));
-                        CommonInfo msg = commonInfoService.findOne(269);
-                        SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), msg.getValue(), msgListUser, 1);
-
-                        if (tbIndent.getOrderId() != null) {
-                            TbOrder order = appOrderService.getById(tbIndent.getOrderId());
-                            String shopTemplate = commonInfoService.findOne(354).getValue();
-                            List<String> msgListShop = new ArrayList<>();
-                            msgListShop.add(tbIndent.getIndentNumber());
-                            log.error("打印:" + tbIndent.getIndentNumber());
-                            msgListShop.add("骑手接单");
-                            msgListShop.add(DateUtils.format(new Date()));
-                            log.error("打印:" + msgListShop.toString());
-                            GoodsShop goodsShop = goodsShopDao.selectById(order.getShopId());
-                            UserEntity shopUser = userService.selectUserById(goodsShop.getUserId());
-
-                            SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
-                        }
-                    } catch (Exception e) {
-                        log.error("订单编号:{},骑手接单成功信息发送失败,失败原因:{}", tbIndent.getIndentNumber(), e);
+        // 发送骑手接单消息
+        sendOrderReceivingMsg(tbIndent, riderUser);
+
+        return Result.success();
+    }
+
+    private void sendOrderReceivingMsg(TbIndent tbIndent, UserEntity riderUser) {
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                List<String> msgList = new ArrayList<>();
+                msgList.add("接单项目");
+                msgList.add(riderUser.getNickName());
+                msgList.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                msgList.add("接单成功,请及时取货!");
+                CommonInfo five = commonInfoService.findOne(310);
+                userService.pushToSingleRider("接单成功", "您已接单成功,请及时派送", riderUser.getRiderClientid());
+                SenInfoCheckUtil.sendRiderMsg(riderUser.getRiderOpenId(), five.getValue(), msgList, 4);
+
+                MessageInfo messageInfo = new MessageInfo();
+                messageInfo.setContent("骑手已接单");
+                messageInfo.setTitle("订单状态通知");
+                messageInfo.setState(String.valueOf(5));
+                messageInfo.setCreateAt(DateUtils.format(new Date()));
+                messageInfo.setIsSee("0");
+                UserEntity userEntity = userService.selectUserById(tbIndent.getUserId());
+                messageInfo.setUserName(userEntity.getUserName());
+                messageInfo.setUserId(String.valueOf(userEntity.getUserId()));
+                messageService.saveBody(messageInfo);
+
+                List<String> msgListUser = new ArrayList<>();
+                String value = commonInfoService.findOne(12).getValue();
+                if (tbIndent.getOrderId() != null) {
+                    TbOrder order = appOrderService.getById(tbIndent.getOrderId());
+                    if (order != null) {
+                        Long shopId = order.getShopId();
+                        GoodsShop goodsShop = goodsShopDao.selectById(shopId);
+                        msgListUser.add(goodsShop.getShopName());
+                    } else {
+                        msgListUser.add(value);
                     }
-                });
-            } else {
-                return Result.error("你的保证金不足,请缴纳保证金后再接单");
+                } else {
+                    msgListUser.add(value);
+                }
+                msgListUser.add("骑手已接单");
+                msgListUser.add(tbIndent.getIndentNumber());
+                msgListUser.add(DateUtils.format(new Date()));
+                CommonInfo msg = commonInfoService.findOne(269);
+                SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), msg.getValue(), msgListUser, 1);
+
+                if (tbIndent.getOrderId() != null) {
+                    TbOrder order = appOrderService.getById(tbIndent.getOrderId());
+                    String shopTemplate = commonInfoService.findOne(354).getValue();
+                    List<String> msgListShop = new ArrayList<>();
+                    msgListShop.add(tbIndent.getIndentNumber());
+                    msgListShop.add("骑手接单");
+                    msgListShop.add(DateUtils.format(new Date()));
+                    GoodsShop goodsShop = goodsShopDao.selectById(order.getShopId());
+                    UserEntity shopUser = userService.selectUserById(goodsShop.getUserId());
+
+                    SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+                }
+            } catch (Exception e) {
+                log.error("订单编号:{},骑手接单成功信息发送失败,失败原因:{}", tbIndent.getIndentNumber(), e);
             }
-            return Result.success();
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.error("骑手接单 异常:" + e.getMessage(), e);
-        }
-        return Result.error("系统繁忙,请稍后再试!");
+        });
     }
 
     @Override
@@ -1109,14 +1117,17 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     //region
     @Override
     public Result orderRiderDelivery(Long userId, OrderRiderDeliveryDTO orderDeliveryDTO) {
-        // 添加拍照发短信逻辑
-        // 因为原有的确认送达方法代码比较凌乱,且不好重新封装,所以这里就在原有确认收货方法之前添加拍照发短信逻辑
         String acquireCode = orderDeliveryDTO.getAcquireCode();
         TbIndent indentOrder = tbIndentDao.findIndentByOrderId(acquireCode);
         if (ObjectUtil.isNull(indentOrder)) {
             throw new SqxException("扫码无效的跑腿订单id");
         }
 
+        // 判断是否为当前骑手订单
+        if (indentOrder.getRiderUserId() != userId) {
+            throw new SqxException("不能完成非本人订单!");
+        }
+
         // 如果是外卖订单
         if (ObjectUtil.equal(indentOrder.getIndentType(), "5")) {
             orderHandTakeoutOrder(indentOrder, userId, orderDeliveryDTO);
@@ -1125,14 +1136,23 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         RLock lock = redissonClient.getLock(String.format(RedisKey.UPDATE_INDENT_LOCK, indentOrder.getIndentNumber()));
         lock.lock();
         try {
+            indentOrder = tbIndentDao.selectById(indentOrder.getIndentId());
 
-            return orderFinshOrder(userId, indentOrder.getIndentNumber());
+            // 4:骑手已取货/购买 只有订单在4状态下才可以完成订单
+            if (!"4".equals(indentOrder.getIndentState())) {
+                throw new SqxException("订单状态已变更,请刷新页面后重试!");
+            }
+
+            log.info("骑手通过收单码完成订单:订单id【{}】", indentOrder.getOrderId());
+            appOrderService.accomplishOrder(indentOrder.getOrderId(), 1);
         } catch (Exception e) {
-            log.error("完成订单异常:" + e.getMessage(), e);
+            log.error("完成订单异常:{}", e.getMessage(), e);
             throw new SqxException(e.getMessage());
         } finally {
             lock.unlock();
         }
+
+        return Result.success();
     }
 
     /**
@@ -1143,41 +1163,21 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
      * @param deliveryDTO 送达信息
      */
     private void orderHandTakeoutOrder(TbIndent indentOrder, Long userId, OrderRiderDeliveryDTO deliveryDTO) {
-        // 6表示跑腿订单处于已完成状态
-        if ("6".equals(indentOrder.getIndentState())) {
-            return;
-        }
-
         Long smsTemplateId = deliveryDTO.getSmsTemplateId();
-        //String imgs = deliveryDTO.getImgs();
         if (ObjectUtil.isNull(smsTemplateId)) {
             throw new SqxException("短信模板id不能为空");
         }
 
-        // 收货人手机
-        String userPhone = indentOrder.getUserPhone();
-        // 当前骑手
-        UserEntity riderUser = userService.getById(userId);
-
-        if (StrUtil.isBlank(userPhone)) {
-            log.error("外卖跑腿订单【{}】收货人手机号码为空...", indentOrder.getIndentNumber());
-            return;
-        }
-
-        if (ObjectUtil.isNull(riderUser) || StrUtil.isBlank(riderUser.getPhone())) {
-            log.error("外卖跑腿订单【{}】当前骑手id【{}】骑手不存在,或当前骑手手机号码为空...", indentOrder.getIndentNumber(), userId);
-            return;
-        }
-
-        // 订单新增送达图片
-//        TbOrder tbOrder = appOrderService.getById(indentOrder.getOrderId());
-//        tbOrder.setDeliveryImgs(imgs);
-//        appOrderService.updateById(tbOrder);
         MyGlobalThreadPool.execute(() -> {
             try {
+                // 收货人手机
+                String userPhone = indentOrder.getUserPhone();
+                // 当前骑手
+                UserEntity riderUser = userService.selectUserById(userId);
+
                 // 发送短信并记录短信发送记录
-                TbIndentSmsSendLog tbIndentSmsSendLog=smsSendLogService.getSendSuccessByOrderId(indentOrder.getIndentId());
-                if(tbIndentSmsSendLog!=null){
+                TbIndentSmsSendLog tbIndentSmsSendLog = smsSendLogService.getSendSuccessByOrderId(indentOrder.getIndentId());
+                if(tbIndentSmsSendLog != null){
                     log.error("外卖跑腿订单id【{}】短信已发送成功,短信id【{}】",tbIndentSmsSendLog.getOrderId(),tbIndentSmsSendLog.getId());
                     return;
                 }
@@ -1188,28 +1188,6 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 log.error("订单:{},完成跑腿订单成功通知发送失败,失败原因:{}", e);
             }
         });
-
-    }
-
-    @Transactional
-    public Result orderFinshOrder(Long userId, String indentNumber) {
-        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
-        TbIndent indentByNumber = tbIndentDao.findIndentByNumber(indentNumber);
-        if ("6".equals(indentByNumber.getIndentState())) {
-            return Result.success();
-        }
-        if ("4".equals(indentByNumber.getIndentState())) {
-            if ("5".equals(indentByNumber.getIndentType())) {
-                log.info("骑手完成订单1:" + indentByNumber.getOrderId());
-                appOrderService.accomplishOrder(indentByNumber.getOrderId());
-            } else {
-                tbIndentDao.riderDelivery(indentByNumber.getIndentId(), date);
-                finshIndent(userId, indentNumber);
-            }
-
-            return Result.success();
-        }
-        return Result.error("订单已完成!");
     }
     //endregion
 
@@ -1225,6 +1203,16 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         appOrderService.updateById(tbOrder);
     }
 
+    @Override
+    public TbIndent getByOrderId(String orderId) {
+        // 根据收单码查询订单
+        TbIndent tbIndent = tbIndentDao.findIndentByOrderId(orderId);
+        if (ObjectUtil.isNull(tbIndent)) {
+            throw new SqxException("无效的收单码");
+        }
+        return tbIndent;
+    }
+
     @Transactional
     @Override
     public Result riderCancleIndent(String indentNumber, Integer type) {
@@ -1406,7 +1394,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         if ("4".equals(indentByNumber.getIndentState())) {
             if ("5".equals(indentByNumber.getIndentType())) {
                 log.info("骑手完成订单2:" + indentByNumber.getOrderId());
-                appOrderService.accomplishOrder(indentByNumber.getOrderId());
+                appOrderService.accomplishOrder(indentByNumber.getOrderId(), 1);
             } else {
                 if (indentByNumber.getItemCodeFlag() != null && indentByNumber.getItemCodeFlag() == 0) {
                     if (indentByNumber.getOrderCode().equals(itemCode)) {
@@ -1437,7 +1425,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             tbIndentDao.userDelivery(userId, indentNumber, date);
             finshIndent(userId, indentNumber);
             log.info("操作完成订单5:" + indentByNumber.getOrderId());
-            appOrderService.accomplishOrders(indentByNumber.getOrderId(), 1);
+            appOrderService.accomplishOrder(indentByNumber.getOrderId(), 1);
             return Result.success();
         } finally {
             lock.unlock();
@@ -1472,7 +1460,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         UserEntity userMessage = userService.selectUserById(tbIndent.getRiderUserId());
         BigDecimal balance = userMessage.getBalance().add(tbIndent.getRiderMoney());
         tbIndentDao.updateRiderBalance(balance, tbIndent.getRiderUserId());
-        //将接单明细添加到钱包明细表里
+        // 将接单明细添加到钱包明细表里
         UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
         userMoneyDetails.setMoney(tbIndent.getRiderMoney());
         userMoneyDetails.setUserId(tbIndent.getRiderUserId());
@@ -1483,7 +1471,6 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         userMoneyDetails.setState(2);
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
-        //tbIndentDao.insertUserMoneyDetails(userMoneyDetails.getUserId(), userMoneyDetails.getTitle(), userMoneyDetails.getType(), userMoneyDetails.getMoney(), userMoneyDetails.getContent(), userMoneyDetails.getCreateTime());
         userMoneyDetailsService.save(userMoneyDetails);
 
         MyGlobalThreadPool.execute(() -> {
@@ -1500,7 +1487,6 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
             }
         });
-
     }
 
     @Override
@@ -1990,18 +1976,10 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 
     @Override
     public PageUtils selectIndentPage(Integer page, Integer limit, String acquireCode, Long userId) {
-        List<Integer> states = new ArrayList<>();
-        states.add(2);
-        states.add(3);
-        states.add(4);
         IPage<TbIndent> pages = new Page<>(page, limit);
         QueryWrapper<TbIndent> queryWrapper = new QueryWrapper();
-        queryWrapper.like(StrUtil.isNotBlank(acquireCode), "order_id", acquireCode);
-        queryWrapper.in("indent_state", states);
-        queryWrapper.and(qw -> qw.isNull("rider_user_id").or().eq("rider_user_id", userId));
-        queryWrapper.orderByAsc("create_time");
+        queryWrapper.eq("order_id", acquireCode);
         IPage<TbIndent> result = baseMapper.selectPage(pages, queryWrapper);
-
         return new PageUtils(result);
     }
 

+ 2 - 2
src/main/java/com/sqx/modules/order/controller/app/AppOrderController.java

@@ -222,8 +222,8 @@ public class AppOrderController {
     @ApiOperation("用户选择完成订单")
     @PostMapping(value = "accomplishOrder")
     public Result accomplishOrder(Long orderId){
-        log.info("操作完成订单3:"+orderId);
-        return appOrderService.accomplishOrder( orderId);
+        log.info("操作完成订单3:{}", orderId);
+        return appOrderService.accomplishOrder( orderId, 1);
     }
 
     @Login

+ 1 - 4
src/main/java/com/sqx/modules/order/service/AppOrderService.java

@@ -65,10 +65,7 @@ public interface AppOrderService extends IService<TbOrder> {
 
     Result adminCancelOrder(Long orderId);
 
-    Result accomplishOrder(Long orderId);
-
-
-    Result accomplishOrders(Long orderId, Integer type);
+    Result accomplishOrder(Long orderId, Integer type);
 
     Result insertEvaluate(Evaluate evaluate);
 

+ 92 - 130
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -20,7 +20,12 @@ import com.github.wxpay.sdk.WXPay;
 import com.sqx.common.constant.RedisKey;
 import com.sqx.common.exception.SqxException;
 import com.sqx.common.sms.SmsSendResult;
-import com.sqx.common.utils.*;
+import com.sqx.common.utils.Constant;
+import com.sqx.common.utils.DateUtils;
+import com.sqx.common.utils.DistanceUtil;
+import com.sqx.common.utils.MyGlobalThreadPool;
+import com.sqx.common.utils.PageUtils;
+import com.sqx.common.utils.Result;
 import com.sqx.modules.activity.entity.ActivityPartRecord;
 import com.sqx.modules.activity.service.ActivityPartRecordService;
 import com.sqx.modules.activity.service.ActivityService;
@@ -114,7 +119,12 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @Service
 @Slf4j
@@ -784,7 +794,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             }
 
             log.info("商户自配完成订单:{},订单状态:{}", orderId, order.getStatus());
-            accomplishOrder(orderId);
+            accomplishOrder(orderId, 1);
         } finally {
             lock.unlock();
         }
@@ -1860,7 +1870,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
                 return Result.success();
             }
             log.info("操作完成订单4:" + order.getOrderId());
-            Result result = this.accomplishOrder(order.getOrderId());
+            Result result = this.accomplishOrder(order.getOrderId(), 1);
             if ("500".equals(String.valueOf(result.get("code")))) {
                 return result;
             }
@@ -2009,12 +2019,28 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         }
     }
 
+    /**
+     * @param orderId
+     * @param type    1用户操作 2自动任务超时直接完成订单
+     * @return
+     */
     @Override
-    public Result accomplishOrder(Long orderId) {
+    public Result accomplishOrder(Long orderId, Integer type) {
+        TransactionStatus status = null;
         RLock lock = redissonClient.getLock(String.format(RedisKey.FINISH_ORDER_LOCK, orderId));
         lock.lock();
         try {
-            return accomplishOrders(orderId, 1);
+            status = transactionManager.getTransaction(new DefaultTransactionDefinition());
+
+            Result result = doAccomplishOrders(orderId, type);
+
+            transactionManager.commit(status);
+            return result;
+        } catch (Exception e) {
+            if (ObjectUtil.isNotNull(status)) {
+                transactionManager.rollback(status);
+            }
+            throw e;
         } finally {
             lock.unlock();
         }
@@ -2025,15 +2051,12 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
      * @param type    1用户操作 2自动任务超时直接完成订单
      * @return
      */
-    @Transactional
-    @Override
-    public Result accomplishOrders(Long orderId, Integer type) {
-        log.info("订单id:" + orderId + ",类型:" + type);
+    public Result doAccomplishOrders(Long orderId, Integer type) {
+        log.info("订单id:{},类型:{}", orderId, type);
         TbOrder tbOrder = appOrderDao.selectById(orderId);
-        log.info("订单状态 :" + tbOrder.getStatus());
         if (tbOrder.getStatus().equals(4)) {
-            log.info("订单id【{}】,订单状态为【4】,属于已完成状态,直接返回", orderId);
-            log.info("订单id【{}】,accomplishOrders逻辑执行完成", orderId);
+            log.warn("订单id【{}】,订单状态为【4】,属于已完成状态,直接返回", orderId);
+            log.warn("订单id【{}】,accomplishOrders逻辑执行完成", orderId);
             return Result.success();
         }
         String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
@@ -2041,31 +2064,27 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder().equals(0)) {
             if (type == 1) {
                 if (indent == null || !"4".equals(indent.getIndentState())) {
-                    log.info("订单id【{}】,请等待骑手送达!", orderId);
+                    log.warn("订单id【{}】,请等待骑手送达!", orderId);
                     return Result.error("请等待骑手送达!");
                 }
             }
 
-            tbOrder.setStatus(4);
-            appOrderDao.updateById(tbOrder);
-            //修改跑腿订单的状态和给骑手佣金
-            indent.setIndentState("6");
-            indent.setFinishTime(DateUtils.format(new Date()));
-            tbIndentService.updateById(indent);
-            tbIndentService.finshIndent(tbOrder.getUserId(), indent.getIndentNumber());
-        } else {
-            if (tbOrder.getStatus().equals(4)) {
-                return Result.success();
-            }
+            // 修改跑腿订单的状态和给骑手佣金
+            TbIndent newTbIndent = new TbIndent();
+            newTbIndent.setIndentId(indent.getIndentId());
+            newTbIndent.setIndentState("6");
+            newTbIndent.setFinishTime(DateUtils.format(new Date()));
+            tbIndentService.updateById(newTbIndent);
 
-            tbOrder.setStatus(4);
-            appOrderDao.updateById(tbOrder);
+            tbIndentService.finshIndent(tbOrder.getUserId(), indent.getIndentNumber());
         }
 
+        tbOrder.setStatus(4);
         log.info("订单id【{}】,开始计算商户应得金额", orderId);
 
         GoodsShop goodsShop = shopMessageService.selectShopId(tbOrder.getShopId());
-        //计算商户应得金额
+
+        // 计算商户应得金额
         BigDecimal shopRate = goodsShop.getShopRate();
         BigDecimal sumMoney = tbOrder.getPayMoney();
         BigDecimal couponMoney = BigDecimal.ZERO;
@@ -2082,9 +2101,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             //判断是否达到商家满减  如果达到商家满减 跑腿费让商家承担
             if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 0) {
                 errandMoney = tbOrder.getErrandMoney();
-                /*if(!"本单已达到商家满减金额,跑腿费由商家承担".equals(tbOrder.getErrandMoneyIsShop())){
-                    sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
-                }*/
                 sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
             } else {
                 sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
@@ -2114,7 +2130,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             }
         }
 
-        //这里再判断 是否是商家优惠券  如果是商家优惠券  这笔钱商家承担
+        // 这里再判断 是否是商家优惠券  如果是商家优惠券  这笔钱商家承担
         if (shopIds != -1 && shopIds != 0) {
             shopMoney = shopMoney.subtract(couponMoney);
         }
@@ -2141,16 +2157,15 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         appOrderDao.updateById(tbOrder);
         log.info("订单id【{}】,商户应得金额计算完毕", orderId);
         log.info("订单id【{}】,开始添加商户用户钱包收入记录", orderId);
-        //添加商户用户钱包收入记录
+
+        // 添加商户用户钱包收入记录
         UserMoneyDetails userMoneyDetails1 = new UserMoneyDetails();
         userMoneyDetails1.setShopId(goodsShop.getShopId());
         userMoneyDetails1.setTitle("商户订单收入,订单号:" + tbOrder.getOrderNumber());
-//        userMoneyDetails1.setContent("商户本单收入金额:" + shopMoney + "元");
 
         StringBuffer contentBuffer = new StringBuffer();
         // 订单金额
         BigDecimal orderAmount = tbOrder.getPayMoney().add(couponMoney).add(activityDiscountAmount);
-
         contentBuffer.append("订单金额:").append(orderAmount.setScale(2, BigDecimal.ROUND_DOWN));
         if (!couponMoney.equals(BigDecimal.ZERO)) {
             contentBuffer.append(",优惠券金额:").append(couponMoney.setScale(2, BigDecimal.ROUND_DOWN));
@@ -2174,53 +2189,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         } else if (shopIds != -1) {
             contentBuffer.append("(本单为商家优惠券,商家补贴)");
         }
-        //计算积分
-        String flag = commonInfoService.findOne(436).getValue();
-        if ("1".equals(flag)) {
-            try {
-                UserIntegralDetails userIntegralDetails = new UserIntegralDetails();
-                String rules = commonInfoService.findOne(437).getValue();
-                //积分过期规则 -1永不过期
-//                String overdue= commonInfoService.findOne(438).getValue();
-                String maxIntegral = commonInfoService.findOne(439).getValue();
-                String[] split = rules.split(",", 5);
-                int am1 = Integer.parseInt(split[0]);
-                int av1 = Integer.parseInt(split[1]);
-                int mx = Integer.parseInt(split[2]);
-                int am2 = Integer.parseInt(split[3]);
-                int av2 = Integer.parseInt(split[4]);
-                double amount = tbOrder.getPayMoney().doubleValue();
-                int intergral = 0;
-                if (amount > am1) {
-                    if (amount < mx) {
-                        intergral = intergral + (int) (amount / am1) * av1;
-                    } else if (amount >= mx + am2) {
-                        int count = (int) ((amount - mx) / am2);
-                        intergral = intergral + (mx / am1) * av1 + count * av2;
-                    } else {
-                        intergral = intergral + (mx / am1) * av1;
-                    }
-                }
-                int max = Math.min(Integer.parseInt(maxIntegral), intergral);
-                userIntegralDetails.setContent("完成订单获得积分");
-                userIntegralDetails.setClassify(4);
-                userIntegralDetails.setType(1);
-                userIntegralDetails.setNum(max);
-                userIntegralDetails.setOrderNumber(tbOrder.getOrderNumber());
-//                if(!"-1".equals(overdue)){
-//                     Date expdata=DateUtils.addDateDays(new Date(), Integer.parseInt(overdue));
-//                    userIntegralDetails.setExpTime(new SimpleDateFormat("yyyy-MM-dd").format(expdata));
-//                }
-
-                userIntegralDetails.setCreateTime(format);
-                userIntegralDetails.setUserId(tbOrder.getUserId());
-                userIntegralDetailsDao.insert(userIntegralDetails);
-                //添加积分
-                userIntegralDao.addUserIntegral(max, tbOrder.getUserId());
-            } catch (NumberFormatException e) {
-                log.error("订单{}====积分入账异常{}", orderId, e.getMessage());
-            }
-        }
 
         userMoneyDetails1.setContent(contentBuffer.toString());
 
@@ -2238,6 +2206,48 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
 
         MyGlobalThreadPool.execute(() -> {
             try {
+                // 计算积分
+                String flag = commonInfoService.findOne(436).getValue();
+                if ("1".equals(flag)) {
+                    try {
+                        UserIntegralDetails userIntegralDetails = new UserIntegralDetails();
+                        String rules = commonInfoService.findOne(437).getValue();
+                        String maxIntegral = commonInfoService.findOne(439).getValue();
+                        String[] split = rules.split(",", 5);
+                        int am1 = Integer.parseInt(split[0]);
+                        int av1 = Integer.parseInt(split[1]);
+                        int mx = Integer.parseInt(split[2]);
+                        int am2 = Integer.parseInt(split[3]);
+                        int av2 = Integer.parseInt(split[4]);
+                        double amount = tbOrder.getPayMoney().doubleValue();
+                        int intergral = 0;
+                        if (amount > am1) {
+                            if (amount < mx) {
+                                intergral = intergral + (int) (amount / am1) * av1;
+                            } else if (amount >= mx + am2) {
+                                int count = (int) ((amount - mx) / am2);
+                                intergral = intergral + (mx / am1) * av1 + count * av2;
+                            } else {
+                                intergral = intergral + (mx / am1) * av1;
+                            }
+                        }
+                        int max = Math.min(Integer.parseInt(maxIntegral), intergral);
+                        userIntegralDetails.setContent("完成订单获得积分");
+                        userIntegralDetails.setClassify(4);
+                        userIntegralDetails.setType(1);
+                        userIntegralDetails.setNum(max);
+                        userIntegralDetails.setOrderNumber(tbOrder.getOrderNumber());
+
+                        userIntegralDetails.setCreateTime(format);
+                        userIntegralDetails.setUserId(tbOrder.getUserId());
+                        userIntegralDetailsDao.insert(userIntegralDetails);
+                        // 添加积分
+                        userIntegralDao.addUserIntegral(max, tbOrder.getUserId());
+                    } catch (NumberFormatException e) {
+                        log.error("订单{}====积分入账异常{}", orderId, e.getMessage());
+                    }
+                }
+
                 // 用户通知
                 MessageInfo messageInfo = new MessageInfo();
                 messageInfo.setTitle("订单完成");
@@ -2258,7 +2268,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
                 UserEntity userEntity = userDao.selectById(tbOrder.getUserId());
 
                 SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 1);
-                // userService.pushToSingle("订单完成", "您的订单已完成,欢迎下次光临!", userEntity.getClientid());
 
                 // 商家通知
                 String shopTemplate = commonInfoService.findOne(354).getValue();
@@ -2277,53 +2286,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         return Result.success();
     }
 
-    // @Scheduled(cron = "0 */10 * * * ?")
-    // public void orderEnd() {
-    //     CommonInfo one = commonInfoService.findOne(268);
-    //     DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-    //     List<TbOrder> orderList = appOrderDao.selectList(new QueryWrapper<TbOrder>().eq("status", 3));
-    //     for (TbOrder tbOrder : orderList) {
-    //         LocalDateTime updateTime = LocalDateTime.parse(tbOrder.getUpdateTime(), df);
-    //         //计算当前订单什么时候超时完成
-    //         LocalDateTime overDateTime = updateTime.plusHours(Integer.parseInt(one.getValue()));
-    //         if (LocalDateTime.now().isAfter(overDateTime)) {
-    //             log.info("操作完成订单6:"+tbOrder.getOrderId());
-    //             accomplishOrders(tbOrder.getOrderId(),2);
-    //             //管理端完成订单,则消息通知用户
-    //             //添加消息记录
-    //             MessageInfo messageInfo = new MessageInfo();
-    //             messageInfo.setState(String.valueOf(5));
-    //             messageInfo.setTitle("订单完成");
-    //             messageInfo.setContent("您的订单已完成,欢迎下次光临");
-    //             messageInfo.setCreateAt(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-    //             messageInfo.setUserId(tbOrder.getUserId().toString());
-    //             messageInfoDao.insert(messageInfo);
-    //             //设置小程序消息推送
-    //             CommonInfo one1 = commonInfoService.findOne(269);
-    //             List<String> msgList = new ArrayList<>();
-    //             Long shopId = tbOrder.getShopId();
-    //             GoodsShop goodsShop = goodsShopDao.selectById(shopId);
-    //             String orderNum1 = tbOrder.getOrderNumber();
-    //             msgList.add("订单完成");
-    //             msgList.add(orderNum1);
-    //             if (goodsShop != null && goodsShop.getShopName() != null) {
-    //                 String shopName = goodsShop.getShopName();
-    //                 msgList.add(shopName);
-    //             } else {
-    //                 msgList.add("");
-    //             }
-    //             msgList.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-    //             UserEntity userEntity = userDao.selectById(tbOrder.getUserId());
-    //             if (userEntity != null && userEntity.getOpenId() != null) {
-    //                 SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one1.getValue(), msgList, 1);
-    //                 userService.pushToSingle("订单完成", "亲爱的用户您好,您的订单已完成,欢迎下次光临!", userEntity.getClientid());
-    //             }
-    //
-    //         }
-    //
-    //     }
-    // }
-
     @Transactional
     @Override
     public Result insertEvaluate(Evaluate evaluate) {

+ 7 - 3
src/main/java/com/sqx/scheduler/order/OrderScheduler.java

@@ -2,7 +2,6 @@ package com.sqx.scheduler.order;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.ekyong.www.pay.pay.qrcode.api.RhtQrcodePayApi;
@@ -29,7 +28,12 @@ import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -160,7 +164,7 @@ public class OrderScheduler {
                     LocalDateTime overDateTime = updateTime.plusHours(Integer.parseInt(one.getValue()));
                     if (LocalDateTime.now().isAfter(overDateTime)) {
                         log.info("订单id:{},开始自动完成", order.getOrderId());
-                        orderService.accomplishOrders(order.getOrderId(),2);
+                        orderService.accomplishOrder(order.getOrderId(), 2);
                         log.info("订单id:{},完成自动完成", order.getOrderId());
                     }
                 } catch (Exception e) {