feat : basic
This commit is contained in:
@@ -12,7 +12,7 @@ namespace App\Service\Admin\System;
|
||||
|
||||
use App\Cache\Redis\Common\CityCache;
|
||||
use App\Constants\Common\CityCode;
|
||||
use App\Exception\AdminException;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\SystemCity;
|
||||
use App\Model\SystemCityConfig;
|
||||
use App\Service\Admin\BaseService;
|
||||
@@ -78,9 +78,9 @@ class CityService extends BaseService
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
|
||||
$info = $this->systemCityConfigModel->getAddressByIdAndPid($cityId,$provinceId);
|
||||
if (empty($info)) throw new AdminException('城市选择错误');
|
||||
if (empty($info)) throw new ErrException('城市选择错误');
|
||||
|
||||
if ($this->systemCityModel->getInfoByCityId($cityId)) throw new AdminException('城市已存在');
|
||||
if ($this->systemCityModel->getInfoByCityId($cityId)) throw new ErrException('城市已存在');
|
||||
|
||||
$model = new SystemCity();
|
||||
|
||||
@@ -90,7 +90,7 @@ class CityService extends BaseService
|
||||
$model->status = $this->request->input('status', 1);
|
||||
$model->is_del = 1;
|
||||
|
||||
if (!$model->save()) throw new AdminException('添加失败');
|
||||
if (!$model->save()) throw new ErrException('添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -101,11 +101,11 @@ class CityService extends BaseService
|
||||
|
||||
$model = $this->systemCityModel->getInfoById($id);
|
||||
|
||||
if (!$model) throw new AdminException('数据不存在');
|
||||
if (!$model) throw new ErrException('数据不存在');
|
||||
|
||||
$model->status = $model->status == CityCode::STATUS_ENABLE ? CityCode::STATUS_DISABLE : CityCode::STATUS_ENABLE;
|
||||
|
||||
if (!$model->save()) throw new AdminException('修改失败');
|
||||
if (!$model->save()) throw new ErrException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -119,11 +119,11 @@ class CityService extends BaseService
|
||||
|
||||
$model = $this->systemCityModel->getInfoById($id);
|
||||
|
||||
if (!$model) throw new AdminException('数据不存在');
|
||||
if (!$model) throw new ErrException('数据不存在');
|
||||
|
||||
$model->is_del = CityCode::IS_DELETE;
|
||||
|
||||
if (!$model->save()) throw new AdminException('删除失败');
|
||||
if (!$model->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class CityService extends BaseService
|
||||
|
||||
$info = $this->systemCityModel->getInfoById($id);
|
||||
|
||||
if (!$info) throw new AdminException('数据不存在');
|
||||
if (!$info) throw new ErrException('数据不存在');
|
||||
|
||||
$allInfo = $this->cityCache->getCityList();
|
||||
$allInfo = array_column($allInfo,'title','id');
|
||||
|
||||
@@ -10,7 +10,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\System;
|
||||
|
||||
use App\Exception\AdminException;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Config;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -42,7 +42,7 @@ class ConfigService extends BaseService
|
||||
|
||||
$res = (new Config)->where('key', $editKey)->update(['value' => $editValue]);
|
||||
|
||||
if (!$res) throw new AdminException('配置更新失败');
|
||||
if (!$res) throw new ErrException('配置更新失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace App\Service\Admin\System;
|
||||
use App\Cache\Redis\Common\CommonRedisKey;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\Common\SiteCode;
|
||||
use App\Exception\AdminException;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Kitchen;
|
||||
use App\Model\Site;
|
||||
use App\Model\SystemCity;
|
||||
@@ -94,7 +94,7 @@ class KitchenService extends BaseService
|
||||
$name = $this->request->input('name');
|
||||
|
||||
$info = $this->kitchenModel->getInfoByName($name);
|
||||
if (!empty($info)) throw new AdminException('数据已存在');
|
||||
if (!empty($info)) throw new ErrException('数据已存在');
|
||||
|
||||
$model = new Kitchen();
|
||||
|
||||
@@ -105,7 +105,7 @@ class KitchenService extends BaseService
|
||||
$model->lat = $this->request->input('lat');
|
||||
$model->status = $this->request->input('status');
|
||||
|
||||
if (!$model->save()) throw new AdminException('添加失败');
|
||||
if (!$model->save()) throw new ErrException('添加失败');
|
||||
|
||||
// if ($model->status == SiteCode::KITCHEN_ENABLE) {
|
||||
// $this->setSiteCache(SiteCode::KITCHEN_REDIS_PREFIX.$model->id,$model->lng,$model->lat);
|
||||
@@ -124,10 +124,10 @@ class KitchenService extends BaseService
|
||||
$status = (int)$this->request->input('status');
|
||||
|
||||
$info = $this->kitchenModel->getInfoById($id);
|
||||
if (empty($info)) throw new AdminException('数据不存在');
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$name = $this->kitchenModel->getInfoByName($name);
|
||||
if ($name->id != $info->id) throw new AdminException('数据已存在');
|
||||
if ($name->id != $info->id) throw new ErrException('数据已存在');
|
||||
|
||||
if ($info->status == SiteCode::KITCHEN_ENABLE && $status == SiteCode::KITCHEN_DISABLE) {
|
||||
$this->siteModel->disableStatusByKitchenId($info->id);
|
||||
@@ -139,7 +139,7 @@ class KitchenService extends BaseService
|
||||
$info->lat = $this->request->input('lat');
|
||||
$info->status = $status;
|
||||
|
||||
if (!$info->save()) throw new AdminException('修改失败');
|
||||
if (!$info->save()) throw new ErrException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -153,13 +153,13 @@ class KitchenService extends BaseService
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->kitchenModel->getInfoById($id);
|
||||
if (empty($info)) throw new AdminException('数据不存在');
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$this->siteModel->disableStatusByKitchenId($info->id);
|
||||
|
||||
$info->is_del = SiteCode::SITE_DEL;
|
||||
|
||||
if (!$info->save()) throw new AdminException('删除失败');
|
||||
if (!$info->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class KitchenService extends BaseService
|
||||
{
|
||||
$data = $this->kitchenModel
|
||||
->getInfoById((int)$this->request->input('id'));
|
||||
if (empty($data)) throw new AdminException('数据不存在');
|
||||
if (empty($data)) throw new ErrException('数据不存在');
|
||||
|
||||
$res = [
|
||||
'id' => $data->id,
|
||||
|
||||
@@ -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