feat : order
This commit is contained in:
@@ -219,8 +219,8 @@ abstract class LoginBaseService extends BaseService
|
||||
*/
|
||||
protected function addCoupon(): void
|
||||
{
|
||||
$couponTemplateId = $this->configCache->getConfigValue(ConfigCode::COUPONS_FOR_NEWCOMERS);
|
||||
$couponValidity = $this->configCache->getConfigValue(ConfigCode::NEWBIE_COUPON_VALIDITY);
|
||||
$couponTemplateId = $this->configCache->getConfigValueByKey(ConfigCode::COUPONS_FOR_NEWCOMERS);
|
||||
$couponValidity = $this->configCache->getConfigValueByKey(ConfigCode::NEWBIE_COUPON_VALIDITY);
|
||||
|
||||
// 随便一个为0代表不赠送
|
||||
if ($couponValidity == 0 || $couponTemplateId == 0) return;
|
||||
|
||||
@@ -70,6 +70,11 @@ abstract class BaseOrderService extends BaseService
|
||||
*/
|
||||
protected array $skuArr;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $skuImageArr;
|
||||
|
||||
/**
|
||||
* 订单结果
|
||||
* @var array
|
||||
|
||||
@@ -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'];
|
||||
|
||||
@@ -77,7 +77,7 @@ class SiteService extends BaseService
|
||||
|
||||
if (in_array($id, $siteIds)) throw new ErrException('已添加该地点');
|
||||
|
||||
$poolNumber = $this->configCache->getConfigValue(ConfigCode::NUMBER_OF_USER_ADDRESS_POOLS);
|
||||
$poolNumber = $this->configCache->getConfigValueByKey(ConfigCode::NUMBER_OF_USER_ADDRESS_POOLS);
|
||||
if (count($siteIds) >= $poolNumber) throw new ErrException('已达到地址最大添加数量,请删除后再添加');
|
||||
|
||||
$insertModel = new UserSite();
|
||||
|
||||
@@ -167,15 +167,32 @@ trait OrderTrait
|
||||
$optionalGood = json_decode($optionalGood, true);
|
||||
|
||||
$skuArr = [];
|
||||
$skuImageArr = [];
|
||||
|
||||
foreach ($mealGood as $one){
|
||||
$skuArr = array_merge($skuArr,$one['sku_list']);
|
||||
$newSkuList = array_map(function($sku) use($one) {
|
||||
$sku['spu_title'] = $one['title'];
|
||||
$sku['type'] = GoodCode::SPU_TYPE_MEAL;
|
||||
return $sku;
|
||||
}, $one['sku_list']);
|
||||
|
||||
$skuImageArr = array_merge($skuImageArr,$one['image_list']);
|
||||
$skuArr = array_merge($skuArr,$newSkuList);
|
||||
}
|
||||
|
||||
foreach ($optionalGood as $one){
|
||||
$skuArr = array_merge($skuArr,$one['sku_list']);
|
||||
$newSkuList = array_map(function($sku) use($one) {
|
||||
$sku['spu_title'] = strtolower($one['title']);
|
||||
$sku['type'] = GoodCode::SPU_TYPE_OPTIONAL;
|
||||
return $sku;
|
||||
}, $one['sku_list']);
|
||||
|
||||
$skuImageArr = array_merge($skuImageArr,$one['image_list']);
|
||||
$skuArr = array_merge($skuArr,$newSkuList);
|
||||
}
|
||||
|
||||
$this->skuArr = array_column($skuArr,null,'id');
|
||||
$this->skuImageArr = array_column($skuArr,null,'id');
|
||||
$this->goodIds = array_column($skuArr,'id');
|
||||
unset($skuArr);
|
||||
}
|
||||
@@ -202,29 +219,31 @@ trait OrderTrait
|
||||
$copiesType = 1;
|
||||
|
||||
$oneCopiesGoodInfo = [];
|
||||
foreach ($oneCopies as $oneGood) {
|
||||
if (empty($oneCopiesGoodInfo[$oneGood])) {
|
||||
$oneCopiesGoodInfo[$oneGood] = [
|
||||
'num' => 1,
|
||||
'good_name' => '1',
|
||||
'good_url' => '1',
|
||||
'unit_price' => $this->skuArr[$oneGood]['price'],
|
||||
'type' => $this->skuArr[$oneGood]['type'],
|
||||
|
||||
foreach ($oneCopies as $key => $oneGood) {
|
||||
if (empty($oneCopiesGoodInfo[$key])) {
|
||||
$oneCopiesGoodInfo[$key] = [
|
||||
'num' => $oneGood,
|
||||
'good_name' => $this->skuArr[$key]['spu_title'] ?? '' . $this->skuArr[$key]['title'] ?? '',
|
||||
'good_url' => $this->skuImageArr[$this->skuArr[$key]['image_ids']]['url'] ?? '',
|
||||
'unit_price' => $this->skuArr[$key]['price'],
|
||||
'type' => $this->skuArr[$key]['type'],
|
||||
'id' => $key,
|
||||
'spu_id' => $this->skuArr[$key]['spu_id'],
|
||||
];
|
||||
} else {
|
||||
$oneCopiesGoodInfo[$oneGood]['num'] += 1;
|
||||
$oneCopiesGoodInfo[$key]['num'] += $oneGood;
|
||||
}
|
||||
|
||||
$oneCopiesTotalPrice = bcadd($oneCopiesTotalPrice, $this->skuArr[$oneGood]['price'],2);
|
||||
$oneCopiesTotalPrice = bcadd($oneCopiesTotalPrice, bcmul($this->skuArr[$key]['price'],(string)$oneGood,2),2);
|
||||
|
||||
if ($copiesType == 1 && $this->skuArr[$oneGood]['type'] == GoodCode::SPU_TYPE_MEAL) {
|
||||
if ($copiesType == 1 && $this->skuArr[$key]['type'] == GoodCode::SPU_TYPE_MEAL) {
|
||||
$copiesType = 2;
|
||||
}
|
||||
}
|
||||
|
||||
$this->orderRes['good'][] = [
|
||||
'good_ids' => $oneCopies,
|
||||
'good_info' => $oneCopiesGoodInfo,
|
||||
'good_info' => array_values($oneCopiesGoodInfo),
|
||||
'price' => $oneCopiesTotalPrice,
|
||||
];
|
||||
|
||||
@@ -246,15 +265,15 @@ trait OrderTrait
|
||||
*/
|
||||
protected function computeSundryPrice(): void
|
||||
{
|
||||
$this->orderRes['sundry_num'] = match ($this->configCache->getConfigValue(ConfigCode::SUNDRY_PRICE_COMPUTE_TYPE))
|
||||
$this->orderRes['sundry_num'] = match ($this->configCache->getConfigValueByKey(ConfigCode::SUNDRY_PRICE_COMPUTE_TYPE))
|
||||
{
|
||||
1 => $this->orderRes['optional_copies'],
|
||||
2 => $this->orderRes['meal_copies'],
|
||||
3 => $this->copies,
|
||||
};
|
||||
|
||||
$this->orderRes['sundry_price'] = $this->configCache->getConfigValue(ConfigCode::SUNDRY_UNIT_PRICE);
|
||||
$this->orderRes['total_sundry_price'] = bcmul($this->orderRes['sundry_price'],$this->orderRes['sundry_num'],2);
|
||||
$this->orderRes['sundry_price'] = $this->configCache->getConfigValueByKey(ConfigCode::SUNDRY_UNIT_PRICE);
|
||||
$this->orderRes['total_sundry_price'] = bcmul($this->orderRes['sundry_price'],(string)$this->orderRes['sundry_num'],2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user