first commit
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\validate\finance;
|
||||
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\finance\AccountCost;
|
||||
use app\common\service\qywx\MediaChannelService;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class AccountCostValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkExists',
|
||||
'cost_date' => 'require|dateFormat:Y-m-d',
|
||||
'media_channel_code' => 'require|checkMediaChannelCode',
|
||||
'dept_id' => 'require|checkDeptId',
|
||||
'amount' => 'require|float|egt:0',
|
||||
'remark' => 'max:255',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'cost_date.require' => '请选择日期',
|
||||
'cost_date.dateFormat' => '日期格式错误',
|
||||
'media_channel_code.require' => '请选择自媒体渠道',
|
||||
'dept_id.require' => '请选择绑定部门',
|
||||
'amount.require' => '请输入账户消耗金额',
|
||||
'amount.float' => '账户消耗金额格式错误',
|
||||
'amount.egt' => '账户消耗金额不能小于0',
|
||||
'remark.max' => '备注不能超过255个字符',
|
||||
];
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
if (!AccountCost::supportsDeptBinding()) {
|
||||
return $this->remove('id', true)->remove('dept_id', true);
|
||||
}
|
||||
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
public function sceneEdit()
|
||||
{
|
||||
if (!AccountCost::supportsDeptBinding()) {
|
||||
return $this->remove('cost_date', true)->remove('dept_id', true);
|
||||
}
|
||||
|
||||
return $this->remove('cost_date', true);
|
||||
}
|
||||
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkExists($value)
|
||||
{
|
||||
$model = AccountCost::find($value);
|
||||
if (!$model) {
|
||||
return '记录不存在';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkMediaChannelCode($value)
|
||||
{
|
||||
if (!MediaChannelService::isValidCode((string) $value)) {
|
||||
return '自媒体渠道不合法';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkDeptId($value)
|
||||
{
|
||||
if (!AccountCost::supportsDeptBinding()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$deptId = (int) $value;
|
||||
if ($deptId <= 0) {
|
||||
return '请选择绑定部门';
|
||||
}
|
||||
|
||||
if (!Dept::find($deptId)) {
|
||||
return '绑定部门不存在';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\validate\finance;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class DeptPerformanceTargetValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'year_month' => 'require|regex:/^\d{4}-\d{2}$/',
|
||||
'items' => 'require|array',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'year_month.require' => '请选择月份',
|
||||
'year_month.regex' => '月份格式须为 YYYY-MM',
|
||||
'items.require' => '请提交目标数据',
|
||||
'items.array' => '目标数据格式错误',
|
||||
];
|
||||
|
||||
public function sceneMonthMatrix(): DeptPerformanceTargetValidate
|
||||
{
|
||||
return $this->only(['year_month']);
|
||||
}
|
||||
|
||||
public function sceneBatchSave(): DeptPerformanceTargetValidate
|
||||
{
|
||||
return $this->only(['year_month', 'items']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user