feat : order

This commit is contained in:
2025-03-04 15:41:51 +08:00
parent 319f0c03d4
commit 11b4496fa7
7 changed files with 69 additions and 29 deletions

View File

@@ -70,6 +70,11 @@ abstract class BaseOrderService extends BaseService
*/
protected array $skuArr;
/**
* @var array
*/
protected array $skuImageArr;
/**
* 订单结果
* @var array

View File

@@ -67,7 +67,7 @@ class PlaceOrderService extends BaseOrderService
$this->joinCancelDelayQueue(
$this->orderId,
OrderCode::ORDER_TYPE_GOOD,
(int)$this->configCache->getConfigValue(ConfigCode::ORDER_CANCEL_TIME_KEY) * DateUtil::MINUTE * DateUtil::MS
(int)$this->configCache->getConfigValueByKey(ConfigCode::ORDER_CANCEL_TIME_KEY) * DateUtil::MINUTE * DateUtil::MS
);
$this->sendStockMq($this->orderId,OrderCode::WAIT_PAY);
@@ -84,10 +84,11 @@ class PlaceOrderService extends BaseOrderService
private function reduceStock(): void
{
$this->rollbackStockCache = [];
// var_dump($this->cartFirstData);
foreach ($this->cartFirstData as $goodId => $stock) {
$this->rollbackStockCache[$goodId] = $stock;
if (!($this->redis->zAdd($this->stockKey,'-'.$stock,$goodId))) {
if (!($this->redis->zIncrBy($this->stockKey,-$stock,$goodId))) {
echo '123';
throw new Exception('cache error');
}
}
@@ -103,7 +104,7 @@ class PlaceOrderService extends BaseOrderService
if (empty($this->rollbackStockCache)) return;
foreach ($this->rollbackStockCache as $goodId => $stock) {
$this->redis->zAdd($this->stockKey,$stock,$goodId);
$this->redis->zIncrBy($this->stockKey,$stock,$goodId);
}
}
@@ -126,6 +127,7 @@ class PlaceOrderService extends BaseOrderService
Db::commit();
} catch (Exception $e){
echo $e->getMessage();
//回滚数据库 和 缓存
Db::rollBack();
$this->rollbackStock();
@@ -181,7 +183,7 @@ class PlaceOrderService extends BaseOrderService
$orderInsertModel->user_id = $this->userId;
$orderInsertModel->cycle_id = $this->cycleId;
$orderInsertModel->site_id = $this->siteId;
$orderInsertModel->city_id = $this->orderRes['site']['city_id'];
$orderInsertModel->city_id = $this->orderRes['site_info']['city_id'];
$orderInsertModel->coupon_id = $this->couponId;
$orderInsertModel->meal_copies = $this->orderRes['meal_copies'];
$orderInsertModel->optional_copies = $this->orderRes['optional_copies'];