Files
fdesk/app/admin/service/SysPortService.php
T
2025-08-28 16:01:41 +08:00

103 lines
2.5 KiB
PHP

<?php
namespace app\admin\service;
use app\admin\validate\SysPortValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysPort;
use support\Request;
class SysPortService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysPort::class;
/**
* 验证器
*/
protected $validator = SysPortValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['port_code','port_name'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
if(empty($data['lat']))
unset($data['lat']);
if(empty($data['lng']))
unset($data['lng']);
return $data;
}
/**
* 添加前置处理
*/
public function beforeServiceUpdate($data, Request $request)
{
if(empty($data['lat']))
unset($data['lat']);
if(empty($data['lng']))
unset($data['lng']);
return $data;
}
}