| | |
| | | package com.ruoyi.account.controller; |
| | | |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.api.model.*; |
| | | import com.ruoyi.account.api.vo.CouponListVOVO; |
| | | import com.ruoyi.account.service.*; |
| | | import com.ruoyi.account.util.PointDetailUtil; |
| | | import com.ruoyi.account.util.SignDayUtil; |
| | | import com.ruoyi.account.wx.body.resp.Code2SessionRespBody; |
| | | import com.ruoyi.account.wx.body.resq.Code2SessionResqBody; |
| | | import com.ruoyi.account.wx.model.WeixinProperties; |
| | |
| | | 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.TIntegralRule; |
| | | import com.ruoyi.other.api.domain.TUserTag; |
| | | import com.ruoyi.other.api.feignClient.IntegralRuleClient; |
| | | import com.ruoyi.other.api.feignClient.OtherClient; |
| | | import com.ruoyi.system.api.domain.SysRole; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import com.ruoyi.system.api.model.LoginUserApplet; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | |
| | | @Resource |
| | | private TAppUserIntegralChangeService integralChangeService; |
| | | @Resource |
| | | private SignDayUtil signDayUtil; |
| | | |
| | | @Resource |
| | | private ExchangeOrderClient exchangeOrderClient; |
| | |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private RedisService redisService; |
| | | @Autowired |
| | | private WeixinProperties wxConfig; |
| | | @Autowired |
| | | private RestTemplate wxRestTemplate; |
| | | @Resource |
| | | private PointDetailUtil pointDetailUtil; |
| | | |
| | | @Resource |
| | | private TAppUserSignService signService; |
| | |
| | | private TAppCouponService appCouponService; |
| | | @Resource |
| | | private TAppUserCarService carService; |
| | | @Resource |
| | | private IntegralRuleClient integralRuleClient; |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "查询当前用户是否为会员 0否1是", tags = {"小程序--查询当前用户是否为会员"}) |
| | |
| | | } |
| | | List<Integer> vipIds = new ArrayList<>(); |
| | | vipIds = page.getRecords().stream().map(TAppUser::getVipId).collect(Collectors.toList()); |
| | | //获取会员map |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(vipIds); |
| | | //循环处理 |
| | | for (TAppUser appUser : page.getRecords()) { |
| | | //拿到最新的tagId |
| | | TAppUserTag one = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, appUser.getId()).orderByDesc(TAppUserTag::getCreateTime).last("limit 1").one(); |
| | | //设置最新的tagName |
| | | R<TUserTag> byIdTag = otherClient.getByIdTag(one.getUserTagId()); |
| | | if (byIdTag.getData()!=null) { |
| | | appUser.setTagName(byIdTag.getData().getName()); |
| | | } |
| | | //匹配vipMap的值 |
| | | appUser.setVipName(vipMap.getData().get(appUser.getVipId())); |
| | | //累计充电次数 |
| | | R<Long> useOrderCount = chargingOrderClient.useOrderCount(appUser.getId()); |
| | | appUser.setOrderCount(useOrderCount.getData()); |
| | | |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | @ApiOperation(value = "会员列表", tags = {"用户管理-会员列表"}) |
| | | @PostMapping(value = "/user/vip/page") |
| | | public R<Page<TAppUser>> vipPage(@RequestBody UserListQueryDto userListQueryDto) { |
| | | List<Long> userIds = new ArrayList<>(); |
| | | //如果要筛选标签。用标签获取useids |
| | | if (userListQueryDto.getUserTagId() != null){ |
| | | userIds = appUserTagService.lambdaQuery().eq(TAppUserTag::getUserTagId, userListQueryDto.getUserTagId()).list().stream().map(TAppUserTag::getAppUserId).collect(Collectors.toList()); |
| | | } |
| | | //列表查询 |
| | | Page<TAppUser> page = appUserService.lambdaQuery() |
| | | .like(userListQueryDto.getUserPhone() != null && !"".equals(userListQueryDto.getUserPhone()), TAppUser::getPhone, userListQueryDto.getUserPhone()) |
| | | .eq(userListQueryDto.getCompanyId() != null, TAppUser::getCompanyId, userListQueryDto.getCompanyId()) |
| | | .eq(userListQueryDto.getCityCode() != null && !"".equals(userListQueryDto.getCityCode()), TAppUser::getCityCode, userListQueryDto.getCityCode()) |
| | | .eq(userListQueryDto.getStatus() != null, TAppUser::getStatus, userListQueryDto.getStatus()) |
| | | .eq(userListQueryDto.getVipTypeId() != null, TAppUser::getVipId, userListQueryDto.getVipTypeId()) |
| | | .in(!userIds.isEmpty(),TAppUser::getId,userIds) |
| | | .page(Page.of(userListQueryDto.getPageCurr(), userListQueryDto.getPageSize())); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(page); |
| | | } |
| | | List<Integer> vipIds = new ArrayList<>(); |
| | | vipIds = page.getRecords().stream().map(TAppUser::getVipId).collect(Collectors.toList()); |
| | | //获取会员map |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(vipIds); |
| | | //循环处理 |
| | |
| | | |
| | | List<Integer> tagIds = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, id).orderByDesc(TAppUserTag::getCreateTime).list().stream().map(TAppUserTag::getUserTagId).collect(Collectors.toList()); |
| | | R<Map<Integer, String>> tagMap = otherClient.getTagMap(tagIds); |
| | | userDetailDto.setTagName(tagMap.getData().values().toString()); |
| | | userDetailDto.setTagName(tagMap.getData().values() |
| | | .stream() |
| | | .collect(Collectors.joining(","))); |
| | | return R.ok(userDetailDto); |
| | | } |
| | | |
| | |
| | | .last("LIMIT 1"))); |
| | | } |
| | | |
| | | // @ApiOperation(value = "签到", tags = {"小程序-个人中心-签到"}) |
| | | // @PostMapping(value = "/user/sign") |
| | | // public R sign() { |
| | | // |
| | | // } |
| | | @ApiOperation(value = "签到", tags = {"小程序-个人中心-签到"}) |
| | | @PostMapping(value = "/user/sign") |
| | | public R sign() { |
| | | LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet(); |
| | | Long userId = loginUserApplet.getUserId(); |
| | | |
| | | TAppUser byId = appUserService.getById(userId); |
| | | |
| | | |
| | | if (signService.lambdaQuery().eq(TAppUserSign::getSignDay, LocalDate.now()).eq(TAppUserSign::getAppUserId, userId).count()>0){ |
| | | return R.fail("今日已签到"); |
| | | } |
| | | //签到业务 |
| | | TAppUserSign appUserSign = new TAppUserSign(); |
| | | appUserSign.setSignDay(LocalDate.now()); |
| | | appUserSign.setRewardPoints(2); |
| | | appUserSign.setCreateTime(LocalDateTime.now()); |
| | | appUserSign.setAppUserId(userId); |
| | | signService.save(appUserSign); |
| | | //签到加积分记录 |
| | | R<TIntegralRule> set = integralRuleClient.getSet(); |
| | | TIntegralRule data = set.getData(); |
| | | JSONObject jsonObject = JSON.parseObject(data.getAddVehiclesEarnsPoints()); |
| | | //增加每日积分 |
| | | Integer points = 0; |
| | | Integer point = jsonObject.getInteger("num1"); |
| | | points= points+point; |
| | | JSONArray num2 = jsonObject.getJSONArray("num2"); |
| | | if (num2!=null) { |
| | | //获取连续签到的规则放入map |
| | | Map<Integer,Integer> map = new HashMap<>(); |
| | | for (Object o : num2) { |
| | | String o1 = (String) o; |
| | | String[] split = o1.split(","); |
| | | map.put(Integer.parseInt(split[0]), Integer.parseInt(split[1])); |
| | | } |
| | | //加上今日签到,计算连续了多少天,如果到达就增加奖励的分数 |
| | | int days = signDayUtil.calculateContinuousSignDays(userId); |
| | | Integer i = map.get(days); |
| | | if (i!=null){ |
| | | points= points+i; |
| | | appUserSign.setIsGift(1); |
| | | signService.updateById(appUserSign); |
| | | } |
| | | } |
| | | pointDetailUtil.addDetail(byId.getPoints(),byId.getPoints()+points,1,userId,"每日签到",""); |
| | | byId.setPoints(byId.getPoints()+points); |
| | | appUserService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "添加编辑车辆", tags = {"小程序-个人中心-车辆"}) |
| | | @PostMapping(value = "/user/car/addOrUpdate") |
| | | public R carAdd(@RequestBody TAppUserCar appUserCar) { |
| | | |
| | | LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet(); |
| | | Long userId = loginUserApplet.getUserId(); |
| | | TAppUser byId = appUserService.getById(userId); |
| | | |
| | | |
| | | //如果是第一次添加车辆,增加积分 |
| | | Long count = appUserCarService.lambdaQuery().eq(TAppUserCar::getAppUserId, userId).count(); |
| | | |
| | | |
| | | if (count==0){ |
| | | R<TIntegralRule> set = integralRuleClient.getSet(); |
| | | TIntegralRule data = set.getData(); |
| | | JSONObject jsonObject = JSON.parseObject(data.getAddVehiclesEarnsPoints()); |
| | | |
| | | |
| | | Integer point = 0; |
| | | //增加车牌50分,必填 |
| | | point = point+jsonObject.getInteger("num1"); |
| | | //增加车型分 |
| | | if (StringUtils.isNotEmpty(appUserCar.getVehicleModel())){ |
| | | point = point+jsonObject.getInteger("num2"); |
| | | } |
| | | //增加车辆用途分 |
| | | if (StringUtils.isNotEmpty(appUserCar.getVehicleUse())){ |
| | | point = point+jsonObject.getInteger("num3"); |
| | | } |
| | | //增加续航分 |
| | | if (StringUtils.isNotEmpty(appUserCar.getEndurance())){ |
| | | point = point+jsonObject.getInteger("num4"); |
| | | } |
| | | |
| | | //增加积分记录 |
| | | pointDetailUtil.addDetail(byId.getPoints(),byId.getPoints()+point,5,userId,appUserCar.getLicensePlate(),""); |
| | | byId.setPoints(byId.getPoints()+point); |
| | | appUserService.updateById(byId); |
| | | |
| | | |
| | | } |
| | | |
| | | // |
| | | appUserCarService.saveOrUpdate(appUserCar); |
| | | |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |