| | |
| | | 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; |
| | |
| | | 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.domain.R; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | |
| | | 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; |
| | |
| | | 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.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; |
| | |
| | | |
| | | @Resource |
| | | private ExchangeOrderClient exchangeOrderClient; |
| | | @Autowired |
| | | 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") |
| | | public AjaxResult<Integer> getUserInfo() { |
| | | TAppUser byId = appUserService.getById(tokenService.getLoginUserApplet().getUserId()); |
| | | if (byId.getVipEndTime() == null){ |
| | | return AjaxResult.ok(0); |
| | | }else if (byId.getVipEndTime().isAfter(LocalDateTime.now())){ |
| | | return AjaxResult.ok(1); |
| | | }else{ |
| | | 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) { |
| | |
| | | } |
| | | 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") |
| | |
| | | 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<>(); |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) |
| | | @ApiOperation(value = "冻结解冻用户", tags = {"后台-用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/status/change") |
| | | public R pointsDetail(@RequestBody UserChangeDto userChangeDto) { |
| | | TAppUser appUser = appUserService.getById(userChangeDto.getUserId()); |
| | |
| | | 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(); |
| | | } |
| | |
| | | return R.ok(appUserService.list(Wrappers.<TAppUser>lambdaQuery().in(TAppUser::getId,appUserIds))); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据用户id获取用户 |
| | | * @param id |
| | |
| | | TAppUser appUser = appUserService.getById(id); |
| | | return R.ok(appUser); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 修改用户信息 |
| | | * @param appUser |