Pu Zhibing
2024-09-23 e49f212c5ae9c5382386ddc0d34e346799720116
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -16,10 +16,15 @@
import com.github.binarywang.wxpay.service.WxPayService;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.UserStatus;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.ip.IpUtils;
import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.CodeFactoryUtil;
@@ -60,6 +65,8 @@
import com.ruoyi.system.api.domain.poji.shop.Shop;
import com.ruoyi.system.api.domain.poji.sys.SysUser;
import com.ruoyi.system.api.domain.vo.*;
import com.ruoyi.system.api.model.QwH5LoginVo;
import com.ruoyi.system.api.model.QwUserDetailDto;
import com.ruoyi.system.api.service.*;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.log4j.Log4j2;
@@ -156,6 +163,7 @@
    @Value("${wx.pay.callbackPath}")
    private String callbackPath;
    /**
@@ -359,58 +367,6 @@
                sureOrderGoodsVo.setAppMemberCouponVoList(appGoodsMemberCouponVoList);
            }
        }
        /*if (appMemberCouponVoList != null && !appMemberCouponVoList.isEmpty()) {
            // 获取商品关联优惠券
            appGoodsMemberCouponVoList = new ArrayList<>();
            for(AppSureOrderGoodsVo sureOrderGoodsVo : appSureOrderGoodsVoList){
                for (AppMemberCouponVo entity : appMemberCouponVoList) {
                    if (StringUtils.isBlank(entity.getRelGoodsIds())) {
                        if (entity.getCouponType() == 1 && entity.getMoneyThreshold() != null && entity.getDiscountMoney() != null) {
                            moneyThreshold = entity.getMoneyThreshold();
                            if (sureOrderGoodsVo.getGoodsTotalPrice().compareTo(moneyThreshold) >= 0) {
                                if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){
                                    appGoodsMemberCouponVoList.add(entity);
                                }else{
                                    if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){
                                        appGoodsMemberCouponVoList.add(entity);
                                    }
                                }
                            }
                        }else{
                            if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){
                                appGoodsMemberCouponVoList.add(entity);
                            }else{
                                if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){
                                    appGoodsMemberCouponVoList.add(entity);
                                }
                            }
                        }
                    } else if (entity.getRelGoodsIds().contains(sureOrderGoodsVo.getGoodsId())) {
                        if (entity.getCouponType() == 1 && entity.getMoneyThreshold() != null && entity.getDiscountMoney() != null) {
                            moneyThreshold = entity.getMoneyThreshold();
                            if (sureOrderGoodsVo.getGoodsTotalPrice().compareTo(moneyThreshold) >= 0) {
                                if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){
                                    appGoodsMemberCouponVoList.add(entity);
                                }else{
                                    if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){
                                        appGoodsMemberCouponVoList.add(entity);
                                    }
                                }
                            }
                        }else{
                            if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){
                                appGoodsMemberCouponVoList.add(entity);
                            }else{
                                if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){
                                    appGoodsMemberCouponVoList.add(entity);
                                }
                            }
                        }
                    }
                }
                sureOrderGoodsVo.setAppMemberCouponVoList(appGoodsMemberCouponVoList);
            }
        }*/
        // 设置订单相关金额
        appSureOrderVo.setOrderGoodsMoney(orderGoodsMoney);
        appSureOrderVo.setCouponDiscount(couponDiscount);
@@ -640,6 +596,9 @@
            // 如果使用了优惠券,计算优惠后的价格
            if (memberCouponId != null) {
                appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId.toString());
                if(null == appMemberCouponVo){
                    throw new ServiceException("优惠券已使用");
                }
                // 如果优惠券适用于该商品
                if (StringUtils.isBlank(appMemberCouponVo.getRelGoodsIds()) || appMemberCouponVo.getRelGoodsIds().contains(goodsId)) {
                    couponType = appMemberCouponVo.getCouponType();
@@ -1616,7 +1575,64 @@
     */
    @Override
    public MerHomeShopTotalVo getMerHomeTotal(MerHomeShopTotalVo merHomeShopTotalVo) {
        Long shopId = merHomeShopTotalVo.getShopId();
        // 查询用户信息
        QwUserDetailDto qwUserDetail = new QwUserDetailDto();
        Long userId = SecurityUtils.getUserId();
        qwUserDetail.setUserid(userId.toString());
        // 查询用户信息
        R<QwH5LoginVo> userResult = remoteShopService.qwH5Login(qwUserDetail);
        if(userResult==null){
            throw new ServiceException(AppErrorConstant.USER_NO_SHOP);
        }
        if (R.FAIL == userResult.getCode())
        {
            throw new ServiceException(userResult.getMsg());
        }
        if (401 == userResult.getCode())
        {
            throw new ServiceException("商户已被冻结,请联系管理员",401);
        }
        QwH5LoginVo userInfo = userResult.getData();
        SysUser user = userInfo.getSysUser();
        String username = user.getUserName();
        // IP黑名单校验
        String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
        if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
        {
            throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
        }
        if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
        {
            throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
        }
        if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
        {
            throw new ServiceException("对不起,您的账号:" + username + " 已停用");
        }
        // 查询用户商户
        R<ShopRelUserVo> shopResult = remoteShopService.getShopByUserId(user.getUserId());
        if (R.FAIL == userResult.getCode()) {
            throw new ServiceException(userResult.getMsg());
        }
        ShopRelUserVo shopInfo = shopResult.getData();
        if(null == shopInfo){
            throw new ServiceException("未查询到商户信息");
        }
        Long shopId = shopInfo.getShopId();
        Shop shop = remoteShopService.getShop(shopId).getData();
        if(-1 == shop.getShopStatus()){
            throw new ServiceException("对应商户已删除,请联系管理员");
        }
        if(0 == shop.getShopStatus()){
            throw new ServiceException("对应商户已冻结,请联系管理员");
        }
        if(2 == shop.getShopStatus()){
            throw new ServiceException("对应商户已终止合作,请联系管理员");
        }
        shopId = merHomeShopTotalVo.getShopId();
        //获取今日到店
        Integer todayShop = userServiceRecordService.countShopServicePerson(shopId);
        //获取待处理订单和营业额