feat : spu
This commit is contained in:
13
app/Constants/Common/CategoryCode.php
Normal file
13
app/Constants/Common/CategoryCode.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Constants\Common;
|
||||||
|
|
||||||
|
class CategoryCode
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 商品分类 1=菜品 2=主食 3=加饭
|
||||||
|
*/
|
||||||
|
CONST DISH = 1;
|
||||||
|
CONST STAPLE = 2;
|
||||||
|
CONST EXTRA_STAPLE = 3;
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Model;
|
namespace App\Model;
|
||||||
|
|
||||||
|
use App\Constants\Common\CategoryCode;
|
||||||
use App\Constants\Common\GoodCode;
|
use App\Constants\Common\GoodCode;
|
||||||
use Hyperf\Database\Model\Builder;
|
use Hyperf\Database\Model\Builder;
|
||||||
use Hyperf\Database\Model\Collection;
|
use Hyperf\Database\Model\Collection;
|
||||||
@@ -102,4 +103,17 @@ class Spu extends Model
|
|||||||
|
|
||||||
return $res->toArray();
|
return $res->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $cycle_id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCycleIdAddStapleFoodSkuIds(int $cycle_id): array
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->leftJoin('sku','sku.spu_id','=','spu.id')
|
||||||
|
->where('spu.cycle_id',$cycle_id)
|
||||||
|
->where('spu.category_id',CategoryCode::EXTRA_STAPLE)->pluck('sku.id')
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,19 @@ class OptionalListService extends BaseService
|
|||||||
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
|
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
|
||||||
$data = $this->goodCache->getOptionalGoodList();
|
$data = $this->goodCache->getOptionalGoodList();
|
||||||
|
|
||||||
|
$this->buildData(&$data);
|
||||||
|
|
||||||
return $this->return->success('success', ['list' => $data]);
|
return $this->return->success('success', ['list' => $data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function buildData(&$data): void
|
||||||
|
{
|
||||||
|
foreach ($data as &$spu) {
|
||||||
|
$spu['price'] = min(array_column($spu['sku_list'], 'price'));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,8 @@ use App\Constants\Admin\CateringCode;
|
|||||||
use App\Constants\Common\OrderCode;
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Model\OrderMealCateringLog;
|
use App\Model\OrderMealCateringLog;
|
||||||
use App\Model\OrderOptionCateringLog;
|
use App\Model\OrderOptionCateringLog;
|
||||||
|
use App\Model\Sku;
|
||||||
|
use App\Model\Spu;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
@@ -65,8 +67,15 @@ trait CateringTrait
|
|||||||
*/
|
*/
|
||||||
private function manageSubOptionCateringLog(): void
|
private function manageSubOptionCateringLog(): void
|
||||||
{
|
{
|
||||||
// todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力
|
$extraStapleArr = $this->spuModel->getCycleIdAddStapleFoodSkuIds($this->orderInfo->cycle_id);
|
||||||
// $addStapleFoodNum = 0;
|
$orderGoods = $this->orderGoodModel->where('order_id',$this->orderInfo->id)->pluck('copies','sku_id')->toArray();
|
||||||
|
|
||||||
|
$addStapleFoodNum = 0;
|
||||||
|
foreach ($orderGoods as $key => $copies) {
|
||||||
|
if (!in_array($key, $extraStapleArr)) continue;
|
||||||
|
|
||||||
|
$addStapleFoodNum = $copies + $addStapleFoodNum;
|
||||||
|
}
|
||||||
|
|
||||||
$siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id);
|
$siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id);
|
||||||
|
|
||||||
@@ -83,8 +92,8 @@ trait CateringTrait
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$logInfo->quantity = $logInfo->quantity + $this->orderInfo->copies;
|
$logInfo->quantity = $logInfo->quantity - $this->orderInfo->copies;
|
||||||
// $logInfo->add_staple_food_num = $this->orderInfo->add_staple_food_num - $addStapleFoodNum;
|
$logInfo->add_staple_food_num = $this->orderInfo->add_staple_food_num - $addStapleFoodNum;
|
||||||
|
|
||||||
if (!$logInfo->save()) {
|
if (!$logInfo->save()) {
|
||||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:修改配餐记录失败,订单信息:'.json_encode($this->orderInfo->toArray()));
|
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:修改配餐记录失败,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||||
@@ -121,6 +130,12 @@ trait CateringTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Spu
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Spu $spuModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加自选配餐数据
|
* 添加自选配餐数据
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -129,8 +144,16 @@ trait CateringTrait
|
|||||||
*/
|
*/
|
||||||
private function manageAddOptionCateringLog(): bool
|
private function manageAddOptionCateringLog(): bool
|
||||||
{
|
{
|
||||||
//todo 根据订单 cycle_id 获取加一碗米饭 的数量
|
//根据订单 cycle_id 获取加一碗米饭 的数量
|
||||||
|
$extraStapleArr = $this->spuModel->getCycleIdAddStapleFoodSkuIds($this->orderInfo->cycle_id);
|
||||||
|
$orderGoods = $this->orderGoodModel->where('order_id',$this->orderInfo->id)->pluck('copies','sku_id')->toArray();
|
||||||
|
|
||||||
$addStapleFoodNum = 0;
|
$addStapleFoodNum = 0;
|
||||||
|
foreach ($orderGoods as $key => $copies) {
|
||||||
|
if (!in_array($key, $extraStapleArr)) continue;
|
||||||
|
|
||||||
|
$addStapleFoodNum = $copies + $addStapleFoodNum;
|
||||||
|
}
|
||||||
|
|
||||||
$siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id);
|
$siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id);
|
||||||
//需要绑定一个 kitchen_id
|
//需要绑定一个 kitchen_id
|
||||||
|
|||||||
Reference in New Issue
Block a user