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.
|
|
<?php
namespace App\Admin\Common;
use App\Models\AdminRoles;use App\Models\AdminRoleUsers;use App\Models\AdminUsers;use App\Models\LanzuAdminUserMarket;use App\Models\LanzuUserBalance;use Dcat\Admin\Admin;use Dcat\Admin\Controllers\AdminController;use Illuminate\Support\Facades\Hash;
class Auth extends AdminController{ /** * 添加管理员帐号 * @param $form //表单模型
* @param $model * @param $newId //添加信息成功后返回的ID
* @param $roles * @return mixed */ public static function addAdminUser($form, $model, $cid, $roles,$type=0) { $adu = new AdminUsers(); if (!$cid) { return '-2'; } $row = $model::find($cid);
//>>1.添加前,去查询是否已存在相同的帐号
$count = $adu->where(['username' => $form->phone])->count(); if ($count) { $row->delete(); return '-1'; } //>>2.添加登陆帐号
$adu->username = $form->phone; $adu->password = Hash::make(substr($form->phone, -5)); $adu->name = $form->name; $adu->status = $form->status; $res = $adu->save(); if (!$res) { //删除刚添加数据
$row->delete(); return '-2'; } //>>3.将帐号id关联
$row->admin_user_id = $adu->id; $row->save();
//>>4.添加到admin roles中
$lanzu_role = AdminRoles::where('slug', $roles)->first(); $aru = new AdminRoleUsers(); $aru->role_id = $lanzu_role->id; $aru->user_id = $adu->id; $aru->save();
//>>5.生成可提现金额信息
LanzuUserBalance::create($adu->id, $type); }
/** * 获取登陆账号对应的市场ID * @return bool|mixed */ public static function getMarket() { $adu = Admin::user(); $row = LanzuAdminUserMarket::where('admin_user_id',$adu->id)->first(); if ($row){ return $row->market_id; } return false; }}
|