UsersInfoForm.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use App\Models\User;
  4. use App\Models\UserInfoModel;
  5. use Dcat\Admin\Contracts\LazyRenderable;
  6. use Dcat\Admin\Traits\LazyWidget;
  7. use Dcat\Admin\Widgets\Form;
  8. use PHPUnit\Util\Exception;
  9. class UsersInfoForm extends Form implements LazyRenderable
  10. {
  11. use LazyWidget;
  12. public function __construct($data = [], $key = null)
  13. {
  14. parent::__construct($data, $key);
  15. }
  16. public function handle(array $input)
  17. {
  18. $user = User::query()->find($input['id']);
  19. if(!$user){
  20. return $this->response()->error('请刷新后重试');
  21. }
  22. if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
  23. return $this->response()->error('该手机号码已被使用');
  24. }else{
  25. $user->mobile = $input['mobile'];
  26. }
  27. if($input['password']!=''){
  28. $user->password = $input['password'];
  29. }
  30. $user->save();
  31. return $this->response()->success('保存成功')->refresh();
  32. }
  33. public function form()
  34. {
  35. $user_info = UserInfoModel::query()->where('user_id',$this->payload['user_id'])->first();
  36. $this->fill($user_info);
  37. $this->text('user_id',"用户ID")->readOnly();
  38. $this->text('nickname', '昵称')->required();
  39. $this->image('avatar', '头像')->uniqueName()->removable(false);
  40. $this->text('weixin', '微信号');
  41. $this->text('birthday', '生日');
  42. $this->text('height', '身高');
  43. $this->text('weight', '体重');
  44. $this->text('work', '职业');
  45. $this->text('info', '个人简介');
  46. $this->text('area', '所在地区')->default("成都市");
  47. $this->text('figure', '身材');
  48. $this->text('feeling', '感情状态');
  49. $this->text('education', '学历');
  50. $this->text('income', '年收入');
  51. $this->text('hobby', '兴趣爱好')->help("多个字段用,隔开,例如:唱歌,跳舞");
  52. $this->text('hobby', '兴趣爱好')->help("多个字段用,隔开,例如:唱歌,跳舞");
  53. $this->text('drink', '喝酒');
  54. $this->text('smoke', '抽烟');
  55. $this->array('photo', function ($form) {
  56. $form->image('url','图片')->uniqueName()->removable(false);
  57. $form->radio('state','阅后即焚')->options([0=>"否",1=>"是"]);
  58. })->saveAsJson()->label('相册');
  59. }
  60. }