160 lines
4.3 KiB
PHP
160 lines
4.3 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\project;
|
||
|
||
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectPersonnel;
|
||
use app\common\model\project\ProjectSalaryDetail;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 工资付款验证器
|
||
* Class ProjectSalaryPaymentValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectSalaryPaymentValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'project_id' => 'require|checkProject',
|
||
'payment_type' => 'require|checkPaymentType',
|
||
'apply_date' => 'require|dateFormat:Y-m-d',
|
||
'annex' => 'checkAnnex',
|
||
'payment_detail' => 'require|checkPaymentDetail'
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'project_id.require' => '请选择项目',
|
||
'payment_type.require' => '请选择付款类型',
|
||
'apply_date.require' => '请选择申请日期',
|
||
'apply_date.dateFormat' => '申请日期格式错误',
|
||
'payment_detail.require' => '工资支付明细不能为空',
|
||
];
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectSalaryPaymentValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/27 16:08
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectSalaryPaymentValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/27 16:08
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectSalaryPaymentValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/27 16:08
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectSalaryPaymentValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/27 16:08
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkProject($value): bool|string
|
||
{
|
||
$data = Project::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '项目不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkPaymentType($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','salary_payment_type')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '付款类型无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
if(!is_array($value)){
|
||
return '附件必须是json数组';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkPaymentDetail($value,$rule,$data): bool|string
|
||
{
|
||
$payment_detail = $value;//json_decode($value,true);
|
||
if(empty($payment_detail) || !is_array($payment_detail)){
|
||
return '工资支付明细数据格式错误';
|
||
}
|
||
foreach($payment_detail as $v) {
|
||
if(isset($v['id']) && $v['id'] != ''){
|
||
$info = ProjectSalaryDetail::where('id',$v['id'])->findOrEmpty();
|
||
if($info->isEmpty()){
|
||
return '工资支付明细信息不存在';
|
||
}
|
||
}
|
||
if(empty($v['person_id'])){
|
||
return '请选择项目人员';
|
||
}else{
|
||
$person = ProjectPersonnel::where('id',$v['person_id'])->findOrEmpty();
|
||
if($person->isEmpty() || $person['project_id'] != $data['project_id']){
|
||
return '项目人员不存在';
|
||
}
|
||
}
|
||
if(empty($v['apply_amount'])){
|
||
return '申请付款金额不能为空';
|
||
}else{
|
||
if(!is_numeric($v['apply_amount']) || $v['apply_amount'] <= 0){
|
||
return '申请付款金额必须是大于0的数字';
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |