链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

  1. <?php
  2. namespace App\Admin\Common;
  3. use App\Models\AdminRoles;
  4. use App\Models\AdminRoleUsers;
  5. use App\Models\AdminUsers;
  6. use App\Models\LanzuUserBalance;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use Illuminate\Support\Facades\Hash;
  9. class Auth extends AdminController
  10. {
  11. /**
  12. * 添加管理员帐号
  13. * @param $form //表单模型
  14. * @param $model
  15. * @param $newId //添加信息成功后返回的ID
  16. * @param $roles
  17. * @return mixed
  18. */
  19. public static function addAdminUser($form, $model, $cid, $roles,$type=0)
  20. {
  21. $adu = new AdminUsers();
  22. if (!$id) {
  23. return '-2';
  24. }
  25. $row = $model::find($id);
  26. //>>1.添加前,去查询是否已存在相同的帐号
  27. $count = $adu->where(['username' => $form->phone])->count();
  28. if ($count) {
  29. $row->delete();
  30. return '-1';
  31. }
  32. //>>2.添加登陆帐号
  33. $adu->username = $form->phone;
  34. $adu->password = Hash::make(substr($form->phone, -5));
  35. $adu->name = $form->name;
  36. $adu->status = $form->status;
  37. $res = $adu->save();
  38. if (!$res) {
  39. //删除刚添加数据
  40. $row->delete();
  41. return '-2';
  42. }
  43. //>>3.将帐号id关联
  44. $row->admin_user_id = $adu->id;
  45. $row->save();
  46. //>>4.添加到admin roles中
  47. $lanzu_role = AdminRoles::where('slug', $roles)->first();
  48. $aru = new AdminRoleUsers();
  49. $aru->role_id = $lanzu_role->id;
  50. $aru->user_id = $adu->id;
  51. $aru->save();
  52. //>>5.生成可提现金额信息
  53. LanzuUserBalance::create($adu->id, $type);
  54. }
  55. }