| | |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.biz.system.OperationConfigBiz; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.jwt.JwtTokenUtil; |
| | | import com.doumee.config.wx.WxMiniConfig; |
| | |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.CouponMapper; |
| | | import com.doumee.dao.business.MemberCouponMapper; |
| | | import com.doumee.dao.business.OrdersMapper; |
| | | import com.doumee.dao.business.ShopInfoMapper; |
| | | import com.doumee.dao.business.SmsrecordMapper; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Coupon; |
| | | import com.doumee.dao.business.model.MemberCoupon; |
| | | import com.doumee.dao.business.model.Orders; |
| | | import com.doumee.dao.business.model.ShopInfo; |
| | | import com.doumee.dao.business.model.MemberRevenue; |
| | | import com.doumee.dao.business.model.Smsrecord; |
| | | import com.doumee.dao.dto.MemberListQueryDTO; |
| | | import com.doumee.dao.dto.OperationConfigDTO; |
| | | import com.doumee.dao.dto.UpdMobileRequest; |
| | | import com.doumee.dao.dto.WxPhoneRequest; |
| | | import com.doumee.dao.vo.AccountResponse; |
| | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import nonapi.io.github.classgraph.json.Id; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | |
| | | * @author 江蹄蹄 |
| | | * @date 2025/07/09 12:00 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MemberServiceImpl implements MemberService { |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private OrdersMapper ordersMapper; |
| | | |
| | | @Autowired |
| | | private OperationConfigBiz operationConfigBiz; |
| | | |
| | | @Autowired |
| | | private CouponMapper couponMapper; |
| | | |
| | | @Autowired |
| | | private MemberCouponMapper memberCouponMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public void giftRegisterCoupon() { |
| | | // 1. 读取配置 |
| | | OperationConfigDTO config = operationConfigBiz.getConfig(); |
| | | String yearsStr = config.getRegisterCouponYears(); |
| | | String maxGiftStr = config.getRegisterCouponGiftCount(); |
| | | String couponIdStr = config.getRegisterCouponId(); |
| | | if (StringUtils.isBlank(yearsStr) || StringUtils.isBlank(maxGiftStr) || StringUtils.isBlank(couponIdStr)) { |
| | | return; |
| | | } |
| | | int configYears = Integer.parseInt(yearsStr); |
| | | int maxGiftCount = Integer.parseInt(maxGiftStr); |
| | | int couponId = Integer.parseInt(couponIdStr); |
| | | if (configYears <= 0 || maxGiftCount <= 0) { |
| | | return; |
| | | } |
| | | |
| | | // 2. 校验优惠券存在且启用 |
| | | Coupon coupon = couponMapper.selectById(couponId); |
| | | if (coupon == null || !Constants.equalsInteger(coupon.getIsdeleted(), Constants.ZERO) |
| | | || !Constants.equalsInteger(coupon.getStatus(), Constants.ZERO)) { |
| | | return; |
| | | } |
| | | |
| | | // 3. 查询所有普通会员 |
| | | List<Member> members = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getDeleted, Constants.ZERO) |
| | | .eq(Member::getStatus, Constants.ZERO) |
| | | .eq(Member::getUserType, Constants.ZERO) |
| | | .isNotNull(Member::getCreateTime)); |
| | | |
| | | Date now = new Date(); |
| | | long msPerYear = 365L * 24 * 60 * 60 * 1000; |
| | | int giftedMemberCount = 0; |
| | | |
| | | for (Member member : members) { |
| | | int alreadyGifted = member.getRegisterCouponGiftCount() != null ? member.getRegisterCouponGiftCount() : 0; |
| | | // 已注册年数(取整) |
| | | int registeredYears = (int) ((now.getTime() - member.getCreateTime().getTime()) / msPerYear); |
| | | // 应赠送总次数 |
| | | int shouldGiftTotal = registeredYears / configYears; |
| | | // 实际还需赠送次数 |
| | | int remainGift = Math.min(shouldGiftTotal, maxGiftCount) - alreadyGifted; |
| | | if (remainGift <= 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 4. 赠送优惠券 |
| | | for (int i = 0; i < remainGift; i++) { |
| | | MemberCoupon mc = new MemberCoupon(); |
| | | mc.setCouponId(couponId); |
| | | mc.setMemberId(member.getId()); |
| | | mc.setStatus(Constants.CouponStatus.waitClaim.getKey()); |
| | | // 推送后领取有效期 |
| | | Calendar validCal = Calendar.getInstance(); |
| | | validCal.add(Calendar.DAY_OF_MONTH, coupon.getPushDays() != null ? coupon.getPushDays() : 7); |
| | | mc.setValidDate(validCal.getTime()); |
| | | // 拷贝优惠券信息 |
| | | mc.setName(coupon.getName()); |
| | | mc.setInfo(coupon.getInfo()); |
| | | mc.setType(coupon.getType()); |
| | | mc.setLimitPrice(coupon.getLimitPrice()); |
| | | mc.setPrice(coupon.getPrice()); |
| | | mc.setGetMethod(coupon.getGetMethod()); |
| | | mc.setCouponType(coupon.getCouponType()); |
| | | mc.setPushDays(coupon.getPushDays()); |
| | | mc.setValidDays(coupon.getValidDays()); |
| | | mc.setIsdeleted(Constants.ZERO); |
| | | mc.setCreateDate(now); |
| | | mc.setEditDate(now); |
| | | memberCouponMapper.insert(mc); |
| | | } |
| | | |
| | | // 5. 更新会员已赠送次数 |
| | | memberMapper.update(new UpdateWrapper<Member>().lambda() |
| | | .set(Member::getRegisterCouponGiftCount, alreadyGifted + remainGift) |
| | | .eq(Member::getId, member.getId())); |
| | | giftedMemberCount++; |
| | | } |
| | | log.info("注册满年赠送优惠券完成,共处理{}名会员", giftedMemberCount); |
| | | } |
| | | |
| | | } |