179 lines
4.3 KiB
PHP
179 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\validate\custom;
|
|
|
|
use app\common\model\auth\Admin;
|
|
use app\common\model\contract\Contract;
|
|
use app\common\model\dict\DictData;
|
|
use app\common\model\project\Project;
|
|
use app\common\validate\BaseValidate;
|
|
|
|
|
|
/**
|
|
* CustomService验证器
|
|
* Class CustomServiceValidate
|
|
* @package app\adminapi\validate\custom_service
|
|
*/
|
|
class CustomServiceValidate extends BaseValidate
|
|
{
|
|
|
|
/**
|
|
* 设置校验规则
|
|
* @var string[]
|
|
*/
|
|
protected $rule = [
|
|
'id' => 'require',
|
|
'project_id' => 'require|checkProject',
|
|
'contract_id' => 'require|checkContract',
|
|
'date' => 'require|dateFormat:Y-m-d',
|
|
'classification' => 'require|checkClassify',
|
|
'urgency' => 'require|checkUrgency',
|
|
'receiver' => 'require',
|
|
'processed_user' => 'require|checkProUser',
|
|
'name' => 'require',
|
|
'annex' => 'checkAnnex',
|
|
'processing_result' => 'require|checkProRes',
|
|
'processing_hours' => 'require|float|egt:0',
|
|
'done_date' => 'require|dateFormat:Y-m-d',
|
|
'score' => 'require|integer|egt:0',
|
|
'is_solve' => 'require|in:0,1',
|
|
];
|
|
|
|
protected $field = [
|
|
'id' => '数据id',
|
|
'project_id' => '项目id',
|
|
'contract_id' => '合同id',
|
|
'date' => '日期',
|
|
'classification' => '分类',
|
|
'urgency' => '紧急程度',
|
|
'receiver' => '接待人',
|
|
'processed_user' => '指定处理人',
|
|
'name' => '投诉主题',
|
|
'processing_result' => '处理结果',
|
|
'processing_hours' => '花费工时',
|
|
'done_date' => '完成日期',
|
|
'score' => '客户评分',
|
|
'is_solve' => '是否解决',
|
|
];
|
|
|
|
|
|
/**
|
|
* @notes 添加场景
|
|
* @return CustomServiceValidate
|
|
* @author likeadmin
|
|
* @date 2023/11/12 14:00
|
|
*/
|
|
public function sceneAdd()
|
|
{
|
|
return $this->remove('id', true)
|
|
->remove('processing_result', true)
|
|
->remove('processing_hours', true)
|
|
->remove('done_date', true)
|
|
->remove('score', true)->remove('is_solve', true);
|
|
}
|
|
|
|
/**
|
|
* @notes 编辑场景
|
|
* @return CustomServiceValidate
|
|
* @author likeadmin
|
|
* @date 2023/11/12 14:00
|
|
*/
|
|
public function sceneEdit()
|
|
{
|
|
return $this->remove('processing_result', true)
|
|
->remove('processing_hours', true)
|
|
->remove('done_date', true)
|
|
->remove('score', true)->remove('is_solve', true);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 处理场景
|
|
* @return CustomServiceValidate
|
|
* @author likeadmin
|
|
* @date 2023/11/12 14:00
|
|
*/
|
|
public function sceneCheck()
|
|
{
|
|
return $this->only(['id', 'processing_result', 'processing_hours', 'done_date', 'score', 'is_solve']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除场景
|
|
* @return CustomServiceValidate
|
|
* @author likeadmin
|
|
* @date 2023/11/12 14:00
|
|
*/
|
|
public function sceneDelete()
|
|
{
|
|
return $this->only(['id'])->remove('id', 'checkData');
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 详情场景
|
|
* @return CustomServiceValidate
|
|
* @author likeadmin
|
|
* @date 2023/11/12 14:00
|
|
*/
|
|
public function sceneDetail()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function checkProject($value): bool|string
|
|
{
|
|
$project = Project::where('id', $value)->findOrEmpty();
|
|
if ($project->isEmpty()) {
|
|
return '项目不存在';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function checkContract($value, $rule, $params): bool|string
|
|
{
|
|
$contract = Contract::where('id', $value)->where('project_id', $params['project_id'])->findOrEmpty();
|
|
if ($contract->isEmpty()) {
|
|
return '项目合同不存在';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function checkClassify($value): bool|string
|
|
{
|
|
$dictData = DictData::where('type_value', 'classification')->column('value');
|
|
if (!in_array($value, $dictData)) {
|
|
return '分类无效';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function checkUrgency($value): bool|string
|
|
{
|
|
$dictData = DictData::where('type_value', 'urgency')->column('value');
|
|
if (!in_array($value, $dictData)) {
|
|
return '紧急程度无效';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function checkProUser($value): bool|string
|
|
{
|
|
$admin = Admin::where('id', $value)->findOrEmpty();
|
|
if ($admin->isEmpty()) {
|
|
return '指定处理人不存在';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function checkProRes($value): bool|string
|
|
{
|
|
$dictData = DictData::where('type_value', 'custom_service_solve_result')->column('value');
|
|
if (!in_array($value, $dictData)) {
|
|
return '处理结果无效';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} |