| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | @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; |
| | | } |
| | | } |