feat : add_staple_food
This commit is contained in:
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\Api\Order;
|
namespace App\Service\Api\Order;
|
||||||
|
|
||||||
use App\Cache\Redis\Api\SiteCache;
|
use App\Cache\Redis\Api\SiteCache;
|
||||||
|
use App\Constants\Common\GoodCode;
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Exception\ErrException;
|
use App\Exception\ErrException;
|
||||||
use App\Model\AdminUser;
|
use App\Model\AdminUser;
|
||||||
use App\Model\Chef;
|
use App\Model\Chef;
|
||||||
@@ -121,13 +123,25 @@ class OrderInfoService extends BaseService
|
|||||||
$chefList = array_column($chefList, null,'id');
|
$chefList = array_column($chefList, null,'id');
|
||||||
|
|
||||||
$orderCopiesList = [];
|
$orderCopiesList = [];
|
||||||
for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) {
|
$addStapleFood = [];
|
||||||
|
if ($orderInfo['type'] == OrderCode::ORDER_TYPE_MEAL) {
|
||||||
|
$addStapleFood = [
|
||||||
|
'total_price' => '0.00',
|
||||||
|
'total_quantity' => 0,
|
||||||
|
'sku_list' => [],
|
||||||
|
'take_food_code' => '', //取餐码
|
||||||
|
'url' => '',
|
||||||
|
'is_add_staple_food' => GoodCode::IS_ADD_STAPLE_FOOD,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) {
|
||||||
$oneCopiesInfo = [
|
$oneCopiesInfo = [
|
||||||
'total_price' => '0.00',
|
'total_price' => '0.00',
|
||||||
'total_quantity' => 0,
|
'total_quantity' => 0,
|
||||||
'sku_list' => [],
|
'sku_list' => [],
|
||||||
'take_food_code' => '', //todo 取餐码
|
'take_food_code' => '', //todo 取餐码
|
||||||
|
'is_add_staple_food' => GoodCode::IS_NOT_ADD_STAPLE_FOOD,
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($newOrderSkuList[$i] as $item) {
|
foreach ($newOrderSkuList[$i] as $item) {
|
||||||
@@ -135,6 +149,15 @@ class OrderInfoService extends BaseService
|
|||||||
|
|
||||||
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
$imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
$imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
||||||
|
|
||||||
|
if ($skuInfo['is_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) {
|
||||||
|
$addStapleFood['total_price'] = bcadd((string)$oneCopiesInfo['total_price'], bcmul((string)$item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
|
$addStapleFood['total_quantity'] += $item['quantity'];
|
||||||
|
$addStapleFood['url'] = $imageList[$imageId]['url'] ?? '';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// $skuInfo['url'] = $imageList[$imageId]['url'] ?? '';
|
// $skuInfo['url'] = $imageList[$imageId]['url'] ?? '';
|
||||||
// $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
// $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
||||||
|
|
||||||
@@ -153,6 +176,7 @@ class OrderInfoService extends BaseService
|
|||||||
$orderCopiesList[] = $oneCopiesInfo;
|
$orderCopiesList[] = $oneCopiesInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($addStapleFood)) $orderCopiesList[] = $addStapleFood;
|
||||||
$orderInfo['copies_list'] = $orderCopiesList;
|
$orderInfo['copies_list'] = $orderCopiesList;
|
||||||
$orderInfo['site'] = $this->siteCache->getSiteInfo($orderInfo['site_id']);
|
$orderInfo['site'] = $this->siteCache->getSiteInfo($orderInfo['site_id']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\Api\Order;
|
namespace App\Service\Api\Order;
|
||||||
|
|
||||||
use App\Cache\Redis\Api\SiteCache;
|
use App\Cache\Redis\Api\SiteCache;
|
||||||
|
use App\Constants\Common\GoodCode;
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Model\Order;
|
use App\Model\Order;
|
||||||
use App\Model\OrderGood;
|
use App\Model\OrderGood;
|
||||||
use App\Model\Sku;
|
use App\Model\Sku;
|
||||||
@@ -124,6 +126,17 @@ class OrderListService extends BaseService
|
|||||||
|
|
||||||
foreach ($orderList as &$order) {
|
foreach ($orderList as &$order) {
|
||||||
$orderCopiesList = [];
|
$orderCopiesList = [];
|
||||||
|
$addStapleFood = [];
|
||||||
|
if ($order['type'] == OrderCode::ORDER_TYPE_MEAL) {
|
||||||
|
$addStapleFood = [
|
||||||
|
'total_price' => '0.00',
|
||||||
|
'total_quantity' => 0,
|
||||||
|
'sku_list' => [],
|
||||||
|
'take_food_code' => '', //取餐码
|
||||||
|
'is_add_staple_food' => GoodCode::IS_ADD_STAPLE_FOOD,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
for ($i = 1; $i <= ($order['copies'] ?? 0); $i++) {
|
for ($i = 1; $i <= ($order['copies'] ?? 0); $i++) {
|
||||||
|
|
||||||
$oneCopiesInfo = [
|
$oneCopiesInfo = [
|
||||||
@@ -140,6 +153,14 @@ class OrderListService extends BaseService
|
|||||||
|
|
||||||
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
$imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
$imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
||||||
|
|
||||||
|
if ($skuInfo['is_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) {
|
||||||
|
$addStapleFood['total_price'] = bcadd((string)$oneCopiesInfo['total_price'], bcmul((string)$item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
|
$addStapleFood['total_quantity'] += $item['quantity'];
|
||||||
|
$addStapleFood['url'] = $imageList[$imageId]['url'] ?? '';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2);
|
$oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
// $oneCopiesInfo['sku_list'][] = [];
|
// $oneCopiesInfo['sku_list'][] = [];
|
||||||
@@ -158,6 +179,7 @@ class OrderListService extends BaseService
|
|||||||
// $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
// $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if (!empty($addStapleFood)) $oneCopiesInfo[] = $addStapleFood;
|
||||||
$orderCopiesList[] = $oneCopiesInfo;
|
$orderCopiesList[] = $oneCopiesInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ trait OrderTrait
|
|||||||
'id' => $key,
|
'id' => $key,
|
||||||
'spu_id' => $this->skuArr[$key]['spu_id'],
|
'spu_id' => $this->skuArr[$key]['spu_id'],
|
||||||
'is_add_staple_food' => $this->skuArr[$key]['is_add_staple_food'],
|
'is_add_staple_food' => $this->skuArr[$key]['is_add_staple_food'],
|
||||||
|
'meal_copies' => $this->skuArr[$key]['is_add_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD ? 0 : 1,
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$oneCopiesGoodInfo[$key]['num'] += $oneGood;
|
$oneCopiesGoodInfo[$key]['num'] += $oneGood;
|
||||||
@@ -265,11 +266,16 @@ trait OrderTrait
|
|||||||
'price' => $oneCopiesTotalPrice,
|
'price' => $oneCopiesTotalPrice,
|
||||||
];
|
];
|
||||||
|
|
||||||
// if ($copiesType == 1) {
|
// 加一份米饭不算份数
|
||||||
// $this->orderRes['optional_copies']++;
|
switch ($this->orderType) {
|
||||||
// } else {
|
case OrderCode::ORDER_TYPE_OPTIONAL:
|
||||||
$this->orderRes['copies']++;
|
$this->orderRes['copies']++;
|
||||||
// }
|
break;
|
||||||
|
case OrderCode::ORDER_TYPE_MEAL:
|
||||||
|
$this->orderRes['copies'] = $this->orderRes['copies'] + array_sum(array_column($oneCopiesGoodInfo,'meal_copies'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// if ($this->skuArr[$key]['is_add_staple_food'] != GoodCode::IS_ADD_STAPLE_FOOD) $this->orderRes['copies']++;
|
||||||
|
|
||||||
$this->orderRes['total_good_price'] = bcadd($this->orderRes['total_good_price'],$oneCopiesTotalPrice,2);
|
$this->orderRes['total_good_price'] = bcadd($this->orderRes['total_good_price'],$oneCopiesTotalPrice,2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user