feat : catering

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

View File

@@ -45,4 +45,19 @@ class CateringController
{ {
return (new OptionCycleListService)->remainCount(); return (new OptionCycleListService)->remainCount();
} }
public function getMealGoodsList()
{
return (new MealCycleListService)->skuList();
}
public function mealCatering()
{
}
public function optionCatering()
{
}
} }

View File

@@ -9,7 +9,8 @@ use Hyperf\DbConnection\Model\Model;
/** /**
* @property int $id * @property int $id
* @property int $cycle_id * @property int $cycle_id
* @property int $kitchen_id
* @property int $site_id * @property int $site_id
* @property int $quantity * @property int $quantity
* @property int $add_staple_food_num * @property int $add_staple_food_num
@@ -32,15 +33,16 @@ class OrderOptionCateringLog extends Model
/** /**
* The attributes that should be cast to native types. * The attributes that should be cast to native types.
*/ */
protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'site_id' => 'integer', 'quantity' => 'integer', 'add_staple_food_num' => 'integer', 'status' => 'integer']; protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'kitchen_id' => 'integer', 'site_id' => 'integer', 'quantity' => 'integer', 'add_staple_food_num' => 'integer', 'status' => 'integer'];
/** /**
* @param int $siteId * @param int $siteId
* @param int $cycleId * @param int $cycleId
* @param int $kitchenId
* @return Builder|\Hyperf\Database\Model\Model|null * @return Builder|\Hyperf\Database\Model\Model|null
*/ */
public function getInfoBySiteIdAndCycleId(int $siteId, int $cycleId): \Hyperf\Database\Model\Model|Builder|null public function getInfoBySiteIdAndCycleIdAndSiteId(int $siteId, int $cycleId, int $kitchenId): \Hyperf\Database\Model\Model|Builder|null
{ {
return $this->where('site_id', $siteId)->where('cycle_id', $cycleId)->first(); return $this->where('site_id', $siteId)->where('cycle_id', $cycleId)->where('kitchen_id',$kitchenId)->first();
} }
} }

View File

