jiangqs
2023-07-07 5627daeb1ac1a29947e902f9a7efb6730ed98611
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/activity/ActivityServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.goods.service.impl.activity;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
@@ -14,14 +15,16 @@
import com.ruoyi.goods.domain.vo.*;
import com.ruoyi.goods.mapper.activity.ActivityMapper;
import com.ruoyi.goods.service.activity.ActivityGoodsService;
import com.ruoyi.goods.service.activity.ActivityRecordService;
import com.ruoyi.goods.service.activity.ActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.goods.service.activity.ActivityTotalService;
import com.ruoyi.system.api.constant.AppErrorConstant;
import com.ruoyi.system.api.domain.dto.ActivityGoodsGetDto;
import com.ruoyi.system.api.domain.dto.MerPageDto;
import com.ruoyi.system.api.domain.dto.MgtBaseBathDto;
import com.ruoyi.system.api.domain.dto.MgtUserIdByKeywordDto;
import com.ruoyi.system.api.domain.poji.activity.ActivityGoods;
import com.ruoyi.system.api.domain.vo.ActivityGoodsGetVo;
import com.ruoyi.system.api.domain.vo.MgtSimpleMemberVo;
import com.ruoyi.system.api.domain.vo.MgtSimpleShopVo;
import com.ruoyi.system.api.domain.vo.MgtUserIdByKeywordVo;
@@ -57,6 +60,9 @@
    @Resource
    private ActivityTotalService activityTotalService;
    @Resource
    private ActivityRecordService activityRecordService;
    @Resource
    private RemoteShopService remoteShopService;
@@ -145,6 +151,8 @@
                        activityGoods.setActivityNumber(dto.getActivityNumber());
                        activityGoods.setActivityDeadline(activity.getActivityEndTime());
                        activityGoods.setSellOutFlag(0);
                        activityGoods.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag());
                        activityGoods.setLimitNumber(activity.getLimitNumber());
                        return activityGoods;
                    }
            ).collect(Collectors.toList());
@@ -266,4 +274,84 @@
        List<MerActivityPageVo> activityPageVoList = activityMapper.pagePlatformMerActivity(page, merPageDto);
        return activityPageVoList;
    }
    /**
     * @description  获取活动列表
     * @author  jqs
     * @date    2023/7/4 15:31
     * @param
     * @return  List<MgtActivityListVo>
     */
    @Override
    public List<MgtActivityListVo> listMgtActivity(){
        return activityMapper.listMgtActivity();
    }
    /**
     * @description  获取商户推荐活动
     * @author  jqs
     * @date    2023/7/4 18:14
     * @param shopId
     * @return  Activity
     */
    @Override
    public Activity getRecommendActivity(Long shopId){
        return activityMapper.getRecommendActivity(shopId);
    }
    /**
     * @description  获取商户参与活动id
     * @author  jqs
     * @date    2023/7/4 19:55
     * @param shopId
     * @return  List<Long>
     */
    @Override
    public List<String> listActivityIdByShopId(Long shopId){
        return activityMapper.listActivityIdByShopId(shopId);
    }
    /**
     * @description  分页获取活动列表
     * @author  jqs
     * @date    2023/7/5 18:45
     * @param page
     * @param shopId
     * @return  List<AppActivityPageVo>
     */
    @Override
    public List<AppActivityPageVo> pageAppActivity(Page page, Long shopId){
        return activityMapper.pageAppActivity(page, shopId);
    }
    /**
     * @description  获取用户活动商品信息
     * @author  jqs
     * @date    2023/7/6 16:18
     * @param activityGoodsGetDto
     * @return  ActivityGoodsGetVo
     */
    @Override
    public ActivityGoodsGetVo getUserActivityGoods(ActivityGoodsGetDto activityGoodsGetDto){
        ActivityGoodsGetVo activityGoodsGetVo = new ActivityGoodsGetVo();
        String activityId = activityGoodsGetDto.getActivityId();
        String goodsId = activityGoodsGetDto.getGoodsId();
        Activity activity = this.getById(activityId);
        ActivityGoods activityGoods = activityGoodsService.getByGoodsId(activityId,goodsId);
        activityGoodsGetVo.setActivityPrice(activityGoods.getActivityPrice());
        activityGoodsGetVo.setActivitySubscription(activityGoods.getActivitySubscription());
        activityGoodsGetVo.setActivityStatus(activity.getActivityStatus());
        Integer availableBuyNum = activityGoods.getActivityNumber() - activityGoods.getSalesNumber();
        //限购判断
        if(activityGoods.getPurchaseLimitationFlag()==1){
            Integer buyNum = activityRecordService.getUserActivityGoodsNum(goodsId,activityId,activityGoodsGetDto.getUserId());
            Integer limitBuyNum = activityGoods.getLimitNumber() - buyNum;
            if(limitBuyNum<availableBuyNum){
                availableBuyNum = limitBuyNum;
            }
        }
        activityGoodsGetVo.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag());
        activityGoodsGetVo.setAvailableBuyNum(availableBuyNum);
        return activityGoodsGetVo;
    }
}