erp/app/admin/validate/merchant/MerchantValidate.php
2024-05-22 09:39:15 +08:00

129 lines
2.7 KiB
PHP

<?php
namespace app\admin\validate\merchant;
use app\common\validate\BaseValidate;
use function Symfony\Component\Translation\t;
/**
* 商户列表验证器
* Class MerchantValidate
* @package app\admin\validate\merchant
*/
class MerchantValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'mer_id' => 'require',
'category_id' => 'require|integer',
'mer_name' => 'require',
'credit_buy' => 'require|in:0,1',
'settle_cycle' => 'require|integer',
'interest_rate' => 'require|float',
'mer_address' => 'require',
'mark' => 'require',
'sort' => 'require',
'status' => 'require|in:0,1',
'service_phone' => 'require|mobile',
'mer_money' => 'require|float',
'commission_switch' => 'in:0,1',
'financial_type' => 'in:1,2,3',
'bind_data' => 'require|checkBindData'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'mer_id' => 'mer_id',
'category_id' => '商户分类',
'mer_name' => '商户名称',
'credit_buy' => '是否支持先货后款',
'settle_cycle' => '结算周期,单位天',
'interest_rate' => '利率',
'mer_address' => '商户地址',
'mark' => '商户备注',
'sort' => 'sort',
'status' => '商户是否禁用0锁定,1正常',
'service_phone' => '店铺电话',
'mer_money' => '商户余额',
'commission_switch' => '商户手续费单独设置',
'financial_type' => '默认使用类型',
'bind_data' => '绑定商品数据'
];
/**
* @notes 状态场景
* @return MerchantValidate
* @author likeadmin
* @date 2024/04/23 16:35
*/
public function sceneStatus()
{
return $this->only(['mer_id', 'status'])->append('apply_id', 'require')->append('service_phone','require');
}
/**
* @notes 添加场景
* @return MerchantValidate
* @author likeadmin
* @date 2024/04/23 16:35
*/
public function sceneAdd()
{
return $this->remove('mer_id', true)->remove('bind_data', true);
}
/**
* @notes 编辑场景
* @return MerchantValidate
* @author likeadmin
* @date 2024/04/23 16:35
*/
public function sceneEdit()
{
return $this->remove('bind_data', true);
}
/**
* @notes 删除场景
* @return MerchantValidate
* @author likeadmin
* @date 2024/04/23 16:35
*/
public function sceneDelete()
{
return $this->only(['mer_id']);
}
/**
* @notes 详情场景
* @return MerchantValidate
* @author likeadmin
* @date 2024/04/23 16:35
*/
public function sceneDetail()
{
return $this->only(['mer_id']);
}
public function checkBindData($value)
{
if (!is_array($value)) {
return '数据格式错误';
}
return true;
}
}