luodangjia
2024-12-19 60f70f7409ec1ece8905e088fb43e0cb0258a70b
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
@@ -6,6 +6,7 @@
import com.ruoyi.account.api.model.UserCancellationLog;
import com.ruoyi.account.api.model.UserCoupon;
import com.ruoyi.account.api.model.UserSignRecord;
import com.ruoyi.account.mapper.AppUserMapper;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.UserCancellationLogService;
import com.ruoyi.account.service.UserCouponService;
@@ -34,6 +35,7 @@
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -74,6 +76,8 @@
   private UserPointService userPointService;
   @Resource
   private VipSettingService vipSettingService;
   @Resource
   private AppUserMapper appUserMapper;
   @ResponseBody
@@ -187,9 +191,6 @@
   public R<AppUser> info(){
      Long userId = tokenService.getLoginUserApplet().getUserid();
      AppUser user = appUserService.getById(userId);
      return R.ok(user);
   }
   @Resource
@@ -403,6 +404,27 @@
      return R.ok(appuserPage);
   }
   @GetMapping("/shop/getAppuserPage")
   @ApiOperation(value = "用户列表", tags = {"门店后台"})
   public R<IPage<AppUser>> shopGetAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                 @ApiParam("每一页数据大小") Integer pageSize,
                                 AppUser appUser)
   {
      Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
      List<Long> userIds = new ArrayList<>();
      userIds.add(-1L);
      //获取在该本店下单的用户ids
      R<List<Order>> listR = remoteOrderGoodsClient.byShopId(objectId);
      for (Order datum : listR.getData()) {
         userIds.add(datum.getAppUserId());
      }
      IPage<AppUser> appuserPage = appUserService.getAppuserPage1(pageNum, pageSize, appUser,objectId,userIds);
      return R.ok(appuserPage);
   }
   @GetMapping("/danger/info")
   @ApiOperation(value = "用户列表-保级条件详情", tags = {"管理后台"})
   public R<DangerInfoDto> dangerinfo(Long id)
@@ -463,6 +485,52 @@
      appUserService.updateById(byId);
      return R.ok();
   }
   @GetMapping("/select")
   @ApiOperation(value = "用户列表-查询绑定人", tags = {"管理后台"})
   public R<AppUser> select(String phone)
   {
      AppUser byId = appUserService.lambdaQuery().eq(AppUser::getPhone,phone).one();
      if (byId==null){
         return R.fail("搜索失败,手机号错误。");
      }
      return R.ok(byId);
   }
   @GetMapping("/change/bind")
   @ApiOperation(value = "用户列表-更换绑定人", tags = {"管理后台"})
   public R<AppUser> select(Long id,Long inviteId)
   {
      AppUser byId = appUserService.getById(id);
      byId.setInviteUserId(inviteId);
      byId.setTopInviteId(getTop(inviteId));
      appUserService.updateById(byId);
      return R.ok();
   }
   @GetMapping("/change/shop")
   @ApiOperation(value = "用户列表-更换门店", tags = {"管理后台"})
   public R<AppUser> shop(Long id,Long shopId)
   {
      AppUser byId = appUserService.getById(id);
      byId.setShopId(shopId);
      appUserService.updateById(byId);
      return R.ok();
   }
   public  Long getTop(Long inviteId){
      AppUser byId = appUserService.getById(inviteId);
      if (byId!=null){
         return getTop(byId.getInviteUserId());
      }else {
         return inviteId;
      }
   }
   @Resource
   private ShopClient shopClient;
   @Resource
@@ -497,8 +565,35 @@
      if (lastOrder.getData()!=null){
         byId.setLastOrderTime(lastOrder.getData().getCreateTime());
      }
      //消费总金额
      return R.ok(byId);
   }
   @Resource
   private UserChangeLogService userChangeLogService;
   @GetMapping("/change/vip")
   @ApiOperation(value = "用户列表-修改会员等级", tags = {"管理后台"})
   public R<Page<AppUser>> changevip(Long id,Integer vipId)
   {
      AppUser byId = appUserService.getById(id);
      UserChangeLog userChangeLog = new UserChangeLog();
      userChangeLog.setCreateTime(LocalDateTime.now());
      userChangeLog.setAppUserId(byId.getId());
      userChangeLog.setBeforeVipId(byId.getVipId());
      userChangeLog.setAfterVipId(vipId);
      if (userChangeLog.getBeforeVipId()>userChangeLog.getAfterVipId()) {
         userChangeLog.setChangeType(0);
      }else {
         userChangeLog.setChangeType(1);
      }
      userChangeLogService.save(userChangeLog);
      byId.setVipId(vipId);
      appUserService.updateById(byId);
      return R.ok();
   }
   @GetMapping("/bottom")
   @ApiOperation(value = "用户列表-绑定下级列表", tags = {"管理后台"})
   public R<Page<AppUser>> bottom(Long id,Integer pageNum,Integer pageSize)
@@ -509,6 +604,16 @@
   }
   @GetMapping("/orders")
   @ApiOperation(value = "用户列表-订单列表", tags = {"管理后台"})
   public R<List<Order>> orders(Long id)
   {
      R<List<Order>> listR = remoteOrderGoodsClient.byUserId(id);
      return R.ok(listR.getData());
   }
@@ -516,8 +621,9 @@
   @GetMapping("/listByIds")
   List<AppUser> listByIds(List<String> list){
      return appUserService.listByIds(list);
   List<AppUser> listByIds(@RequestParam("ids") List<Long> ids){
      List<AppUser> appUsers = appUserService.listByIds(ids);
      return appUsers;
   }
   
   
@@ -529,5 +635,25 @@
      return R.ok(appUser);
   }
   /**
    * 用户统计
    */
   @GetMapping("/statistics")
   @ApiOperation(value = "用户统计",tags = {"管理后台-首页统计-用户统计"})
   public R<UserStatistics> statistics() {
      UserStatistics userStatistics = appUserMapper.getUserStatistics();
      return R.ok(userStatistics);
   }
   /**
    * 用户统计详情
    */
   @GetMapping("/statistics/detail")
   @ApiOperation(value = "用户统计详情",tags = {"管理后台-首页统计-用户统计详情"})
   public R<UserStatisticsDetail> statisticsDetail(String userName) {
      UserStatisticsDetail userStatisticsDetail = appUserMapper.getUserStatisticsDetail(userName);
      return R.ok(userStatisticsDetail);
   }
}