95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Admin\Catering\Meal;
|
|
|
|
use App\Exception\ErrException;
|
|
use App\Model\OrderMealCateringLog;
|
|
use App\Model\Sku;
|
|
use App\Model\Spu;
|
|
use App\Service\Admin\Catering\CateringBaseService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class CycleListService extends CateringBaseService
|
|
{
|
|
/**
|
|
* @var OrderMealCateringLog $orderMealCateringLogModel
|
|
*/
|
|
#[Inject]
|
|
protected OrderMealCateringLog $orderMealCateringLogModel;
|
|
|
|
/**
|
|
* @var Sku
|
|
*/
|
|
#[Inject]
|
|
protected Sku $skuModel;
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$skuInfo = $this->skuModel->getInfoById((int)$this->request->input('sku_id'));
|
|
if (empty($skuInfo)) throw new ErrException('该套餐不存在,请刷新后重试');
|
|
|
|
$cycleCateringLogs = $this->orderMealCateringLogModel
|
|
->where('cycle_id',$this->cycleId)
|
|
->where('sku_id',$skuInfo->id)
|
|
->select(['site_id','quantity','status','id'])
|
|
->get();
|
|
|
|
$res = $this->buildResArr($cycleCateringLogs);
|
|
|
|
if (empty($res)) return $this->return->success('success',['list' => []]);
|
|
|
|
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]);
|
|
}
|
|
|
|
/**
|
|
* @var Spu
|
|
*/
|
|
#[Inject]
|
|
protected Spu $spuModel;
|
|
|
|
public function skuList()
|
|
{
|
|
$spuList = $this->spuModel->where('caterer_id',$this->adminId)->select(['title','sub_title','id'])->get();
|
|
if (empty($spuList)) return $this->return->success('success',['list' => []]);
|
|
$spuList = $spuList->toArray();
|
|
|
|
$skuList = $this->skuModel->where('spu_id',array_column($spuList,'id'))->pluck('id','spu_id');
|
|
|
|
foreach ($spuList as &$v) {
|
|
$v['sku_id'] = $skuList[$v['id']] ?? 0;
|
|
}
|
|
|
|
return $this->return->success('success',['list' => $spuList]);
|
|
}
|
|
|
|
} |