Pu Zhibing
2025-01-01 e0623f1a914ecbc99d5926c0df3cf26032c02499
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/CouponInfoController.java
@@ -25,6 +25,7 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -74,11 +75,11 @@
    @ApiOperation(value = "优惠劵管理-详情", tags = {"管理后台-活动管理"})
    public R<CouponInfo> detail(@RequestParam("id") Integer id) {
        CouponInfo byId = couponInfoService.getById(id);
        byId.setGoodsNameList(JSON.parseArray(byId.getGoodsNameJson(), String.class));
        String forGoodIds = byId.getForGoodIds();
        if (StringUtils.isNotEmpty(forGoodIds)){
        if (!"-1".equals(forGoodIds) && StringUtils.isNotEmpty(forGoodIds)){
            List<Goods> goods = goodsService.listByIds(Arrays.asList(forGoodIds.split(",")));
            byId.setGoods(goods);
            byId.setGoodsNameList(goods.stream().map(Goods::getName).collect(Collectors.toList()));
        }
        String personIds = byId.getPersonIds();
        if (StringUtils.isNotEmpty(personIds)){
@@ -104,6 +105,11 @@
    public R<Void> edit(@RequestBody CouponInfo couponInfo) {
        List<String> goodsNameList = couponInfo.getGoodsNameList();
        couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList));
        if(couponInfo.getPeriodType() == 2){
            Integer periodDays = couponInfo.getPeriodDays();
            couponInfo.setPeriodStartTime(LocalDate.now());
            couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays));
        }
        couponInfoService.updateById(couponInfo);
        return R.ok();
    }
@@ -128,6 +134,11 @@
        List<String> goodsNameList = couponInfo.getGoodsNameList();
        couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList));
        couponInfo.setShelfStatus(1);
        if(couponInfo.getPeriodType() == 2){
            Integer periodDays = couponInfo.getPeriodDays();
            couponInfo.setPeriodStartTime(LocalDate.now());
            couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays));
        }
        couponInfoService.save(couponInfo);
        return R.ok();
    }