puzhibing
2026-09-21 008ffb622f7e8b941245a4cf19042c7baef39b24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.ruoyi.goods.controller.business;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.goods.domain.dto.MerGoodsPageDto;
import com.ruoyi.goods.domain.dto.MerShopGoodsEditDto;
import com.ruoyi.goods.domain.dto.MgtSelectGoodsPageDto;
import com.ruoyi.goods.domain.vo.MerGoodsPageVo;
import com.ruoyi.goods.service.goods.GoodsService;
import com.ruoyi.goods.service.goods.ShopGoodsService;
import com.ruoyi.system.api.domain.dto.MerBaseDto;
import com.ruoyi.system.api.domain.poji.goods.ShopGoods;
import com.ruoyi.system.api.domain.poji.shop.Shop;
import com.ruoyi.system.api.domain.vo.MgtSelectGoodsPageVo;
import com.ruoyi.system.api.service.RemoteShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @author jqs34
 * @ClassName MerGoodsController
 * @description: TODO
 * @date 2023年05月04日
 * @version: 1.0
 */
@Api(value = "商户端商品相关接口", tags = "商户端商品相关接口", description = "商户端商品相关接口")
@RestController
@RequestMapping("/mer/goods")
public class MerGoodsController {
    
    @Resource
    private GoodsService goodsService;
    
    @Resource
    private RemoteShopService remoteShopService;
    
    @Resource
    private ShopGoodsService shopGoodsService;
    
    
    @RequestMapping(value = "/pageMerShopGoods", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取商户商品列表【2.0】")
    public R<Page<MerGoodsPageVo>> pageMerShopGoods(@RequestBody MerGoodsPageDto merGoodsPageDto) {
        Long userId = SecurityUtils.getUserId();
        Page<MerGoodsPageVo> page = new Page<>();
        page.setSize(merGoodsPageDto.getPageSize());
        page.setCurrent(merGoodsPageDto.getPageNum());
        page.setOptimizeCountSql(false);
        List<MerGoodsPageVo> merGoodsPageVoList = goodsService.pageMerShopGoods(page, merGoodsPageDto);
        Shop shop = remoteShopService.getShop(merGoodsPageDto.getShopId()).getData();
        merGoodsPageVoList.forEach(merGoodsPageVo -> {
            ShopGoods shopGoods = shopGoodsService.getByShopIdAndGoodsId(merGoodsPageDto.getShopId(), merGoodsPageVo.getGoodsId());
            //经销商不限制修改价格权限
            if(1 == shop.getShopType()){
                merGoodsPageVo.setModifyPricePermission(shop.getModifyPricePermission());
                merGoodsPageVo.setIsUnifiedPrice(0);
                if (null != shopGoods) {
                    merGoodsPageVo.setIsUnifiedPrice(1);
                    merGoodsPageVo.setUnifiedPrice(shopGoods.getSalesPrice());
                    merGoodsPageVo.setUnifiedServerNum(shopGoods.getServiceNum());
                }
            }else{
                Shop shop1 = remoteShopService.getShop(shop.getBelongShopId()).getData();
                if(null == shop1){
                    merGoodsPageVo.setModifyPricePermission(1);
                    merGoodsPageVo.setIsUnifiedPrice(0);
                    if(null != shopGoods){
                        merGoodsPageVo.setUnifiedPrice(shopGoods.getSalesPrice());
                        merGoodsPageVo.setUnifiedServerNum(shopGoods.getServiceNum());
                    }
                }else{
                    ShopGoods shopGoods1 = shopGoodsService.getByShopIdAndGoodsId(shop1.getShopId(), merGoodsPageVo.getGoodsId());
                    //经销商设置了统一售价
                    if(null != shopGoods1){
                        merGoodsPageVo.setModifyPricePermission(0);
                        merGoodsPageVo.setIsUnifiedPrice(1);
                        merGoodsPageVo.setUnifiedPrice(shopGoods1.getSalesPrice());
                        merGoodsPageVo.setUnifiedServerNum(shopGoods1.getServiceNum());
                    }else{
                        merGoodsPageVo.setModifyPricePermission(1);
                        merGoodsPageVo.setIsUnifiedPrice(0);
                        if(null != shopGoods){
                            merGoodsPageVo.setUnifiedPrice(shopGoods.getSalesPrice());
                            merGoodsPageVo.setUnifiedServerNum(shopGoods.getServiceNum());
                        }
                    }
                }
            }
 
        });
        return R.ok(page.setRecords(merGoodsPageVoList));
    }
 
    @RequestMapping(value = "/listMerCycleGoods", method = RequestMethod.POST)
    @ApiOperation(value = "获取商户周期商品列表")
    public R<List<MerGoodsPageVo>> listMerCycleGoods(@RequestBody MerBaseDto merBaseDto) {
        List<MerGoodsPageVo> merGoodsPageVoList = goodsService.listMerCycleGoods(merBaseDto.getShopId());
        return R.ok(merGoodsPageVoList);
    }
    
    @RequestMapping(value = "/editMerShopGoods", method = RequestMethod.POST)
    @ApiOperation(value = "编辑商户商品价格【2.0】")
    public R editMerShopGoods(@RequestBody MerShopGoodsEditDto merShopGoodsEditDto) {
        Long userId = SecurityUtils.getUserId();
        merShopGoodsEditDto.setUserId(userId);
        goodsService.editMerShopGoods(merShopGoodsEditDto);
        return R.ok();
    }
    
    
    @RequestMapping(value = "/cancelUniformPrice", method = RequestMethod.POST)
    @ApiOperation(value = "取消统一售价【2.0】")
    public R cancelUniformPrice(@RequestBody MerShopGoodsEditDto merShopGoodsEditDto) {
        shopGoodsService.remove(new LambdaUpdateWrapper<ShopGoods>().eq(ShopGoods::getShopId, merShopGoodsEditDto.getShopId())
                .eq(ShopGoods::getGoodsId, merShopGoodsEditDto.getGoodsId()));
        return R.ok();
    }
    
    
    @RequestMapping(value = "/pageMerSelectGoods", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取商品选择列表")
    public R<Page<MgtSelectGoodsPageVo>> pageMerSelectGoods(@RequestBody MgtSelectGoodsPageDto mgtSelectGoodsPageDto) {
        Page<MgtSelectGoodsPageVo> page = new Page<>();
        page.setSize(mgtSelectGoodsPageDto.getPageSize());
        page.setCurrent(mgtSelectGoodsPageDto.getPageNum());
        page.setOptimizeCountSql(false);
        List<MgtSelectGoodsPageVo> mgtSelectGoodsPageVos = goodsService.pageMgtSelectGoods(page, mgtSelectGoodsPageDto);
        return R.ok(page.setRecords(mgtSelectGoodsPageVos));
    }
}