|
|
@@ -3,13 +3,12 @@ package com.kxs.product.biz.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
-import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kxs.common.core.constant.CommonConstants;
|
|
|
+import com.kxs.common.core.constant.SecurityConstants;
|
|
|
import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.common.mq.handlers.IMQSender;
|
|
|
@@ -30,6 +29,9 @@ import com.kxs.product.biz.constant.enums.TicketTypeEnum;
|
|
|
import com.kxs.product.biz.mapper.*;
|
|
|
import com.kxs.product.biz.service.KxsShopOrderService;
|
|
|
import com.kxs.product.biz.service.KxsTicketService;
|
|
|
+import com.kxs.store.api.feign.RemoteKxsStoreService;
|
|
|
+import com.kxs.store.api.model.KxsWarehouseLimit;
|
|
|
+import com.kxs.system.api.util.ParamResolver;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -63,10 +65,18 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
private final RemoteKxsUserService remoteKxsUserService;
|
|
|
|
|
|
private final PaymentFactory paymentFactory;
|
|
|
+
|
|
|
private final KxsShopGoodsSkuMapper kxsShopGoodsSkuMapper;
|
|
|
+
|
|
|
private final KxsTicketService kxsTicketService;
|
|
|
+
|
|
|
private final IMQSender mqSender;
|
|
|
+
|
|
|
private final KxsShopGoodsMapper kxsShopGoodsMapper;
|
|
|
+
|
|
|
+ private final RemoteKxsStoreService remoteKxsStoreService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R submitOrder(GoodsSubmitDTO param) {
|
|
|
@@ -83,7 +93,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
KxsShopGoodsSku kxsShopGoodsSku = kxsShopGoodsSkuMapper.selectById(param.getSkuId());
|
|
|
Optional.ofNullable(kxsShopGoodsSku).orElseThrow(() -> new GlobalCustomerException("商品sku不存在"));
|
|
|
BigDecimal totalPrice = kxsShopGoodsSku.getPrice().multiply(new BigDecimal(param.getNumber()));
|
|
|
- if(totalPrice.compareTo(param.getTotalPrice()) != 0){
|
|
|
+ if (totalPrice.compareTo(param.getTotalPrice()) != 0) {
|
|
|
return R.failed("订单金额不一致");
|
|
|
}
|
|
|
|
|
|
@@ -98,9 +108,9 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
|
|
|
|
|
|
//当sku库存不为null时需做存量校验
|
|
|
- if (kxsShopGoodsSku.getStockNum() != null && kxsShopGoodsSku.getStockNum() != -1){
|
|
|
+ if (kxsShopGoodsSku.getStockNum() != null && kxsShopGoodsSku.getStockNum() != -1) {
|
|
|
int i = kxsShopGoodsSku.getStockNum() - param.getNumber();
|
|
|
- if(i < 0){
|
|
|
+ if (i < 0) {
|
|
|
throw new GlobalCustomerException("当前库存不足");
|
|
|
}
|
|
|
kxsShopGoodsSku.setStockNum(i);
|
|
|
@@ -108,14 +118,14 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
kxsShopGoodsSkuMapper.updateById(kxsShopGoodsSku);
|
|
|
}
|
|
|
//校验是否存在起购以及限购数量校验
|
|
|
- if (kxsShopGoodsSku.getStartByCount() != null && kxsShopGoodsSku.getStartByCount() != 0){
|
|
|
+ if (kxsShopGoodsSku.getStartByCount() != null && kxsShopGoodsSku.getStartByCount() != 0) {
|
|
|
boolean b = kxsShopGoodsSku.getStartByCount() > param.getNumber();
|
|
|
- if (b){
|
|
|
+ if (b) {
|
|
|
throw new GlobalCustomerException("该商品最低" + kxsShopGoodsSku.getStartByCount() + "件起购");
|
|
|
}
|
|
|
- }else if (kxsShopGoodsSku.getLimitCount() != null && kxsShopGoodsSku.getLimitCount() != 0){
|
|
|
+ } else if (kxsShopGoodsSku.getLimitCount() != null && kxsShopGoodsSku.getLimitCount() != 0) {
|
|
|
boolean b = kxsShopGoodsSku.getLimitCount() < param.getNumber();
|
|
|
- if (b){
|
|
|
+ if (b) {
|
|
|
throw new GlobalCustomerException("该商品每人最多购买" + kxsShopGoodsSku.getLimitCount() + "件");
|
|
|
}
|
|
|
}
|
|
|
@@ -133,8 +143,8 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
|
|
|
//发送订单延时取消消息
|
|
|
RabbitShopTimeoutQueueMQ.MsgEntity msgEntity = new RabbitShopTimeoutQueueMQ.MsgEntity();
|
|
|
- BeanUtils.copyProperties(order,msgEntity);
|
|
|
- mqSender.send(RabbitShopTimeoutQueueMQ.build(msgEntity),60*20);
|
|
|
+ BeanUtils.copyProperties(order, msgEntity);
|
|
|
+ mqSender.send(RabbitShopTimeoutQueueMQ.build(msgEntity), 60 * 20);
|
|
|
return R.ok(order.getId());
|
|
|
|
|
|
}
|
|
|
@@ -143,7 +153,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
public ShopOrderDetailVO getByOrderId(Integer orderId) {
|
|
|
|
|
|
KxsShopOrder order = baseMapper.selectById(orderId);
|
|
|
- if(order == null){
|
|
|
+ if (order == null) {
|
|
|
return null;
|
|
|
}
|
|
|
ShopOrderDetailVO shopOrderDetailVO = new ShopOrderDetailVO();
|
|
|
@@ -171,22 +181,22 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
|
public R payOrder(PayOrderDTO param) {
|
|
|
|
|
|
- if(param.getId() == null){
|
|
|
+ if (param.getId() == null) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
|
}
|
|
|
- if(param.getPayType() == null){
|
|
|
+ if (param.getPayType() == null) {
|
|
|
return R.failed("请选择支付方式");
|
|
|
}
|
|
|
KxsShopOrder order = baseMapper.selectById(param.getId());
|
|
|
- if(order == null){
|
|
|
+ if (order == null) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
|
}
|
|
|
- if(!Objects.equals(order.getStatus(), KxsShopEnum.ORDER_NO_PAY.getType())){
|
|
|
+ if (!Objects.equals(order.getStatus(), KxsShopEnum.ORDER_NO_PAY.getType())) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_STATUS_ERROR.getDescription());
|
|
|
}
|
|
|
|
|
|
//校验支付方式,邮寄需要
|
|
|
- if (Objects.equals(param.getGetMode(), KxsShopEnum.ORDER_ERP.getType())){
|
|
|
+ if (Objects.equals(param.getGetMode(), KxsShopEnum.ORDER_ERP.getType())) {
|
|
|
order.setGetMode(param.getGetMode());
|
|
|
order.setPhone(param.getPhone());
|
|
|
order.setConsignee(param.getConsignee());
|
|
|
@@ -195,7 +205,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
order.setRemark(param.getRemark());
|
|
|
//修改订单地址
|
|
|
updateById(order);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
order.setGetMode(param.getGetMode());
|
|
|
order.setPayType(param.getPayType());
|
|
|
order.setRemark(param.getRemark());
|
|
|
@@ -205,16 +215,16 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
String subject = kxsShopOrderInfos.stream().map(KxsShopOrderInfo::getGoodsName).collect(Collectors.joining(","));
|
|
|
|
|
|
//支付宝支付
|
|
|
- if(param.getPayType().equals(KxsShopEnum.ALI_PAY.getType())){
|
|
|
+ if (param.getPayType().equals(KxsShopEnum.ALI_PAY.getType())) {
|
|
|
return this.aliPay(order, subject);
|
|
|
}
|
|
|
|
|
|
//余额支付
|
|
|
- if(param.getPayType().equals(KxsShopEnum.YUE_PAY.getType())){
|
|
|
+ if (param.getPayType().equals(KxsShopEnum.YUE_PAY.getType())) {
|
|
|
|
|
|
//校验支付密码
|
|
|
R<Boolean> booleanR = remoteKxsUserService.checkPayPwd(param.getPayPwd());
|
|
|
- if(booleanR.getStatus() != 1 || !booleanR.getData()){
|
|
|
+ if (booleanR.getStatus() != 1 || !booleanR.getData()) {
|
|
|
throw new GlobalCustomerException("支付密码错误");
|
|
|
}
|
|
|
|
|
|
@@ -230,7 +240,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
if (payMessage != null) {
|
|
|
//支付成功回调
|
|
|
this.payBack(order.getOrderSn());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new GlobalCustomerException("余额支付异常");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -246,10 +256,10 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
@Override
|
|
|
public void payBack(String outTradeNo) {
|
|
|
KxsShopOrder order = baseMapper.selectOne(Wrappers.<KxsShopOrder>lambdaQuery().eq(KxsShopOrder::getOrderSn, outTradeNo).last("FOR UPDATE"));
|
|
|
- if(order == null){
|
|
|
+ if (order == null) {
|
|
|
throw new GlobalCustomerException("订单支付回调未找到订单号:" + outTradeNo);
|
|
|
}
|
|
|
- if(!Objects.equals(order.getStatus(), KxsShopEnum.ORDER_NO_PAY.getType())){
|
|
|
+ if (!Objects.equals(order.getStatus(), KxsShopEnum.ORDER_NO_PAY.getType())) {
|
|
|
throw new GlobalCustomerException("订单支付回调状态错误订单号:" + outTradeNo);
|
|
|
}
|
|
|
order.setStatus(KxsShopEnum.ORDER_NO_SEND.getType());
|
|
|
@@ -257,19 +267,44 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
List<KxsShopOrderInfo> kxsShopOrderInfos = orderInfoMapper.selectList(Wrappers.<KxsShopOrderInfo>lambdaQuery().eq(KxsShopOrderInfo::getOrderId, order.getId()));
|
|
|
//目前只能下单一个商品,故直接取之
|
|
|
KxsShopOrderInfo kxsShopOrderInfo = kxsShopOrderInfos.get(0);
|
|
|
- switch(kxsShopOrderInfo.getGoodsId()){
|
|
|
- case 10:
|
|
|
- if(!kxsTicketService.userBuyTicket(order.getUserId(), TicketTypeEnum.CODE_DQ.getType(), order.getId(), kxsShopOrderInfo.getNumber() * 3)){
|
|
|
- throw new GlobalCustomerException("兑换电签机具券失败订单号:" + outTradeNo);
|
|
|
- }
|
|
|
- case 11:
|
|
|
- if(!kxsTicketService.userBuyTicket(order.getUserId(), TicketTypeEnum.CODE_DJ.getType(), order.getId(), kxsShopOrderInfo.getNumber() * 2)){
|
|
|
- throw new GlobalCustomerException("兑换大机机具券失败订单号:" + outTradeNo);
|
|
|
- }
|
|
|
+ Integer dqGoodsId = ParamResolver.getInteger("DQ_GOODS_ID", 10);
|
|
|
+ Integer djGoodsId = ParamResolver.getInteger("DJ_GOODS_ID", 11);
|
|
|
+ Integer preLimitGoodsId100 = ParamResolver.getInteger("PRE_LIMIT_GOODS_ID_100", 58);
|
|
|
+ Integer preLimitGoodsId500 = ParamResolver.getInteger("PRE_LIMIT_GOODS_ID_500", 57);
|
|
|
+ Integer preLimitGoodsId1000 = ParamResolver.getInteger("PRE_LIMIT_GOODS_ID_1000", 56);
|
|
|
+ Integer storeForLimit2000 = ParamResolver.getInteger("STORE_FOR_LIMIT_2000", 30);
|
|
|
+ Integer storeForLimit10000 = ParamResolver.getInteger("STORE_FOR_LIMIT_10000", 31);
|
|
|
+ Integer storeForLimit20000 = ParamResolver.getInteger("STORE_FOR_LIMIT_20000", 32);
|
|
|
+ //电签
|
|
|
+ if (Objects.equals(kxsShopOrderInfo.getGoodsId(), dqGoodsId)) {
|
|
|
+ if (!kxsTicketService.userBuyTicket(order.getUserId(), TicketTypeEnum.CODE_DQ.getType(), order.getId(), kxsShopOrderInfo.getNumber() * 3)) {
|
|
|
+ throw new GlobalCustomerException("兑换电签机具券失败订单号:" + outTradeNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //大机
|
|
|
+ if (Objects.equals(kxsShopOrderInfo.getGoodsId(), djGoodsId)) {
|
|
|
+ if (!kxsTicketService.userBuyTicket(order.getUserId(), TicketTypeEnum.CODE_DJ.getType(), order.getId(), kxsShopOrderInfo.getNumber() * 2)) {
|
|
|
+ throw new GlobalCustomerException("兑换大机机具券失败订单号:" + outTradeNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //小分仓预发额度
|
|
|
+ if (Objects.equals(kxsShopOrderInfo.getGoodsId(), preLimitGoodsId100)
|
|
|
+ || Objects.equals(kxsShopOrderInfo.getGoodsId(), preLimitGoodsId500)
|
|
|
+ || Objects.equals(kxsShopOrderInfo.getGoodsId(), preLimitGoodsId1000)) {
|
|
|
+
|
|
|
+ addForLimit(order, 1);
|
|
|
}
|
|
|
+ //仓库临时额度
|
|
|
+ if (Objects.equals(kxsShopOrderInfo.getGoodsId(), storeForLimit2000)
|
|
|
+ || Objects.equals(kxsShopOrderInfo.getGoodsId(), storeForLimit10000)
|
|
|
+ || Objects.equals(kxsShopOrderInfo.getGoodsId(), storeForLimit20000)) {
|
|
|
+
|
|
|
+ addForLimit(order, 0);
|
|
|
+ }
|
|
|
+
|
|
|
KxsShopGoods goods = kxsShopGoodsMapper.selectById(kxsShopOrderInfo.getGoodsId());
|
|
|
//虚拟商品改为已完成
|
|
|
- if(Objects.equals(goods.getGoodsType(), KxsShopEnum.GOODS_VIRTUAL.getType())){
|
|
|
+ if (Objects.equals(goods.getGoodsType(), KxsShopEnum.GOODS_VIRTUAL.getType())) {
|
|
|
order.setStatus(KxsShopEnum.ORDER_CONFIRM.getType());
|
|
|
}
|
|
|
|
|
|
@@ -277,16 +312,43 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加临时额度
|
|
|
+ *
|
|
|
+ * @param order 订单
|
|
|
+ * @param warehouseType 仓库类型 0分仓 1小分仓
|
|
|
+ */
|
|
|
+ private void addForLimit(KxsShopOrder order, int warehouseType) {
|
|
|
+
|
|
|
+ BigDecimal totalPrice = order.getTotalPrice();
|
|
|
+ if(warehouseType == 0){
|
|
|
+ totalPrice = totalPrice.multiply(new BigDecimal(2));
|
|
|
+ }
|
|
|
+
|
|
|
+ KxsWarehouseLimit kxsWarehouseLimit = new KxsWarehouseLimit();
|
|
|
+ kxsWarehouseLimit.setUserId(order.getUserId().intValue());
|
|
|
+ kxsWarehouseLimit.setWarehouseType(warehouseType);
|
|
|
+ if (Objects.equals(order.getPayType(), KxsShopEnum.YUE_PAY.getType())) {
|
|
|
+ kxsWarehouseLimit.setYueForAmount(totalPrice);
|
|
|
+ }
|
|
|
+ if (Objects.equals(order.getPayType(), KxsShopEnum.ALI_PAY.getType())) {
|
|
|
+ kxsWarehouseLimit.setForAmount(totalPrice);
|
|
|
+ }
|
|
|
+ R<Boolean> booleanR = remoteKxsStoreService.addForAmount(kxsWarehouseLimit, SecurityConstants.FROM_IN);
|
|
|
+ if (!booleanR.getData()) {
|
|
|
+ throw new GlobalCustomerException("新增临时额度失败订单号:" + order.getOrderSn());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public R cancelOrder(KxsShopOrder param) {
|
|
|
|
|
|
KxsShopOrder order = baseMapper.selectById(param.getId());
|
|
|
- if(order == null){
|
|
|
+ if (order == null) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
|
}
|
|
|
- if(!order.getStatus().equals(KxsShopEnum.ORDER_NO_PAY.getType())){
|
|
|
+ if (!order.getStatus().equals(KxsShopEnum.ORDER_NO_PAY.getType())) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_NO_CANCEL.getDescription());
|
|
|
}
|
|
|
order.setStatus(KxsShopEnum.ORDER_CANCEL.getType());
|
|
|
@@ -299,10 +361,10 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
public R confirmOrder(KxsShopOrder param) {
|
|
|
|
|
|
KxsShopOrder order = baseMapper.selectById(param.getId());
|
|
|
- if(order == null){
|
|
|
+ if (order == null) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
|
}
|
|
|
- if(!order.getStatus().equals(KxsShopEnum.ORDER_NO_TAKE.getType())){
|
|
|
+ if (!order.getStatus().equals(KxsShopEnum.ORDER_NO_TAKE.getType())) {
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_NO_CONFIRM.getDescription());
|
|
|
}
|
|
|
order.setStatus(KxsShopEnum.ORDER_CONFIRM.getType());
|
|
|
@@ -351,7 +413,6 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 支付宝支付
|
|
|
*
|
|
|
@@ -359,7 +420,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
* @param subject 订单标题。
|
|
|
* @return {@link R}
|
|
|
*/
|
|
|
- private R aliPay(KxsShopOrder param, String subject){
|
|
|
+ private R aliPay(KxsShopOrder param, String subject) {
|
|
|
|
|
|
try {
|
|
|
PayRequest payReq = new PayRequest();
|