Пример #1
0
 public function postRegister()
 {
     $this->validate($this->request(), array('realname' => 'required', 'mobile' => 'required|size:11|unique:users,mobile', 'sex' => 'required:in:' . array_keys_impload(\App\Enum\User::$sexLang), 'birthday' => 'required|date', 'marriage' => 'required|in:' . array_keys_impload(\App\Enum\User::$marriageLang), 'like' => 'exists:users,user_id'), array('realname.required' => '请填写真实姓名', 'mobile.required' => '请填写手机号', 'mobile.size' => '手机号格式不正确', 'mobile.unique' => '手机号已被注册', 'sex.required' => '请选择您的性别', 'sex.in' => '您填写的性别有误', 'birthday.required' => '请填写您的生日', 'birthday.date' => '您填写的生日格式不正确', 'marriage.required' => '您填写您的婚姻状态', 'marriage.in' => '婚姻状态不正确', 'like.exist' => '您报名的对象不存在'));
     $form = $this->request()->only('realname', 'mobile', 'sex', 'birthday', 'marriage');
     try {
         transaction();
         //创建用户
         $user = User::create($form);
         if ($this->request()->has('like')) {
             //创建喜欢的人
             $user->like()->create(array('like_user_id' => $this->request()->get('like')));
         }
         //创建用户信息
         $user->info()->create(array());
         //创建择偶条件
         $user->object()->create(array('sex' => $user->sex == \App\Enum\User::SEX_FEMALE ? \App\Enum\User::SEX_MALE : \App\Enum\User::SEX_FEMALE));
         commit();
         return $this->rest()->success($user, '报名成功,管理员审核通过后即可登录');
     } catch (\Exception $ex) {
         rollback();
         dd($ex->getMessage());
         return $this->rest()->error('抱歉,报名失败,请稍后再试');
     }
 }
Пример #2
0
 public function postAdd(Register $register)
 {
     //验证表单
     $this->validate($this->request(), ['mobile' => 'required|digits:11', 'birthday' => 'required|date', 'sex' => 'required|in:' . array_keys_impload(UserEnum::$sexForm), 'password' => 'required|min:5|max:20', 'password_confirm' => 'required|required_with:password|same:password', 'marital_status' => 'in:' . array_keys_impload(UserEnum::$maritalForm), 'height' => 'digits:3|between:130,210', 'education' => 'in:' . array_keys_impload(UserEnum::$educationForm), 'salary' => 'in:' . array_keys_impload(UserEnum::$salaryForm), 'user_name' => 'required|min:2|max:15|unique:users', 'email' => 'required|email|unique:users']);
     $form = $this->request()->only(['user_name', 'email', 'mobile', 'birthday', 'password', 'marital_status', 'height', 'education', 'salary', 'province', 'city', 'area']);
     try {
         transaction();
         $user = User::create($form);
         $register->delete();
         commit();
         return $this->success('添加成功', $user);
     } catch (\Exception $exp) {
         rollback();
         return $this->error('抱歉,添加失败');
     }
 }