feat : catering
This commit is contained in:
@@ -84,6 +84,10 @@ class CateringController
|
|||||||
return (new MealCycleListService)->skuList();
|
return (new MealCycleListService)->skuList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配餐
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
#[RequestMapping(path: "meal/catering", methods: "GET")]
|
#[RequestMapping(path: "meal/catering", methods: "GET")]
|
||||||
#[Scene(scene: "meal_catering")]
|
#[Scene(scene: "meal_catering")]
|
||||||
public function mealCatering()
|
public function mealCatering()
|
||||||
@@ -91,6 +95,10 @@ class CateringController
|
|||||||
return (new MealCateringService)->handle();
|
return (new MealCateringService)->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完成检测
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
#[RequestMapping(path: "meal/catering/finish_check", methods: "GET")]
|
#[RequestMapping(path: "meal/catering/finish_check", methods: "GET")]
|
||||||
#[Scene(scene: "meal_catering_finish_check")]
|
#[Scene(scene: "meal_catering_finish_check")]
|
||||||
public function mealFinishCheck()
|
public function mealFinishCheck()
|
||||||
|
|||||||
@@ -10,12 +10,104 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service\Admin\Catering\Meal;
|
namespace App\Service\Admin\Catering\Meal;
|
||||||
|
|
||||||
|
use App\Constants\Admin\CateringCode;
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
|
use App\Model\OrderMealCateringLog;
|
||||||
|
use App\Model\Site;
|
||||||
use App\Service\Admin\Catering\CateringBaseService;
|
use App\Service\Admin\Catering\CateringBaseService;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
class CateringService extends CateringBaseService
|
class CateringService extends CateringBaseService
|
||||||
{
|
{
|
||||||
public function handle()
|
/**
|
||||||
{
|
* @var OrderMealCateringLog
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderMealCateringLog $orderMealCateringLogModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderMealCateringLog
|
||||||
|
*/
|
||||||
|
protected OrderMealCateringLog $logInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Site
|
||||||
|
*/
|
||||||
|
protected Site $siteInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected int $resCount = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
|
{
|
||||||
|
$id = (int)$this->request->input('id');
|
||||||
|
|
||||||
|
// 获取数据源
|
||||||
|
$this->logInfo = $this->orderMealCateringLogModel->find($id);
|
||||||
|
$this->siteInfo = $this->siteModel->find($this->logInfo->site_id);
|
||||||
|
$this->resCount = $this->logInfo->quantity;
|
||||||
|
|
||||||
|
// 检测数据
|
||||||
|
$this->check();
|
||||||
|
|
||||||
|
// 配餐
|
||||||
|
$this->catering();
|
||||||
|
|
||||||
|
return $this->return->success('success',['num' => $this->resCount]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function catering(): void
|
||||||
|
{
|
||||||
|
$this->logInfo->status = CateringCode::CATERING_STATUS_FINISH;
|
||||||
|
if (!$this->logInfo->save()) throw new ErrException('配餐失败1');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function check(): void
|
||||||
|
{
|
||||||
|
if (empty($this->logInfo)) throw new ErrException('配餐数据不存在');
|
||||||
|
|
||||||
|
if ($this->logInfo->quantity <= 0) throw new ErrException('该配餐数量为0,不可配餐');
|
||||||
|
|
||||||
|
$allOrderIds = $this->orderModel
|
||||||
|
->where('site_id', $this->logInfo->site_id)
|
||||||
|
->where('cycle_id', $this->cycleId)
|
||||||
|
->where('type',OrderCode::ORDER_TYPE_MEAL)
|
||||||
|
->where('status',OrderCode::PAYED)
|
||||||
|
->pluck('order_id')
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$totalCopies = $this->orderGoodModel
|
||||||
|
->whereIn('order_id', $allOrderIds)
|
||||||
|
->where('cycle_id', $this->cycleId)
|
||||||
|
->where('sku_id', $this->logInfo->sku_id)
|
||||||
|
->sum('copies') ?? 0;
|
||||||
|
|
||||||
|
if ($totalCopies != $this->logInfo->quantity) $this->resCount = $totalCopies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,16 +10,16 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service\Admin\Catering\Meal;
|
namespace App\Service\Admin\Catering\Meal;
|
||||||
|
|
||||||
|
use App\Constants\Admin\CateringCode;
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Model\Order;
|
||||||
use App\Model\OrderMealCateringLog;
|
use App\Model\OrderMealCateringLog;
|
||||||
use App\Service\Admin\Catering\CateringBaseService;
|
use App\Service\Admin\Catering\CateringBaseService;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
class CheckService extends CateringBaseService
|
class CheckService extends CateringBaseService
|
||||||
{
|
{
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//todo Write logic
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var OrderMealCateringLog
|
* @var OrderMealCateringLog
|
||||||
@@ -32,10 +32,51 @@ class CheckService extends CateringBaseService
|
|||||||
*/
|
*/
|
||||||
protected OrderMealCateringLog $logInfo;
|
protected OrderMealCateringLog $logInfo;
|
||||||
|
|
||||||
public function info()
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
{
|
{
|
||||||
$this->logInfo = $this->orderMealCateringLog->find($this->request->input('id'));
|
$this->logInfo = $this->orderMealCateringLog
|
||||||
|
->where('sku_id', $this->request->input('sku_id'))
|
||||||
|
->where('cycle_id',$this->cycleId)
|
||||||
|
->where('status',CateringCode::CATERING_STATUS_UNDERWAY)
|
||||||
|
->where('quantity','>',0)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!empty($this->logInfo)) $this->tips();
|
||||||
|
|
||||||
|
$orderIds = $this->orderModel
|
||||||
|
->where('cycle_id', $this->cycleId)
|
||||||
|
->where('type',OrderCode::ORDER_TYPE_MEAL)
|
||||||
|
->where('status',OrderCode::PAYED)
|
||||||
|
->pluck('order_id')
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
if (empty($orderIds)) throw new ErrException('数据错误');
|
||||||
|
|
||||||
|
$this->orderModel->whereIn('id', $orderIds)->update(['status' => OrderCode::PLAN]);
|
||||||
|
|
||||||
|
return $this->return->success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function tips(): void
|
||||||
|
{
|
||||||
|
$siteInfo = $this->siteModel->find($this->logInfo->site_id);
|
||||||
|
if (empty($siteInfo)) throw new ErrException('数据错误');
|
||||||
|
$driverInfo = $this->driverSequenceModel->find($siteInfo->delivered_id);
|
||||||
|
if (empty($driverInfo)) throw new ErrException('数据错误');
|
||||||
|
|
||||||
|
throw new ErrException($driverInfo->driver_num.'-'.$siteInfo->sequence.'还未配餐完成,请刷新页面并完成配餐再执行');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user