From 5a22de857470ed18e993260e2cf3a38a1a43de7e Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 19 八月 2024 17:13:38 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java | 205 ++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 144 insertions(+), 61 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java index 9c6f99d..6915db6 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java @@ -1,6 +1,7 @@ package com.ruoyi.account.controller; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; @@ -14,7 +15,10 @@ import com.ruoyi.account.wx.body.resq.Code2SessionResqBody; import com.ruoyi.account.wx.model.WeixinProperties; import com.ruoyi.account.wx.tools.WxAppletTools; +import com.ruoyi.account.util.GiveVipUtil; +import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.bean.BeanUtils; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.BasePojo; @@ -27,6 +31,7 @@ import com.ruoyi.order.api.model.TChargingOrder; import com.ruoyi.order.api.model.TExchangeOrder; import com.ruoyi.other.api.domain.TCompany; +import com.ruoyi.other.api.domain.TCoupon; import com.ruoyi.other.api.domain.TUserTag; import com.ruoyi.other.api.feignClient.OtherClient; import com.ruoyi.system.api.domain.SysRole; @@ -34,14 +39,17 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.formula.functions.T; import lombok.extern.slf4j.Slf4j; import org.aspectj.weaver.loadtime.Aj; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -83,10 +91,14 @@ private TokenService tokenService; @Autowired private RedisService redisService; - @Autowired - private WeixinProperties wxConfig; - @Autowired - private RestTemplate wxRestTemplate; + + @Resource + private TAppUserSignService signService; + @Resource + private TAppCouponService appCouponService; + @Resource + private TAppUserCarService carService; + @ApiOperation(value = "查询当前用户是否为会员 0否1是", tags = {"小程序--查询当前用户是否为会员"}) @PostMapping(value = "/getUserInfo") @@ -100,39 +112,14 @@ return AjaxResult.ok(0); } } - @ApiOperation(value = "通过code获得openid, 1 --->对应的appid:wx4c405fa42539fc21 2---->对应的appid:wx02d9f6c92e6d3c86") - @GetMapping("openId-by-jscode2session/{code}") - public AjaxResult<Map<String, Object>> jscode2session(@PathVariable String code) { - log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", code); - WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig); - Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(code)); - String openid = body.getOpenid(); - String sessionKey = body.getSessionKey(); - TAppUser appUser = appUserService.getOne(Wrappers.lambdaQuery(TAppUser.class).eq(TAppUser::getWxOpenid, openid).last("limit 1")); - if (Objects.isNull(appUser)) { - appUser = new TAppUser(); - appUser.setWxOpenid(openid); - appUserService.save(appUser); - } - // 提前对sessionKey进行删除 - log.info("换取sessionKey:{}", sessionKey); - // 将sessionKey进行存储,后续获取信息需要 - redisService.setCacheObject(openid, sessionKey); - LoginUserApplet loginUserApplet = new LoginUserApplet(); - if(ObjectUtils.isNotNull(appUser)){ - loginUserApplet.setUserId(appUser.getId()); - } - HashMap<String, Object> tokenInfos = new HashMap<>(); - tokenInfos.put("token",tokenService.createTokenApplet(loginUserApplet)); - tokenInfos.put("info",loginUserApplet); - return AjaxResult.ok(tokenInfos); - } @ApiOperation(value = "管理后台-根据手机号查询用户ids", tags = {"管理后台-活动费用统计"}) @PostMapping(value = "/user/getUserIdsByPhone") public R<List<Long>> getUserIdsByPhone(@RequestParam("phone") String phone) { return R.ok(appUserService.list(new QueryWrapper<TAppUser>().like("phone",phone)).stream().map(TAppUser::getId).collect(Collectors.toList())); } + @Resource + private GiveVipUtil giveVipUtil; @ApiOperation(value = "单位管理列表", tags = {"用户管理-单位管理"}) @PostMapping(value = "/unit/page") public R<Page<TCompany>> unitPage(@RequestBody UnitListQueryDto unitListQueryDto) { @@ -146,6 +133,20 @@ return R.ok(data); } + + @ApiOperation(value = "单位下拉框", tags = {"用户管理-单位管理"}) + @PostMapping(value = "/unit/select") + public R<List<TCompany>> unitSelect() { + UnitListQueryDto unitListQueryDto = new UnitListQueryDto(); + unitListQueryDto.setPageCurr(1); + unitListQueryDto.setPageSize(9999); + //拿到单位列表 + R<Page<TCompany>> pageR = otherClient.queryUnitPage(unitListQueryDto); + + return R.ok(pageR.getData().getRecords()); + } + + @ApiOperation(value = "单位管理添加或编辑", tags = {"用户管理-单位管理"}) @PostMapping(value = "/unit/addOrUpdate") public R add(@RequestBody TCompany tCompany) { @@ -153,10 +154,17 @@ otherClient.unitAddorUpadate(tCompany); return R.ok(); } + + + + @ApiOperation(value = "单位管理删除", tags = {"用户管理-单位管理"}) - @PostMapping(value = "/unit/delete/{id}") - public R add(@PathVariable Integer id) { - otherClient.unitDelete(id); + @DeleteMapping(value = "/unit/delete") + public R add(@RequestParam String ids) { + String[] split = ids.split(","); + for (String s : split) { + otherClient.unitDelete(Integer.valueOf(s)); + } return R.ok(); } @@ -316,7 +324,7 @@ return R.ok(userDetailDto); } - @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) + @ApiOperation(value = "用户详情积分明细", tags = {"后台-用户管理-用户列表","小程序-个人中心"}) @PostMapping(value = "/user/points/page") public R<Page<TAppUserIntegralChange>> pointsDetail(@RequestBody PointsQueryDto pointsQueryDto) { List<Integer> types = new ArrayList<>(); @@ -352,7 +360,7 @@ } - @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) + @ApiOperation(value = "冻结解冻用户", tags = {"后台-用户管理-用户列表"}) @PostMapping(value = "/user/status/change") public R pointsDetail(@RequestBody UserChangeDto userChangeDto) { TAppUser appUser = appUserService.getById(userChangeDto.getUserId()); @@ -361,39 +369,96 @@ return R.ok(); } + @ApiOperation(value = "个人中心信息", tags = {"小程序-个人中心"}) + @PostMapping(value = "/user/info") + public R<AppUserInfoDto> info() { + Long userId = 1L; + TAppUser byId = appUserService.getById(userId); + AppUserInfoDto appUserInfoDto = new AppUserInfoDto(); + + //判断会员 + if (byId.getVipEndTime()==null||byId.getVipEndTime().isBefore(LocalDateTime.now())){ + appUserInfoDto.setIsVip(0); + }else { + appUserInfoDto.setIsVip(1); + appUserInfoDto.setVipExpireTime(byId.getVipEndTime()); + } + //判断当天是否签到 + Long count = signService.lambdaQuery().eq(TAppUserSign::getSignDay, LocalDate.now()).count(); + appUserInfoDto.setIsSign(count>0?1:0); + //获取当前拥有的优惠卷数量 + Long coupons = appCouponService.lambdaQuery().eq(TAppCoupon::getAppUserId, userId).eq(TAppCoupon::getStatus, 1).count(); + appUserInfoDto.setCouponNum(Math.toIntExact(coupons)); + //当前绑定的车辆 + List<TAppUserCar> list = carService.lambdaQuery().eq(TAppUserCar::getAppUserId, userId).list(); + appUserInfoDto.setUserCars(list); + return R.ok(appUserInfoDto); + + + } + + @ApiOperation(value = "优惠卷列表不分页(1可使用2不可用)", tags = {"小程序-个人中心"}) + @PostMapping(value = "/user/coupon") + public R<List<InfoCouponDto>> userCoupon(@RequestParam("type") Integer type) { + LocalDateTime now = LocalDateTime.now(); + + List<InfoCouponDto> couponDtos = new ArrayList<>(); + List<TAppCoupon> list = appCouponService.lambdaQuery().le(TAppCoupon::getStartTime, now).ge(TAppCoupon::getEndTime, now).eq(TAppCoupon::getStatus, type).list(); + for (TAppCoupon tAppCoupon : list) { + TCoupon coupon = JSON.toJavaObject(JSON.parseObject(tAppCoupon.getCouponJson()), TCoupon.class); + InfoCouponDto infoCouponDto = new InfoCouponDto(); + BeanUtils.copyProperties(coupon,infoCouponDto); + couponDtos.add(infoCouponDto); + + } + + + return R.ok(couponDtos); + + + } + + @ApiOperation(value = "赠送会员", tags = {"用户管理-用户列表"}) @PostMapping(value = "/user/give/vip") public R giveVip(@RequestBody GiveVipDto giveVipDto) { TAppUser nowUser = appUserService.getById(giveVipDto.getUserId()); - - //如果vipEndTime为空或已过期,直接增加 - if (nowUser.getVipEndTime()==null||nowUser.getVipEndTime().isBefore(LocalDateTime.now())) { - if (giveVipDto.getType() == 1) { - nowUser.setVipEndTime(LocalDateTime.now().plusDays(31)); - //直接增加vipDetail - } else if (giveVipDto.getType() == 2) { - nowUser.setVipEndTime(LocalDateTime.now().plusDays(93)); - } else if (giveVipDto.getType() == 3) { - nowUser.setVipEndTime(LocalDateTime.now().plusDays(365)); - } - //直接赠送优惠卷 - }else { - if (giveVipDto.getType() == 1) { - nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(31)); - //如果有这个类型的vip,累加,没有的话,从entTime新增 - } else if (giveVipDto.getType() == 2) { - nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(93)); - } else if (giveVipDto.getType() == 3) { - nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(365)); - } + int plusDay = 0; + if (giveVipDto.getType() == 1) { + plusDay = 1; + } else if (giveVipDto.getType() == 2) { + plusDay = 3; + } else if (giveVipDto.getType() == 3) { + plusDay = 12; } + //增加vipDetail + giveVipUtil.sendVip(nowUser, giveVipDto.getVipId(),plusDay); - + appUserService.updateById(nowUser); + //执行一次赠送优惠卷的定时任务 return R.ok(); + } + + @ApiOperation(value = "更换手机号", tags = {"小程序-用户管理-更换手机号"}) + @PostMapping(value = "/user/updatePhone") + public AjaxResult<String> updatePhone(@Validated @RequestBody UpdatePhoneDTO dto) { + String code = redisService.getCacheObject(dto.getPhone() + Constants.APPLET); + if(StringUtils.isEmpty(code)){ + return AjaxResult.error("验证码已过期,请重新获取验证码!"); + } + if(!code.equals(dto.getCode())){ + return AjaxResult.error("验证码错误!"); + } + // 获取当前用户信息 + Long userId = tokenService.getLoginUserApplet().getUserId(); + TAppUser appUser = appUserService.getById(userId); + appUser.setPhone(dto.getPhone()); + appUserService.updateById(appUser); + return AjaxResult.success(); } /** @@ -406,7 +471,7 @@ return R.ok(appUserService.list(Wrappers.<TAppUser>lambdaQuery().in(TAppUser::getId,appUserIds))); } - + /** * 根据用户id获取用户 * @param id @@ -417,8 +482,8 @@ TAppUser appUser = appUserService.getById(id); return R.ok(appUser); } - - + + /** * 修改用户信息 * @param appUser @@ -430,5 +495,23 @@ appUserService.updateById(appUser); return R.ok(); } + + /** + * 通过手机号查询用户 + * @param phone + * @return + */ + @GetMapping("/user/selectByPhone") + public R<TAppUser> selectByPhone(@RequestParam("phone") String phone){ + return R.ok(appUserService.getOne(Wrappers.lambdaQuery(TAppUser.class) + .eq(TAppUser::getPhone,phone) + .last("LIMIT 1"))); + } + +// @ApiOperation(value = "签到", tags = {"小程序-个人中心-签到"}) +// @PostMapping(value = "/user/sign") +// public R sign() { +// +// } } -- Gitblit v1.7.1