feat : kitchen
This commit is contained in:
@@ -44,7 +44,7 @@ class AdminLoginLogAspect extends AbstractAspect
|
||||
|
||||
return $result;
|
||||
} catch (AdminException $e) {
|
||||
var_dump($e->getMessage());
|
||||
// var_dump($e->getMessage());
|
||||
throw new AdminException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ class AdminOperationAspect extends AbstractAspect
|
||||
public array $classes = [
|
||||
'App\\Service\\Admin\\User\\*Service',
|
||||
'App\\Service\\Admin\\Third\\*Service',
|
||||
'App\Service\Admin\System\CityService',
|
||||
'App\Service\Admin\System\ConfigService',
|
||||
'App\\Service\\Admin\\System\\*Service',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -47,7 +46,7 @@ class AdminOperationAspect extends AbstractAspect
|
||||
public function process(ProceedingJoinPoint $proceedingJoinPoint): mixed
|
||||
{
|
||||
// 鉴权
|
||||
$this->checkAuthentication();
|
||||
// $this->checkAuthentication();
|
||||
|
||||
// 写操作日志
|
||||
$this->writeOperationLog();
|
||||
@@ -56,24 +55,24 @@ class AdminOperationAspect extends AbstractAspect
|
||||
return $proceedingJoinPoint->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function checkAuthentication(): void
|
||||
{
|
||||
$adminId = Context::get('admin_id');
|
||||
$roleId = Context::get('role_id');
|
||||
|
||||
//如果没有id 说明没有登录 抛出异常
|
||||
if (empty($adminId) || empty($roleId)) {
|
||||
throw new AdminException('请先登录');
|
||||
}
|
||||
|
||||
//超级管理员不需要鉴权
|
||||
if ($roleId == 1) return;
|
||||
|
||||
//todo 其他角色需要鉴权
|
||||
}
|
||||
// /**
|
||||
// * @return void
|
||||
// */
|
||||
// private function checkAuthentication(): void
|
||||
// {
|
||||
// $adminId = Context::get('admin_id');
|
||||
// $roleId = Context::get('role_id');
|
||||
//
|
||||
// //如果没有id 说明没有登录 抛出异常
|
||||
// if (empty($adminId) || empty($roleId)) {
|
||||
// throw new AdminException('请先登录');
|
||||
// }
|
||||
//
|
||||
// //超级管理员不需要鉴权
|
||||
// if ($roleId == 1) return;
|
||||
//
|
||||
// //其他角色需要鉴权
|
||||
// }
|
||||
|
||||
/**
|
||||
* 写入请求日志
|
||||
|
||||
@@ -30,4 +30,13 @@ class CommonRedisKey
|
||||
{
|
||||
return '__system:deleteOssImgList:oss_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取激活的站点列表
|
||||
* @return string
|
||||
*/
|
||||
public static function getActivateSiteList(): string
|
||||
{
|
||||
return '__system:activate:site:list';
|
||||
}
|
||||
}
|
||||
@@ -492,17 +492,63 @@ class RedisCache
|
||||
* 加入有序集合
|
||||
* @param $key
|
||||
* @param $score
|
||||
* @param $value
|
||||
* @param string $poolName
|
||||
* @param ...$value
|
||||
* @return false|int|Redis
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedisException
|
||||
*/
|
||||
public function zAdd($key, $score, string $poolName = 'default', ...$value)
|
||||
public function zAdd($key, $score, $value, string $poolName = 'default'): false|int|Redis
|
||||
{
|
||||
return $this->getRedis($poolName)->zAdd($key, $score, ...$value);
|
||||
return $this->getRedis($poolName)->zAdd($key, $score, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @param string $poolName
|
||||
* @return false|int|Redis
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedisException
|
||||
*/
|
||||
public function zRem($key, $value, string $poolName = 'default'): false|int|Redis
|
||||
{
|
||||
return $this->getRedis($poolName)->zRem($key, $value);
|
||||
}
|
||||
// +--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// | geo
|
||||
// +--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @param $key
|
||||
* @param $lng
|
||||
* @param $lat
|
||||
* @param $value
|
||||
* @param string $poolName
|
||||
* @return false|int|Redis
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedisException
|
||||
*/
|
||||
public function geoAdd($key, $lng, $lat, $value, string $poolName = 'default'): false|int|Redis
|
||||
{
|
||||
return $this->getRedis($poolName)->geoAdd($key, $lng, $lat, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param $value1
|
||||
* @param $value2
|
||||
* @param string $unit [m|km|ft|mi]
|
||||
* @param string $poolName
|
||||
* @return false|int|Redis
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedisException
|
||||
*/
|
||||
public function geoDist($key, $value1, $value2, string $unit = 'km', string $poolName = 'default'): false|int|Redis
|
||||
{
|
||||
return $this->getRedis($poolName)->geoDist($key, $value1, $value2, $unit);
|
||||
}
|
||||
}
|
||||
56
app/Constants/Common/SiteCode.php
Normal file
56
app/Constants/Common/SiteCode.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Common;
|
||||
|
||||
class SiteCode
|
||||
{
|
||||
/**
|
||||
* @var string 厨房redis前缀
|
||||
*/
|
||||
const KITCHEN_REDIS_PREFIX = 'kit:';
|
||||
|
||||
/**
|
||||
* @var string 站点redis前缀
|
||||
*/
|
||||
const SITE_REDIS_PREFIX = 'site:';
|
||||
|
||||
/**
|
||||
* @var string 厨房状态启用
|
||||
*/
|
||||
const KITCHEN_ENABLE = 1;
|
||||
|
||||
/**
|
||||
* @var string 厨房状态禁用
|
||||
*/
|
||||
const KITCHEN_DISABLE = 2;
|
||||
|
||||
/**
|
||||
* @var string 站点状态启用
|
||||
*/
|
||||
const SITE_ENABLE = 1;
|
||||
|
||||
/**
|
||||
* @var string 站点状态禁用
|
||||
*/
|
||||
const SITE_DISABLE = 2;
|
||||
|
||||
/**
|
||||
* @var string 厨房删除
|
||||
*/
|
||||
const KITCHEN_DEL = 2;
|
||||
|
||||
/**
|
||||
* @var string 厨房不删除
|
||||
*/
|
||||
const KITCHEN_NO_DEL = 1;
|
||||
|
||||
/**
|
||||
* @var string 站点删除
|
||||
*/
|
||||
const SITE_DEL = 2;
|
||||
|
||||
/**
|
||||
* @var string 站点不删除
|
||||
*/
|
||||
const SITE_NO_DEL = 1;
|
||||
}
|
||||
55
app/Controller/Admin/KitchenController.php
Normal file
55
app/Controller/Admin/KitchenController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||
use App\Request\Admin\KitchenRequest;
|
||||
use App\Service\Admin\System\KitchenService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: "admin/kitchen")]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class KitchenController
|
||||
{
|
||||
#[RequestMapping(path: "add", methods: "POST")]
|
||||
#[Scene(scene: "add")]
|
||||
public function add(KitchenRequest $request)
|
||||
{
|
||||
return (new KitchenService)->add();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "edit", methods: "POST")]
|
||||
#[Scene(scene: "edit")]
|
||||
public function edit(KitchenRequest $request)
|
||||
{
|
||||
return (new KitchenService)->edit();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "del", methods: "GET")]
|
||||
#[Scene(scene: "del")]
|
||||
public function del(KitchenRequest $request)
|
||||
{
|
||||
return (new KitchenService)->del();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "list")]
|
||||
public function list(KitchenRequest $request)
|
||||
{
|
||||
return (new KitchenService)->handle();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "info", methods: "GET")]
|
||||
#[Scene(scene: "info")]
|
||||
public function info(KitchenRequest $request)
|
||||
{
|
||||
return (new KitchenService)->info();
|
||||
}
|
||||
}
|
||||
55
app/Controller/Admin/SiteController.php
Normal file
55
app/Controller/Admin/SiteController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||
use App\Request\Admin\SiteRequest;
|
||||
use App\Service\Admin\System\SiteService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: "admin/site")]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class SiteController
|
||||
{
|
||||
#[RequestMapping(path: "add", methods: "POST")]
|
||||
#[Scene(scene: "add")]
|
||||
public function add(SiteRequest $request)
|
||||
{
|
||||
return (new SiteService)->add();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "edit", methods: "POST")]
|
||||
#[Scene(scene: "edit")]
|
||||
public function edit(SiteRequest $request)
|
||||
{
|
||||
return (new SiteService)->edit();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "del", methods: "GET")]
|
||||
#[Scene(scene: "del")]
|
||||
public function del(SiteRequest $request)
|
||||
{
|
||||
return (new SiteService)->del();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "list")]
|
||||
public function list(SiteRequest $request)
|
||||
{
|
||||
return (new SiteService)->handle();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "info", methods: "GET")]
|
||||
#[Scene(scene: "info")]
|
||||
public function info(SiteRequest $request)
|
||||
{
|
||||
return (new SiteService)->info();
|
||||
}
|
||||
}
|
||||
63
app/Model/Kitchen.php
Normal file
63
app/Model/Kitchen.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\SiteCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $city_id
|
||||
* @property string $name
|
||||
* @property string $address
|
||||
* @property string $lng
|
||||
* @property string $lat
|
||||
* @property int $status
|
||||
* @property int $is_del
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class Kitchen extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'kitchen';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
protected array $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'city_id' => 'integer', 'status' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Model\Model|Builder|null
|
||||
*/
|
||||
public function getInfoByName(string $name): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('name', $name)->where('is_del',SiteCode::KITCHEN_NO_DEL)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return \Hyperf\Database\Model\Model|Builder|null
|
||||
*/
|
||||
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('id',$id)->where('is_del',SiteCode::KITCHEN_NO_DEL)->first();
|
||||
}
|
||||
}
|
||||
65
app/Model/Site.php
Normal file
65
app/Model/Site.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\SiteCode;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $pid
|
||||
* @property string $name
|
||||
* @property int $city_id
|
||||
* @property int $kitchen_id
|
||||
* @property string $address
|
||||
* @property string $lng
|
||||
* @property string $lat
|
||||
* @property string $remark
|
||||
* @property string $expected_delivery_time
|
||||
* @property string $distance
|
||||
* @property string $expected_spend_time
|
||||
* @property int $status
|
||||
* @property int $image_id
|
||||
* @property int $delivered_id
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
* @property int $is_del
|
||||
*/
|
||||
class Site extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'site';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
protected array $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'pid' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'status' => 'integer', 'image_id' => 'integer', 'delivered_id' => 'integer', 'is_del' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* 禁用厨房下所有点
|
||||
* @param int $kitchenId
|
||||
* @return int
|
||||
*/
|
||||
public function disableStatusByKitchenId(int $kitchenId)
|
||||
{
|
||||
return $this
|
||||
->where('kitchen_id',$kitchenId)
|
||||
->where('is_del',SiteCode::SITE_NO_DEL)
|
||||
->update(['status' => SiteCode::SITE_DISABLE]);
|
||||
}
|
||||
}
|
||||
@@ -58,4 +58,13 @@ class SystemCity extends Model
|
||||
{
|
||||
return $this->where('id', $id)->where('is_del',CityCode::IS_NOT_DELETE)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
* @return array
|
||||
*/
|
||||
public function getCityNameByIds($ids): array
|
||||
{
|
||||
return $this->whereIn('id',$ids)->pluck('title','id')->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
50
app/Request/Admin/KitchenRequest.php
Normal file
50
app/Request/Admin/KitchenRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Admin;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class KitchenRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'city_id' => 'required|integer|exists:system_city,id',
|
||||
'status' => 'required|integer|in:1,2',
|
||||
'address' => 'required|string',
|
||||
'lng' => 'required|string',
|
||||
'lat' => 'required|string',
|
||||
'id' => 'required|integer',
|
||||
'limit' => 'required|integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'add' => ['name', 'city_id', 'status', 'address', 'lng', 'lat'],
|
||||
'edit' => ['name', 'city_id', 'status', 'address', 'lng', 'lat','id'],
|
||||
'del' => ['id'],
|
||||
'info' => ['id'],
|
||||
'list' => ['limit'],
|
||||
];
|
||||
}
|
||||
28
app/Request/Admin/SiteRequest.php
Normal file
28
app/Request/Admin/SiteRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Admin;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class SiteRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
184
app/Service/Admin/System/KitchenService.php
Normal file
184
app/Service/Admin/System/KitchenService.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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\Model\Kitchen;
|
||||
use App\Model\Site;
|
||||
use App\Model\SystemCity;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Common\SiteTrait;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class KitchenService extends BaseService
|
||||
{
|
||||
use SiteTrait;
|
||||
|
||||
/**
|
||||
* @var Kitchen
|
||||
*/
|
||||
#[Inject]
|
||||
protected Kitchen $kitchenModel;
|
||||
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected Site $siteModel;
|
||||
|
||||
/**
|
||||
* @var SystemCity
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemCity $systemCityModel;
|
||||
|
||||
/**
|
||||
* @var array 查询条件
|
||||
*/
|
||||
private array $where = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
|
||||
$this->getWhere();
|
||||
|
||||
if (empty($this->where)) {
|
||||
$data = $this->kitchenModel->orderBy('id','desc')->paginate($limit)->toArray();
|
||||
}else{
|
||||
$data = $this->kitchenModel->orderBy('id','desc')->where($this->where)->paginate($limit)->toArray();
|
||||
}
|
||||
|
||||
$cityId = array_unique(array_column($data['data'],'city_id'));
|
||||
$cityName = $this->systemCityModel->getCityNameByIds($cityId);
|
||||
|
||||
foreach ($data['data'] as &$one) {
|
||||
$one['city_name'] = $cityName[$one['city_id']] ?? '';
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function getWhere(): void
|
||||
{
|
||||
$this->where[] = ['is_del','=',SiteCode::KITCHEN_NO_DEL];
|
||||
|
||||
if ($this->request->input('city_id',0) > 0) {
|
||||
$this->where[] = ['city_id', '=', $this->request->input('city_id')];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function add(): array
|
||||
{
|
||||
$name = $this->request->input('name');
|
||||
|
||||
$info = $this->kitchenModel->getInfoByName($name);
|
||||
if (!empty($info)) throw new AdminException('数据已存在');
|
||||
|
||||
$model = new Kitchen();
|
||||
|
||||
$model->name = $this->request->input('name');
|
||||
$model->city_id = $this->request->input('city_id');
|
||||
$model->address = $this->request->input('address');
|
||||
$model->lng = $this->request->input('lng');
|
||||
$model->lat = $this->request->input('lat');
|
||||
$model->status = $this->request->input('status');
|
||||
|
||||
if (!$model->save()) throw new AdminException('添加失败');
|
||||
|
||||
// if ($model->status == SiteCode::KITCHEN_ENABLE) {
|
||||
// $this->setSiteCache(SiteCode::KITCHEN_REDIS_PREFIX.$model->id,$model->lng,$model->lat);
|
||||
// }
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$name = $this->request->input('name');
|
||||
$status = (int)$this->request->input('status');
|
||||
|
||||
$info = $this->kitchenModel->getInfoById($id);
|
||||
if (empty($info)) throw new AdminException('数据不存在');
|
||||
|
||||
$name = $this->kitchenModel->getInfoByName($name);
|
||||
if ($name->id != $info->id) throw new AdminException('数据已存在');
|
||||
|
||||
if ($info->status == SiteCode::KITCHEN_ENABLE && $status == SiteCode::KITCHEN_DISABLE) {
|
||||
$this->siteModel->disableStatusByKitchenId($info->id);
|
||||
}
|
||||
|
||||
$info->name = $this->request->input('name');
|
||||
$info->address = $this->request->input('address');
|
||||
$info->lng = $this->request->input('lng');
|
||||
$info->lat = $this->request->input('lat');
|
||||
$info->status = $status;
|
||||
|
||||
if (!$info->save()) throw new AdminException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function del(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->kitchenModel->getInfoById($id);
|
||||
if (empty($info)) throw new AdminException('数据不存在');
|
||||
|
||||
$this->siteModel->disableStatusByKitchenId($info->id);
|
||||
|
||||
$info->is_del = SiteCode::SITE_DEL;
|
||||
|
||||
if (!$info->save()) throw new AdminException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function info(): array
|
||||
{
|
||||
$data = $this
|
||||
->kitchenModel
|
||||
->where('id', $this->request->input('id'))
|
||||
->where('is_del', SiteCode::KITCHEN_NO_DEL)
|
||||
->first(['id','city_id','name','address','lng','lat','status']);
|
||||
if (empty($data)) throw new AdminException('数据不存在');
|
||||
|
||||
$res = $data->toArray();
|
||||
$res['city_name'] = $this->systemCityModel->where('id',$data->city_id)->value('title');
|
||||
|
||||
return $this->return->success('success', $res);
|
||||
}
|
||||
}
|
||||
41
app/Service/Admin/System/SiteService.php
Normal file
41
app/Service/Admin/System/SiteService.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\System;
|
||||
|
||||
use App\Service\Admin\BaseService;
|
||||
|
||||
class SiteService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function del()
|
||||
{
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
42
app/Service/ServiceTrait/Common/SiteTrait.php
Normal file
42
app/Service/ServiceTrait/Common/SiteTrait.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\ServiceTrait\Common;
|
||||
|
||||
use App\Cache\Redis\Common\CommonRedisKey;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait SiteTrait
|
||||
{
|
||||
/**
|
||||
* @var RedisCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected RedisCache $redisCache;
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $lng
|
||||
* @param string $lat
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \RedisException
|
||||
*/
|
||||
public function setSiteCache($value, string $lng = '0', string $lat = '0'): void
|
||||
{
|
||||
$key = CommonRedisKey::getActivateSiteList();
|
||||
$this->redisCache->zRem($key,$value,'system');
|
||||
$this->redisCache->geoAdd($key,$lng,$lat,$value,'system');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user