feat : catering

This commit is contained in:
2025-03-10 18:00:55 +08:00
parent 11b0782568
commit e3ecd93b2d
7 changed files with 62 additions and 16 deletions

View File

@@ -36,13 +36,13 @@ class CateringController
#[Scene(scene: "meal_remain_count")] #[Scene(scene: "meal_remain_count")]
public function remainMealCateringCount() public function remainMealCateringCount()
{ {
return (new MealCycleListService)->remainCount();
} }
#[RequestMapping(path: "option/remain_count", methods: "GET")] #[RequestMapping(path: "option/remain_count", methods: "GET")]
#[Scene(scene: "option_remain_count")] #[Scene(scene: "option_remain_count")]
public function remainOptionCateringCount() public function remainOptionCateringCount()
{ {
return (new OptionCycleListService)->remainCount();
} }
} }

View File

@@ -34,7 +34,7 @@ abstract class CateringBaseService extends BaseService
protected int $cycleId; protected int $cycleId;
/** /**
* @var int * @var int todo 厨房id 自选的需要
*/ */
protected int $kitchenId; protected int $kitchenId;

View File

@@ -0,0 +1,19 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Admin\Catering;
class CycleOrderCountService extends
{
public function handle()
{
//todo Write logic
}
}

View File

@@ -11,9 +11,7 @@ declare(strict_types=1);
namespace App\Service\Admin\Catering\Meal; namespace App\Service\Admin\Catering\Meal;
use App\Exception\ErrException; use App\Exception\ErrException;
use App\Model\DriverSequence;
use App\Model\OrderMealCateringLog; use App\Model\OrderMealCateringLog;
use App\Model\Site;
use App\Model\Sku; use App\Model\Sku;
use App\Service\Admin\Catering\CateringBaseService; use App\Service\Admin\Catering\CateringBaseService;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@@ -56,4 +54,19 @@ class CycleListService extends CateringBaseService
return $this->return->success('success',['list' => array_values($res)]); return $this->return->success('success',['list' => array_values($res)]);
} }
/**
* @return array
*/
public function remainCount(): array
{
$skuInfo = $this->skuModel->getInfoById((int)$this->request->input('sku_id'));
if (empty($skuInfo)) throw new ErrException('该套餐不存在,请刷新后重试');
$count = $this->orderMealCateringLogModel
->where('cycle_id',$this->cycleId)
->where('sku_id',$skuInfo->id)
->sum('quantity') ?? 0;
return $this->return->success('success',['count' => $count]);
}
} }

View File

@@ -43,4 +43,16 @@ class CycleListService extends CateringBaseService
return $this->return->success('success',['list' => array_values($res)]); return $this->return->success('success',['list' => array_values($res)]);
} }
/**
* @return array
*/
public function remainCount(): array
{
$count = $this->orderOptionCateringLogModel
->where('cycle_id',$this->cycleId)
->sum('quantity') ?? 0;
return $this->return->success('success',['count' => $count]);
}
} }

View File

@@ -44,17 +44,6 @@ trait GoodOrderTrait
#[Inject] #[Inject]
protected OrderGood $orderGoodModel; protected OrderGood $orderGoodModel;
/**
* @var OrderOptionCateringLog
*/
#[Inject]
protected OrderOptionCateringLog $orderOptionCateringLogModel;
/**
* @var OrderMealCateringLog
*/
#[Inject]
protected OrderMealCateringLog $orderMealCateringLogModel;
/** /**
* @return void * @return void

View File

@@ -5,12 +5,23 @@ namespace App\Service\ServiceTrait;
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 Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
trait CateringTrait trait CateringTrait
{ {
/**
* @var OrderOptionCateringLog
*/
#[Inject]
protected OrderOptionCateringLog $orderOptionCateringLogModel;
/**
* @var OrderMealCateringLog
*/
#[Inject]
protected OrderMealCateringLog $orderMealCateringLogModel;
/** /**
* @return bool 添加失败需要退款 * @return bool 添加失败需要退款
@@ -49,6 +60,7 @@ trait CateringTrait
// todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力 // todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力
// $addStapleFoodNum = 0; // $addStapleFoodNum = 0;
//todo 需要绑定一个 kitchen_id
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id); $logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id);
if (empty($logInfo)) { if (empty($logInfo)) {
@@ -108,6 +120,7 @@ trait CateringTrait
//todo 根据订单 cycle_id 获取加一碗米饭 的数量 //todo 根据订单 cycle_id 获取加一碗米饭 的数量
$addStapleFoodNum = 0; $addStapleFoodNum = 0;
//todo 需要绑定一个 kitchen_id
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id); $logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id);
if (empty($logInfo)) { if (empty($logInfo)) {