@@ -67,6 +67,8 @@ abstract class CateringBaseService extends BaseService
$this->checkRole(); $this->checkRole();
$this->getCycleId(); $this->getCycleId();
$this->getKitchenId();
} }
/** /**
@@ -96,6 +98,12 @@ abstract class CateringBaseService extends BaseService
$this->cycleId = (int)$cycleId; $this->cycleId = (int)$cycleId;
} }
private function getKitchenId(): void
{
//todo 自选配餐员工要绑定厨房 套餐配餐员工要绑定每日套餐
$this->kitchenId = 1;
}
/** /**
* @param array $data * @param array $data
* @return array * @return array

View File

@@ -69,4 +69,21 @@ class CycleListService extends CateringBaseService
return $this->return->success('success',['count' => $count]); return $this->return->success('success',['count' => $count]);
} }
public function skuList()
{
$res = [
[
'id' => 1,
'name' => 'spu_name'
],
[
'id' => 2,
'name' => 'spu2_name'
]
];
return $this->return->success('success',$res);
}
} }

View File

@@ -34,6 +34,7 @@ class CycleListService extends CateringBaseService
{ {
$cycleCateringLogs = $this->orderOptionCateringLogModel $cycleCateringLogs = $this->orderOptionCateringLogModel
->where('cycle_id',$this->cycleId) ->where('cycle_id',$this->cycleId)
->where('kitchen_id',$this->kitchenId)
->select(['site_id','quantity','status','id']) ->select(['site_id','quantity','status','id'])
->get(); ->get();
@@ -51,6 +52,7 @@ class CycleListService extends CateringBaseService
{ {
$count = $this->orderOptionCateringLogModel $count = $this->orderOptionCateringLogModel
->where('cycle_id',$this->cycleId) ->where('cycle_id',$this->cycleId)
->where('kitchen_id',$this->kitchenId)
->sum('quantity') ?? 0; ->sum('quantity') ?? 0;
return $this->return->success('success',['count' => $count]); return $this->return->success('success',['count' => $count]);

View File

@@ -25,7 +25,7 @@ trait CouponDispenseTrait
$this->cycleId = $cycleInfo->id; $this->cycleId = $cycleInfo->id;
$appointValue = json_encode($this->request->input('appoint_value')); $appointValue = $this->request->input('appoint_value');
// if ($this->groupType == CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_SITES_AND_GOODS) { // if ($this->groupType == CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_SITES_AND_GOODS) {
// $this->appointValue = [ // $this->appointValue = [
// 'site' => explode(',', $appointValue['site']), // 'site' => explode(',', $appointValue['site']),
@@ -152,7 +152,7 @@ trait CouponDispenseTrait
{ {
$this->checkAppointValue(); $this->checkAppointValue();
$appointValue = json_encode($this->request->input('appoint_value')); $appointValue = $this->request->input('appoint_value');
return explode(',', $appointValue['user_ids']); return explode(',', $appointValue['user_ids']);
} }

View File

@@ -2,6 +2,7 @@
namespace App\Service\ServiceTrait; namespace App\Service\ServiceTrait;
use App\Cache\Redis\Api\SiteCache;
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;
@@ -23,8 +24,16 @@ trait CateringTrait
#[Inject] #[Inject]
protected OrderMealCateringLog $orderMealCateringLogModel; protected OrderMealCateringLog $orderMealCateringLogModel;
/**
* @var SiteCache
*/
#[Inject]
protected SiteCache $siteCache;
/** /**
* @return bool 添加失败需要退款 * @return bool 添加失败需要退款
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function manageAddCateringLog(): bool private function manageAddCateringLog(): bool
{ {
@@ -46,8 +55,6 @@ trait CateringTrait
OrderCode::ORDER_TYPE_MEAL => $this->manageSubMealCateringLog(), OrderCode::ORDER_TYPE_MEAL => $this->manageSubMealCateringLog(),
OrderCode::ORDER_TYPE_OPTIONAL => $this->manageSubOptionCateringLog(), OrderCode::ORDER_TYPE_OPTIONAL => $this->manageSubOptionCateringLog(),
}; };
} }
/** /**
@@ -60,8 +67,10 @@ trait CateringTrait
// todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力 // todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力
// $addStapleFoodNum = 0; // $addStapleFoodNum = 0;
//todo 需要绑定一个 kitchen_id $siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id);
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id);
//需要绑定一个 kitchen_id
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleIdAndSiteId($this->orderInfo->site_id, $this->orderInfo->cycle_id, (int)$siteInfo['kitchen_id']);
if (empty($logInfo)) { if (empty($logInfo)) {
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:订单套餐配餐记录不存在,订单信息:'.json_encode($this->orderInfo->toArray())); $this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:订单套餐配餐记录不存在,订单信息:'.json_encode($this->orderInfo->toArray()));
@@ -114,20 +123,24 @@ trait CateringTrait
/** /**
* 添加自选配餐数据 * 添加自选配餐数据
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function manageAddOptionCateringLog(): bool private function manageAddOptionCateringLog(): bool
{ {
//todo 根据订单 cycle_id 获取加一碗米饭 的数量 //todo 根据订单 cycle_id 获取加一碗米饭 的数量
$addStapleFoodNum = 0; $addStapleFoodNum = 0;
//todo 需要绑定一个 kitchen_id $siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id);
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id); //需要绑定一个 kitchen_id
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleIdAndSiteId($this->orderInfo->site_id, $this->orderInfo->cycle_id,(int)$siteInfo['kitchen_id']);
if (empty($logInfo)) { if (empty($logInfo)) {
$logInfo = new OrderOptionCateringLog(); $logInfo = new OrderOptionCateringLog();
$logInfo->site_id = $this->orderInfo->site_id; $logInfo->site_id = $this->orderInfo->site_id;
$logInfo->cycle_id = $this->orderInfo->cycle_id; $logInfo->cycle_id = $this->orderInfo->cycle_id;
$logInfo->kitchen_id = (int)$siteInfo['kitchen_id'];
$logInfo->quantity = 0; $logInfo->quantity = 0;
$logInfo->add_staple_food_num = 0; $logInfo->add_staple_food_num = 0;
$logInfo->status = 1; $logInfo->status = 1;