“mitao”
2025-12-12 0434bb26bedded4de281f0a23c8e6ca6f83a27b0
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
package com.ruoyi.web.controller.api;
 
import cn.hutool.core.util.PhoneUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUserApplet;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.TAppUser;
import com.ruoyi.system.model.TBanner;
import com.ruoyi.system.model.TBigGiftPackage;
import com.ruoyi.system.model.TPhysicalGoods;
import com.ruoyi.system.query.AppletPhysicalGoodsQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.SupervisorUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
 
@Slf4j
@RestController
@RequestMapping("/index")
@Api(tags = "首页模块")
@Validated
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class IndexController {
 
    private final TBannerService tBannerService;
    private final TAppUserService tAppUserService;
    private final TokenService tokenService;
    private final ISysUserService sysUserService;
    private final TBigGiftPackageService bigGiftPackageService;
    private final TPhysicalGoodsService physicalGoodsService;
 
    @ApiOperation("根据推广码获取上级用户信息")
    @GetMapping("/getSuperiorInfo")
    public R<SupervisorUserVO> getSuperiorInfo(@ApiParam(name = "superiorType", value = "上级类型 1:股东;2:营销员")
                                               @NotNull(message = "上级类型不能为空") @RequestParam Integer superiorType,
                                               @ApiParam(name = "spreadCode", value = "推广码")
                                               @NotNull(message = "推广码不能为空") @RequestParam String spreadCode) {
        SupervisorUserVO supervisorUserVO = new SupervisorUserVO();
        //根据上级类型获取上级用户信息
        if (superiorType.equals(1)) {
            SysUser sysUser = sysUserService.selectByCode(spreadCode);
            if (Objects.nonNull(sysUser)) {
                supervisorUserVO.setId(sysUser.getUserId().intValue());
                supervisorUserVO.setPhone((String) PhoneUtil.hideBetween(sysUser.getPhonenumber()));
                supervisorUserVO.setNickName(sysUser.getNickName());
                supervisorUserVO.setAvatar(""); //todo 设置默认头像
            }
        } else {
            tAppUserService.lambdaQuery().eq(TAppUser::getCode, spreadCode).ne(TAppUser::getStatus, 3).last("LIMIT 1").oneOpt()
                    .ifPresent(appUser -> {
                        supervisorUserVO.setId(appUser.getId());
                        supervisorUserVO.setPhone((String) PhoneUtil.hideBetween(appUser.getPhone()));
                        supervisorUserVO.setAvatar(appUser.getProfilePhoto());
                        supervisorUserVO.setNickName(appUser.getName());
                    });
        }
        return R.ok(supervisorUserVO);
    }
 
    @ApiOperation("确认上级用户-接受邀请")
    @GetMapping("/confirmSuperior")
    public R<?> confirmSuperior(@ApiParam(name = "superiorType", value = "上级类型 1:股东;2:营销员")
                                @NotNull(message = "上级类型不能为空") @RequestParam Integer superiorType,
                                @ApiParam(name = "superiorId", value = "上级用户ID")
                                @NotNull(message = "上级ID不能为空") @RequestParam Integer superiorId) {
        LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet();
        tAppUserService.confirmSuperior(superiorType, superiorId, loginUserApplet);
        return R.ok();
    }
 
    @ApiOperation(value = "首页模块--轮播图",response = TBanner.class)
    @GetMapping(value = "/getBannerList")
    public R<List<TBanner>> getBannerList() {
        List<TBanner> tBannerList = tBannerService.list();
        return R.ok(tBannerList);
    }
 
    @ApiOperation(value = "首页模块--轮播图详情",response = TBanner.class)
    @GetMapping(value = "/getBannerDetail/{id}")
    public R<TBanner> getBannerDetail(@PathVariable String id) {
        TBanner tBanner = tBannerService.getById(id);
        return R.ok(tBanner);
    }
    @ApiOperation("获取大礼包列表")
    @GetMapping("/big-gift/list")
    public R<List<TBigGiftPackage>> getBigGiftList() {
        return R.ok(bigGiftPackageService.list());
    }
 
    @ApiOperation("大礼包商品详情")
    @GetMapping("/big-gift/detail/{id}")
    public R<TBigGiftPackage> getBigGiftDetail(@ApiParam(name = "id", value = "大礼包ID") @PathVariable Integer id) {
        return R.ok(bigGiftPackageService.getById(id));
    }
 
    @ApiOperation("实物商品分页列表")
    @PostMapping("/physical-goods/page")
    public R<IPage<TPhysicalGoods>> getPhysicalGoodsPageList(@RequestBody AppletPhysicalGoodsQuery query) {
        return R.ok(physicalGoodsService.getPageList(query));
    }
    @ApiOperation("实物商品详情")
    @GetMapping("/physical-goods/detail/{id}")
    public R<TPhysicalGoods> getPhysicalGoodsDetail(@ApiParam(name = "id", value = "实物商品ID")@PathVariable Integer id) {
        return  R.ok(physicalGoodsService.getById(id));
    }
}