| | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void useGoodsCoupon(Long uid, Long id, Long goodId) throws UserSystemCouponException, Exception {
|
| | | public void useGoodsCoupon(Long uid, Long id, Long goodId, Integer sourceType) throws UserSystemCouponException, Exception {
|
| | | if (uid == null) {
|
| | | throw new UserSystemCouponException(1, "用户未登录");
|
| | | }
|
| | |
| | | // 插入使用券记录
|
| | | UserSystemCouponRecord couponRecord = new UserSystemCouponRecord();
|
| | | couponRecord.setGoodId(goodId);
|
| | | couponRecord.setGoodSource(Constant.SOURCE_TYPE_TAOBAO); // 默认淘宝
|
| | | couponRecord.setGoodSource(sourceType); // 默认淘宝
|
| | | couponRecord.setState(UserSystemCouponRecord.STATE_WAIT); // 正在匹配
|
| | | couponRecord.setUserSystemCoupon(userSystemCoupon);
|
| | | couponRecord.setCouponType(baseCoupon.getType().name());
|
| | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void useOrderCoupon(Long uid, Long id, String orderNo) throws UserSystemCouponException, Exception {
|
| | | public void useOrderCoupon(Long uid, Long id, String orderNo, Integer sourceType) throws UserSystemCouponException, Exception {
|
| | |
|
| | | if (id == null) {
|
| | | throw new UserSystemCouponException(1, "券id不存在");
|
| | | }
|
| | |
|
| | | |
| | | if (sourceType == null) {
|
| | | sourceType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | }
|
| | | |
| | | // 用户券
|
| | | UserSystemCoupon userSystemCoupon = selectByPrimaryKey(id);
|
| | | if (userSystemCoupon == null) {
|
| | |
| | | }
|
| | |
|
| | | // 订单
|
| | | CommonOrderVO orderVO = commonOrderService.getCommonOrderByOrderNo(uid, orderNo, CommonOrder.STATE_JS);
|
| | | CommonOrderVO orderVO = commonOrderService.getCommonOrderByOrderNo(uid, orderNo, CommonOrder.STATE_JS, sourceType);
|
| | | if (orderVO == null) {
|
| | | throw new UserSystemCouponException(1, "订单信息获取失败");
|
| | | }
|
| | |
| | | // 条件: A:必须是返利订单 、B:必须已经处于已到账状态
|
| | | if (HongBaoV2.TYPE_ZIGOU == hongBaoType && HongBaoV2.STATE_YILINGQU == hongBaoState || hongBao != null) {
|
| | |
|
| | | Order order = orderService.findOrderByOrderIdAndType(orderNo, Order.ORDER_TYPE_TAOBAO);
|
| | | Order order = orderService.findOrderByOrderIdAndType(orderNo, sourceType);
|
| | | if (order == null)
|
| | | return;
|
| | |
|
| | |
| | | hongBaoV2.setUserInfo(new UserInfo(uid));
|
| | | hongBaoV2.setPreGetTime(new Date());
|
| | | hongBaoV2.setGetTime(new Date());
|
| | | |
| | | hongBaoV2Service.insertSelective(hongBaoV2);
|
| | |
|
| | | // 2.插入关联
|
| | | orderHongBaoMapService.addOrderHongBaoMap(hongBaoV2, order);
|
| | |
|
| | | // 3.插入资金明细,用户余额
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createOrderReward(orderNo, money,
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createOrderReward(orderNo, sourceType, money,
|
| | | new UserInfo(uid));
|
| | | userMoneyDetailService.addUserMoneyDetail(userMoneyDetail);
|
| | | userInfoService.addMoney(new UserInfo(uid), money);
|
| | |
|
| | | // 插入资金通知
|
| | | userMoneyMsgNotificationService.orderReward(uid, orderNo, money,
|
| | | userMoneyMsgNotificationService.orderReward(uid, orderNo, sourceType, money,
|
| | | userInfoService.selectByPKey(uid).getMyHongBao());
|
| | |
|
| | | /* 用户券信息状态及记录处理 */
|
| | |
| | | // 插入使用券记录
|
| | | UserSystemCouponRecord couponRecord = new UserSystemCouponRecord();
|
| | | couponRecord.setState(UserSystemCouponRecord.STATE_SUCCESS);
|
| | | couponRecord.setGoodSource(sourceType);
|
| | | couponRecord.setOrderNo(orderNo);
|
| | | couponRecord.setUserSystemCoupon(userSystemCoupon);
|
| | | couponRecord.setCouponType(systemCoupon.getType().name());
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public UserSystemCouponRecordVO getRewardCouponRecord(String orderNo) throws UserSystemCouponException, Exception {
|
| | | public UserSystemCouponRecordVO getRewardCouponRecord(String orderNo, Integer sourceType) throws UserSystemCouponException, Exception {
|
| | |
|
| | | if (orderNo == null || orderNo.trim().length() == 0) {
|
| | | throw new UserSystemCouponException(1, "订单号不存在");
|
| | |
| | | Long uid = userSystemCoupon.getUid();
|
| | |
|
| | | CommonOrderVO commonOrderVO = commonOrderService.getCommonOrderByOrderNo(userSystemCoupon.getUid(), orderNo,
|
| | | CommonOrder.STATE_JS);
|
| | | CommonOrder.STATE_JS, sourceType);
|
| | |
|
| | | if (commonOrderVO == null) {
|
| | | throw new UserSystemCouponException(1, "订单信息获取失败");
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public UserSystemCouponRecordVO getFreeCouponRecord(String orderNo) throws UserSystemCouponException, Exception {
|
| | | public UserSystemCouponRecordVO getFreeCouponRecord(String orderNo, Integer sourceType) throws UserSystemCouponException, Exception {
|
| | |
|
| | | if (orderNo == null || orderNo.trim().length() == 0) {
|
| | | throw new UserSystemCouponException(1, "订单号不存在");
|
| | |
| | | }
|
| | |
|
| | | // 订单
|
| | | CommonOrderVO orderVO = commonOrderService.getCommonOrderByOrderNo(userSystemCoupon.getUid(), orderNo, null);
|
| | | CommonOrderVO orderVO = commonOrderService.getCommonOrderByOrderNo(userSystemCoupon.getUid(), orderNo, null, sourceType);
|
| | | if (orderVO == null) {
|
| | | throw new UserSystemCouponException(1, "订单信息获取失败");
|
| | | }
|
| | |
| | | }
|
| | | userInfoExtraService.saveUserInfoExtra(userInfoExtra);
|
| | |
|
| | | }
|
| | | |
| | | |
| | | |
| | | @Transactional
|
| | | public void randomRewardCouponForPush(Integer amount, Long uid) throws Exception {
|
| | | int coupon = 0;
|
| | | |
| | | for (int i = 0; i < amount; i++) {
|
| | | // 系统随机
|
| | | BigDecimal percent = new BigDecimal(randomNum());
|
| | | |
| | | // 查询奖励券
|
| | | SystemCoupon systemCoupon = systemCouponService.getCouponByTypeAndPercent(
|
| | | CouponTypeEnum.rebatePercentCoupon.name(),percent);
|
| | | |
| | | if (systemCoupon == null) {
|
| | | return;
|
| | | }
|
| | | |
| | | // 结束日期
|
| | | // 今天在内 减去一天
|
| | | String endDay = DateUtil.plusDay(systemCoupon.getExpiryDay() - 1, new Date());
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
| | | Date endTime = format.parse(endDay);
|
| | | |
| | | UserSystemCoupon userCoupon = new UserSystemCoupon();
|
| | | userCoupon.setUid(uid);
|
| | | userCoupon.setSource(UserSystemCoupon.SOURCE_SYSTEM_PUSH);
|
| | | userCoupon.setSystemCoupon(systemCoupon);
|
| | | userCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
|
| | | userCoupon.setStateActivated(1);
|
| | | userCoupon.setStartTime(new Date());
|
| | | userCoupon.setEndTime(endTime);
|
| | | userCoupon.setCreateTime(new Date());
|
| | | userCoupon.setUpdateTime(new Date());
|
| | | // 插入数据库
|
| | | insertSelective(userCoupon);
|
| | | |
| | | // 券数量
|
| | | coupon ++;
|
| | | |
| | | // 消息推送
|
| | | try {
|
| | | userOtherMsgNotificationService.rewardCouponGet(userCoupon,systemCoupon.getPercent().intValue());
|
| | | } catch(Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | // 获取额外信息
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null) {
|
| | | return;
|
| | | }
|
| | | |
| | | Integer couponNews = userInfoExtra.getCouponNews();
|
| | | if (couponNews == null) {
|
| | | userInfoExtra.setCouponNews(coupon);
|
| | | } else {
|
| | | userInfoExtra.setCouponNews(couponNews + coupon);
|
| | | }
|
| | | userInfoExtraService.saveUserInfoExtra(userInfoExtra);
|
| | | }
|
| | |
|
| | |
|