feat : basic
This commit is contained in:
@@ -10,15 +10,76 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\System;
|
||||
|
||||
use App\Constants\Admin\AuthCode;
|
||||
use App\Constants\Admin\UserCode;
|
||||
use App\Constants\Common\CityCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Constants\Common\SiteCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminSection;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Kitchen;
|
||||
use App\Model\Site;
|
||||
use App\Model\SystemCity;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class SiteService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly Site $siteModel;
|
||||
|
||||
/**
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @var SystemCity
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly SystemCity $systemCityModel;
|
||||
|
||||
/**
|
||||
* @var Kitchen
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly Kitchen $kitchenModel;
|
||||
|
||||
/**
|
||||
* 注入部门类
|
||||
* @var AdminSection
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly AdminSection $adminSectionModel;
|
||||
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $cityId = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $driverId = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $kitchenId = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $imageId = 0;
|
||||
|
||||
protected mixed $kitchenInfo;
|
||||
protected mixed $driverInfo;
|
||||
protected mixed $cityInfo;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
return $this->return->success();
|
||||
@@ -26,9 +87,57 @@ class SiteService extends BaseService
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->checkData();
|
||||
|
||||
Db::transaction(function () {
|
||||
$model = new Site();
|
||||
|
||||
$model->name = $this->request->input('name');
|
||||
$model->city_id = $this->cityId;
|
||||
$model->delivered_id = $this->driverId;
|
||||
$model->kitchen_id = $this->kitchenId;
|
||||
$model->address = $this->request->input('address');
|
||||
$model->lng = $this->request->input('lng');
|
||||
$model->lat = $this->request->input('lat');
|
||||
$model->remark = $this->request->input('remark');
|
||||
$model->status = $this->request->input('status');
|
||||
$model->expected_delivery_time = $this->request->input('expected_delivery_time');
|
||||
$model->expected_spend_time = $this->request->input('expected_spend_time');
|
||||
$model->distance = 0;
|
||||
|
||||
if (!$model->save()) throw new ErrException('添加失败');
|
||||
});
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
private function checkData(): void
|
||||
{
|
||||
$this->cityId = (int)$this->request->input('city_id');
|
||||
$this->driverId = (int)$this->request->input('driver_id');
|
||||
$this->kitchenId = (int)$this->request->input('kitchen_id');
|
||||
$this->imageId = (int)$this->request->input('image_id');
|
||||
|
||||
$this->cityInfo = $this->systemCityModel->getInfoByCityId($this->cityId);
|
||||
if (
|
||||
empty($this->cityInfo) ||
|
||||
$this->cityInfo->status == CityCode::STATUS_DISABLE
|
||||
) throw new ErrException('该城市已被禁用');
|
||||
|
||||
$this->driverInfo = $this->adminUserModel->getAdminInfoById($this->driverId);
|
||||
if (
|
||||
empty($this->driverInfo) ||
|
||||
$this->driverInfo->status == UserCode::DISABLE ||
|
||||
$this->driverInfo->role_id != RoleCode::DRIVER
|
||||
) throw new ErrException('该司机已被禁用');
|
||||
|
||||
$this->kitchenInfo = $this->kitchenModel->getInfoById($this->kitchenId);
|
||||
if (
|
||||
empty($this->kitchenInfo) ||
|
||||
$this->kitchenInfo->status == SiteCode::KITCHEN_DISABLE
|
||||
) throw new ErrException('该厨房已被禁用');
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
return $this->return->success();
|
||||
@@ -44,19 +153,6 @@ class SiteService extends BaseService
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入用户类
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* 注入部门类
|
||||
* @var AdminSection
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminSection $adminSectionModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
||||
Reference in New Issue
Block a user