| | |
| | | import com.yeshi.fanli.entity.bus.user.DeviceLotteryRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.Order;
|
| | | import com.yeshi.fanli.entity.bus.user.TokenRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
|
| | |
| | | import com.yeshi.fanli.service.inter.push.PushCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.push.PushCouponService;
|
| | | import com.yeshi.fanli.service.inter.user.DeviceLotteryRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.TokenRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserMoneyDetailService;
|
| | |
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
|
| | |
| | |
|
| | | @Resource
|
| | | private PushCouponRecordService pushCouponRecordService;
|
| | | |
| | | @Resource
|
| | | private TokenRecordService tokenRecordService;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void exchangeCoupon(Long uid, String couponType, String source, boolean give, BigDecimal percent) throws UserSystemCouponException, Exception {
|
| | | public void exchangeCoupon(Long uid, String couponType, String source, BigDecimal percent) throws UserSystemCouponException, Exception {
|
| | | if (couponType == null || uid == null) {
|
| | | throw new UserSystemCouponException(1, "参数不正确");
|
| | | }
|
| | |
| | | UserSystemCoupon userCoupon = new UserSystemCoupon();
|
| | | userCoupon.setUid(uid);
|
| | | userCoupon.setSource(source);
|
| | | userCoupon.setGive(give);
|
| | | userCoupon.setSystemCoupon(coupon);
|
| | | userCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
|
| | | userCoupon.setStateActivated(stateActivated);
|
| | | userCoupon.setStartTime(new Date());
|
| | | userCoupon.setEndTime(endTime);
|
| | | userCoupon.setGive(false);
|
| | | userCoupon.setCreateTime(new Date());
|
| | | userCoupon.setUpdateTime(new Date());
|
| | | userCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
|
| | | |
| | | insertSelective(userCoupon);
|
| | | }
|
| | |
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public List<UserSystemCouponVO> getCouponList(long start, int count, Long uid)throws UserSystemCouponException, Exception {
|
| | | if (uid == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | public List<UserSystemCouponVO> getCouponList(long start, int count, Long uid)
|
| | | throws UserSystemCouponException, Exception {
|
| | | // 更新过期券
|
| | | updateCounponInvalid(uid);
|
| | | // 退回券
|
| | | sendBackTimeOutCoupon(uid);
|
| | | |
| | |
|
| | | List<UserSystemCouponVO> listVO = userSystemCouponMapper.getUserCouponVOList(start, count, uid);
|
| | | if (listVO == null || listVO.size() == 0) {
|
| | | return listVO;
|
| | |
| | | if (userInfoExtra != null) {
|
| | | inviteCode = userInfoExtra.getInviteCode();
|
| | | }
|
| | | |
| | |
|
| | | for (UserSystemCouponVO userCouponVO : listVO) {
|
| | | SystemCoupon systemCoupon = userCouponVO.getSystemCoupon();
|
| | | if (systemCoupon != null && systemCoupon.getId() != null) {
|
| | |
| | | userCouponVO.setCouponEffect(systemCoupon.getEffect());
|
| | | userCouponVO.setCouponRule(systemCoupon.getRule());
|
| | | userCouponVO.setCouponRuleLink(systemCoupon.getRuleLink());
|
| | | |
| | | Integer state = userCouponVO.getState();
|
| | | // 券失效图片替换
|
| | | if (UserSystemCoupon.STATE_END_USE == state || UserSystemCoupon.STATE_OVERDUE == state) {
|
| | | userCouponVO.setCouponPicture(systemCoupon.getPictureInvalid());
|
| | | } else {
|
| | | userCouponVO.setCouponPicture(systemCoupon.getPicture());
|
| | | }
|
| | |
|
| | | Map<String, Object> jumpBtn = null;
|
| | | CouponTypeEnum type = systemCoupon.getType();
|
| | | Integer stateActivated = userCouponVO.getStateActivated();
|
| | |
|
| | | // 状态待激活 -且可使用
|
| | | if (UserSystemCoupon.STATE_CAN_USE == state && (stateActivated == null || stateActivated == 0)) {
|
| | | userCouponVO.setState(0);
|
| | | userCouponVO.setCouponEffect("待激活");
|
| | | if (CouponTypeEnum.freeCoupon == type) {
|
| | | List<String> listTip = new ArrayList<String>();
|
| | | listTip.add("本免单券由好友赠送,从获赠日起60天内需产生3笔返利订单;");
|
| | | listTip.add("返利订单“已到账”后,方能视为订单产生成功;");
|
| | | listTip.add("满足条件后,系统将自动激活,并在消息-其它消息中提醒。");
|
| | | } else if (CouponTypeEnum.welfareFreeCoupon == type) {
|
| | | // 未激活规则
|
| | | userCouponVO.setCouponRule(systemCoupon.getRemark());
|
| | | |
| | | jumpBtn = new HashMap<String, Object>();
|
| | | if (inviteCode != null && inviteCode.trim().length() > 0) {
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("invite_friends"));
|
| | | } else {
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("invite_activate"));
|
| | | }
|
| | | }
|
| | | } else if (stateActivated == 1) {
|
| | | // 显示规则
|
| | | userCouponVO.setCouponRule(systemCoupon.getRule());
|
| | |
|
| | | if (UserSystemCoupon.STATE_CAN_USE == state) {
|
| | | Map<String, Object> jumpLink = new HashMap<String, Object>();
|
| | |
|
| | | if (CouponTypeEnum.freeCoupon == type || CouponTypeEnum.welfareFreeCoupon == type) {
|
| | | // 免单券、 福利免单券
|
| | |
|
| | | // 免单商品列表
|
| | | jumpLink.put("url", configService.get("free_goods_list"));
|
| | |
|
| | | jumpBtn = new HashMap<String, Object>();
|
| | | jumpBtn.put("params", jumpLink);
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("web"));
|
| | |
|
| | | } else if (CouponTypeEnum.rebatePercentCoupon == type) {
|
| | | // 返利奖励券- 跳转至订单到账界面
|
| | | jumpLink.put("state", "2");
|
| | |
|
| | | jumpBtn = new HashMap<String, Object>();
|
| | | jumpBtn.put("params", jumpLink);
|
| | | // 跳转订单列表
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("orderList"));
|
| | | }
|
| | |
|
| | | } else if (UserSystemCoupon.STATE_IN_USE == state) {
|
| | | // 使用中
|
| | | userCouponVO.setInUseExplain(configService.get("free_coupon_using-help"));
|
| | | }
|
| | | }
|
| | |
|
| | | userCouponVO.setJumpBtn(jumpBtn);
|
| | |
|
| | | String couponTerm = "有效期:";
|
| | | Date startTime = userCouponVO.getStartTime();
|
| | |
| | | couponTerm = couponTerm + sdf.format(startTime) + "-" + sdf.format(endTime);
|
| | | }
|
| | | userCouponVO.setCouponTerm(couponTerm);
|
| | |
|
| | | Integer state = userCouponVO.getState();
|
| | | if (UserSystemCoupon.STATE_END_USE == state || UserSystemCoupon.STATE_OVERDUE == state) {
|
| | | userCouponVO.setCouponPicture(systemCoupon.getPictureInvalid());
|
| | | } else {
|
| | | userCouponVO.setCouponPicture(systemCoupon.getPicture());
|
| | | }
|
| | |
|
| | | if (UserSystemCoupon.STATE_CAN_USE == state) {
|
| | | int differentDays = 0;
|
| | |
| | | remainDays.put("fontColor", "#F14242");
|
| | | userCouponVO.setRemainDays(remainDays);
|
| | | }
|
| | |
|
| | | Map<String, Object> jumpBtn = null;
|
| | | CouponTypeEnum type = systemCoupon.getType();
|
| | | Integer stateActivated = userCouponVO.getStateActivated();
|
| | |
|
| | | // 未激活
|
| | | if (stateActivated == null || stateActivated == 0) {
|
| | | userCouponVO.setCouponEffect("待激活");
|
| | | userCouponVO.setCouponRule(systemCoupon.getRemark());
|
| | | if (UserSystemCoupon.STATE_CAN_USE == state) {
|
| | | state = 0;
|
| | | userCouponVO.setState(state);
|
| | | if (CouponTypeEnum.freeCoupon == type) {
|
| | | List<String> listTip = new ArrayList<String>();
|
| | | listTip.add("本免单券由好友赠送,从获赠日起60天内需产生3笔返利订单;");
|
| | | listTip.add("返利订单“已到账”后,方能视为订单产生成功;");
|
| | | listTip.add("满足条件后,系统将自动激活,并在消息-其它消息中提醒。");
|
| | | userCouponVO.setTips(listTip);
|
| | | userCouponVO.setPopup(true);
|
| | | } else if (CouponTypeEnum.welfareFreeCoupon == type) {
|
| | | jumpBtn = new HashMap<String, Object>();
|
| | | if (inviteCode != null && inviteCode.trim().length() > 0) {
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("invite_friends"));
|
| | | } else {
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("invite_activate"));
|
| | | }
|
| | | }
|
| | | } |
| | | }
|
| | |
|
| | | if (UserSystemCoupon.STATE_IN_USE == state && (CouponTypeEnum.freeCouponBuy == type
|
| | | || CouponTypeEnum.freeCoupon == type || CouponTypeEnum.welfareFreeCoupon == type)) {
|
| | | userCouponVO.setInUseExplain(configService.get("free_coupon_using-help"));
|
| | | }
|
| | |
|
| | | // 是否已赠送
|
| | | Boolean give = userCouponVO.getGive();
|
| | | if (give == null) {
|
| | | give = false;
|
| | | }
|
| | | |
| | | if (UserSystemCoupon.STATE_CAN_USE == state) {
|
| | | Map<String, Object> jumpLink = new HashMap<String, Object>();
|
| | | if (CouponTypeEnum.freeCouponGive == type) {
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_GIVE_ONLY);
|
| | | } else if (CouponTypeEnum.freeCoupon == type || CouponTypeEnum.welfareFreeCoupon == type
|
| | | || CouponTypeEnum.freeCouponBuy == type) {
|
| | | jumpLink.put("url", configService.get("free_goods_list"));
|
| | | jumpBtn = new HashMap<String, Object>();
|
| | | jumpBtn.put("params", jumpLink);
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("web"));
|
| | | } else if (CouponTypeEnum.rebatePercentCoupon == type) {
|
| | | // 可使用、 可赠送
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_USE_GIVE);
|
| | |
|
| | | // 返利奖励券- 跳转至订单到账界面
|
| | | jumpLink.put("state", "2");
|
| | | jumpBtn = new HashMap<String, Object>();
|
| | | jumpBtn.put("params", jumpLink);
|
| | | jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("orderList"));
|
| | | }
|
| | | } else if (UserSystemCoupon.STATE_IN_USE == state) {
|
| | | if (CouponTypeEnum.freeCouponGive == type) {
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_GIVE_IN);
|
| | | }
|
| | | |
| | | if (give && CouponTypeEnum.rebatePercentCoupon == type) {
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_GIVE_IN);
|
| | | }
|
| | | } else if (UserSystemCoupon.STATE_END_USE == state) {
|
| | | if (CouponTypeEnum.freeCouponGive == type) {
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_GIVE_END);
|
| | | }
|
| | | |
| | | if (give && CouponTypeEnum.rebatePercentCoupon == type) {
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_GIVE_END);
|
| | | }
|
| | | }
|
| | | userCouponVO.setJumpBtn(jumpBtn);
|
| | | }
|
| | | return listVO;
|
| | | }
|
| | | |
| | | |
| | | @Transactional
|
| | | @Override
|
| | | public String giveCoupon(Long uid, Long id) throws UserSystemCouponException {
|
| | | UserSystemCoupon userSystemCoupon = userSystemCouponMapper.selectByPrimaryKey(id);
|
| | | if (userSystemCoupon == null)
|
| | | throw new UserSystemCouponException(1, "该券已不存在");
|
| | | |
| | | SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
|
| | | if (systemCoupon == null)
|
| | | throw new UserSystemCouponException(1, "该券已不存在");
|
| | | |
| | | systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
|
| | | if (systemCoupon == null)
|
| | | throw new UserSystemCouponException(1, "该券已失效");
|
| | | |
| | | Integer state = userSystemCoupon.getState();
|
| | | if (state == UserSystemCoupon.STATE_OVERDUE) |
| | | throw new UserSystemCouponException(1, "该券已过期");
|
| | | |
| | | if (state == UserSystemCoupon.STATE_END_USE) |
| | | throw new UserSystemCouponException(1, "该券使用/赠送成功");
|
| | | |
| | | CouponTypeEnum type = systemCoupon.getType();
|
| | | if (type != CouponTypeEnum.freeCouponGive && type != CouponTypeEnum.rebatePercentCoupon )
|
| | | throw new UserSystemCouponException(1, "该券不支持赠送");
|
| | | |
| | | |
| | | Date startTime = new Date();
|
| | | Date endTime = DateUtil.plusDayDate(3, new Date());
|
| | | |
| | | long num = 10000 + (long) (Math.random() * 10000);
|
| | | String token = UserUtil.getInviteCode(num);
|
| | | |
| | | TokenRecord tokenRecord = new TokenRecord();
|
| | | tokenRecord.setUid(uid);
|
| | | tokenRecord.setIdentify(id+"");
|
| | | tokenRecord.setType(TokenTypeEnum.coupon);
|
| | | tokenRecord.setEndTime(endTime);
|
| | | tokenRecord.setStartTime(startTime);
|
| | | tokenRecord.setToken(token);
|
| | | tokenRecord.setState(state);
|
| | | tokenRecordService.insertSelective(tokenRecord);
|
| | | |
| | |
|
| | | String tips = "送给你一张返利奖励券快去领取吧,复制本条消息[&%s&],打开[返利券]App领取,使用后可让返利加倍。\r\n" |
| | | +"----------------------------\r\n" |
| | | + "下载[返利券]App链接:http://t.cn/2H7AXAH\r\n"
|
| | | + "PS:口令将会24小时内失效,请及时领取。";
|
| | | |
| | | tips = String.format(tips, token);
|
| | | |
| | | return tips;
|
| | | }
|
| | |
|
| | | }
|