'require|checkId', 'name' => 'require|checkName', 'icon' => 'require', 'sort' => 'require|number|max:5', ]; protected $message = [ 'id.require' => 'id不能为空', 'name.require' => '支付名称不能为空', 'icon.require' => '支付图标不能为空', 'sort.require' => '排序不能为空', 'sort,number' => '排序必须是纯数字', 'sort.max' => '排序最大不能超过五位数', ]; public function sceneGet() { return $this->only(['id']) ->remove('id','checkId'); } /** * @notes 检查ID是否存在 * @param $value * @param $rule * @param $data * @return bool|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2021/7/27 6:01 下午 */ public function checkId($value,$rule,$data) { $result = PayConfig::where('id',$value)->find(); if (empty($result)) { return '支付方式不存在'; } if ($result['pay_way'] == PayEnum::WECHAT_PAY) { if (empty($data['interface_version'])) { return '微信支付接口版本不能为空'; } if (empty($data['merchant_type'])) { return '商户类型不能为空'; } if(! in_array($data['interface_version'], [ 'v2', 'v3' ])) { return '微信支付接口版本 必须为v2或v3'; } if (! in_array($data['merchant_type'], [ 'ordinary_merchant', 'partner_sub_merchant' ])) { return '商户类型 错误'; } if ($data['interface_version'] == 'v2' && $data['merchant_type'] == 'partner_sub_merchant') { return 'v2版本暂不支持子商户'; } if (empty($data['mch_id'])) { return '微信支付商户号不能为空'; } if (empty($data['pay_sign_key'])) { return '商户API密钥不能为空'; } if (empty($data['apiclient_cert'])) { return '微信支付证书不能为空'; } if (empty($data['apiclient_key'])) { return '微信支付证书密钥不能为空'; } } if ($result['pay_way'] == PayEnum::ALI_PAY) { if (empty($data['mode'])) { return '模式不能为空'; } // if (empty($data['merchant_type'])) { // return '商户类型不能为空'; // } if (empty($data['app_id'])) { return '应用ID不能为空'; } if (empty($data['private_key'])) { return '应用私钥不能为空'; } if (empty($data['ali_public_key'])) { return '支付宝公钥不能为空'; } } return true; } /** * @notes 检查支付名称是否已存在 * @param $value * @param $rule * @param $data * @author ljj * @date 2021/7/27 5:50 下午 */ public function checkName($value,$rule,$data) { $result = PayConfig::where('name', $value)->where('id','<>', $data['id'])->findOrEmpty(); if (!$result->isEmpty()) { return '支付名称已存在'; } return true; } }