| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.DateUtil;
|
| | | import org.yeshi.utils.entity.DateInfo;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.UserSystemCouponMapper;
|
| | | import com.yeshi.fanli.dto.msg.MsgOtherCouponActivateDTO;
|
| | | import com.yeshi.fanli.dto.msg.MsgOtherGiveContentDTO;
|
| | | import com.yeshi.fanli.dto.msg.MsgOtherSystemGiveDTO;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.Order;
|
| | |
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TokenUtil;
|
| | | import com.yeshi.fanli.util.VersionUtil;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.util.factory.msg.MsgOtherSystemGiveDTOFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void useOrderCoupon(Long uid, Long id, String orderNo, Integer sourceType)
|
| | | public void useOrderCoupon(Long uid, Long id, String orderNo, Integer sourceType, AcceptData acceptData)
|
| | | throws UserSystemCouponException, Exception {
|
| | |
|
| | | if (id == null) {
|
| | | if (id == null)
|
| | | throw new UserSystemCouponException(1, "券id不存在");
|
| | | }
|
| | |
|
| | | if (sourceType == null) {
|
| | | if (sourceType == null)
|
| | | sourceType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | }
|
| | |
|
| | | // 用户券
|
| | | UserSystemCoupon userSystemCoupon = selectByPrimaryKey(id);
|
| | | if (userSystemCoupon == null) {
|
| | | if (userSystemCoupon == null)
|
| | | throw new UserSystemCouponException(1, "券信息不存在");
|
| | | }
|
| | |
|
| | | if (userSystemCoupon.getUid().longValue() != uid) {
|
| | | if (userSystemCoupon.getUid().longValue() != uid)
|
| | | throw new UserSystemCouponException(1, "不属于该用户的券");
|
| | | }
|
| | |
|
| | | Integer state = userSystemCoupon.getState();
|
| | | Integer stateActivated = userSystemCoupon.getStateActivated();
|
| | | if (UserSystemCoupon.STATE_CAN_USE != state || 1 != stateActivated) {
|
| | | if (UserSystemCoupon.STATE_CAN_USE != state || 1 != stateActivated)
|
| | | throw new UserSystemCouponException(1, "该券不能被使用");
|
| | | }
|
| | |
|
| | | // 系统券信息
|
| | | SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
|
| | | if (systemCoupon != null && systemCoupon.getId() != null) {
|
| | | systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
|
| | | if (systemCoupon == null) {
|
| | | if (systemCoupon == null)
|
| | | throw new UserSystemCouponException(1, "券已不存在");
|
| | | }
|
| | | }
|
| | |
|
| | | if (systemCoupon.getType() != CouponTypeEnum.rebatePercentCoupon) {
|
| | | |
| | | if (systemCoupon.getType() != CouponTypeEnum.rebatePercentCoupon)
|
| | | throw new UserSystemCouponException(1, "券类型不匹配");
|
| | | }
|
| | |
|
| | | if (orderNo == null || orderNo.trim().length() == 0) {
|
| | | if (orderNo == null || orderNo.trim().length() == 0)
|
| | | throw new UserSystemCouponException(1, "订单号不存在");
|
| | | }
|
| | |
|
| | | // 订单
|
| | | CommonOrderVO orderVO = commonOrderService.getCommonOrderByOrderNo(uid, orderNo, CommonOrder.STATE_JS,
|
| | | sourceType);
|
| | | if (orderVO == null) {
|
| | | if (orderVO == null)
|
| | | throw new UserSystemCouponException(1, "订单信息获取失败");
|
| | | |
| | | // 版本区分:2.0.2
|
| | | if (VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(), acceptData.getVersion())) {
|
| | | Date thirdCreateTime = orderVO.getThirdCreateTime();
|
| | | if (thirdCreateTime != null) {
|
| | | long downOrderTime = thirdCreateTime.getTime();
|
| | | long limitDate = Long.parseLong("1573315200000"); // TODO 日期待确定2019-11-10
|
| | | if (downOrderTime > limitDate) {
|
| | | Date endDay = DateUtil.plusDayDate(4, thirdCreateTime);
|
| | | long currentTime = java.lang.System.currentTimeMillis();
|
| | | if (endDay.getTime() > currentTime) {
|
| | | boolean valid = false;
|
| | | DateInfo dateInfo = DateUtil.dateDiff3(currentTime, endDay.getTime());
|
| | | if (dateInfo != null) {
|
| | | if (dateInfo.getDay() > 0) |
| | | valid = true;
|
| | |
|
| | | if (!valid && dateInfo.getHour() > 0)
|
| | | valid = true;
|
| | | |
| | |
|
| | | if (!valid && dateInfo.getMinute() > 0) |
| | | valid = true;
|
| | | |
| | | if (!valid && dateInfo.getSecond() >= 0)
|
| | | valid = true;
|
| | | }
|
| | | |
| | | if (!valid) |
| | | throw new UserSystemCouponException(1, "该订单已不能使用使用奖励券,详情请咨询客服");
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | BigDecimal hongBao = orderVO.getHongBao();
|