210 lines
5.7 KiB
PHP
210 lines
5.7 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\validate\custom;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\contract\Contract;
|
||
use app\common\model\custom\Custom;
|
||
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',
|
||
'custom_id' => 'require|checkCustom',
|
||
'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 $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'custom_id.require' => '请选择客户',
|
||
'project_id.require' => '请选择项目',
|
||
'contract_id.require' => '请选择项目合同',
|
||
'date.require' => '请选择日期',
|
||
'date.dateFormat' => '日期格式错误',
|
||
'classification.require' => '请选择分类',
|
||
'urgency.require' => '请选择紧急程度',
|
||
'receiver.require' => '请填写接待人',
|
||
'processed_user.require' => '请选择指定处理人',
|
||
'name.require' => '请填写投诉主题',
|
||
'annex' => 'checkAnnex',
|
||
'processing_result.require' => '请填写处理结果',
|
||
'processing_hours.require' => '请填写花费工时',
|
||
'processing_hours.float' => '花费工时值必须是数字',
|
||
'processing_hours.egt' => '花费工时值必须大于等于0',
|
||
'done_date.require' => '请选择完成日期',
|
||
'done_date.dateFormat' => '完成日期格式错误',
|
||
'score.require' => '请填写评分',
|
||
'score.integer' => '评分值必须是整数',
|
||
'score.egt' => '评分值必须大于等于0',
|
||
'is_solve.require' => '请选择问题是否解决',
|
||
'is_solve.in' => '问题是否解决选项值错误',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return CustomServiceValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/12 14:00
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return CustomServiceValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/12 14:00
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return CustomServiceValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/12 14:00
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return CustomServiceValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/12 14:00
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkCustom($value): bool|string
|
||
{
|
||
$custom = Custom::where('id',$value)->findOrEmpty();
|
||
if($custom->isEmpty()){
|
||
return '客户信息不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProject($value,$rule,$data): bool|string
|
||
{
|
||
$project = Project::where('id',$value)->findOrEmpty();
|
||
if($project->isEmpty()){
|
||
return '项目不存在';
|
||
}
|
||
if($project['custom_id'] != $data['custom_id']){
|
||
return '项目信息无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkContract($value,$rule,$data): bool|string
|
||
{
|
||
$contract = Contract::where('id',$value)->findOrEmpty();
|
||
if($contract->isEmpty()){
|
||
return '项目合同不存在';
|
||
}
|
||
if($contract['project_id'] != $data['project_id']){
|
||
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 checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
if(!is_array($value)){
|
||
return '附件格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProRes($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','custom_service_solv_result')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '处理结果无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |