feat : order
This commit is contained in:
@@ -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