|
|
@@ -33,6 +33,7 @@ import com.cyksj.common.snowflake.Sequence;
|
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
import com.cyksj.common.util.Codec;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
+import com.cyksj.common.util.SmsUtil;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.config.WeChatConfig;
|
|
|
import com.cyksj.config.zfb.AliPayClientFactory;
|
|
|
@@ -77,6 +78,7 @@ import com.cyksj.service.order.OrderDonService;
|
|
|
import com.cyksj.service.pay.AliPayCommonService;
|
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
+import com.cyksj.service.relation.GroupsRelationExpiryRecordService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.cyksj.service.telegram.TelegramService;
|
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
|
@@ -219,6 +221,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final ChannelPopularizeMapper channelPopularizeMapper;
|
|
|
|
|
|
+ private final GroupsRelationExpiryRecordService groupsRelationExpiryRecordService;
|
|
|
+
|
|
|
+ private final UserPhoneSendRecordMapper userPhoneSendRecordMapper;
|
|
|
+
|
|
|
private final TelegramService telegramService;
|
|
|
|
|
|
private final GiftCardUserRecordService giftCardUserRecordService;
|
|
|
@@ -268,7 +274,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
User user;
|
|
|
String payOpenId = null;
|
|
|
Long relationId = 0L;
|
|
|
-
|
|
|
Boolean isNeedTicket = checkIsNeedGroupsRelation(goodsDon);
|
|
|
Long userId = payRequest.getUserId();
|
|
|
if (userId != null) {
|
|
|
@@ -277,6 +282,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw new BusinessRuntimeException("您有未支付订单.");
|
|
|
}
|
|
|
}
|
|
|
+ GroupsRelation relation = null;
|
|
|
if (userId == null) {
|
|
|
user = new User();
|
|
|
user.setId(0l);
|
|
|
@@ -291,7 +297,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
if (goodsDon.getType() == 1 && isNeedTicket) {
|
|
|
//获取座位
|
|
|
- relationId = getRelation(payRequest, sku);
|
|
|
+ relation = getRelation(payRequest, sku);
|
|
|
+ relationId = relation.getId();
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
@@ -314,9 +321,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
//是否是特定价格 且是否满足
|
|
|
Boolean isSpecificPrice = Optional.ofNullable(payRequest.getIsSpecificPrice()).orElse(false);
|
|
|
- BigDecimal specificPrice = null;
|
|
|
+ String specificGoodsIds = null;
|
|
|
+ BigDecimal specificPrice = BigDecimal.ZERO;
|
|
|
if (isSpecificPrice) {
|
|
|
- String specificGoodsIds = sku.getSpecificGoodsIds();
|
|
|
+ specificGoodsIds = sku.getSpecificGoodsIds();
|
|
|
if (StrUtil.isEmpty(specificGoodsIds)) {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
}
|
|
|
@@ -338,7 +346,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
specificPrice = sku.getSpecificPrice();
|
|
|
}
|
|
|
|
|
|
- if (sku != null && !isSpecificPrice && payRequest.getDonMoney().compareTo(sku.getPrice()) < 0) {
|
|
|
+ if (sku != null && payRequest.getDonMoney().compareTo(sku.getPrice()) < 0 && !isSpecificPrice) {
|
|
|
log.info("规格:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", sku.getSpecVal(), payRequest.getDonMoney(), user.getId(), sku.getPrice());
|
|
|
payRequest.setDonMoney(sku.getPrice());
|
|
|
}
|
|
|
@@ -392,6 +400,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setIsWebPay(payRequest.getIsWebPay());
|
|
|
orderDon.setSource(payRequest.getSource());
|
|
|
orderDon.setCouponExCode(payRequest.getCouponExCode());
|
|
|
+ if (relation != null && relation.getStatus() == GroupsRelation.Status.outside) {
|
|
|
+ orderDon.setIsOt(true);
|
|
|
+ }
|
|
|
//设置分销订单
|
|
|
setDistributeOrderMark(orderDon, goodsDon.getType(), user.getId());
|
|
|
if (relationId != 0) {
|
|
|
@@ -479,6 +490,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (Constant.realGoodsType.contains(goodsDon.getType()) && !goodsDon.getId().equals(27l)) {
|
|
|
saveTransport(payRequest.getAddressId(), orderDon.getId());
|
|
|
}
|
|
|
+ //保存加购发货地址
|
|
|
+ if (orderDon.getIsDp() && payRequest.getAddressId() != null) {
|
|
|
+ redisService.set(RedisService.key.PLUS_GOODS_ADDRESS_KEY.getName() + orderDon.getId(), payRequest.getAddressId(), RedisService.key.PLUS_GOODS_ADDRESS_KEY.getTimeout());
|
|
|
+ }
|
|
|
if (orderDon.getStatus() == OrderDon.Status.noPayment) {
|
|
|
jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
closeOrder(orderDon.getId(), null);
|
|
|
@@ -727,12 +742,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//throw new BusinessRuntimeException("订单用户与车位用户不匹配!");
|
|
|
} else {
|
|
|
- if (GroupsRelation.Status.locking.equals(groupsRelation.getStatus())) {
|
|
|
+ if (GroupsRelation.Status.locking == groupsRelation.getStatus() || GroupsRelation.Status.outside == groupsRelation.getStatus()) {
|
|
|
log.info("清理用户userId:{}未支付订单", orderDon.getUserId());
|
|
|
groupsRelation.setUserId(0L);
|
|
|
- groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
+ if (GroupsRelation.Status.outside != groupsRelation.getStatus()) {
|
|
|
+ groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
+ }
|
|
|
groupsRelationMapper.updateById(groupsRelation);
|
|
|
- orderCommonService.delRelation(groupsRelation.getId());
|
|
|
+ orderCommonService.delRelation(groupsRelation);
|
|
|
|
|
|
//车位空余发送模板消息
|
|
|
// TASK_POOL.execute(() -> {
|
|
|
@@ -874,6 +891,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setPreSkuId(tripsSkuId);
|
|
|
}
|
|
|
orderDon.setGoodsId(goodsDon.getId());
|
|
|
+ if (relation != null && relation.getStatus() == GroupsRelation.Status.outside) {
|
|
|
+ orderDon.setIsOt(true);
|
|
|
+ }
|
|
|
//虚拟商品订单,是否是分销订单
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
UserDistributeShared userDistributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class).eq(UserDistributeShared::getUserId, user.getId()).last("limit 1"));
|
|
|
@@ -983,11 +1003,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
unifiedHandlerOrderNotify(orderDon, goodsDon, sku);
|
|
|
}
|
|
|
|
|
|
- public void setRelation(Long relationId, Long groupsId, Long userId, Long goodsId, Boolean isLoginPopularize) {
|
|
|
+ public void setRelation(Long relationId, Long groupsId, Long userId, Long goodsId, Boolean isLoginPopularize, GroupsRelation.Status status) {
|
|
|
if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
}
|
|
|
+ if (status == GroupsRelation.Status.outside) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
int count = groupsMapper.decrAvailableNum(groupsId);
|
|
|
if (count == 0) {
|
|
|
log.error("车位异常 groupId:{}", groupsId);
|
|
|
@@ -1006,15 +1029,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (address == null) {
|
|
|
throw new BusinessRuntimeException("请添加收货地址.");
|
|
|
}
|
|
|
- OrderDonTransport transport = new OrderDonTransport();
|
|
|
- transport.setOrderId(orderId);
|
|
|
- transport.setReceiver(address.getReceiver());
|
|
|
- transport.setPhone(address.getPhone());
|
|
|
- transport.setProvince(address.getProvince());
|
|
|
- transport.setCity(address.getCity());
|
|
|
- transport.setDistrict(address.getDistrict());
|
|
|
- transport.setAddress(address.getAddress());
|
|
|
- orderDonTransportMapper.insert(transport);
|
|
|
+ saveTransportByAddress(address, orderId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1138,6 +1153,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("订单异常");
|
|
|
}
|
|
|
+ if (orderDon.getStatus() != OrderDon.Status.noPayment) {
|
|
|
+ throw BusinessRuntimeException.getInstance("订单状态已修改");
|
|
|
+ }
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
GoodsDonSku sku = null;
|
|
|
if (orderDon.getSkuId() != null) {
|
|
|
@@ -1172,21 +1190,49 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
try {
|
|
|
List<Long> plusSkuIds = Jsons.parseList(plusSkuIdsStr, Long.class);
|
|
|
//发送优惠加购 规格车票
|
|
|
- List<Long> dis_relation_ids = new ArrayList<>();
|
|
|
- plusSkuIds.forEach(plus_skuId -> {
|
|
|
+ List<Long> dis_relation_ids = null;
|
|
|
+ List<Long> plus_order_ids = null;
|
|
|
+ Address address = null;
|
|
|
+ for (Long plus_skuId : plusSkuIds) {
|
|
|
GoodsDonSku plus_sku = goodsDonSkuMapper.selectById(plus_skuId);
|
|
|
if (plus_sku == null) {
|
|
|
log.error("订单id:{}优惠加购规格已被删除 skuId:{},车票未发送", order.getId(), plus_skuId);
|
|
|
- return;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ GoodsDon plus_goods = goodsDonMapper.selectById(plus_sku.getGoodsId());
|
|
|
+ if (plus_goods.getType() != 1) {
|
|
|
+ log.info("orderId:{}存在非虚拟规格加购,添加{}发货信息", order.getId(), plus_goods.getTitle());
|
|
|
+ if (plus_order_ids == null) {
|
|
|
+ plus_order_ids = new ArrayList<>();
|
|
|
+ }
|
|
|
+ if (address == null) {
|
|
|
+ Long addressId = Long.parseLong(redisService.getStr(RedisService.key.PLUS_GOODS_ADDRESS_KEY.getName() + order.getId()));
|
|
|
+ if (addressId == null) {
|
|
|
+ log.error("用户userId{}缓存的收货地址addressId:{}不存在", order.getUserId(), addressId);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ address = addressMapper.selectById(addressId);
|
|
|
+ if (address == null) {
|
|
|
+ log.error("用户userId{}收货地址addressId:{}已不存在", order.getUserId(), addressId);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成实物订单 0元实物订单
|
|
|
+ createRealOrderAndTransport(order.getUserId(), address, plus_goods, plus_sku, plus_order_ids);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (dis_relation_ids == null) {
|
|
|
+ dis_relation_ids = new ArrayList<>();
|
|
|
}
|
|
|
GroupsRelation relationNoOrder = exchangeCodeService.getRelationNoOrder(plus_sku, order.getUserId());
|
|
|
dis_relation_ids.add(relationNoOrder.getId());
|
|
|
- });
|
|
|
+ }
|
|
|
+ redisService.del(RedisService.key.PLUS_GOODS_ADDRESS_KEY.getName() + order.getId());
|
|
|
//保存订单关联优惠加购车票
|
|
|
orderDiscountPlusPurchaseSkuRelationMapper.update(null, Wrappers.lambdaUpdate(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
|
- .set(OrderDiscountPlusPurchaseSkuRelation::getRelationIds, dis_relation_ids.toString())
|
|
|
- .eq(OrderDiscountPlusPurchaseSkuRelation::getOrderId, order.getId())
|
|
|
- .isNull(OrderDiscountPlusPurchaseSkuRelation::getRelationIds));
|
|
|
+ .set(CollUtil.isNotEmpty(dis_relation_ids), OrderDiscountPlusPurchaseSkuRelation::getRelationIds, Jsons.toJson(dis_relation_ids))
|
|
|
+ .set(CollUtil.isNotEmpty(plus_order_ids), OrderDiscountPlusPurchaseSkuRelation::getPlusOrderIds, Jsons.toJson(plus_order_ids))
|
|
|
+ .eq(OrderDiscountPlusPurchaseSkuRelation::getOrderId, order.getId()));
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
@@ -1237,7 +1283,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
//下架POE会员车队
|
|
|
- if (order.getGoodsId() != null && order.getGoodsId().equals(35l)) {
|
|
|
+ if (order.getGoodsId() != null && Constant.DOWN_GOODS_PAY.contains(order.getGoodsId())) {
|
|
|
if (groupsTrips.getAccountId() != null && groupsTrips.getStatus() == GroupsTrips.Status.validity) {
|
|
|
groupsTrips.setStatus(GroupsTrips.Status.down);
|
|
|
groupsMapper.updateById(groupsTrips);
|
|
|
@@ -1347,6 +1393,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
BigDecimal returnPoints = returnMoney.multiply(BigDecimal.valueOf(distributePointsExchangeMoney.getPoints())).divide(distributePointsExchangeMoney.getMoney(), 2, RoundingMode.HALF_DOWN);
|
|
|
points = returnPoints;
|
|
|
}
|
|
|
+ if (userDistribute != null) {
|
|
|
+ //处理渠道规则分销
|
|
|
+ points = handlerDistributeRule(order, distributeWaitingSendPoints, userDistribute.getId(), distributePointsExchangeMoney, points);
|
|
|
+ }
|
|
|
+
|
|
|
distributeWaitingSendPoints.setPoints(points);
|
|
|
if (points != null && points.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
log.info("用户{}邀请{},产生分销订单分发积分记录入库", userDistributeShared.getSharedId(), order.getUserId());
|
|
|
@@ -1615,12 +1666,15 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param preSkuId 续费之前的规格id
|
|
|
- * @param preRelationId 续费之前的座位id
|
|
|
- * @param orderId 订单id
|
|
|
+ * @param orderDon 续费订单
|
|
|
* @param afterSku 续费之后的规格
|
|
|
*/
|
|
|
- private void changeTicketAndRecord(Long preSkuId, Long preRelationId, Long orderId, Integer num, GoodsDonSku afterSku, Long userId) {
|
|
|
+ private void changeTicketAndRecord(OrderDon orderDon,GoodsDonSku afterSku) {
|
|
|
+ Long preSkuId = orderDon.getSkuId();
|
|
|
+ Long preRelationId = orderDon.getRelationId();
|
|
|
+ Long orderId = orderDon.getId();
|
|
|
+ Integer num = orderDon.getNum();
|
|
|
+ Long userId = orderDon.getUserId();
|
|
|
//清理之前的车票
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(preRelationId);
|
|
|
if (relation != null) {
|
|
|
@@ -1638,6 +1692,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
afterRelation.setExpiryTime(afterExpiryTime);
|
|
|
groupsRelationMapper.updateById(afterRelation);
|
|
|
|
|
|
+ //更新订单对应的relation_id
|
|
|
+ orderDon.setRelationId(afterRelation.getId());
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+
|
|
|
//保存更换车票记录
|
|
|
saveChangeTicketRecord(preStartTime, preExpiryTime, preRelationId, userId, preSkuId, orderId, num, afterSku, afterRelation.getId());
|
|
|
|
|
|
@@ -1665,6 +1723,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
.set(GroupsRelation::getExpiryTime, relationView.getExpiryTime())
|
|
|
.eq(GroupsRelation::getId, relationView.getId()));
|
|
|
|
|
|
+ //更新订单对应的relation_id
|
|
|
+ orderDon.setRelationId(relationView.getId());
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+
|
|
|
//保存更换车票记录
|
|
|
saveChangeTicketRecord(preStartTime, preExpiryTime, relationView.getId(), userId, preSkuId, orderId, num, afterSku, relationView.getId());
|
|
|
}
|
|
|
@@ -1855,7 +1917,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/**
|
|
|
* 获取车位
|
|
|
*/
|
|
|
- public Long getRelation(OrderPayRequest payRequest, GoodsDonSku sku) {
|
|
|
+ public GroupsRelation getRelation(OrderPayRequest payRequest, GoodsDonSku sku) {
|
|
|
GroupsRelation relation;
|
|
|
Long payRelationId = payRequest.getRelationId();
|
|
|
Boolean isLoginPopularize = payRequest.getIsLoginPopularize();
|
|
|
@@ -1875,22 +1937,54 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getDays(), sku.getMonths(), null);
|
|
|
if (relation == null) {
|
|
|
//TODO 如果没指定座位,等待逻辑确认
|
|
|
- GroupsTrips groups = groupsMapper.selectOne( Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
.eq(GroupsTrips::getSkuId, sku.getId())
|
|
|
.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
.eq(GroupsTrips::getStatus, GroupsTrips.Status.validity)
|
|
|
.orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
- //待发车
|
|
|
if (groups == null) {
|
|
|
- groups = groupsMapper.selectOne( Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
- .eq(GroupsTrips::getSkuId, sku.getId())
|
|
|
- .gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
- .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
|
|
|
- .orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
+ //若是MidJourney、ChatGPT PLUS每个已满车队 硬塞5个座位
|
|
|
+ //主账号过期时间10天以外
|
|
|
+ if (sku.getNum() > 1 && Constant.AI_goodsIds.contains(sku.getGoodsId())) {
|
|
|
+ DateTime tenExpiry = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 10);
|
|
|
+ //不塞存在该用户的车队
|
|
|
+ Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5, userId);
|
|
|
+ if (groupsId != null) {
|
|
|
+ relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getGroupsId, groupsId)
|
|
|
+ .eq(GroupsRelation::getUserId, 0)
|
|
|
+ .eq(GroupsRelation::getStatus, GroupsRelation.Status.outside)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (relation == null) {
|
|
|
+ if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getName() + groupsId, groupsId, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
|
|
|
+ relation = new GroupsRelation();
|
|
|
+ relation.setStatus(GroupsRelation.Status.outside);
|
|
|
+ relation.setUserId(userId);
|
|
|
+ relation.setGroupsId(groupsId);
|
|
|
+ GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
|
|
|
+ relation.setNum(maxNumRelation.getNum() + 1);
|
|
|
+ groupsRelationMapper.insert(relation);
|
|
|
+ redisService.del(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getName() + groupsId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ groups = groupsMapper.selectById(groupsId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (relation == null) {
|
|
|
+ //待发车
|
|
|
+ groups = groupsMapper.selectOne( Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ .eq(GroupsTrips::getSkuId, sku.getId())
|
|
|
+ .gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
+ .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
|
|
|
+ .orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (groups == null) {
|
|
|
relation = groupsFuncService.createNewGroupsTrips(sku);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+
|
|
|
+ if (relation == null) {
|
|
|
//寻找快满编车队进行占座
|
|
|
relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
|
|
|
if (relation == null) {
|
|
|
@@ -1901,18 +1995,23 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
//锁定座位
|
|
|
- setRelation(relation.getId(), relation.getGroupsId(), userId, sku.getGoodsId(), isLoginPopularize);
|
|
|
+ setRelation(relation.getId(), relation.getGroupsId(), userId, sku.getGoodsId(), isLoginPopularize, relation.getStatus());
|
|
|
relation.setUserId(userId);
|
|
|
- relation.setStatus(GroupsRelation.Status.locking);
|
|
|
+ if (relation.getStatus() != GroupsRelation.Status.outside) {
|
|
|
+ relation.setStatus(GroupsRelation.Status.locking);
|
|
|
+ }
|
|
|
groupsRelationMapper.updateById(relation);
|
|
|
redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
- return relation.getId();
|
|
|
+ return relation;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 使用优惠营销 订单金额抵扣
|
|
|
*/
|
|
|
public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, Integer goodsType, BigDecimal gcCash, List<Long> gcpIds) {
|
|
|
+ if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0 && couponUser != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("现金卡不能与其他优惠叠加使用");
|
|
|
+ }
|
|
|
BigDecimal first_money = orderDon.getMoney();
|
|
|
//礼品卡现金支付 不参与其他优惠
|
|
|
if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
@@ -1968,6 +2067,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
BigDecimal discountMoney = orderDon.getMoney().multiply(coupon.getDiscount());
|
|
|
orderDon.setMoney(discountMoney);
|
|
|
couponMoney = orderDon.getRealMoney().subtract(discountMoney);
|
|
|
+ //记录折扣 用于分销
|
|
|
+ couponUser.setDiscount(coupon.getDiscount());
|
|
|
+ couponUserMapper.updateById(couponUser);
|
|
|
} else if (coupon.getType() == Coupon.Type.reduce) {
|
|
|
if (goodsType == 2) {
|
|
|
if (skuMoney.compareTo(coupon.getReduceCondition()) < 0) {
|
|
|
@@ -2026,16 +2128,57 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
public void updateGroupsTicket(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
if (orderDon.getOrderType() == 2 && orderDon.getIsChangeTicket()) {
|
|
|
//将奈飞月付车票更换成其他规格的车票
|
|
|
- changeTicketAndRecord(orderDon.getPreSkuId(), orderDon.getRelationId(), orderDon.getId(), orderDon.getNum(), sku, orderDon.getUserId());
|
|
|
+ changeTicketAndRecord(orderDon, sku);
|
|
|
} else {
|
|
|
//修改车位状态并发送模板消息
|
|
|
updateCarParkAndSendMsg(goodsDon, sku, orderDon);
|
|
|
}
|
|
|
+ //同步车票是否重购 记录
|
|
|
+ TASK_POOL.execute(() -> {
|
|
|
+ groupsRelationExpiryRecordService.syncGroupsRelationExpiryRecord(orderDon, goodsDon, sku);
|
|
|
+
|
|
|
+ //发送下单后 若有手机 发送短信
|
|
|
+ sendOrderPhoneMsg(orderDon.getUserId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendOrderPhoneMsg(Long userId) {
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ String phone = null;
|
|
|
+ if (StrUtil.isNotBlank(user.getLoginPhone())) {
|
|
|
+ phone = user.getLoginPhone();
|
|
|
+ } else {
|
|
|
+ //获取对应手机号
|
|
|
+ UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
+ .eq(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId, user.getId())
|
|
|
+ .eq(StrUtil.isNotBlank(user.getEmail()), UserBindDetail::getEmailUserId, user.getId()));
|
|
|
+ if (userBindDetail != null && StrUtil.isNotBlank(userBindDetail.getPhone())) {
|
|
|
+ phone = userBindDetail.getPhone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(phone)) {
|
|
|
+ //是否发送过手机短信
|
|
|
+ UserPhoneSendRecord userPhoneSendRecord = userPhoneSendRecordMapper.selectOne(Wrappers.lambdaQuery(UserPhoneSendRecord.class)
|
|
|
+ .eq(UserPhoneSendRecord::getPhone, phone).last("limit 1"));
|
|
|
+ if (userPhoneSendRecord == null) {
|
|
|
+ try {
|
|
|
+ Boolean is_success = SmsUtil.sendLuoKey2Msg(phone, String.format(Constant.ORDER_MSG_FIRST_NOTIFY, user.getNickname()));
|
|
|
+ if (is_success) {
|
|
|
+ log.info("用户userId:{},购买成功,发送第一次手机号:{}短信官网信息通知", userId, phone);
|
|
|
+ userPhoneSendRecord = new UserPhoneSendRecord();
|
|
|
+ userPhoneSendRecord.setOrderUserId(userId);
|
|
|
+ userPhoneSendRecord.setPhone(phone);
|
|
|
+ userPhoneSendRecordMapper.insert(userPhoneSendRecord);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void orderNotify(OrderDon orderDon){
|
|
|
+ public void orderNotify(OrderDon orderDon) {
|
|
|
Long goodsId = orderDon.getGoodsId();
|
|
|
if (orderDon.getIsNoLogin()) {
|
|
|
orderDon.setExCode(exchangeCodeService.getExCode(goodsId, orderDon.getSkuId(), 1));
|
|
|
@@ -2137,29 +2280,43 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//虚拟物品购买推送电报消息
|
|
|
if(goodsDon.getType() == 1){
|
|
|
TASK_POOL.execute(()->{
|
|
|
- sendTelegramMsg(orderDon, goodsDon);
|
|
|
+ sendTelegramMsg(orderDon, goodsDon, sku);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void sendTelegramMsg(OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
- if(!redisService.hasKey(RedisKey.TELEGRAM_BOT_MSG)){
|
|
|
+ private void sendTelegramMsg(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
+ if (!redisService.hasKey(RedisKey.TELEGRAM_BOT_MSG)) {
|
|
|
+ //礼品卡类似订单过滤
|
|
|
+ if (orderDon.getRelationId() != null && orderDon.getRelationId() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
TelegramBotMsgReq msgReq = new TelegramBotMsgReq();
|
|
|
msgReq.setGoodsName(goodsDon.getTitle());
|
|
|
User user = userMapper.selectById(orderDon.getUserId());
|
|
|
msgReq.setName(user.getNickname());
|
|
|
GroupsRelation groupsRelation = groupsRelationMapper.selectById(orderDon.getRelationId());
|
|
|
- long day = DateUtil.betweenDay(new Date(), groupsRelation.getExpiryTime(),true);
|
|
|
- if(day > 1000){
|
|
|
+ Date expiryTime = groupsRelation.getExpiryTime();
|
|
|
+ if (expiryTime == null) {
|
|
|
+ Integer days = sku.getDays();
|
|
|
+ Integer months = sku.getMonths();
|
|
|
+ if (days != null && days > 0) {
|
|
|
+ expiryTime = DateUtil.offsetDay(new Date(), days);
|
|
|
+ } else {
|
|
|
+ expiryTime = DateUtil.offsetMonth(new Date(), months);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long day = DateUtil.betweenDay(new Date(), expiryTime, true);
|
|
|
+ if (day > 1000) {
|
|
|
day = 365;
|
|
|
}
|
|
|
msgReq.setDay(day);
|
|
|
msgReq.setNumber(groupsRelation.getNum() >= 10 ? RandomUtil.randomInt(10) + 1 : groupsRelation.getNum());
|
|
|
try {
|
|
|
telegramService.sendMsg(msgReq);
|
|
|
- redisService.set(RedisKey.TELEGRAM_BOT_MSG,1, 60L * 3L);
|
|
|
+ redisService.set(RedisKey.TELEGRAM_BOT_MSG, 1, 60L * 3L);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("发送电报推送消息错误 msg:{}",StringUtil.getErrorText(e));
|
|
|
+ log.error("发送电报推送消息错误 msg:{}", StringUtil.getErrorText(e));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2179,7 +2336,40 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setIsDistribute(true);
|
|
|
UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, userDistributeShared.getSharedId()));
|
|
|
if (userDistribute != null) {
|
|
|
- orderDon.setIsFixedDistribute(true);
|
|
|
+ //直接去除
|
|
|
+ if (!userDistributeShared.getIsBind()) {
|
|
|
+ orderDon.setIsDistribute(false);
|
|
|
+ } else {
|
|
|
+ //45天内是否下单成功
|
|
|
+ Date createdTime = userDistributeShared.getCreatedTime();
|
|
|
+ DateTime forty_five = DateUtil.offsetDay(createdTime, 45);
|
|
|
+ //在45天内
|
|
|
+ Boolean is_fit = false;
|
|
|
+ boolean before = DateTime.now().isBefore(forty_five);
|
|
|
+ //超过45天还未下过单
|
|
|
+ //直接不参与后续的 提成
|
|
|
+ if (before) {
|
|
|
+ is_fit = true;
|
|
|
+ } else {
|
|
|
+ int count = this.count(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getUserId, userId)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
+ .le(OrderDon::getCreatedTime, forty_five));
|
|
|
+ if (count > 0) {
|
|
|
+ is_fit = true;
|
|
|
+ } else {
|
|
|
+ userDistributeShared.setIsBind(false);
|
|
|
+ userDistributeSharedMapper.updateById(userDistributeShared);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //未达标
|
|
|
+ if (is_fit) {
|
|
|
+ orderDon.setIsFixedDistribute(true);
|
|
|
+ } else {
|
|
|
+ orderDon.setIsDistribute(false);
|
|
|
+ orderDon.setIsFixedDistribute(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
orderDon.setCpsPopularizeId(userDistributeShared.getDsPopularizeId());
|
|
|
}
|
|
|
}
|
|
|
@@ -2245,4 +2435,98 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("用户userId:{}礼品订单orderId:{}支付成功,记录购买成功记录错误,e:{}", orderDon.getUserId(), orderDon.getId(), StringUtil.getErrorText(e));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成实物订单
|
|
|
+ */
|
|
|
+ public void createRealOrderAndTransport(Long userId, Address address, GoodsDon goodsDon, GoodsDonSku sku, List<Long> plusOrderIds) {
|
|
|
+ OrderDon orderDon = new OrderDon();
|
|
|
+ orderDon.setUserId(userId);
|
|
|
+ orderDon.setRelationId(0l);
|
|
|
+ orderDon.setMoney(BigDecimal.ZERO);
|
|
|
+ orderDon.setIsDp(true);
|
|
|
+ orderDon.setSkuId(sku.getId());
|
|
|
+ orderDon.setGoodsId(goodsDon.getId());
|
|
|
+ orderDon.setPayTitle(goodsDon.getTitle() + sku.getSpecVal());
|
|
|
+ orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
+ orderDonMapper.insert(orderDon);
|
|
|
+ //处理收货地址
|
|
|
+ saveTransportByAddress(address, orderDon.getId());
|
|
|
+
|
|
|
+ plusOrderIds.add(orderDon.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveTransportByAddress(Address address,Long orderId) {
|
|
|
+ OrderDonTransport transport = new OrderDonTransport();
|
|
|
+ transport.setOrderId(orderId);
|
|
|
+ transport.setReceiver(address.getReceiver());
|
|
|
+ transport.setPhone(address.getPhone());
|
|
|
+ transport.setProvince(address.getProvince());
|
|
|
+ transport.setCity(address.getCity());
|
|
|
+ transport.setDistrict(address.getDistrict());
|
|
|
+ transport.setAddress(address.getAddress());
|
|
|
+ orderDonTransportMapper.insert(transport);
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal handlerDistributeRule(OrderDon order, DistributeWaitingSendPoints distributeWaitingSendPoints, Long distributeId, DistributePointsExchangeMoney distributePointsExchangeMoney, BigDecimal points) {
|
|
|
+ //是否使用优惠券 且优惠券折扣小于低于9折
|
|
|
+ if (order.getCouponUserId() != 0) {
|
|
|
+ //是否开启了渠道规则分销
|
|
|
+ SysConfig ruleConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.DISTRIBUTE_RULE_KEY).last("limit 1"));
|
|
|
+ if (ruleConfig != null && StrUtil.equals(Constant.ONE_STR, ruleConfig.getSysValue())) {
|
|
|
+ //是否是规则过滤平台
|
|
|
+ SysConfig ruleFilterGoods = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.DISTRIBUTE_RULE_FILTER_GOODS_KEY).last("limit 1"));
|
|
|
+ List<Long> filterGoodsIds = null;
|
|
|
+ if (ruleFilterGoods != null && StrUtil.isNotBlank(ruleFilterGoods.getSysValue())) {
|
|
|
+ try {
|
|
|
+ filterGoodsIds = Jsons.parseList(ruleFilterGoods.getSysValue(), Long.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (filterGoodsIds == null || !filterGoodsIds.contains(order.getGoodsId())) {
|
|
|
+ //优惠券折扣是否小于低于9折
|
|
|
+ CouponUser couponUser = couponUserMapper.getCouponByCouponUserId(order.getCouponUserId());
|
|
|
+ BigDecimal plat_discount = couponUser.getDiscount();
|
|
|
+ BigDecimal nineDis = BigDecimal.valueOf(0.90);
|
|
|
+ if (plat_discount != null && plat_discount.compareTo(BigDecimal.ZERO) > 0 && plat_discount.compareTo(nineDis) <= 0) {
|
|
|
+ //是否参与渠道分销规则
|
|
|
+ //用户下单订单 是否使用 优惠券小于低于9折
|
|
|
+ //分销利润金额 减去(规格原价 * 目前使用的折扣 - 规格原价 * 渠道自身折扣 /2)
|
|
|
+ BigDecimal realMoney = order.getRealMoney();
|
|
|
+ //查询渠道对应的折扣
|
|
|
+ Coupon coupon = couponDistributePopularizeMapper.selectDiscountCouponByUserId(distributeId, order.getSkuId());
|
|
|
+ //未配置对应折扣
|
|
|
+ //按优惠多少对半平摊
|
|
|
+ if (coupon == null) {
|
|
|
+ BigDecimal splitDiscount = BigDecimal.valueOf(1).subtract(plat_discount);
|
|
|
+ BigDecimal avg = realMoney.multiply(splitDiscount).divide(BigDecimal.valueOf(2));
|
|
|
+ points = points.subtract(avg.multiply(BigDecimal.valueOf(distributePointsExchangeMoney.getPoints())).divide(distributePointsExchangeMoney.getMoney(), 2, RoundingMode.HALF_DOWN));
|
|
|
+ if (points.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ points = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ distributeWaitingSendPoints.setIsRule(true);
|
|
|
+ }
|
|
|
+ if (coupon != null) {
|
|
|
+ BigDecimal distribute_discount = coupon.getDiscount();
|
|
|
+
|
|
|
+ BigDecimal ds_money = realMoney.multiply(distribute_discount);
|
|
|
+ BigDecimal plat_ds_money = realMoney.multiply(plat_discount);
|
|
|
+ BigDecimal subtractMoney = ds_money.subtract(plat_ds_money);
|
|
|
+ if (subtractMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal avg = subtractMoney.divide(BigDecimal.valueOf(2));
|
|
|
+ points = points.subtract(avg.multiply(BigDecimal.valueOf(distributePointsExchangeMoney.getPoints())).divide(distributePointsExchangeMoney.getMoney(), 2, RoundingMode.HALF_DOWN));
|
|
|
+ if (points.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ points = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ distributeWaitingSendPoints.setIsRule(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return points;
|
|
|
+ }
|
|
|
}
|