['规则1','规则2'...] * * @var array */ protected $rule = [ 'user_id|用户id' => 'require|number', 'quota|额度' => 'require|number|egt:1', 'password|密码' => 'require|min:6|max:20', 'repassword|确认密码' => 'require|confirm:password', 'aid|代理id' => 'require|number', 'phone|手机号' => 'require|mobile', 'rebate_ratio|返点占比' => 'float|between:0.01,100', 'rate|比率' => 'float|between:0.01,100', ]; /** * 定义错误信息 * 格式:'字段名.规则名' => '错误信息' * * @var array */ protected $message = []; protected $scene = [ 'scores' => ['user_id','quota'], 'edit' => ['aid','password','rebate_ratio'], 'del' => ['aid'], 'register' => ['phone','password','rebate_ratio','rate'], 'modifyPassword' => ['password','repassword'], 'promotion' => ['user_id','rebate_ratio'] ]; /** * 验证用户 * @param $aid * @param $user_id * @return bool|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function validateUserInfo($aid,$user_id) { $query = \app\model\User::where('aid',$aid)->where('id',$user_id)->find(); if (!$query) return '当前用户不在你管理之下'; return true; } /** * 验证 返点比率 不得超出上级代理 * @param $aid * @param $rebate_ratio * @return bool|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function validateRebateRatio($aid,$rebate_ratio) { $agentInfo = AgentInfo::where('aid',$aid)->field('rebate_ratio')->find(); if (empty($agentInfo['rebate_ratio'])) return '当前代理账号未有返点权限,未能升级用户为代理'; $rebate_ratio = $rebate_ratio / 100; if ($rebate_ratio >= $agentInfo['rebate_ratio']) { return '填写返点占比不能超出代理本身的返点占比,代理返点比率为:'.($agentInfo['rebate_ratio']*100).'%'; } return true; } /** * 限制总后台设置代理反比权限 * @param $aid * @param $rebate_ratio * @return bool|string */ public function validateAgentRebateRatio($aid,$rebate_ratio) { $last_aid = \app\model\User::where('id',$aid)->where('identity',2)->value('aid'); if (!empty($last_aid)) { $last_rebate_ratio = AgentInfo::where('aid',$last_aid)->value('rebate_ratio'); if (empty($last_rebate_ratio)) return '当前代理上级代理未有返点权限,不能设置该代理返点占比'; $rebate_ratio = $rebate_ratio / 100; if ($rebate_ratio >= $last_rebate_ratio) { return '填写返点占比不能超出上级代理的返点占比,上级代理返点比率为:'.($last_rebate_ratio*100).'%'; } } return true; } }