|
|
@@ -16,7 +16,6 @@ import com.alipay.api.request.*;
|
|
|
import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
-import com.alipay.api.response.AlipayTradeRefundResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -30,15 +29,12 @@ 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.config.WeChatConfig;
|
|
|
import com.cyksj.config.zfb.AliPayClientFactory;
|
|
|
import com.cyksj.config.zfb.BaseZfbConfig;
|
|
|
import com.cyksj.config.zfb.ZfbProductCode;
|
|
|
import com.cyksj.dto.RedisKey;
|
|
|
-import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
-import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.channel.ShopConfigMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
|
@@ -57,8 +53,9 @@ import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.AccountView;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
|
-import com.cyksj.model.request.*;
|
|
|
-import com.cyksj.model.response.AliPayRefundRep;
|
|
|
+import com.cyksj.model.request.OrderAttach;
|
|
|
+import com.cyksj.model.request.OrderPayRequest;
|
|
|
+import com.cyksj.model.request.TransferAccountsReq;
|
|
|
import com.cyksj.model.views.CouponNewUserView;
|
|
|
import com.cyksj.model.views.CouponUserView;
|
|
|
import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
@@ -77,7 +74,7 @@ import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
|
-import com.cyksj.service.user.UserPointsService;
|
|
|
+import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.task.JobManager;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -93,7 +90,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.*;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
@@ -107,9 +107,7 @@ import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
@RequiredArgsConstructor
|
|
|
public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> implements OrderDonService {
|
|
|
|
|
|
- private static final Long EXPIRY_TIME = 1000 * 60 * 5L;
|
|
|
-
|
|
|
- private static final GlobalThreadPoolTaskExecutor THREAD_POOL_TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
+ private static final Long EXPIRY_TIME = 1000 * 60 * 5L;
|
|
|
|
|
|
private static final Sequence SEQUENCE = new Sequence(0);
|
|
|
|
|
|
@@ -207,7 +205,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final OrderCommonService orderCommonService;
|
|
|
|
|
|
- private final UserPointsService userPointsService;
|
|
|
+ private final UserBenefitsService userBenefitsService;
|
|
|
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@@ -222,7 +220,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(payRequest.getSkuId());
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- Boolean isNew = false;
|
|
|
if (goodsDon == null || !goodsDon.getStatus()) {
|
|
|
throw new BusinessRuntimeException("商品已下架");
|
|
|
}
|
|
|
@@ -242,54 +239,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
checkChatGPTPlusPurchaseLimit(user.getId(), goodsDon.getId(), goodsDon.getTitle(), sku.getId(), sku.getSpecVal());
|
|
|
payOpenId = user.getOpenId();
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
- GroupsRelation relation = null;
|
|
|
- //锁定座位
|
|
|
- if (payRequest.getRelationId() != null && payRequest.getRelationId() > 0) {
|
|
|
- relation = groupsRelationMapper.selectById(payRequest.getRelationId());
|
|
|
- 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.getMonths(), null);
|
|
|
- if (relation == null) {
|
|
|
- //TODO 如果没指定座位,等待逻辑确认
|
|
|
- LambdaQueryWrapper<GroupsTrips> queryWrapper = Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
- .eq(GroupsTrips::getSkuId, payRequest.getSkuId())
|
|
|
- .gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
- .ne(GroupsTrips::getStatus, GroupsTrips.Status.down)
|
|
|
- .orderByAsc(GroupsTrips::getAvailableNum);
|
|
|
- GroupsTrips groups = groupsMapper.selectOne(queryWrapper);
|
|
|
- if (groups == null) {
|
|
|
- relation = createNewGroupsTrips(sku);
|
|
|
- isNew = true;
|
|
|
- } else {
|
|
|
- //寻找快满编车队进行占座
|
|
|
- relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
- .eq(GroupsRelation::getGroupsId, groups.getId())
|
|
|
- .eq(GroupsRelation::getStatus, "none")
|
|
|
- .eq(GroupsRelation::getUserId, 0)
|
|
|
- .orderByAsc(GroupsRelation::getNum)
|
|
|
- .last("limit 1")
|
|
|
- );
|
|
|
- if (relation == null) {
|
|
|
- throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //锁定座位
|
|
|
- setRelation(relation.getId(), user.getId(), goodsDon.getId(), payRequest.getIsLoginPopularize());
|
|
|
- relation.setUserId(user.getId());
|
|
|
- relation.setStatus(GroupsRelation.Status.locking);
|
|
|
- groupsRelationMapper.updateById(relation);
|
|
|
- relationId = relation.getId();
|
|
|
- }else {
|
|
|
+ //获取座位
|
|
|
+ relationId = getRelation(payRequest, sku);
|
|
|
+ } else {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -309,36 +261,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setRealMoney(payRequest.getDonMoney());
|
|
|
|
|
|
//渠道链接id
|
|
|
- if(payRequest.getPopularizeId() != null){
|
|
|
+ if (payRequest.getPopularizeId() != null) {
|
|
|
orderDon.setPopularizeId(payRequest.getPopularizeId());
|
|
|
}
|
|
|
- //存在优惠券
|
|
|
- if (couponUser != null) {
|
|
|
- Long couponId = couponUser.getCouponId();
|
|
|
- Coupon coupon = couponMapper.getCouponById(couponId);
|
|
|
- BigDecimal couponMoney = null;
|
|
|
- if (coupon.getType() == Coupon.Type.discount) {
|
|
|
- BigDecimal discountMoney = payRequest.getDonMoney().multiply(coupon.getDiscount());
|
|
|
- orderDon.setMoney(discountMoney);
|
|
|
- couponMoney = payRequest.getDonMoney().subtract(discountMoney);
|
|
|
- } else if (coupon.getType() == Coupon.Type.reduce) {
|
|
|
- if (goodsDon.getType() == Constant.realGoodsType.get(0)) {
|
|
|
- BigDecimal reduceCondition = coupon.getReduceCondition();
|
|
|
- if (reduceCondition.compareTo(BigDecimal.ZERO) > 0 && reduceCondition.compareTo(payRequest.getDonMoney()) > 0) {
|
|
|
- throw BusinessRuntimeException.getInstance(String.format("满%s可用", reduceCondition.divide(BigDecimal.valueOf(100))));
|
|
|
- }
|
|
|
- }
|
|
|
- BigDecimal subtractMoney = payRequest.getDonMoney().subtract(coupon.getReduceMoney());
|
|
|
- orderDon.setMoney(subtractMoney);
|
|
|
- couponMoney = payRequest.getDonMoney().subtract(subtractMoney);
|
|
|
- }
|
|
|
- orderDon.setCouponMoney(couponMoney);
|
|
|
- orderDon.setCouponUserId(couponUser.getId());
|
|
|
- orderDon.setDsPopularizeId(couponUser.getPopularizeId());
|
|
|
- }
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("支付金额小于0");
|
|
|
- }
|
|
|
+ //扣除使用优惠券、余额的订单金额
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user);
|
|
|
+
|
|
|
orderDon.setSkuId(payRequest.getSkuId());
|
|
|
orderDon.setRelationId(relationId);
|
|
|
orderDon.setNum(payRequest.getNum());
|
|
|
@@ -373,29 +301,17 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance("车位与车队规格不一致");
|
|
|
}
|
|
|
}
|
|
|
+ orderDon.setPayDesc(goodsDon.getPayDesc());
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
if (Constant.realGoodsType.contains(goodsDon.getType()) && !goodsDon.getId().equals(27l)) {
|
|
|
saveTransport(payRequest.getAddressId(), orderDon.getId());
|
|
|
}
|
|
|
- if (isNew) {
|
|
|
- //新增空车队发送模板消息
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- try {
|
|
|
- List<CustomerService> customerServices = customerServiceMapper.selectList(null);
|
|
|
- for (CustomerService customerService : customerServices) {
|
|
|
- log.info("发送客服{}空车位通知消息", customerService.getNickName());
|
|
|
- templateCommonService.emptySendMsgNotify(orderDon, customerService.getOpenId());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("发送{}空车位模板消息至客服失败:{}", orderDon.getGoodsId(), e);
|
|
|
- }
|
|
|
+ if (orderDon.getStatus() == OrderDon.Status.noPayment) {
|
|
|
+ jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
+ closeOrder(orderDon.getId());
|
|
|
});
|
|
|
}
|
|
|
- jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
- closeOrder(orderDon.getId());
|
|
|
- });
|
|
|
-
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -413,7 +329,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//获取微信默认商户
|
|
|
String shopId = sysConfigService.getDefaultShopConfigByType("wx");
|
|
|
|
|
|
- ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(),"wx");
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(), "wx");
|
|
|
if (shopConfig != null) {
|
|
|
shopId = shopConfig.getAppId();
|
|
|
}
|
|
|
@@ -451,7 +367,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//获取微信默认商户
|
|
|
String shopId = sysConfigService.getDefaultShopConfigByType("wx");
|
|
|
|
|
|
- ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(),"wx");
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(), "wx");
|
|
|
if (shopConfig != null) {
|
|
|
shopId = shopConfig.getAppId();
|
|
|
}
|
|
|
@@ -570,7 +486,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//购买Midjourney课程 赠送Midjourney车票
|
|
|
if (goodsId != null && goodsId.equals(27l)) {
|
|
|
order.setStatus(OrderDon.Status.complete);
|
|
|
- TASK_POOL.execute(()->sendMidjourneyTicketIfCourse(order.getUserId()));
|
|
|
+ TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(order.getUserId()));
|
|
|
}
|
|
|
this.updateById(order);
|
|
|
//配置了特定奖池,增加抽奖机会
|
|
|
@@ -618,7 +534,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
GroupsRelation groupsRelation = groupsRelationMapper.selectById(orderDon.getRelationId());
|
|
|
if (groupsRelation != null) {
|
|
|
if (!groupsRelation.getUserId().equals(orderDon.getUserId())) {
|
|
|
- TASK_POOL.execute(()->{
|
|
|
+ TASK_POOL.execute(() -> {
|
|
|
orderDon.setStatus(OrderDon.Status.close);
|
|
|
updateById(orderDon);
|
|
|
});
|
|
|
@@ -654,7 +570,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//返还优惠券
|
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
|
- updateOrderDonCouponStatus(orderDon);
|
|
|
+ couponFontService.updateOrderDonCouponStatus(orderDon);
|
|
|
+ }
|
|
|
+ //返还余额
|
|
|
+ if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ userBenefitsService.addUserBalance(orderDon.getUserId(), orderDon.getBalance());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -688,16 +608,16 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(renewSkuId);
|
|
|
|
|
|
- GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
- if (relation == null) {
|
|
|
- throw new BusinessRuntimeException("");
|
|
|
- }
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
+ if (relation == null) {
|
|
|
+ throw new BusinessRuntimeException("");
|
|
|
+ }
|
|
|
|
|
|
//todo 多账号同一用户绑定 续费
|
|
|
if (!relation.getUserId().equals(user.getId())) {
|
|
|
checkIsSameUser(relation.getUserId(), userId, user.getOpenId(), user.getLoginPhone());
|
|
|
}
|
|
|
- GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
+ GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
if (groupsTrips == null) {
|
|
|
throw BusinessRuntimeException.getInstance("该车队不存在,请联系客服");
|
|
|
}
|
|
|
@@ -771,30 +691,19 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
orderDon.setRealMoney(orderDon.getMoney());
|
|
|
- //存在优惠券
|
|
|
- if (couponUser != null) {
|
|
|
- Long couponId = couponUser.getCouponId();
|
|
|
- Coupon coupon = couponMapper.getCouponById(couponId);
|
|
|
- BigDecimal couponMoney = null;
|
|
|
- if (coupon.getType() == Coupon.Type.discount) {
|
|
|
- BigDecimal discountMoney = orderDon.getMoney().multiply(coupon.getDiscount());
|
|
|
- orderDon.setMoney(discountMoney);
|
|
|
- couponMoney = orderDon.getRealMoney().subtract(discountMoney);
|
|
|
- } else if (coupon.getType() == Coupon.Type.reduce) {
|
|
|
- BigDecimal subtractMoney = orderDon.getMoney().subtract(coupon.getReduceMoney());
|
|
|
- orderDon.setMoney(subtractMoney);
|
|
|
- couponMoney = orderDon.getRealMoney().subtract(subtractMoney);
|
|
|
- }
|
|
|
- orderDon.setCouponMoney(couponMoney);
|
|
|
- orderDon.setCouponUserId(couponUser.getId());
|
|
|
- }
|
|
|
-
|
|
|
+ //扣除使用优惠券、余额的订单金额
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user);
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
-
|
|
|
- jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
- closeOrder(orderDon.getId());
|
|
|
- });
|
|
|
-
|
|
|
+ //订单金额为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());
|
|
|
+ });
|
|
|
+ }
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -825,7 +734,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
String appId = sysConfigService.getDefaultShopConfigByType("zfb");
|
|
|
|
|
|
if (orderDon.getPopularizeId() != null) {
|
|
|
- ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(),"zfb");
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(), "zfb");
|
|
|
if (shopConfig != null) {
|
|
|
appId = shopConfig.getAppId();
|
|
|
}
|
|
|
@@ -851,7 +760,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setShopId(null);
|
|
|
}
|
|
|
String appId = params.get("app_id");
|
|
|
- boolean signVerified = AlipaySignature.rsaCheckV1(params,shopConfigMapper.getByAppId(appId).getPublicKey(), BaseZfbConfig.charset, BaseZfbConfig.signType);
|
|
|
+ boolean signVerified = AlipaySignature.rsaCheckV1(params, shopConfigMapper.getByAppId(appId).getPublicKey(), BaseZfbConfig.charset, BaseZfbConfig.signType);
|
|
|
if (!signVerified) {
|
|
|
log.error("支付宝回调校验签名错误,自定义入参:{}", params.get("body"));
|
|
|
throw BusinessRuntimeException.getInstance("支付宝回调校验签名错误");
|
|
|
@@ -890,13 +799,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return;
|
|
|
}
|
|
|
if (!orderDon.getIsNoLogin()) {
|
|
|
- if (orderDon.getOrderType() == 2 && orderDon.getIsChangeTicket()) {
|
|
|
- //将奈飞月付车票更换成其他规格的车票
|
|
|
- changeTicketAndRecord(orderDon.getPreSkuId(), orderDon.getRelationId(), orderDon.getId(), orderDon.getNum(), sku, orderDon.getUserId());
|
|
|
- } else {
|
|
|
- //修改车位状态并发送模板消息
|
|
|
- updateCarParkAndSendMsg(goodsDon, sku, orderDon);
|
|
|
- }
|
|
|
+ //更新座位信息
|
|
|
+ updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0 && orderDon.getIsDistribute()) {
|
|
|
TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(orderDon));
|
|
|
}
|
|
|
@@ -916,7 +820,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//购买Midjourney课程 赠送Midjourney车票
|
|
|
if (goodsId != null && goodsId.equals(27l)) {
|
|
|
orderDon.setStatus(OrderDon.Status.complete);
|
|
|
- TASK_POOL.execute(()->sendMidjourneyTicketIfCourse(orderDon.getUserId()));
|
|
|
+ TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(orderDon.getUserId()));
|
|
|
}
|
|
|
this.updateById(orderDon);
|
|
|
//配置了特定奖池,增加抽奖机会
|
|
|
@@ -936,356 +840,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Throwable.class)
|
|
|
- public Result<String> wxRefund(WxOrderRefundReq wxOrderRefundReq) throws Exception {
|
|
|
- OrderDon orderDon = orderDonMapper.selectById(wxOrderRefundReq.getOrderId());
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- if (OrderDon.Type.EX_CODE == orderDon.getType()) {
|
|
|
- wxOrderRefundReq.setRefundMoney(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- if (OrderDon.Type.EX_CODE != orderDon.getType() && orderDon.getType() != OrderDon.Type.WeChat) {
|
|
|
- throw BusinessRuntimeException.getInstance("该订单不是微信支付的订单");
|
|
|
- }
|
|
|
- //校验订单是否符合退款
|
|
|
- checkOrderRefund(orderDon, goodsDon, sku);
|
|
|
- if (wxOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
|
|
|
- }
|
|
|
- if (!redisService.setNx(String.format("%s", wxOrderRefundReq.getOrderId()), wxOrderRefundReq.getOrderId(), 10l)) {
|
|
|
- throw BusinessRuntimeException.getInstance("请勿重复点击,正在退款中..");
|
|
|
- }
|
|
|
- String outRefundNo = "";
|
|
|
- if (orderDon.getType() != OrderDon.Type.EX_CODE) {
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- //退款订单号
|
|
|
- outRefundNo = Codec.DoDigest.custom()
|
|
|
- .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
- .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
- .toHexString();
|
|
|
- weChatService.refundWxOrder(weChatConfig.getAppid(),
|
|
|
- Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.WX_DEFAULT_APP_ID),
|
|
|
- orderDon.getTransactionId(),
|
|
|
- outRefundNo,
|
|
|
- orderDon.getMoney(),
|
|
|
- wxOrderRefundReq.getRefundMoney(),
|
|
|
- weChatConfig.getDomain() + "applets/order/wx/refund/notify");
|
|
|
- }
|
|
|
- //修改订单状态
|
|
|
- orderDon.setStatus(OrderDon.Status.refund);
|
|
|
- orderDon.setRefundMoney(wxOrderRefundReq.getRefundMoney());
|
|
|
- orderDon.setRefundDesc(wxOrderRefundReq.getRefundDesc());
|
|
|
- //记录退款信息
|
|
|
- final String outNo = outRefundNo;
|
|
|
- THREAD_POOL_TASK_EXECUTOR.execute(()->{
|
|
|
- refundRecord(orderDon, goodsDon, sku, outNo);
|
|
|
- goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
|
|
|
- });
|
|
|
- try {
|
|
|
- //虚物订单退款,清出车队,车票变为已过期
|
|
|
- orderCommonService.clearUnrealGoodsDetail(orderDon, goodsDon.getType(), sku.getMonths());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("清除车票错误:{}", StringUtil.getErrorText(e));
|
|
|
- }
|
|
|
- //若存在优惠券使用,退还优惠券
|
|
|
- if (orderDon.getCouponUserId() != 0) {
|
|
|
- redisService.set(String.format("%s-%s", orderDon.getId(), orderDon.getCouponUserId()), orderDon.getId(), 120l);
|
|
|
- updateOrderDonCouponStatus(orderDon);
|
|
|
- }
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Throwable.class)
|
|
|
- public Result<String> zfbRefund(ZfbOrderRefundReq zfbOrderRefundReq) throws Exception {
|
|
|
- OrderDon orderDon = orderDonMapper.selectById(zfbOrderRefundReq.getOrderId());
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- if (OrderDon.Type.EX_CODE == orderDon.getType()) {
|
|
|
- zfbOrderRefundReq.setRefundMoney(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- if (OrderDon.Type.EX_CODE != orderDon.getType() && orderDon.getType() != OrderDon.Type.ALI_PAY) {
|
|
|
- throw BusinessRuntimeException.getInstance("该订单不是支付宝支付的订单");
|
|
|
- }
|
|
|
- //校验订单是否符合退款
|
|
|
- checkOrderRefund(orderDon, goodsDon, sku);
|
|
|
- if (zfbOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
|
|
|
- }
|
|
|
- if (!redisService.setNx(String.format("%s", zfbOrderRefundReq.getOrderId()), zfbOrderRefundReq.getOrderId(), 10l)) {
|
|
|
- throw BusinessRuntimeException.getInstance("请勿重复点击,正在退款中..");
|
|
|
- }
|
|
|
- AlipayTradeRefundResponse response = null;
|
|
|
- if (OrderDon.Type.EX_CODE == orderDon.getType()) {
|
|
|
- response = new AlipayTradeRefundResponse();
|
|
|
- }
|
|
|
- String outRefundNo = "";
|
|
|
- if (OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
- //支付宝退款
|
|
|
- AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID));
|
|
|
- AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
- AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
- //支付宝交易号
|
|
|
- model.setTradeNo(orderDon.getTransactionId());
|
|
|
- model.setRefundAmount(zfbOrderRefundReq.getRefundMoney().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_EVEN).toString());
|
|
|
- model.setQueryOptions(List.of("gmt_refund_pay"));
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- //退款订单号
|
|
|
- outRefundNo = Codec.DoDigest.custom()
|
|
|
- .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
- .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
- .toHexString();
|
|
|
- //退款请求号
|
|
|
- model.setOutRequestNo(outRefundNo);
|
|
|
- request.setBizModel(model);
|
|
|
- String shopId = orderDon.getShopId();
|
|
|
- ShopConfig shopConfig = shopConfigMapper.selectOne(Wrappers.lambdaQuery(ShopConfig.class).eq(ShopConfig::getAppId, orderDon.getShopId()));
|
|
|
- if (shopId != null && shopConfig != null && shopConfig.getIsCert()) {
|
|
|
- response = alipayClient.certificateExecute(request);
|
|
|
- } else {
|
|
|
- response = alipayClient.execute(request);
|
|
|
- }
|
|
|
- }
|
|
|
- final String outNo = outRefundNo;
|
|
|
- if (response.isSuccess()) {
|
|
|
- //修改订单状态
|
|
|
- orderDon.setStatus(OrderDon.Status.refund);
|
|
|
- if (OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
- AliPayRefundRep aliPayRefundRep = Jsons.parseObject(response.getBody(), AliPayRefundRep.class);
|
|
|
- AliPayRefundRep.AlipayTradeRefundResponse res = aliPayRefundRep.getResponse();
|
|
|
- orderDon.setRefundMoney(res.getRefundFee().multiply(BigDecimal.valueOf(100)));
|
|
|
- } else orderDon.setRefundMoney(BigDecimal.ZERO);
|
|
|
- orderDon.setRefundDesc(zfbOrderRefundReq.getRefundDesc());
|
|
|
- //记录退款信息
|
|
|
- THREAD_POOL_TASK_EXECUTOR.execute(()->{
|
|
|
- refundRecord(orderDon, goodsDon, sku, outNo);
|
|
|
- goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
|
|
|
- try {
|
|
|
- marketFrontService.subSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getUpdateTime());
|
|
|
- if (goodsDon.getType() == 2) {
|
|
|
- equipmentDistributeService.subDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
|
- //扣除用户自身实物权益
|
|
|
- userRealOrderBenefitsService.deductUserRealGoodsBenefits(orderDon.getId());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("zfb减少抽奖机会错误,orderId:{},error:{}", orderDon.getId(), e);
|
|
|
- }
|
|
|
- if (orderDon.getIsDistribute()) {
|
|
|
- DistributeWaitingSendPoints distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId()).last("limit 1"));
|
|
|
- if (distributeWaitingSendPoints != null) {
|
|
|
- Integer success = distributeWaitingSendPointsMapper.updateOrderStatus(orderDon.getId(), DistributeWaitingSendPoints.Status.close);
|
|
|
- //是否积分已经发送
|
|
|
- if (success != 1 && orderDon.getIsFixedDistribute()) {
|
|
|
- //扣除固定推广者积分
|
|
|
- BigDecimal refundMoney = orderDon.getRefundMoney();
|
|
|
- BigDecimal money = orderDon.getMoney();
|
|
|
- BigDecimal needSubPoints = distributeWaitingSendPoints.getPoints();
|
|
|
- if (refundMoney.compareTo(money) == 0) {
|
|
|
- userPointsService.deductDistributePoints(orderDon.getId(), distributeWaitingSendPoints.getSharedId(), needSubPoints);
|
|
|
-
|
|
|
- distributeWaitingSendPointsMapper.update(null, Wrappers.lambdaUpdate(DistributeWaitingSendPoints.class)
|
|
|
- .set(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close)
|
|
|
- .eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId())
|
|
|
- .ne(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close));
|
|
|
- } else {
|
|
|
- Integer thisGoodsRate = Optional.ofNullable(userDistributeMapper.getDistributeGoodsRateByUidAndGid(orderDon.getUserId(), orderDon.getGoodsId())).orElse(0);
|
|
|
- if (thisGoodsRate > 0) {
|
|
|
- needSubPoints = refundMoney.multiply(BigDecimal.valueOf(thisGoodsRate).divide(BigDecimal.valueOf(100))).multiply(BigDecimal.valueOf(10));
|
|
|
- userPointsService.deductDistributePoints(orderDon.getId(), distributeWaitingSendPoints.getSharedId(), needSubPoints);
|
|
|
-
|
|
|
- distributeWaitingSendPointsMapper.update(null, Wrappers.lambdaUpdate(DistributeWaitingSendPoints.class)
|
|
|
- .set(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close)
|
|
|
- .eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId())
|
|
|
- .ne(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- try {
|
|
|
- //虚物订单退款,清出车队,车票变为已过期
|
|
|
- orderCommonService.clearUnrealGoodsDetail(orderDon, goodsDon.getType(), sku.getMonths());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("清除车票错误:{}", StringUtil.getErrorText(e));
|
|
|
- }
|
|
|
- if (orderDon.getCouponUserId() != 0) {
|
|
|
- //zfb订单退款,返还优惠券
|
|
|
- updateOrderDonCouponStatus(orderDon);
|
|
|
- }
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
|
|
|
- }
|
|
|
- throw BusinessRuntimeException.getInstance("退款失败,e:{0}", response.getSubMsg());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验订单是否符合退款操作
|
|
|
- * @param orderDon
|
|
|
- */
|
|
|
- private void checkOrderRefund(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
- if (orderDon == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("订单不存在");
|
|
|
- }
|
|
|
-// if (orderDon.getType() == OrderDon.Type.EX_CODE) {
|
|
|
-// throw BusinessRuntimeException.getInstance("兑换码订单不支持退款");
|
|
|
-// }
|
|
|
- if (OrderDon.Status.refund == orderDon.getStatus()) {
|
|
|
- throw BusinessRuntimeException.getInstance("该订单已退款");
|
|
|
- }
|
|
|
- if (OrderDon.Status.noPayment == orderDon.getStatus() || OrderDon.Status.close == orderDon.getStatus()) {
|
|
|
- throw BusinessRuntimeException.getInstance("订单{0}状态不支持退款", orderDon.getStatus());
|
|
|
- }
|
|
|
- if (goodsDon.getType() == 1) {
|
|
|
- //虚拟原订单是否已过期
|
|
|
- Integer months = sku.getMonths();
|
|
|
- Integer num = orderDon.getNum();
|
|
|
- DateTime now = DateTime.now();
|
|
|
- DateTime endTime = DateUtil.offsetMonth(orderDon.getCreatedTime(), months * num);
|
|
|
- if (now.isAfter(endTime)) {
|
|
|
- throw BusinessRuntimeException.getInstance("该订单车票已过期");
|
|
|
- }
|
|
|
- if (orderDon.getOrderType() == 1) {
|
|
|
- //是否有其他付款订单是否过期
|
|
|
- OrderDon otherOrder = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getRelationId, orderDon.getRelationId())
|
|
|
- .eq(OrderDon::getUserId, orderDon.getUserId())
|
|
|
- .ne(OrderDon::getId, orderDon.getId())
|
|
|
- .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
- .eq(OrderDon::getOrderType, 2)
|
|
|
- .orderByDesc(OrderDon::getId)
|
|
|
- .last("limit 1"));
|
|
|
- if (otherOrder != null) {
|
|
|
- throw BusinessRuntimeException.getInstance("该笔订单存在续费订单,请先退掉续费订单");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //续费订单
|
|
|
-// if (orderDon.getOrderType() == 2 && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
-// throw BusinessRuntimeException.getInstance("续费订单不支持退款");
|
|
|
-// }
|
|
|
-// if (goodsDon != null && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
-// //虚物订单 7天内可退款
|
|
|
-// if (goodsDon.getType() == 1 && DateTime.now().isAfter(DateUtil.offsetDay(orderDon.getPayTime(), 7))) {
|
|
|
-// throw BusinessRuntimeException.getInstance("该虚物订单已过退款时间");
|
|
|
-// }
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 记录退款信息
|
|
|
- */
|
|
|
- private void refundRecord(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku, String outRefundNo) {
|
|
|
- RefundOrderDon refundOrderDon = refundOrderDonMapper.selectOne(Wrappers.lambdaQuery(RefundOrderDon.class).eq(RefundOrderDon::getOrderId, orderDon.getId()).eq(RefundOrderDon::getOutRefundNo, outRefundNo).last("limit 1"));
|
|
|
- if (refundOrderDon == null) {
|
|
|
- RefundOrderDon refund = new RefundOrderDon();
|
|
|
- refund.setOrderId(orderDon.getId());
|
|
|
- refund.setOutRefundNo(outRefundNo);
|
|
|
- refund.setTotalFee(orderDon.getMoney());
|
|
|
- refund.setRefundDesc(orderDon.getRefundDesc());
|
|
|
- //退款金额
|
|
|
- refund.setRefundFee(orderDon.getRefundMoney());
|
|
|
- refund.setUserId(orderDon.getUserId());
|
|
|
- refund.setGoodsId(orderDon.getGoodsId());
|
|
|
- refund.setGoodsTitle(goodsDon == null ? null : goodsDon.getTitle());
|
|
|
- refund.setSkuId(orderDon.getSkuId());
|
|
|
- refund.setSpecVal(sku == null ? null : String.format("%s%s", sku.getSpecVal(), sku.getPrice().divide(BigDecimal.valueOf(100))));
|
|
|
- refund.setRefundMethod(orderDon.getType().name());
|
|
|
- refund.setGoodsType(goodsDon == null ? 0 : goodsDon.getType());
|
|
|
- refundOrderDonMapper.insert(refund);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void wxRefundNotify(Map<String, String> map) throws Exception {
|
|
|
- // 对退款数据 解密
|
|
|
- String md5Key = Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(shopConfigMapper.getByAppId(map.get("mch_id")).getSecret()).toHexString();
|
|
|
- String reqInfoXml = Codec.DoCipher.custom().setAlgorithm(Codec.DoCipher.Trans.AES_ECB_PKCS7Padding).setBase64Data(map.get("req_info")).setStringKey(md5Key).ofDecrypt().toText();
|
|
|
- log.info("=== 退款数据解密: \n {}", reqInfoXml);
|
|
|
- Map<String, String> reqInfoMap = Xmls.toMap(reqInfoXml);
|
|
|
- // 退款失败
|
|
|
- if (StrUtil.equals("CHANGE", reqInfoMap.get("refund_status"))) {
|
|
|
- throw BusinessRuntimeException.getInstance("退款异常.");
|
|
|
- } else if (StrUtil.equals("REFUNDCLOSE", reqInfoMap.get("refund_status"))) {
|
|
|
- throw BusinessRuntimeException.getInstance("退款关闭.");
|
|
|
- }
|
|
|
- /* 此处处理业务逻辑 */
|
|
|
- String outRefundNo = reqInfoMap.get("out_refund_no");
|
|
|
- String transactionId = reqInfoMap.get("transaction_id");
|
|
|
- String refundFee = reqInfoMap.get("refund_fee");
|
|
|
- OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getTransactionId, transactionId).last("limit 1"));
|
|
|
- if (orderDon == null) {
|
|
|
- log.error("退款回调,transactionId:{}订单不存在", transactionId);
|
|
|
- return;
|
|
|
- }
|
|
|
- BigDecimal refundMoney = new BigDecimal(refundFee);
|
|
|
- if (orderDon.getStatus() == OrderDon.Status.refund) {
|
|
|
- if (!orderDon.getRefundMoney().equals(refundMoney)) {
|
|
|
- orderDon.setRefundMoney(refundMoney);
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
- }
|
|
|
- } else {
|
|
|
- orderDon.setStatus(OrderDon.Status.refund);
|
|
|
- orderDon.setRefundMoney(refundMoney);
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
- }
|
|
|
- if (orderDon.getCouponUserId() != 0) {
|
|
|
- Object obj = redisService.get(String.format("%s-%s", orderDon.getId(), orderDon.getCouponUserId()));
|
|
|
- if (obj == null) {
|
|
|
- updateOrderDonCouponStatus(orderDon);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("微信退款: 退款单号[{}] 退款成功.", outRefundNo);
|
|
|
-
|
|
|
- TASK_POOL.execute(()->{
|
|
|
- try {
|
|
|
- marketFrontService.subSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getUpdateTime());
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
- if (goodsDon.getType() == 2) {
|
|
|
- equipmentDistributeService.subDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
|
- //扣除用户自身实物权益
|
|
|
- userRealOrderBenefitsService.deductUserRealGoodsBenefits(orderDon.getId());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("wx减少抽奖机会错误,orderId:{},error:{}", orderDon.getId(), e);
|
|
|
- }
|
|
|
- if (orderDon.getIsDistribute()) {
|
|
|
- DistributeWaitingSendPoints distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId()).last("limit 1"));
|
|
|
- if (distributeWaitingSendPoints != null) {
|
|
|
- Integer success = distributeWaitingSendPointsMapper.updateOrderStatus(orderDon.getId(), DistributeWaitingSendPoints.Status.close);
|
|
|
- //是否产生过积分
|
|
|
- if (success != 1 && orderDon.getIsFixedDistribute()) {
|
|
|
- //扣除固定推广者积分
|
|
|
- BigDecimal money = orderDon.getMoney();
|
|
|
- BigDecimal needSubPoints = distributeWaitingSendPoints.getPoints();
|
|
|
- if (refundMoney.compareTo(money) == 0) {
|
|
|
- userPointsService.deductDistributePoints(orderDon.getId(), distributeWaitingSendPoints.getSharedId(), needSubPoints);
|
|
|
-
|
|
|
- distributeWaitingSendPointsMapper.update(null, Wrappers.lambdaUpdate(DistributeWaitingSendPoints.class)
|
|
|
- .set(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close)
|
|
|
- .eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId())
|
|
|
- .ne(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close));
|
|
|
- } else {
|
|
|
- Integer thisGoodsRate = Optional.ofNullable(userDistributeMapper.getDistributeGoodsRateByUidAndGid(orderDon.getUserId(), orderDon.getGoodsId())).orElse(0);
|
|
|
- if (thisGoodsRate > 0) {
|
|
|
- needSubPoints = refundMoney.multiply(BigDecimal.valueOf(thisGoodsRate).divide(BigDecimal.valueOf(100))).multiply(BigDecimal.valueOf(10));
|
|
|
- userPointsService.deductDistributePoints(orderDon.getId(), distributeWaitingSendPoints.getSharedId(), needSubPoints);
|
|
|
-
|
|
|
- distributeWaitingSendPointsMapper.update(null, Wrappers.lambdaUpdate(DistributeWaitingSendPoints.class)
|
|
|
- .set(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close)
|
|
|
- .eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId())
|
|
|
- .ne(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.close));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void setRelation(Long relationId, Long userId, Long goodsId, Boolean isLoginPopularize) {
|
|
|
+ public void setRelation(Long relationId, Long groupsId, Long userId, Long goodsId, Boolean isLoginPopularize) {
|
|
|
if (isLoginPopularize == null || !isLoginPopularize) {
|
|
|
int noPayCount = count(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, userId).eq(OrderDon::getGoodsId, goodsId).eq(OrderDon::getStatus, OrderDon.Status.noPayment.toString()));
|
|
|
if (noPayCount > 0) {
|
|
|
@@ -1307,10 +862,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
}
|
|
|
- GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
- int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
+ int count = groupsMapper.decrAvailableNum(groupsId);
|
|
|
if (count == 0) {
|
|
|
- log.error("车位异常 groupId:{}", relation.getGroupsId());
|
|
|
+ log.error("车位异常 groupId:{}", groupsId);
|
|
|
throw new BusinessRuntimeException("车位异常");
|
|
|
}
|
|
|
}
|
|
|
@@ -1449,6 +1003,24 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void zeroOrderConfirm(Long orderId) {
|
|
|
+ OrderDon orderDon = this.getById(orderId);
|
|
|
+ if (orderDon == null) throw BusinessRuntimeException.getInstance("订单不存在");
|
|
|
+ if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("订单异常");
|
|
|
+ }
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
+ orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
+ updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
+ if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ orderDon.setType(OrderDon.Type.BALANCE);
|
|
|
+ orderDon.setPayTime(DateTime.now());
|
|
|
+ }
|
|
|
+ this.updateById(orderDon);
|
|
|
+ }
|
|
|
+
|
|
|
public AliPayParams commonAliPay(Long orderId, String returnUrl, String productCode, String appId, String qrPayMode) throws Exception {
|
|
|
AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(Optional.ofNullable(appId).orElse(ShopConfig.ZFB_DEFAULT_APP_ID));
|
|
|
// 创建API对应的request
|
|
|
@@ -1462,7 +1034,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (BaseZfbConfig.qrPayMode_redirect.equals(qrPayMode)) {
|
|
|
returnUrl = String.format("%s%s", envCommonService.getDomain(), BaseZfbConfig.loginReturnUrl);
|
|
|
alipayRequest.setReturnUrl(returnUrl);
|
|
|
- }else if (StrUtil.isNotBlank(returnUrl)){
|
|
|
+ } else if (StrUtil.isNotBlank(returnUrl)) {
|
|
|
alipayRequest.setReturnUrl(returnUrl);
|
|
|
}
|
|
|
alipayRequest.setNotifyUrl(notifyUrl);
|
|
|
@@ -1569,30 +1141,30 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //新订单产生 发送模板消息给用户、客服
|
|
|
- User user = userMapper.selectById(order.getUserId());
|
|
|
- if (user != null) {
|
|
|
- THREAD_POOL_TASK_EXECUTOR.execute(() -> {
|
|
|
- try {
|
|
|
- //发送至用户消息
|
|
|
- templateCommonService.newOderSendMsgByType(order, goodsDon, user, user.getOpenId(), false);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("向用户发送新订单{}通知消息失败:{}", order.getOrderNo(), e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- THREAD_POOL_TASK_EXECUTOR.execute(() -> {
|
|
|
- try {
|
|
|
- //发送至客服消息
|
|
|
- List<CustomerService> customerServices = customerServiceMapper.selectList(null);
|
|
|
- for (CustomerService customerService : customerServices) {
|
|
|
- log.info("向客服{}发送新订单消息通知..", customerService.getNickName());
|
|
|
- templateCommonService.newOderSendMsgByType(order, goodsDon, user, customerService.getOpenId(), true);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("向客服发送新订单{}通知消息失败:{}", order.getOrderNo(), e);
|
|
|
- }
|
|
|
- });
|
|
|
+// //新订单产生 发送模板消息给用户、客服
|
|
|
+// User user = userMapper.selectById(order.getUserId());
|
|
|
+// if (user != null) {
|
|
|
+// THREAD_POOL_TASK_EXECUTOR.execute(() -> {
|
|
|
+// try {
|
|
|
+// //发送至用户消息
|
|
|
+// templateCommonService.newOderSendMsgByType(order, goodsDon, user, user.getOpenId(), false);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("向用户发送新订单{}通知消息失败:{}", order.getOrderNo(), e);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// THREAD_POOL_TASK_EXECUTOR.execute(() -> {
|
|
|
+// try {
|
|
|
+// //发送至客服消息
|
|
|
+// List<CustomerService> customerServices = customerServiceMapper.selectList(null);
|
|
|
+// for (CustomerService customerService : customerServices) {
|
|
|
+// log.info("向客服{}发送新订单消息通知..", customerService.getNickName());
|
|
|
+// templateCommonService.newOderSendMsgByType(order, goodsDon, user, customerService.getOpenId(), true);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("向客服发送新订单{}通知消息失败:{}", order.getOrderNo(), e);
|
|
|
+// }
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1642,7 +1214,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
returnMoney = orderMoney.multiply(BigDecimal.valueOf(rate)).divide(BigDecimal.valueOf(100));
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
businessId = userDistribute.getBusinessId();
|
|
|
//固定推广分销
|
|
|
UserPlatDistributeRate userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
|
|
|
@@ -1789,28 +1361,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return couponUser;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 退款时,归还优惠券
|
|
|
- */
|
|
|
- private void updateOrderDonCouponStatus(OrderDon orderDon) {
|
|
|
- log.info("订单:{}退款,优惠券返还start...", orderDon.getId());
|
|
|
- CouponUser couponUser = couponUserMapper.selectById(orderDon.getCouponUserId());
|
|
|
- if (CouponUser.Channel.exCode == couponUser.getChannel()) {
|
|
|
- //兑换码兑换的优惠券退款时,直接删除
|
|
|
- couponUserMapper.deleteById(couponUser.getId());
|
|
|
- }else {
|
|
|
- CouponUserView couponUserView = beanSearcher.searchFirst(CouponUserView.class, MapUtils.builder()
|
|
|
- .field(CouponUserView::getCouponId, couponUser.getCouponId()).op(Operator.Equal)
|
|
|
- .field(CouponUserView::getUserId, orderDon.getUserId()).op(Operator.Equal)
|
|
|
- .build());
|
|
|
- couponUserView.setCouponUserStatus(CouponUser.Status.unused);
|
|
|
- couponFontService.setCouponUserStatus(couponUserView, DateTime.now());
|
|
|
- couponUser.setStatus(couponUserView.getCouponUserStatus());
|
|
|
- couponUserMapper.updateById(couponUser);
|
|
|
- }
|
|
|
- log.info("订单:{}退款,优惠券返还end...", orderDon.getId());
|
|
|
- }
|
|
|
-
|
|
|
public void checkCouponGoods(GoodsDon goodsDon, Long skuId, Long couponId, Boolean isCouponCode) throws Exception {
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
CouponSku couponSku = couponSkuMapper.selectOne(Wrappers.lambdaQuery(CouponSku.class)
|
|
|
@@ -1821,13 +1371,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance(String.format("该%s不适用于该规格", isCouponCode ? "优惠码" : "优惠券"));
|
|
|
}
|
|
|
} else {
|
|
|
+ //实物、潮玩 优惠码优惠券 针对平台
|
|
|
Long gid = goodsDon.getId();
|
|
|
CouponSku couponSku = couponSkuMapper.selectOne(Wrappers.lambdaQuery(CouponSku.class)
|
|
|
.eq(CouponSku::getGoodsId, gid)
|
|
|
.eq(CouponSku::getCouponId, couponId)
|
|
|
.select(CouponSku::getId).last("limit 1"));
|
|
|
if (couponSku == null) {
|
|
|
- throw BusinessRuntimeException.getInstance(String.format("该%s不可用于ga商品", isCouponCode ? "优惠码" : "优惠券"));
|
|
|
+ throw BusinessRuntimeException.getInstance(String.format("该%s不可用于该商品", isCouponCode ? "优惠码" : "优惠券"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1873,7 +1424,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
groups.setAccountId(accountView.getId());
|
|
|
groups.setStatus(GroupsTrips.Status.validity);
|
|
|
groups.setRemark("已设置唯一账号");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
groups.setStatus(GroupsTrips.Status.waiting);
|
|
|
groups.setRemark("等待设置账号");
|
|
|
}
|
|
|
@@ -1926,7 +1477,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (userDistributeShared == null) {
|
|
|
CouponDistributePopularize couponDistributePopularize = couponDistributePopularizeMapper.selectOne(Wrappers.lambdaQuery(CouponDistributePopularize.class).eq(CouponDistributePopularize::getExCode, couponExCode).last("limit 1"));
|
|
|
Optional.ofNullable(couponDistributePopularize).ifPresent(popularize -> {
|
|
|
- try{
|
|
|
+ try {
|
|
|
UserDistribute userDistribute = userDistributeMapper.selectById(popularize.getDistributeId());
|
|
|
if (userDistribute == null || !userDistribute.getDeleted()) {
|
|
|
return;
|
|
|
@@ -1975,11 +1526,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @param preSkuId 续费之前的规格id
|
|
|
+ * @param preSkuId 续费之前的规格id
|
|
|
* @param preRelationId 续费之前的座位id
|
|
|
- * @param orderId 订单id
|
|
|
- * @param afterSku 续费之后的规格
|
|
|
+ * @param orderId 订单id
|
|
|
+ * @param afterSku 续费之后的规格
|
|
|
*/
|
|
|
private void changeTicketAndRecord(Long preSkuId, Long preRelationId, Long orderId, Integer num, GoodsDonSku afterSku, Long userId) {
|
|
|
//清理之前的车票
|
|
|
@@ -2032,15 +1582,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @param preStartTime 续费之前的开始时间
|
|
|
- * @param preExpiryTime 续费之前的过期时间
|
|
|
- * @param preRelationId 之前的座位id
|
|
|
- * @param userId 用户id
|
|
|
- * @param preSkuId 之前座位的规格id
|
|
|
- * @param orderId 订单id
|
|
|
- * @param num 订单数量
|
|
|
- * @param afterSku 续费之后的规格id
|
|
|
+ * @param preStartTime 续费之前的开始时间
|
|
|
+ * @param preExpiryTime 续费之前的过期时间
|
|
|
+ * @param preRelationId 之前的座位id
|
|
|
+ * @param userId 用户id
|
|
|
+ * @param preSkuId 之前座位的规格id
|
|
|
+ * @param orderId 订单id
|
|
|
+ * @param num 订单数量
|
|
|
+ * @param afterSku 续费之后的规格id
|
|
|
* @param afterRelationId 续费之后的座位id
|
|
|
*/
|
|
|
public void saveChangeTicketRecord(Date preStartTime, Date preExpiryTime, Long preRelationId, Long userId, Long preSkuId, Long orderId, Integer num, GoodsDonSku afterSku, Long afterRelationId) {
|
|
|
@@ -2168,7 +1717,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
try {
|
|
|
//Midjourney车票、ChatGPT独立规格车票
|
|
|
List<Long> skuIds = Jsons.parseList(sysValue, Long.class);
|
|
|
- skuIds.forEach(skuId->{
|
|
|
+ skuIds.forEach(skuId -> {
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
|
|
|
if (sku != null && sku.getStatus()) {
|
|
|
GroupsRelation relation = exchangeCodeService.getRelationNoOrder(sku, userId);
|
|
|
@@ -2226,4 +1775,113 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取车位
|
|
|
+ */
|
|
|
+ public Long getRelation(OrderPayRequest payRequest, GoodsDonSku sku) {
|
|
|
+ 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.getMonths(), null);
|
|
|
+ if (relation == null) {
|
|
|
+ //TODO 如果没指定座位,等待逻辑确认
|
|
|
+ LambdaQueryWrapper<GroupsTrips> queryWrapper = Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ .eq(GroupsTrips::getSkuId, sku.getId())
|
|
|
+ .gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
+ .ne(GroupsTrips::getStatus, GroupsTrips.Status.down)
|
|
|
+ .orderByAsc(GroupsTrips::getAvailableNum);
|
|
|
+ GroupsTrips groups = groupsMapper.selectOne(queryWrapper);
|
|
|
+ if (groups == null) {
|
|
|
+ relation = createNewGroupsTrips(sku);
|
|
|
+ } else {
|
|
|
+ //寻找快满编车队进行占座
|
|
|
+ relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getGroupsId, groups.getId())
|
|
|
+ .eq(GroupsRelation::getStatus, "none")
|
|
|
+ .eq(GroupsRelation::getUserId, 0)
|
|
|
+ .orderByAsc(GroupsRelation::getNum)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (relation == null) {
|
|
|
+ throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //锁定座位
|
|
|
+ setRelation(relation.getId(), relation.getGroupsId(), userId, sku.getGoodsId(), isLoginPopularize);
|
|
|
+ relation.setUserId(userId);
|
|
|
+ relation.setStatus(GroupsRelation.Status.locking);
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
+ return relation.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用优惠营销 订单金额抵扣
|
|
|
+ */
|
|
|
+ public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user) {
|
|
|
+ //存在优惠券
|
|
|
+ if (couponUser != null) {
|
|
|
+ Long couponId = couponUser.getCouponId();
|
|
|
+ Coupon coupon = couponMapper.getCouponById(couponId);
|
|
|
+ BigDecimal couponMoney = null;
|
|
|
+ if (coupon.getType() == Coupon.Type.discount) {
|
|
|
+ BigDecimal discountMoney = orderDon.getMoney().multiply(coupon.getDiscount());
|
|
|
+ orderDon.setMoney(discountMoney);
|
|
|
+ couponMoney = orderDon.getRealMoney().subtract(discountMoney);
|
|
|
+ } else if (coupon.getType() == Coupon.Type.reduce) {
|
|
|
+ BigDecimal subtractMoney = orderDon.getMoney().subtract(coupon.getReduceMoney());
|
|
|
+ orderDon.setMoney(subtractMoney);
|
|
|
+ couponMoney = orderDon.getRealMoney().subtract(subtractMoney);
|
|
|
+ }
|
|
|
+ orderDon.setCouponMoney(couponMoney);
|
|
|
+ orderDon.setCouponUserId(couponUser.getId());
|
|
|
+ }
|
|
|
+ //存在余额
|
|
|
+ if (balance != null && balance.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal money = orderDon.getMoney();
|
|
|
+ //去掉余额 多出的部分
|
|
|
+ BigDecimal subBalance = balance;
|
|
|
+ orderDon.setMoney(money.subtract(subBalance));
|
|
|
+ if (balance.compareTo(money) >= 0) {
|
|
|
+ orderDon.setMoney(BigDecimal.ZERO);
|
|
|
+ orderDon.setBalance(money);
|
|
|
+ subBalance = money;
|
|
|
+ orderDon.setType(OrderDon.Type.BALANCE);
|
|
|
+ }
|
|
|
+ BigDecimal userBalance = user.getBalance();
|
|
|
+ //扣除余额 是否成功
|
|
|
+ Integer success = userMapper.deductBalance(user.getId(), subBalance, userBalance);
|
|
|
+ if (success != 1) throw BusinessRuntimeException.getInstance("您的余额不足!");
|
|
|
+ orderDon.setBalance(balance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车票状态
|
|
|
+ */
|
|
|
+ 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());
|
|
|
+ } else {
|
|
|
+ //修改车位状态并发送模板消息
|
|
|
+ updateCarParkAndSendMsg(goodsDon, sku, orderDon);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|