|
|
@@ -19,7 +19,6 @@ import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.EnvCommonService;
|
|
|
@@ -42,6 +41,7 @@ import com.cyksj.enums.GatewayApiCode;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.channel.ChannelPopularizeMapper;
|
|
|
import com.cyksj.mapper.channel.ShopConfigMapper;
|
|
|
+import com.cyksj.mapper.corp.CorpInteractiveUserOrderRelationMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
|
|
|
@@ -52,17 +52,12 @@ import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.mapper.shop.YhShopGoodsSkuMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.manage.dto.ChannelBaiDuDiscountDto;
|
|
|
import com.cyksj.model.manage.dto.GiftCardDto;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
|
-import com.cyksj.model.request.GiftCardPayReq;
|
|
|
-import com.cyksj.model.request.OrderAttach;
|
|
|
-import com.cyksj.model.request.OrderPayRequest;
|
|
|
-import com.cyksj.model.request.TelegramBotMsgReq;
|
|
|
-import com.cyksj.model.views.CouponNewUserView;
|
|
|
-import com.cyksj.model.views.CouponUserView;
|
|
|
-import com.cyksj.model.views.GiftCardGoodsSkuFrontView;
|
|
|
-import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
+import com.cyksj.model.request.*;
|
|
|
+import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
import com.cyksj.service.distribute.UserBusinessFrontService;
|
|
|
@@ -71,11 +66,13 @@ import com.cyksj.service.exchange.ExchangeCodeService;
|
|
|
import com.cyksj.service.giftcard.GiftCardOrderUseRecordService;
|
|
|
import com.cyksj.service.giftcard.GiftCardUserRecordService;
|
|
|
import com.cyksj.service.groups.GroupsFuncService;
|
|
|
+import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
|
import com.cyksj.service.order.OrderCommonService;
|
|
|
import com.cyksj.service.order.OrderDonPostService;
|
|
|
import com.cyksj.service.order.OrderDonService;
|
|
|
+import com.cyksj.service.order.OrderRefundService;
|
|
|
import com.cyksj.service.pay.AliPayCommonService;
|
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
@@ -87,6 +84,7 @@ import com.cyksj.service.telegram.TelegramService;
|
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
+import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.task.JobManager;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -106,9 +104,6 @@ import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
-import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
-import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
-
|
|
|
/**
|
|
|
* @author chan
|
|
|
* @date 2021/10/11 下午4:08
|
|
|
@@ -126,6 +121,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
+ private final UserService userService;
|
|
|
+
|
|
|
private final WeChatService weChatService;
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
@@ -166,6 +163,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
|
|
|
|
|
|
+ private final BusinessDistributeDefaultSkuRateConfigMapper businessDistributeDefaultSkuRateConfigMapper;
|
|
|
+
|
|
|
+ private final BusinessDistributeDefaultRateConfigMapper businessDistributeDefaultRateConfigMapper;
|
|
|
+
|
|
|
private final CouponMapper couponMapper;
|
|
|
|
|
|
private final CouponFontService couponFontService;
|
|
|
@@ -216,6 +217,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final OrderDonPostService orderDonPostService;
|
|
|
|
|
|
+ private final CorpInteractiveUserOrderRelationMapper corpInteractiveUserOrderRelationMapper;
|
|
|
+
|
|
|
private final GoodsDiscountPlusPurchaseRelationMapper discountPlusPurchaseRelationMapper;
|
|
|
|
|
|
private final OrderDiscountPlusPurchaseSkuRelationMapper orderDiscountPlusPurchaseSkuRelationMapper;
|
|
|
@@ -242,6 +245,18 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final YhShopGoodsSkuMapper yhShopGoodsSkuMapper;
|
|
|
|
|
|
+ private final AccountMapper accountMapper;
|
|
|
+
|
|
|
+ private final CouponCommonService couponCommonService;
|
|
|
+
|
|
|
+ private final UserPlatSkuDistributeRateMapper userPlatSkuDistributeRateMapper;
|
|
|
+
|
|
|
+ private final OrderRefundService orderRefundService;
|
|
|
+
|
|
|
+ private final UserPayOrderBlockMapper userPayOrderBlockMapper;
|
|
|
+
|
|
|
+ private final InformationClickUserRecordMapper informationClickUserRecordMapper;
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@@ -287,7 +302,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
couponUser = couponStatusRecord(payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), couponPopularizeDto);
|
|
|
}
|
|
|
Boolean isNoLogin = payRequest.getIsNoLogin();
|
|
|
- User user;
|
|
|
+ User user = null;
|
|
|
String payOpenId = null;
|
|
|
Long relationId = 0L;
|
|
|
Boolean isNeedTicket = checkIsNeedGroupsRelation(goodsDon);
|
|
|
@@ -301,9 +316,17 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
GroupsRelation relation = null;
|
|
|
+ String orderPhone = payRequest.getPhone();
|
|
|
+ if (StrUtil.isNotBlank(orderPhone)) {
|
|
|
+ user = saveOrGetOrderPhoneUser(payRequest);
|
|
|
+ userId = user.getId();
|
|
|
+ payRequest.setUserId(userId);
|
|
|
+ isNoLogin = false;
|
|
|
+ }
|
|
|
if (userId == null) {
|
|
|
user = new User();
|
|
|
user.setId(0l);
|
|
|
+ isNoLogin = true;
|
|
|
} else {
|
|
|
user = userMapper.selectById(userId);
|
|
|
if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
@@ -325,6 +348,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/* 生成订单 */
|
|
|
String donNo = SEQUENCE.nextId().toString();
|
|
|
OrderDon orderDon = new OrderDon();
|
|
|
+ orderDon.setIp(payRequest.getIp());
|
|
|
+ orderDon.setLocation(payRequest.getLocation());
|
|
|
+
|
|
|
orderDon.setIsDp(false);
|
|
|
if (isNoLogin != null && isNoLogin) {
|
|
|
orderDon.setIsNoLogin(true);
|
|
|
@@ -371,6 +397,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
orderDon.setMoney(payRequest.getDonMoney());
|
|
|
orderDon.setRealMoney(payRequest.getDonMoney());
|
|
|
+ orderDon.setOriMoney(sku.getPrice());
|
|
|
|
|
|
List<Long> dpSkuIds = payRequest.getDpSkuIds();
|
|
|
if (CollUtil.isNotEmpty(dpSkuIds)) {
|
|
|
@@ -386,6 +413,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
for (GoodsDiscountPlusPurchaseRelation re : ds_relations) {
|
|
|
goods_discount_plus_pay = goods_discount_plus_pay.add(re.getDisPrice());
|
|
|
dsSkuIds.add(re.getDisSid());
|
|
|
+ orderDon.setDpMoney(goods_discount_plus_pay);
|
|
|
}
|
|
|
BigDecimal pay_money = sku.getPrice().add(goods_discount_plus_pay);
|
|
|
if (pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
@@ -420,6 +448,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setCouponExCode(payRequest.getCouponExCode());
|
|
|
//店铺id
|
|
|
orderDon.setYhsId(yhsId);
|
|
|
+ orderDon.setInfoId(payRequest.getInfoId());
|
|
|
if (relation != null && relation.getStatus() == GroupsRelation.Status.outside) {
|
|
|
orderDon.setIsOt(true);
|
|
|
}
|
|
|
@@ -498,6 +527,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
});
|
|
|
}
|
|
|
orderDon.setPayTitle(payTitle.toString());
|
|
|
+ //下单手机号
|
|
|
+ orderDon.setPhone(orderPhone);
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
if (orderDon.getIsDp()) {
|
|
|
@@ -558,6 +589,17 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
});
|
|
|
giftCardOrderUseRecordService.saveBatch(orderDon.getGcUseRecords());
|
|
|
}
|
|
|
+ if (payRequest.getRadarId() != null && user != null) {
|
|
|
+ CorpInteractiveUserOrderRelation corpInteractiveUserOrderRelation = new CorpInteractiveUserOrderRelation();
|
|
|
+ corpInteractiveUserOrderRelation.setUserId(user.getId());
|
|
|
+ corpInteractiveUserOrderRelation.setOrderId(orderDon.getId());
|
|
|
+ corpInteractiveUserOrderRelation.setRadarId(payRequest.getRadarId());
|
|
|
+ corpInteractiveUserOrderRelation.setIsNew(false);
|
|
|
+ if (user.getCreatedTime().getTime() >= DateUtil.beginOfDay(DateTime.now()).getTime()) {
|
|
|
+ corpInteractiveUserOrderRelation.setIsNew(true);
|
|
|
+ }
|
|
|
+ corpInteractiveUserOrderRelationMapper.insert(corpInteractiveUserOrderRelation);
|
|
|
+ }
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -759,38 +801,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (groupsRelation.getUserId() != 0) {
|
|
|
User user = userMapper.selectById(orderDon.getUserId());
|
|
|
if (user != null) {
|
|
|
- checkIsSameUser(groupsRelation.getUserId(), orderDon.getUserId(), user.getOpenId(), user.getLoginPhone());
|
|
|
+ checkIsSameUser(groupsRelation.getUserId(), user);
|
|
|
}
|
|
|
}
|
|
|
//throw new BusinessRuntimeException("订单用户与车位用户不匹配!");
|
|
|
} else {
|
|
|
- if (GroupsRelation.Status.locking == groupsRelation.getStatus() || GroupsRelation.Status.outside == groupsRelation.getStatus()) {
|
|
|
- log.info("清理用户userId:{}未支付订单", orderDon.getUserId());
|
|
|
- groupsRelation.setUserId(0L);
|
|
|
- Long groupsId = groupsRelation.getGroupsId();
|
|
|
- GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
|
|
|
- if (groupsRelation.getNum() > groupsTrips.getNum()) {
|
|
|
- groupsRelation.setStatus(GroupsRelation.Status.outside);
|
|
|
- } else {
|
|
|
- groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
- }
|
|
|
- groupsRelation.setYhsId(0l);
|
|
|
- groupsRelationMapper.updateById(groupsRelation);
|
|
|
- orderCommonService.delRelation(groupsRelation);
|
|
|
-
|
|
|
- //车位空余发送模板消息
|
|
|
-// TASK_POOL.execute(() -> {
|
|
|
-// try {
|
|
|
-// List<CustomerService> customerServices = customerServiceMapper.selectList(null);
|
|
|
-// for (CustomerService customerService : customerServices) {
|
|
|
-// log.info("发送客服{}空车位通知消息", customerService.getNickName());
|
|
|
-// emptySendMsgNotify(orderDon, customerService.getOpenId());
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("发送{}空车位模板消息至客服失败:{}", orderDon.getGoodsId(), e);
|
|
|
-// }
|
|
|
-// });
|
|
|
- }
|
|
|
+ clearUserLockingRelation(groupsRelation, orderDon);
|
|
|
}
|
|
|
}
|
|
|
//返还优惠券
|
|
|
@@ -833,9 +849,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//若存在店铺id,校验店铺状态
|
|
|
Long yhsId = yhShopFrontService.checkShopCustomIdAndReturnShopId(customId);
|
|
|
//是否有其他规格的续费订单 若有请先关闭
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, user);
|
|
|
Integer count = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
.eq(OrderDon::getRelationId, payRequest.getRelationId())
|
|
|
.eq(OrderDon::getYhsId, yhsId)
|
|
|
+ .in(OrderDon::getUserId, userIdList)
|
|
|
.eq(OrderDon::getStatus, OrderDon.Status.noPayment).eq(OrderDon::getOrderType, 2));
|
|
|
if (count > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("您有该车票未支付的续费订单..");
|
|
|
@@ -849,7 +867,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
//todo 多账号同一用户绑定 续费
|
|
|
if (!relation.getUserId().equals(user.getId())) {
|
|
|
- checkIsSameUser(relation.getUserId(), userId, user.getOpenId(), user.getLoginPhone());
|
|
|
+ checkIsSameUser(relation.getUserId(), user);
|
|
|
}
|
|
|
GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
if (groupsTrips == null) {
|
|
|
@@ -906,6 +924,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/* 生成订单 */
|
|
|
String donNo = SEQUENCE.nextId().toString();
|
|
|
OrderDon orderDon = new OrderDon();
|
|
|
+ orderDon.setIp(payRequest.getIp());
|
|
|
+ orderDon.setLocation(payRequest.getLocation());
|
|
|
+
|
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setOpenId(payOpenId);
|
|
|
orderDon.setYhsId(yhsId);
|
|
|
@@ -933,11 +954,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds());
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
- //订单金额为0 且订单为已完成 更新虚物车票
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
- updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
- }
|
|
|
if (orderDon.getStatus() == OrderDon.Status.noPayment) {
|
|
|
jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
closeOrder(orderDon.getId(), null);
|
|
|
@@ -950,6 +966,25 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
});
|
|
|
giftCardOrderUseRecordService.saveBatch(orderDon.getGcUseRecords());
|
|
|
}
|
|
|
+ if (payRequest.getRadarId() != null && user != null) {
|
|
|
+ CorpInteractiveUserOrderRelation corpInteractiveUserOrderRelation = new CorpInteractiveUserOrderRelation();
|
|
|
+ corpInteractiveUserOrderRelation.setUserId(user.getId());
|
|
|
+ corpInteractiveUserOrderRelation.setOrderId(orderDon.getId());
|
|
|
+ corpInteractiveUserOrderRelation.setRadarId(payRequest.getRadarId());
|
|
|
+ corpInteractiveUserOrderRelation.setIsNew(false);
|
|
|
+ if (user.getCreatedTime().getTime() >= DateUtil.beginOfDay(DateTime.now()).getTime()) {
|
|
|
+ corpInteractiveUserOrderRelation.setIsNew(true);
|
|
|
+ }
|
|
|
+ corpInteractiveUserOrderRelationMapper.insert(corpInteractiveUserOrderRelation);
|
|
|
+ }
|
|
|
+ //订单金额为0 且订单为已完成 更新虚物车票
|
|
|
+ if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ OrderDon updateOrder = orderDonMapper.selectById(orderDon.getId());
|
|
|
+ updateOrder.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
+ updateGroupsTicket(updateOrder, goodsDon, sku);
|
|
|
+ orderDonMapper.updateById(updateOrder);
|
|
|
+ return updateOrder;
|
|
|
+ }
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -963,8 +998,24 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
builder.field(OrderDonView::getUserId, userId);
|
|
|
}
|
|
|
OrderDetailView detail = beanSearcher.searchFirst(OrderDetailView.class, builder.build());
|
|
|
- detail.setTransport(transportMapper.selectOne(Wrappers.lambdaQuery(OrderDonTransport.class).eq(OrderDonTransport::getOrderId, detail.getId()).last(" limit 1")));
|
|
|
- detail.setWaybill(waybillMapper.selectOne(Wrappers.lambdaQuery(OrderDonWaybill.class).eq(OrderDonWaybill::getOrderId, detail.getId()).last(" limit 1")));
|
|
|
+ //获取对应车票订单 账号密码
|
|
|
+ if (userId != null) {
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
+ RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
|
|
|
+ .field(RenewalView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(RenewalView::getRelationId, detail.getRelationId())
|
|
|
+ .onlySelect(RenewalView::getAccount, RenewalView::getPassword)
|
|
|
+ .build());
|
|
|
+ if (renewalView != null) {
|
|
|
+ detail.setAccount(renewalView.getAccount());
|
|
|
+ detail.setPassword(renewalView.getPassword());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (detail.getRelationId() != 0) {
|
|
|
+ detail.setTransport(transportMapper.selectOne(Wrappers.lambdaQuery(OrderDonTransport.class).eq(OrderDonTransport::getOrderId, detail.getId()).last(" limit 1")));
|
|
|
+ detail.setWaybill(waybillMapper.selectOne(Wrappers.lambdaQuery(OrderDonWaybill.class).eq(OrderDonWaybill::getOrderId, detail.getId()).last(" limit 1")));
|
|
|
+ }
|
|
|
return detail;
|
|
|
}
|
|
|
|
|
|
@@ -974,8 +1025,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AliPayParams aliPay(Long orderId, String returnUrl, String productCode, String qrPayMode) throws Exception {
|
|
|
- return aliPayCommonService.unifiedPay(orderId, productCode, qrPayMode, returnUrl);
|
|
|
+ public AliPayParams aliPay(AlipayOrderDonReq re, String productCode, String qrPayMode) throws Exception {
|
|
|
+ return aliPayCommonService.unifiedPay(re,productCode, qrPayMode);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1000,6 +1051,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
String transactionId = params.get("trade_no");
|
|
|
String payTimeStr = params.get("gmt_payment");
|
|
|
+ //买家支付宝账号
|
|
|
+ String buyerId = params.get("buyer_id");
|
|
|
+ log.info("支付宝回调信息:{}", Jsons.toJson(params));
|
|
|
if (!orderDon.getStatus().equals(OrderDon.Status.noPayment) && !orderDon.getStatus().equals(OrderDon.Status.close)) {
|
|
|
log.info("支付宝已回调,重复修改状态 id:{}", orderDon.getId());
|
|
|
return;
|
|
|
@@ -1023,13 +1077,49 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setShopId(appId);
|
|
|
orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
|
|
|
|
+ orderDon.setBuyerId(buyerId);
|
|
|
+ //该支付账号id 是否被后台拉黑
|
|
|
+ Integer count1 = userPayOrderBlockMapper.selectCount(Wrappers.lambdaQuery(UserPayOrderBlock.class)
|
|
|
+ .eq(UserPayOrderBlock::getBuyerId, buyerId));
|
|
|
+ if (count1 > 0) {
|
|
|
+ log.info("该支付账号id:{} 已被后台拉黑", buyerId);
|
|
|
+ notifyRefundOrder(orderDon, goodsDon, sku);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderDon.getOrderType() == 1 && StrUtil.isNotEmpty(buyerId)) {
|
|
|
+ //近一个月同一买家id 只能购买一次 多人
|
|
|
+ if (orderDon.getGoodsId() == 26l && sku.getNum() != 1) {
|
|
|
+ Integer count = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .ne(OrderDon::getId, orderDon.getId())
|
|
|
+ .eq(OrderDon::getGoodsId, orderDon.getGoodsId())
|
|
|
+ .eq(OrderDon::getBuyerId, buyerId)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
+ .ge(OrderDon::getCreatedTime, DateUtil.offsetMonth(DateTime.now(), -1)));
|
|
|
+ if (count > 1) {
|
|
|
+ //退款
|
|
|
+ log.info("一个月内同一买家id购买过Midjourney账号,对订单号:{}进行退款", orderDon.getOrderNo());
|
|
|
+ notifyRefundOrder(orderDon, goodsDon, sku);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //回调
|
|
|
unifiedHandlerOrderNotify(orderDon, goodsDon, sku);
|
|
|
}
|
|
|
|
|
|
- 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("客官手慢啦,该座位已经有人啦!");
|
|
|
+ public void setRelation(GroupsRelation relation) {
|
|
|
+ Long relationId = relation.getId();
|
|
|
+ Long userId = relation.getUserId();
|
|
|
+ Long groupsId = relation.getGroupsId();
|
|
|
+ GroupsRelation.Status status = relation.getStatus();
|
|
|
+ String relation_num_key = RedisKey.GROUPS_RELATION_NUM_KEY + relationId;
|
|
|
+ if (!redisService.setNx(relation_num_key, userId, 60 * 5L)) {
|
|
|
+ GroupsRelation dbRelation = groupsRelationMapper.selectById(relationId);
|
|
|
+ if (dbRelation.getUserId() != 0) {
|
|
|
+ log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
+ throw new BusinessRuntimeException("系统繁忙,请重试...");
|
|
|
+ }
|
|
|
}
|
|
|
if (status == GroupsRelation.Status.outside) {
|
|
|
return;
|
|
|
@@ -1137,6 +1227,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setPayTime(DateTime.now());
|
|
|
}
|
|
|
this.updateById(orderDon);
|
|
|
+
|
|
|
+ //调整指定规格车队下次可 停用车位数的时间
|
|
|
+ groupRelationFrontService.adjustGroupsParkingTime(orderDon.getRelationId(), sku);
|
|
|
}
|
|
|
|
|
|
public void updateCarParkAndSendMsg(GoodsDon goodsDon, GoodsDonSku sku, OrderDon order) {
|
|
|
@@ -1257,8 +1350,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
order.setStatus(OrderDon.Status.complete);
|
|
|
}
|
|
|
}
|
|
|
- //下架POE会员车队
|
|
|
- if (order.getGoodsId() != null && Constant.DOWN_GOODS_PAY.contains(order.getGoodsId())) {
|
|
|
+ //下架POE会员车队 || GPT Plus独立规格 下架
|
|
|
+ if (order.getGoodsId() != null && Constant.DOWN_GOODS_PAY.contains(order.getGoodsId()) || goodsDonSkuMapper.selectSingleSkuIdsByGoodsId(Constant.AI_goodsIds.get(0)).contains(groupsTrips.getSkuId())) {
|
|
|
if (groupsTrips.getAccountId() != null && groupsTrips.getStatus() == GroupsTrips.Status.validity) {
|
|
|
groupsTrips.setStatus(GroupsTrips.Status.down);
|
|
|
groupsMapper.updateById(groupsTrips);
|
|
|
@@ -1266,6 +1359,30 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//TODO 如未发车逻辑
|
|
|
groupsRelationMapper.updateById(relation);
|
|
|
+
|
|
|
+ if (envCommonService.isPrdEnv() && order.getOrderType() == 2) {
|
|
|
+ //ChatGPT plus 独立和Midjourney 独立有人续费了发短信
|
|
|
+ if (Constant.AI_goodsIds.contains(order.getGoodsId()) && sku.getNum() == 1) {
|
|
|
+ try {
|
|
|
+ String accountStr = StrUtil.EMPTY;
|
|
|
+ Account account = accountMapper.selectById(groupsTrips.getAccountId());
|
|
|
+ if (account != null) {
|
|
|
+ accountStr = account.getAccount();
|
|
|
+ }
|
|
|
+ String renew_msg = String.format(Constant.AI_RENEW_MSG, order.getUserId(), goodsDon.getTitle(), sku.getSpecVal(), accountStr);
|
|
|
+ SmsUtil.sendLuoKey2Msg(Constant.SERVICE_PHONE, renew_msg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //GPT 代充 发送短信通知
|
|
|
+ if (envCommonService.isPrdEnv() && order.getGoodsId() == 40l) {
|
|
|
+ try {
|
|
|
+ String pay_msg = String.format(Constant.PAY_MSG, order.getUserId(), goodsDon.getTitle(), sku.getSpecVal());
|
|
|
+ SmsUtil.sendLuoKey2Msg(Constant.SERVICE_PHONE, pay_msg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1299,13 +1416,31 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
* 分销待发积分记录
|
|
|
*/
|
|
|
public void distributeWaitingSendPointsRecord(OrderDon order) {
|
|
|
+ log.info("订单id:{}产生分销积分开始--->", order.getId());
|
|
|
DistributeWaitingSendPoints distributeWaitingSendPoints = new DistributeWaitingSendPoints();
|
|
|
distributeWaitingSendPoints.setOrderId(order.getId());
|
|
|
distributeWaitingSendPoints.setUserId(order.getUserId());
|
|
|
BigDecimal orderMoney = order.getMoney();
|
|
|
+ //是否是加购订单
|
|
|
+ if (order.getIsDp()) {
|
|
|
+ //加购订单使用 主平台金额 分销
|
|
|
+ orderMoney = order.getOriMoney();
|
|
|
+ if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ log.info("orderId:{}之前加购订单,无主平台金额,使用规格金额", order.getId());
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectById(order.getSkuId());
|
|
|
+ orderMoney = sku.getPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setDsMoney(orderMoney);
|
|
|
BigDecimal points = null;
|
|
|
BigDecimal returnMoney = null;
|
|
|
Long businessId = null;
|
|
|
+ //普通分销
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(order.getGoodsId());
|
|
|
+ if (goodsDon == null || !goodsDon.getIsDistribute()) {
|
|
|
+ log.info("分销订单orderId:{}对应平台goodsId:{}不存在或已不参与分成比例", order.getId(), order.getGoodsId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
UserDistributeShared userDistributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class).eq(UserDistributeShared::getUserId, order.getUserId()).last("limit 1"));
|
|
|
if (userDistributeShared != null) {
|
|
|
distributeWaitingSendPoints.setSharedId(userDistributeShared.getSharedId());
|
|
|
@@ -1314,49 +1449,80 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("分销兑换积分比例未配置");
|
|
|
} else {
|
|
|
UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, userDistributeShared.getSharedId()).eq(UserDistribute::getDeleted, true).last("limit 1"));
|
|
|
- //普通分销
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(order.getGoodsId());
|
|
|
//分销比例
|
|
|
Integer rate = 0;
|
|
|
if (userDistribute == null) {
|
|
|
- if (goodsDon != null) {
|
|
|
- //普通分销者 是否享受过该用户的首单分销
|
|
|
- DistributeWaitingSendPoints isReceived = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class)
|
|
|
- .eq(DistributeWaitingSendPoints::getSharedId, userDistributeShared.getSharedId())
|
|
|
- .eq(DistributeWaitingSendPoints::getUserId, order.getUserId())
|
|
|
- .in(DistributeWaitingSendPoints::getSendStatus, List.of(DistributeWaitingSendPoints.Status.waiting.name(), DistributeWaitingSendPoints.Status.success.name()))
|
|
|
- .last("limit 1"));
|
|
|
- if (isReceived != null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- rate = goodsDon.getRate();
|
|
|
- //实物分销比例
|
|
|
- if (goodsDon.getType() == 2) {
|
|
|
- GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(order.getSkuId());
|
|
|
- if (goodsDonSku != null) {
|
|
|
- //不包含套餐权益
|
|
|
- if (!goodsDonSku.getIsBenefits()) {
|
|
|
- rate = goodsDon.getSecondRate();
|
|
|
- }
|
|
|
+ //普通分销者 是否享受过该用户的首单分销
|
|
|
+ DistributeWaitingSendPoints isReceived = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class)
|
|
|
+ .eq(DistributeWaitingSendPoints::getSharedId, userDistributeShared.getSharedId())
|
|
|
+ .eq(DistributeWaitingSendPoints::getUserId, order.getUserId())
|
|
|
+ .in(DistributeWaitingSendPoints::getSendStatus, List.of(DistributeWaitingSendPoints.Status.waiting.name(), DistributeWaitingSendPoints.Status.success.name()))
|
|
|
+ .last("limit 1"));
|
|
|
+ if (isReceived != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ rate = goodsDon.getRate();
|
|
|
+ //实物分销比例
|
|
|
+ if (goodsDon.getType() == 2) {
|
|
|
+ GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(order.getSkuId());
|
|
|
+ if (goodsDonSku != null) {
|
|
|
+ //不包含套餐权益
|
|
|
+ if (!goodsDonSku.getIsBenefits()) {
|
|
|
+ rate = goodsDon.getSecondRate();
|
|
|
}
|
|
|
}
|
|
|
- returnMoney = orderMoney.multiply(BigDecimal.valueOf(rate)).divide(BigDecimal.valueOf(100));
|
|
|
}
|
|
|
+ returnMoney = orderMoney.multiply(BigDecimal.valueOf(rate)).divide(BigDecimal.valueOf(100));
|
|
|
} else {
|
|
|
businessId = userDistribute.getBusinessId();
|
|
|
- //固定推广分销
|
|
|
- UserPlatDistributeRate userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
|
|
|
- .eq(UserPlatDistributeRate::getGoodsId, order.getGoodsId())
|
|
|
- .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
- .last("limit 1"));
|
|
|
+ UserPlatDistributeRate userPlatDistributeRate = null;
|
|
|
+ Integer secondRate = 0;
|
|
|
+ //该商品是否开启了 规格分销
|
|
|
+ if (goodsDon.getIsSkuDistribute()) {
|
|
|
+ //规格分销 比例
|
|
|
+ UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
|
|
|
+ .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
+ .eq(UserPlatSkuDistributeRate::getSkuId, order.getSkuId()).last("limit 1"));
|
|
|
+ if (userPlatSkuDistributeRate != null) {
|
|
|
+ userPlatDistributeRate = getUserPlatDistributeRate(userPlatSkuDistributeRate.getRate(), userPlatSkuDistributeRate.getSecondRate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (userPlatDistributeRate == null) {
|
|
|
+ //默认规格分销比例
|
|
|
+ if (goodsDon.getIsSkuDistribute()) {
|
|
|
+ BusinessDistributeDefaultSkuRateConfig businessDistributeDefaultSkuRateConfig = businessDistributeDefaultSkuRateConfigMapper.selectOne(Wrappers.lambdaQuery(BusinessDistributeDefaultSkuRateConfig.class)
|
|
|
+ .eq(BusinessDistributeDefaultSkuRateConfig::getSkuId, order.getSkuId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (businessDistributeDefaultSkuRateConfig != null) {
|
|
|
+ userPlatDistributeRate = getUserPlatDistributeRate(businessDistributeDefaultSkuRateConfig.getRate(), businessDistributeDefaultSkuRateConfig.getSecondRate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (userPlatDistributeRate == null) {
|
|
|
+ //固定推广分销 平台比例
|
|
|
+ userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
|
|
|
+ .eq(UserPlatDistributeRate::getGoodsId, order.getGoodsId())
|
|
|
+ .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
+ .last("limit 1"));
|
|
|
+ }
|
|
|
+ //未配置平台分销比例 寻找默认比例
|
|
|
+ if (userPlatDistributeRate == null) {
|
|
|
+ BusinessDistributeDefaultRateConfig defaultRateConfig = businessDistributeDefaultRateConfigMapper.selectOne(Wrappers.lambdaQuery(BusinessDistributeDefaultRateConfig.class)
|
|
|
+ .eq(BusinessDistributeDefaultRateConfig::getGoodsId, order.getGoodsId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (defaultRateConfig != null) {
|
|
|
+ userPlatDistributeRate = getUserPlatDistributeRate(defaultRateConfig.getRate(), defaultRateConfig.getSecondRate());
|
|
|
+ }
|
|
|
+ }
|
|
|
if (userPlatDistributeRate != null) {
|
|
|
rate = userPlatDistributeRate.getRate();
|
|
|
- if (goodsDon != null && goodsDon.getType() == 2) {
|
|
|
+ secondRate = userPlatDistributeRate.getSecondRate();
|
|
|
+ if (goodsDon.getType() == 2) {
|
|
|
GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(order.getSkuId());
|
|
|
if (goodsDonSku != null) {
|
|
|
//不包含套餐权益
|
|
|
if (!goodsDonSku.getIsBenefits()) {
|
|
|
- rate = userPlatDistributeRate.getSecondRate();
|
|
|
+ rate = secondRate;
|
|
|
}
|
|
|
}
|
|
|
distributeWaitingSendPoints.setIsDelivery(false);
|
|
|
@@ -1378,6 +1544,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("用户{}邀请{},产生分销订单分发积分记录入库", userDistributeShared.getSharedId(), order.getUserId());
|
|
|
distributeWaitingSendPoints.setSendStatus(DistributeWaitingSendPoints.Status.waiting);
|
|
|
distributeWaitingSendPoints.setSendTime(DateUtil.offsetDay(order.getPayTime(), 3));
|
|
|
+ distributeWaitingSendPoints.setRate(rate);
|
|
|
distributeWaitingSendPointsMapper.insert(distributeWaitingSendPoints);
|
|
|
//暂定虚物 商务可首单提成
|
|
|
if (businessId != null) {
|
|
|
@@ -1757,38 +1924,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return orderDon.getStatus();
|
|
|
}
|
|
|
|
|
|
- public void checkIsSameUser(Long relationUserId, Long userId, String openId, String loginPhone) {
|
|
|
- //手机用户与微信用户
|
|
|
- LambdaQueryWrapper<UserBindDetail> wrapper = Wrappers.lambdaQuery(UserBindDetail.class);
|
|
|
- Boolean isPcUser = false;
|
|
|
- if (StrUtil.isNotBlank(openId)) {
|
|
|
- wrapper.eq(UserBindDetail::getUserId, userId);
|
|
|
- } else {
|
|
|
- isPcUser = true;
|
|
|
- wrapper.eq(UserBindDetail::getPhone, loginPhone);
|
|
|
- }
|
|
|
- UserBindDetail userBindDetail = userBindDetailMapper.selectOne(wrapper.last("limit 1"));
|
|
|
- if (userBindDetail == null) {
|
|
|
- throw new BusinessRuntimeException("");
|
|
|
- }
|
|
|
- if (userBindDetail != null) {
|
|
|
- if (isPcUser) {
|
|
|
- if (!relationUserId.equals(userBindDetail.getUserId())) {
|
|
|
- throw new BusinessRuntimeException("");
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (StrUtil.isEmpty(userBindDetail.getPhone())) {
|
|
|
- throw new BusinessRuntimeException("");
|
|
|
- }
|
|
|
- User otherUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
|
|
|
- .eq(User::getLoginPhone, userBindDetail.getPhone()).last("limit 1"));
|
|
|
- if (otherUser == null) {
|
|
|
- throw new BusinessRuntimeException("");
|
|
|
- }
|
|
|
- if (!relationUserId.equals(otherUser.getId())) {
|
|
|
- throw new BusinessRuntimeException("");
|
|
|
- }
|
|
|
- }
|
|
|
+ public void checkIsSameUser(Long relationUserId, User renewUser) {
|
|
|
+ List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(renewUser.getId(), renewUser);
|
|
|
+ if (!relationUserIdList.contains(relationUserId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1868,90 +2007,23 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
* yshId 店铺id
|
|
|
*/
|
|
|
public GroupsRelation getRelation(OrderPayRequest payRequest, GoodsDonSku sku, Long yhsId) {
|
|
|
- GroupsRelation relation;
|
|
|
Long payRelationId = payRequest.getRelationId();
|
|
|
- Boolean isLoginPopularize = payRequest.getIsLoginPopularize();
|
|
|
Long userId = payRequest.getUserId();
|
|
|
- //锁定座位
|
|
|
- if (payRelationId != null && payRelationId > 0) {
|
|
|
- relation = groupsRelationMapper.selectById(payRelationId);
|
|
|
- if (relation == null) {
|
|
|
- throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
|
|
|
- }
|
|
|
- if (relation.getUserId() != null && relation.getUserId() > 0L) {
|
|
|
- throw new BusinessRuntimeException(GROUP_INDEX_ALREADY_BE_USER.getCode(), GROUP_INDEX_ALREADY_BE_USER.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- //寻找差不多过期时间规格的车位
|
|
|
- relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getDays(), sku.getMonths(), null);
|
|
|
- if (relation == null) {
|
|
|
- //TODO 如果没指定座位,等待逻辑确认
|
|
|
- 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) {
|
|
|
- //若是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);
|
|
|
- }
|
|
|
-
|
|
|
- if (relation == null) {
|
|
|
- //寻找快满编车队进行占座
|
|
|
- relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
|
|
|
- if (relation == null) {
|
|
|
- throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //获取车票车位
|
|
|
+ GroupsRelation relation = groupRelationFrontService.getRelation(payRelationId, userId, sku);
|
|
|
|
|
|
//锁定座位
|
|
|
- setRelation(relation.getId(), relation.getGroupsId(), userId, sku.getGoodsId(), isLoginPopularize, relation.getStatus());
|
|
|
+ setRelation(relation);
|
|
|
relation.setUserId(userId);
|
|
|
//重新置为锁定
|
|
|
relation.setStatus(GroupsRelation.Status.locking);
|
|
|
relation.setYhsId(yhsId);
|
|
|
groupsRelationMapper.updateById(relation);
|
|
|
- redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
+
|
|
|
+ Long skuId = sku.getId();
|
|
|
+ Long groupsId = relation.getGroupsId();
|
|
|
+ //校验指定平台规格的 目前车队的可停车位数
|
|
|
+ groupRelationFrontService.checkGroupsAvailParkingNum(skuId, groupsId, relation.getGroupsAvailParkingNum(), relation.getMaxNum());
|
|
|
return relation;
|
|
|
}
|
|
|
|
|
|
@@ -2013,10 +2085,20 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
Long couponId = couponUser.getCouponId();
|
|
|
Coupon coupon = couponMapper.getCouponById(couponId);
|
|
|
BigDecimal couponMoney = null;
|
|
|
+ BigDecimal payMoney = orderDon.getMoney();
|
|
|
+ BigDecimal needDeductMoney = payMoney;
|
|
|
+ if (orderDon.getOriMoney() == null) {
|
|
|
+ orderDon.setOriMoney(payMoney);
|
|
|
+ }
|
|
|
+ if (orderDon.getIsDp() != null && orderDon.getIsDp()) {
|
|
|
+ needDeductMoney = needDeductMoney.subtract(orderDon.getDpMoney());
|
|
|
+ }
|
|
|
if (coupon.getType() == Coupon.Type.discount) {
|
|
|
- BigDecimal discountMoney = orderDon.getMoney().multiply(coupon.getDiscount());
|
|
|
- orderDon.setMoney(discountMoney);
|
|
|
- couponMoney = orderDon.getRealMoney().subtract(discountMoney);
|
|
|
+ couponMoney = needDeductMoney.multiply(BigDecimal.valueOf(1).subtract(coupon.getDiscount()));
|
|
|
+ //需支付金额
|
|
|
+ orderDon.setMoney(payMoney.subtract(couponMoney));
|
|
|
+
|
|
|
+ orderDon.setOriMoney(orderDon.getOriMoney().multiply(coupon.getDiscount()));
|
|
|
//记录折扣 用于分销
|
|
|
couponUser.setDiscount(coupon.getDiscount());
|
|
|
couponUserMapper.updateById(couponUser);
|
|
|
@@ -2026,9 +2108,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance(String.format("满%s可用", coupon.getReduceCondition().divide(BigDecimal.valueOf(100))));
|
|
|
}
|
|
|
}
|
|
|
- BigDecimal subtractMoney = orderDon.getMoney().subtract(coupon.getReduceMoney());
|
|
|
+ BigDecimal subtractMoney = payMoney.subtract(coupon.getReduceMoney());
|
|
|
orderDon.setMoney(subtractMoney);
|
|
|
- couponMoney = orderDon.getRealMoney().subtract(subtractMoney);
|
|
|
+ couponMoney = coupon.getReduceMoney();
|
|
|
+
|
|
|
+ orderDon.setOriMoney(orderDon.getOriMoney().subtract(coupon.getReduceMoney()));
|
|
|
}
|
|
|
if (couponMoney != null && couponMoney.compareTo(first_money) >= 0) {
|
|
|
throw BusinessRuntimeException.getInstance("支付金额不能小于优惠金额");
|
|
|
@@ -2040,14 +2124,38 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getPopularizeId() != null && orderDon.getPopularizeId() != 0L) {
|
|
|
//使用了优惠券 不再使用360渠道 折扣
|
|
|
if (couponUser == null && goodsType == 1) {
|
|
|
- String name = channelPopularizeMapper.selectChannelByPid(orderDon.getPopularizeId());
|
|
|
- if (Constant.CHANNEL_NAME_360.equals(name)) {
|
|
|
- SysConfig sysConfig = sysConfigService.getBaseMapper().selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.CHANNEL_360_DISCOUNT));
|
|
|
- if (sysConfig != null) {
|
|
|
- BigDecimal discountMoney = orderDon.getMoney().multiply(BigDecimal.valueOf(Double.valueOf(sysConfig.getSysValue())));
|
|
|
- orderDon.setMoney(discountMoney);
|
|
|
+ //百度渠道 专门优惠链接
|
|
|
+ SysConfig baiduConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.CHANNEL_BAIDU_DISCOUNT_KEY).last("limit 1"));
|
|
|
+ if (baiduConfig != null) {
|
|
|
+ String sysValue = baiduConfig.getSysValue();
|
|
|
+ if (StrUtil.isNotBlank(sysValue)) {
|
|
|
+ try {
|
|
|
+ ChannelBaiDuDiscountDto baiDuDiscountDto = Jsons.parseObject(sysValue, ChannelBaiDuDiscountDto.class);
|
|
|
+ List<Long> baiduPopularizeIds = baiDuDiscountDto.getPopularizeIds();
|
|
|
+ BigDecimal discount = baiDuDiscountDto.getDiscount();
|
|
|
+ if (CollUtil.isNotEmpty(baiduPopularizeIds) && discount != null && discount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (baiduPopularizeIds.contains(orderDon.getPopularizeId())) {
|
|
|
+ BigDecimal discountMoney = orderDon.getMoney().multiply(discount);
|
|
|
+ orderDon.setMoney(discountMoney);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //360
|
|
|
+ String name = channelPopularizeMapper.selectChannelByPid(orderDon.getPopularizeId());
|
|
|
+ if (Constant.CHANNEL_NAME_360.equals(name)) {
|
|
|
+ SysConfig sysConfig = sysConfigService.getBaseMapper().selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.CHANNEL_360_DISCOUNT));
|
|
|
+ if (sysConfig != null) {
|
|
|
+ BigDecimal discountMoney = orderDon.getMoney().multiply(BigDecimal.valueOf(Double.valueOf(sysConfig.getSysValue())));
|
|
|
+ orderDon.setMoney(discountMoney);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2172,6 +2280,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
this.updateById(orderDon);
|
|
|
|
|
|
+ //调整指定规格车队下次可 停用车位数的时间
|
|
|
+ groupRelationFrontService.adjustGroupsParkingTime(orderDon.getRelationId(), sku);
|
|
|
+
|
|
|
TASK_POOL.execute(()->{
|
|
|
try {
|
|
|
//发放积分
|
|
|
@@ -2238,6 +2349,28 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
sendTelegramMsg(orderDon, goodsDon, sku);
|
|
|
});
|
|
|
}
|
|
|
+ if (orderDon.getPopularizeId() != null && orderDon.getPopularizeId() != 0 && StrUtil.isNotEmpty(orderDon.getPhone())) {
|
|
|
+ //百度渠道 专门优惠链接
|
|
|
+ SysConfig baiduConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.CHANNEL_BAIDU_DISCOUNT_KEY).last("limit 1"));
|
|
|
+ if (baiduConfig != null) {
|
|
|
+ String sysValue = baiduConfig.getSysValue();
|
|
|
+ if (StrUtil.isNotBlank(sysValue)) {
|
|
|
+ try {
|
|
|
+ ChannelBaiDuDiscountDto baiDuDiscountDto = Jsons.parseObject(sysValue, ChannelBaiDuDiscountDto.class);
|
|
|
+ List<Long> couponIds = baiDuDiscountDto.getCouponIds();
|
|
|
+ //下单成功后 发送优惠券
|
|
|
+ if (CollUtil.isNotEmpty(couponIds)) {
|
|
|
+ List<Long> baiduPopularizeIds = baiDuDiscountDto.getPopularizeIds();
|
|
|
+ if (baiduPopularizeIds.contains(orderDon.getPopularizeId())) {
|
|
|
+ couponIds.forEach(couponId -> couponCommonService.sendCouponToUser(orderDon.getUserId(), couponId, null, null, null, CouponUser.Channel.manual));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void deductGiftCardCash(Long userId, Long gcId, BigDecimal deductCash, BigDecimal gcRemainCash, List<GiftCardOrderUseRecord> gcUseRecords, Boolean isUsed) {
|
|
|
@@ -2364,6 +2497,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
Coupon coupon = couponDistributePopularizeMapper.selectDiscountCouponByUserId(distributeId, order.getSkuId());
|
|
|
//未配置对应折扣
|
|
|
//按优惠多少对半平摊
|
|
|
+ BigDecimal real_points = points;
|
|
|
if (coupon == null) {
|
|
|
BigDecimal splitDiscount = BigDecimal.valueOf(1).subtract(plat_discount);
|
|
|
BigDecimal avg = realMoney.multiply(splitDiscount).divide(BigDecimal.valueOf(2));
|
|
|
@@ -2372,6 +2506,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
points = BigDecimal.ZERO;
|
|
|
}
|
|
|
distributeWaitingSendPoints.setIsRule(true);
|
|
|
+ //平摊积分
|
|
|
+ distributeWaitingSendPoints.setDeductPoints(real_points.subtract(points));
|
|
|
}
|
|
|
if (coupon != null) {
|
|
|
BigDecimal distribute_discount = coupon.getDiscount();
|
|
|
@@ -2386,6 +2522,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
points = BigDecimal.ZERO;
|
|
|
}
|
|
|
distributeWaitingSendPoints.setIsRule(true);
|
|
|
+ //平摊积分
|
|
|
+ distributeWaitingSendPoints.setDeductPoints(real_points.subtract(points));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2450,12 +2588,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (!userDistributeShared.getIsBind()) {
|
|
|
orderDon.setIsDistribute(false);
|
|
|
} else {
|
|
|
- //45天内是否下单成功
|
|
|
+ //45天内是否下单成功 ==>改为30天
|
|
|
Date createdTime = userDistributeShared.getCreatedTime();
|
|
|
- DateTime forty_five = DateUtil.offsetDay(createdTime, 45);
|
|
|
+ DateTime time = DateUtil.offsetDay(createdTime, 30);
|
|
|
//在45天内
|
|
|
Boolean is_fit = false;
|
|
|
- boolean before = DateTime.now().isBefore(forty_five);
|
|
|
+ boolean before = DateTime.now().isBefore(time);
|
|
|
//超过45天还未下过单
|
|
|
//直接不参与后续的 提成
|
|
|
if (before) {
|
|
|
@@ -2464,7 +2602,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
int count = this.count(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
.eq(OrderDon::getUserId, userId)
|
|
|
.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
- .le(OrderDon::getCreatedTime, forty_five));
|
|
|
+ .le(OrderDon::getCreatedTime, time));
|
|
|
if (count > 0) {
|
|
|
is_fit = true;
|
|
|
} else {
|
|
|
@@ -2503,4 +2641,78 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
return sku;
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ public User saveOrGetOrderPhoneUser(OrderPayRequest payRequest) {
|
|
|
+ String orderPhone = payRequest.getPhone();
|
|
|
+ User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
|
|
|
+ .eq(User::getLoginPhone, orderPhone).last("limit 1"));
|
|
|
+ if (user == null) {
|
|
|
+ user = new User();
|
|
|
+ StringBuilder name = new StringBuilder();
|
|
|
+ name.append(Constant.DEFAULT_NAME);
|
|
|
+ user.setPopularizeId(payRequest.getPopularizeId());
|
|
|
+ user.setLoginPhone(orderPhone);
|
|
|
+ user.setNickname(String.format("%s%s", name.toString(), RandomUtil.randomString(6)));
|
|
|
+ //默认头像
|
|
|
+ user.setHeadimgurl(Constant.DEFAULT_HEAD_IMG);
|
|
|
+ String registerEnv = null;
|
|
|
+ user.setRegisterEnv(StrUtil.isEmpty(registerEnv) ? User.RegisterEnv.pc.name() : registerEnv);
|
|
|
+ userMapper.insert(user);
|
|
|
+ if (StrUtil.isEmpty(user.getShowId())) {
|
|
|
+ user.setShowId(userService.getUserShowId(user.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public UserPlatDistributeRate getUserPlatDistributeRate(Integer rate, Integer secondRate) {
|
|
|
+ UserPlatDistributeRate userPlatDistributeRate = new UserPlatDistributeRate();
|
|
|
+ userPlatDistributeRate.setRate(rate);
|
|
|
+ userPlatDistributeRate.setSecondRate(secondRate);
|
|
|
+ return userPlatDistributeRate;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clearUserLockingRelation(GroupsRelation groupsRelation, OrderDon orderDon) {
|
|
|
+ if (groupsRelation == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (GroupsRelation.Status.locking == groupsRelation.getStatus()) {
|
|
|
+ log.info("清理用户userId:{}未支付订单", orderDon.getUserId());
|
|
|
+ groupsRelation.setUserId(0L);
|
|
|
+ Long groupsId = groupsRelation.getGroupsId();
|
|
|
+ GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
|
|
|
+ if (groupsRelation.getNum() > groupsTrips.getNum()) {
|
|
|
+ groupsRelation.setStatus(GroupsRelation.Status.outside);
|
|
|
+
|
|
|
+ redisService.del(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getNameFormat(groupsId, groupsRelation.getNum()));
|
|
|
+ } else {
|
|
|
+ groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
+ }
|
|
|
+ groupsRelation.setYhsId(0l);
|
|
|
+ groupsRelationMapper.updateById(groupsRelation);
|
|
|
+ orderCommonService.delRelation(groupsRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回调后 直接退款
|
|
|
+ */
|
|
|
+ public void notifyRefundOrder(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) throws Exception {
|
|
|
+ //退款
|
|
|
+ OrderRefundReq orderRefundReq = new OrderRefundReq();
|
|
|
+ orderRefundReq.setOrderId(orderDon.getId());
|
|
|
+ orderRefundReq.setRefundType("ALI_PAY");
|
|
|
+ orderRefundReq.setRefundMoney(orderDon.getMoney());
|
|
|
+ orderDon.setRefundDesc("近一个月内购买过Midjourney账号");
|
|
|
+ String outNo = orderRefundService.centerRefund(orderRefundReq, orderDon);
|
|
|
+
|
|
|
+ orderDon.setStatus(OrderDon.Status.refund);
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+
|
|
|
+ clearUserLockingRelation(groupsRelationMapper.selectById(orderDon.getRelationId()), orderDon);
|
|
|
+
|
|
|
+ //记录退款
|
|
|
+ orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), goodsDon, sku, outNo, orderDon.getType().getType());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+}
|