链街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.

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