|
|
@@ -15,10 +15,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
-import com.cyksj.common.util.Codec;
|
|
|
-import com.cyksj.common.util.Jsons;
|
|
|
-import com.cyksj.common.util.StringUtil;
|
|
|
-import com.cyksj.common.util.Xmls;
|
|
|
+import com.cyksj.common.util.*;
|
|
|
import com.cyksj.config.WeChatConfig;
|
|
|
import com.cyksj.config.zfb.AliPayClientFactory;
|
|
|
import com.cyksj.dto.RedisKey;
|
|
|
@@ -305,43 +302,73 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
public void changeRelation(ChangeRelationReq req) {
|
|
|
- Long orderId = req.getOrderId();
|
|
|
- Long groupId = req.getGroupId();
|
|
|
- OrderDon orderDon = this.getById(orderId);
|
|
|
- Assert.notNull(orderDon, "订单不存在");
|
|
|
- if (orderDon.getRelationId() == 0) throw BusinessRuntimeException.getInstance("车票不存在");
|
|
|
- GroupsRelation relation = relationMapper.selectById(orderDon.getRelationId());
|
|
|
+ Long relationId = req.getRelationId();
|
|
|
+ Long groupId = req.getGroupsId();
|
|
|
+ GroupsRelation relation = relationMapper.selectById(relationId);
|
|
|
Assert.notNull(relation, "车票已不存在");
|
|
|
- //清除原先车票
|
|
|
- relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.change_ticket);
|
|
|
- //移入新车队
|
|
|
+ Long userId = relation.getUserId();
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getUserId, userId)
|
|
|
+ .eq(OrderDon::getRelationId, relationId)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
+ .last("limit 1"));
|
|
|
+ Assert.notNull(orderDon, "订单不存在");
|
|
|
+
|
|
|
+ //获取新车队
|
|
|
LambdaQueryWrapper<GroupsTrips> queryWrapper = Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
.eq(GroupsTrips::getSkuId, orderDon.getSkuId())
|
|
|
.eq(GroupsTrips::getId, groupId)
|
|
|
.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
+ .ne(GroupsTrips::getId, relation.getGroupsId())
|
|
|
.ne(GroupsTrips::getStatus, GroupsTrips.Status.down);
|
|
|
GroupsTrips groups = groupsMapper.selectOne(queryWrapper);
|
|
|
if (groups == null) throw BusinessRuntimeException.getInstance("该新车位人员已满");
|
|
|
|
|
|
- //更新新车队车位
|
|
|
+ //获取新车队车位
|
|
|
GroupsRelation newRelation = getRelationThisTrips(orderDon.getUserId(), groupId, 1);
|
|
|
+
|
|
|
newRelation.setUserId(relation.getUserId());
|
|
|
newRelation.setStartTime(relation.getStartTime());
|
|
|
newRelation.setExpiryTime(relation.getExpiryTime());
|
|
|
newRelation.setCustomerService(relation.getCustomerService());
|
|
|
newRelation.setStatus(GroupsRelation.Status.validity);
|
|
|
- if ((newRelation.getStartTime() == null || newRelation.getExpiryTime() == null) && groups.getStatus() != GroupsTrips.Status.waiting) {
|
|
|
- List<OrderDon> orderDonList = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, relation.getUserId()).eq(OrderDon::getRelationId, relation.getId()).eq(OrderDon::getStatus, OrderDon.Status.hasPayment));
|
|
|
- orderDonList.forEach((relationOrder) -> {
|
|
|
+
|
|
|
+ //清除原先车票
|
|
|
+ relation.setNewRelationId(newRelation.getId());
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.change_ticket);
|
|
|
+
|
|
|
+ if ((newRelation.getStartTime() == null || newRelation.getExpiryTime() == null)) {
|
|
|
+ List<OrderDon> orderDonList = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, userId).eq(OrderDon::getRelationId, relationId).eq(OrderDon::getStatus, OrderDon.Status.hasPayment));
|
|
|
+ if (groups.getStatus() == GroupsTrips.Status.waiting) {
|
|
|
+ orderDonList.forEach(hasPaymentOrder -> {
|
|
|
+ hasPaymentOrder.setRelationId(newRelation.getId());
|
|
|
+ orderDonMapper.updateById(hasPaymentOrder);
|
|
|
+ });
|
|
|
+ relationMapper.updateById(newRelation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ orderDonList.forEach((hasPaymentOrder) -> {
|
|
|
//如果续费增加时间,如果首次则设置当前时间为初始时间
|
|
|
Date expiryTime = Optional.ofNullable(newRelation.getExpiryTime()).orElse(new Date());
|
|
|
- GoodsDonSku donSku = skuMapper.selectById(relationOrder.getSkuId());
|
|
|
- Date newDate = DateUtil.offset(expiryTime, DateField.MONTH, donSku.getMonths() * relationOrder.getNum());
|
|
|
+ GoodsDonSku donSku = skuMapper.selectById(hasPaymentOrder.getSkuId());
|
|
|
+ Date newDate = DateUtil.offset(expiryTime, DateField.MONTH, donSku.getMonths() * hasPaymentOrder.getNum());
|
|
|
newRelation.setExpiryTime(newDate);
|
|
|
newRelation.setStartTime(newRelation.getStartTime() == null ? new Date() : null);
|
|
|
relationMapper.updateById(newRelation);
|
|
|
+
|
|
|
+ hasPaymentOrder.setStatus(OrderDon.Status.complete);
|
|
|
+ hasPaymentOrder.setRelationId(newRelation.getId());
|
|
|
+ orderDonMapper.updateById(hasPaymentOrder);
|
|
|
});
|
|
|
+ return;
|
|
|
}
|
|
|
+ List<OrderDon> orderDonList = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, userId).eq(OrderDon::getRelationId, relationId).eq(OrderDon::getStatus, OrderDon.Status.complete));
|
|
|
+ orderDonList.forEach(completeOrder->{
|
|
|
+ completeOrder.setRelationId(newRelation.getId());
|
|
|
+ orderDonMapper.updateById(completeOrder);
|
|
|
+ });
|
|
|
+ redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + newRelation.getId());
|
|
|
+ relationMapper.updateById(newRelation);
|
|
|
}
|
|
|
|
|
|
public String zfbRefund(OrderRefundReq refundReq, OrderDon orderDon) throws Exception {
|
|
|
@@ -582,29 +609,11 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
*/
|
|
|
public GroupsRelation getRelationThisTrips(Long userId, Long groupsId, Integer retryNum) {
|
|
|
//寻找快满编车队进行占座
|
|
|
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
- .eq(GroupsRelation::getGroupsId, groupsId)
|
|
|
- .eq(GroupsRelation::getStatus, "none")
|
|
|
- .eq(GroupsRelation::getUserId, 0)
|
|
|
- .orderByDesc(GroupsRelation::getNum)
|
|
|
- .last("limit 1")
|
|
|
- );
|
|
|
+ GroupsRelation relation = relationMapper.selectRandomOneRelationByGroupsId(groupsId);
|
|
|
if (relation == null) {
|
|
|
throw BusinessRuntimeException.getInstance("该车队人员已满,请选择另一车队");
|
|
|
}
|
|
|
Long relationId = relation.getId();
|
|
|
- Object value = redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId);
|
|
|
- if (value != null) {
|
|
|
- relation = relationMapper.selectById(relationId);
|
|
|
- if (relation != null && relation.getUserId() == 0l) {
|
|
|
- redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relationId);
|
|
|
- }
|
|
|
- if (relation != null && relation.getUserId() != 0l) {
|
|
|
- if (retryNum == 7) throw BusinessRuntimeException.getInstance("该车队人员已满,请选择另一车队");
|
|
|
- retryNum++;
|
|
|
- getRelationThisTrips(userId, groupsId, retryNum);
|
|
|
- }
|
|
|
- }
|
|
|
if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
if (retryNum == 7) throw BusinessRuntimeException.getInstance("该车队人员已满,请选择另一车队");
|
|
|
retryNum++;
|
|
|
@@ -613,6 +622,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
if (count == 0) {
|
|
|
log.error("车位异常 groupId:{}", groupsId);
|
|
|
+ groupsMapper.updateAvailableNum(groupsId);
|
|
|
throw new BusinessRuntimeException("车位异常");
|
|
|
}
|
|
|
return relation;
|