|
|
@@ -21,6 +21,7 @@ import com.iformall.service.pay.service.pay.entity.PayAdapterResult; |
|
|
|
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; |
|
|
|
import com.iformall.service.pay.service.share.PayShareAdapterService; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import com.iformall.utils.RedisLock; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@@ -60,6 +61,9 @@ public class ProductOrderServiceImpl implements ProductOrderService { |
|
|
|
@Autowired |
|
|
|
PayServiceFactory payServiceFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
RedisLock redisLock; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<ProductOrder> listAsPage(ProductOrder record, Integer pageIndex, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> productOrderMapper.findList(record)); |
|
|
@@ -155,7 +159,7 @@ public class ProductOrderServiceImpl implements ProductOrderService { |
|
|
|
productOrder.setPaymentTime(result.getPayTime()); |
|
|
|
productOrder.setPayWay(result.getWay()); |
|
|
|
productOrder.setOrderStatus(productOrderStatus); |
|
|
|
productOrder.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); |
|
|
|
// productOrder.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); |
|
|
|
productOrder.setUpdateDate(new Date()); |
|
|
|
int num = productOrderMapper.orderPayUpdStatus(productOrder); |
|
|
|
|
|
|
@@ -174,25 +178,40 @@ public class ProductOrderServiceImpl implements ProductOrderService { |
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public void handleProductOrderSuccess(ProductOrder productOrder, PayQueryAdapterResult result) { |
|
|
|
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ |
|
|
|
return; |
|
|
|
} |
|
|
|
String lockKey = "productOrder:success:"+productOrder.getId(); |
|
|
|
long time = System.currentTimeMillis() + 30000; |
|
|
|
String timeStr = String.valueOf(time); |
|
|
|
try{ |
|
|
|
while (!redisLock.lock2(lockKey, timeStr)){ |
|
|
|
Thread.sleep(1000); |
|
|
|
} |
|
|
|
ProductOrder order = this.getById(productOrder.getId()); |
|
|
|
|
|
|
|
productOrder.setOpenId(result.getOpenId()); |
|
|
|
productOrder.setTransactionId(result.getTransactionId()); |
|
|
|
productOrder.setPaymentTime(result.getPayTime()); |
|
|
|
productOrder.setPayWay(result.getWay()); |
|
|
|
productOrder.setOrderStatus(result.getCode()); |
|
|
|
productOrder.setUpdateDate(new Date()); |
|
|
|
int num = productOrderMapper.orderPayUpdStatus(productOrder); |
|
|
|
if(num == 0){ |
|
|
|
return; |
|
|
|
}else if(num > 1){ |
|
|
|
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(order.getOrderStatus())){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
order.setOpenId(result.getOpenId()); |
|
|
|
order.setTransactionId(result.getTransactionId()); |
|
|
|
order.setPaymentTime(result.getPayTime()); |
|
|
|
order.setPayWay(result.getWay()); |
|
|
|
order.setOrderStatus(result.getCode()); |
|
|
|
order.setUpdateDate(new Date()); |
|
|
|
order.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); |
|
|
|
int num = productOrderMapper.orderPayUpdStatus(order); |
|
|
|
if(num == 0){ |
|
|
|
return; |
|
|
|
}else if(num > 1){ |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); |
|
|
|
} |
|
|
|
Product product = productMapper.selectById(order.getProductId()); |
|
|
|
if(EnumProductType.product_1.getCode().equals(product.getType())){ |
|
|
|
userBasicPropertyService.addRechargeGlod(order.getUserId(),product.getProjectType(),order.getId(),product.getGlod()); |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); |
|
|
|
} |
|
|
|
Product product = productMapper.selectById(productOrder.getProductId()); |
|
|
|
if(EnumProductType.product_1.getCode().equals(product.getType())){ |
|
|
|
userBasicPropertyService.addRechargeGlod(productOrder.getUserId(),product.getProjectType(),productOrder.getId(),product.getGlod()); |
|
|
|
}finally { |
|
|
|
redisLock.unlock(lockKey, timeStr); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|