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 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(sysUser.getAvatar()); } } 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> getBannerList() { List tBannerList = tBannerService.list(); return R.ok(tBannerList); } @ApiOperation(value = "首页模块--轮播图详情",response = TBanner.class) @GetMapping(value = "/getBannerDetail/{id}") public R getBannerDetail(@PathVariable String id) { TBanner tBanner = tBannerService.getById(id); //增加阅读量 tBanner.setReadCount(tBanner.getReadCount() + 1); tBannerService.updateById(tBanner); return R.ok(tBanner); } @ApiOperation("获取大礼包列表") @GetMapping("/big-gift/list") public R> getBigGiftList() { return R.ok(bigGiftPackageService.list()); } @ApiOperation("大礼包商品详情") @GetMapping("/big-gift/detail/{id}") public R getBigGiftDetail(@ApiParam(name = "id", value = "大礼包ID") @PathVariable Integer id) { return R.ok(bigGiftPackageService.getById(id)); } @ApiOperation("实物商品分页列表") @PostMapping("/physical-goods/page") public R> getPhysicalGoodsPageList(@RequestBody AppletPhysicalGoodsQuery query) { return R.ok(physicalGoodsService.getPageList(query)); } @ApiOperation("实物商品详情") @GetMapping("/physical-goods/detail/{id}") public R getPhysicalGoodsDetail(@ApiParam(name = "id", value = "实物商品ID")@PathVariable Integer id) { return R.ok(physicalGoodsService.getById(id)); } }