| | |
| | | package com.jilongda.applet.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.jilongda.applet.mapper.TCouponMapper; |
| | | import com.jilongda.applet.mapper.TCouponReceiveMapper; |
| | | import com.jilongda.applet.model.TAppUser; |
| | | import com.jilongda.applet.mapper.TAppUserMapper; |
| | | import com.jilongda.applet.model.TCoupon; |
| | | import com.jilongda.applet.model.TCouponReceive; |
| | | import com.jilongda.applet.service.TAppUserService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.jilongda.applet.utils.RptUtils; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | |
| | | @Service |
| | | public class TAppUserServiceImpl extends ServiceImpl<TAppUserMapper, TAppUser> implements TAppUserService { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | private TCouponMapper couponMapper; |
| | | @Autowired |
| | | private TCouponReceiveMapper couponReceiveMapper; |
| | | @Override |
| | | public void wxLogin(AppletUserDecodeData appletUserDecodeData) { |
| | | public TAppUser wxLogin(AppletUserDecodeData appletUserDecodeData) { |
| | | // 通过手机号查询用户,是否已存在手动导入用户,包含支付宝用户 |
| | | TAppUser appUser = this.getOne(Wrappers.lambdaQuery(TAppUser.class) |
| | | .eq(TAppUser::getOpenId, appletUserDecodeData.getOpenId()) |
| | |
| | | if(Objects.isNull(appUser)){ |
| | | appUser = new TAppUser(); |
| | | appUser.setPhone(appletUserDecodeData.getPhoneNumber()); |
| | | appUser.setAvatar(StringUtils.hasLength(appUser.getAvatar())?appUser.getAvatar():""); |
| | | appUser.setName(StringUtils.hasLength(appUser.getName())?appUser.getName(): RptUtils.around(appletUserDecodeData.getPhoneNumber(),3,4)); |
| | | appUser.setAvatar(StringUtils.hasLength(appUser.getAvatar()) ? appUser.getAvatar() : ""); |
| | | appUser.setName(StringUtils.hasLength(appUser.getName()) ? appUser.getName() : RptUtils.around(appletUserDecodeData.getPhoneNumber(), 3, 4)); |
| | | appUser.setOpenId(appletUserDecodeData.getOpenId()); |
| | | this.save(appUser); |
| | | // 查询有没有注册发放的优惠券活动 |
| | | List<TCoupon> tCoupons = couponMapper.selectList(new LambdaQueryWrapper<TCoupon>() |
| | | .eq(TCoupon::getType, 1) |
| | | .eq(TCoupon::getGrantStatus, 1)); |
| | | for (TCoupon tCoupon : tCoupons) { |
| | | TCouponReceive tCouponReceive = new TCouponReceive(); |
| | | tCouponReceive.setCouponId(tCoupon.getId()); |
| | | tCouponReceive.setUserId(appUser.getId()); |
| | | tCouponReceive.setType(1); |
| | | tCouponReceive.setAmount(tCoupon.getAmount()); |
| | | tCouponReceive.setStoreId(tCoupon.getStoreId()); |
| | | if (tCoupon.getTime()!=0){ |
| | | tCouponReceive.setEndTime(LocalDateTime.now().plusDays(tCoupon.getTime())); |
| | | } |
| | | tCouponReceive.setAmountCondition(tCoupon.getAmountCondition()); |
| | | tCouponReceive.setStatus(1); |
| | | tCouponReceive.setCouponName(tCoupon.getName()); |
| | | couponReceiveMapper.insert(tCouponReceive); |
| | | } |
| | | }else { |
| | | if(appUser.getStatus()!=1){ |
| | | throw new ServiceException("账号被冻结,请联系管理员"); |
| | | } |
| | | appUser.setPhone(appletUserDecodeData.getPhoneNumber()); |
| | | appUser.setAvatar(StringUtils.hasLength(appUser.getAvatar())?appUser.getAvatar():""); |
| | | appUser.setName(StringUtils.hasLength(appUser.getName())?appUser.getName(): RptUtils.around(appletUserDecodeData.getPhoneNumber(),3,4)); |
| | | this.updateById(appUser); |
| | | } |
| | | return appUser; |
| | | } |
| | | } |