| | |
| | | import com.ks.vip.service.VipOrederService; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.DateUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | |
| | | @Override |
| | | public void insertSelective(VipOrder t){ |
| | | public void insertSelective(VipOrder t) { |
| | | vipOrderMapper.insertSelective(t); |
| | | } |
| | | |
| | | @Override |
| | | public void updateByPrimaryKeySelective(VipOrder t){ |
| | | public void updateByPrimaryKeySelective(VipOrder t) { |
| | | vipOrderMapper.updateByPrimaryKeySelective(t); |
| | | } |
| | | |
| | |
| | | return vipOrderMapper.listByPage(query); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addOrderByBuy(VipOrderDTO t) throws VipOrderException { |
| | | if(t.getComboId() == null || t.getComboId() <= 0){ |
| | | throw new VipOrderException(1, "套餐ID不能为空"); |
| | | } |
| | | if(StringUtil.isNullOrEmpty(t.getUid())){ |
| | | throw new VipOrderException(1, "用户ID不能为空"); |
| | | } |
| | | if(t.getPayWay() == null){ |
| | | throw new VipOrderException(1, "付款方式不能为空"); |
| | | } |
| | | if(StringUtil.isNullOrEmpty(t.getThreeOrderId())){ |
| | | throw new VipOrderException(1, "付款订单号不能为空"); |
| | | } |
| | | |
| | | // 检查是否已记录 |
| | | VipOrder order = vipOrderMapper.getByThreeOrderId(t.getThreeOrderId()); |
| | | if (order != null) { |
| | | throw new VipOrderException(1, "该付款订单号已存在"); |
| | | } |
| | | |
| | | VipCombo vipCombo = vipComboService.selectByPrimaryKey(t.getComboId()); |
| | | if (vipCombo == null) { |
| | | throw new VipOrderException(1, "该套餐不存在"); |
| | | } |
| | | // 有效天数 |
| | | Integer validDays = vipCombo.getValidDays(); |
| | | |
| | | // 判断订单类型 |
| | | String orderType = OrderTypeEnum.buyNewly.name(); |
| | | long count = vipOrderMapper.countByTypeAndUid(t.getUid(), orderType); |
| | | if(count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew.name(); |
| | | } |
| | | |
| | | // 插入订单信息 |
| | | VipOrder newOrder = new VipOrder(); |
| | | newOrder.setComboId(t.getComboId()); |
| | | newOrder.setUid(t.getUid()); |
| | | newOrder.setThreeOrderId(t.getThreeOrderId()); |
| | | newOrder.setPayWay(t.getPayWay().name()); |
| | | newOrder.setPayAccount(t.getPayAccount()); |
| | | newOrder.setPayMoney(t.getPayMoney()); |
| | | newOrder.setPayTime(t.getPayTime()); |
| | | newOrder.setType(orderType); |
| | | newOrder.setCreateTime(new Date()); |
| | | vipOrderMapper.insertSelective(newOrder); |
| | | |
| | | // 更新等级 |
| | | vipCenterService.saveVipCenter(t.getUid(), vipCombo.getGradeId(), validDays, newOrder.getId() ); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addOrderByWatchVideo(String uid, Long gradeId, Integer validDays) throws VipOrderException { |
| | | if(StringUtil.isNullOrEmpty(uid)){ |
| | | public void addOrderByWatchVideo(String uid, Long gradeId, Integer hour) throws VipOrderException { |
| | | if (StringUtil.isNullOrEmpty(uid)) { |
| | | throw new VipOrderException(1, "用户ID不能为空"); |
| | | } |
| | | if(gradeId == null){ |
| | | if (gradeId == null) { |
| | | throw new VipOrderException(1, "等级ID不能为空"); |
| | | } |
| | | if(validDays == null || validDays.longValue() <= 0){ |
| | | throw new VipOrderException(1, "有效天数不能为空"); |
| | | if (hour == null || hour.longValue() <= 0) { |
| | | throw new VipOrderException(1, "有效小时数不能为空"); |
| | | } |
| | | if (!canAddOrderByWatchVideo(uid)) { |
| | | throw new VipOrderException(1, "今日次数已经用完"); |
| | | } |
| | | |
| | | |
| | | // 插入订单信息 唯一性处理TODO |
| | | VipOrder newOrder = new VipOrder(); |
| | | newOrder.setUid(uid); |
| | | newOrder.setType(OrderTypeEnum.watchVideo.name()); |
| | | newOrder.setType(OrderTypeEnum.watchVideo); |
| | | newOrder.setCreateTime(new Date()); |
| | | vipOrderMapper.insertSelective(newOrder); |
| | | |
| | | // 更新等级 |
| | | vipCenterService.saveVipCenter(uid, gradeId, validDays,newOrder.getId() ); |
| | | vipCenterService.saveVipCenter(uid, gradeId, hour, newOrder.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public boolean canAddOrderByWatchVideo(String uid) { |
| | | long now = System.currentTimeMillis(); |
| | | VipOrderQuery vipOrderQuery = new VipOrderQuery(); |
| | | vipOrderQuery.uid = uid; |
| | | vipOrderQuery.type = OrderTypeEnum.watchVideo; |
| | | vipOrderQuery.minCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now, "yyyy-MM-dd"), "yyyy-MM-dd")); |
| | | vipOrderQuery.maxCreateTime = DateUtil.plusDayDate(1, vipOrderQuery.minCreateTime); |
| | | long count = vipOrderMapper.count(vipOrderQuery); |
| | | //TODO 写入配置信息 |
| | | return count < 5; |
| | | } |
| | | } |