100], [['salt'], 'string', 'max' => 4], [['phone', 'login_ip','ext_phone','enter_date','job_date','ext_pay','try_pay','try_rate'], 'string', 'max' => 50], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'username' => 'Username', 'password' => 'Password', 'salt' => 'Salt', 'name' => 'Name', 'phone' => 'Phone', 'login_time' => 'Login Time', 'login_ip' => 'Login Ip', 'is_delete' => 'Is Delete', 'is_locked' => 'Is Locked', 'is_login' => 'Is Login', 'is_send' => 'Is Send', 'group_id' => 'Group ID', 'phone_server_id' => 'Phone Server ID', 'ext_phone' => 'Ext Phone', 'role_id' => 'Role ID', 'is_double' => 'Is Double', 'enter_date' => 'Enter Date', 'job_date' => 'Job Date', 'ext_pay' => 'Ext Pay', 'try_pay' => 'Try Pay', 'try_rate' => 'Try Rate', 'worktype_id' => 'Work Type', 'business_group_id' => 'Business Group Id', 'is_leave' => 'Is Leave', 'department_id' => 'Department ID', 'company_id' => 'Company ID', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getGroup() { return $this->hasOne(GroupT::className(),['id'=>'group_id']); } public function getLeftMenus() { $menus = array(); if($this->id == 1) { $menu_items = MenuT::find() ->where('parent_id=0') ->orderBy('order_id ASC') ->all(); foreach($menu_items as $item) { $row = $item->toArray(); $child_items = MenuT::find() ->where('parent_id='.$item->id) ->orderBy('order_id ASC') ->all(); $sub = array(); foreach($child_items as $child) { $sub_row = $child->toArray(); $sub[] = $sub_row; } $row['children'] = $sub; $menus[] = $row; } } else { $menu_items = $this->getMenus() ->where('parent_id=0') ->orderBy('order_id ASC') ->all(); foreach($menu_items as $item) { $row = $item->toArray(); $child_items = $this->getMenus() ->where('parent_id='.$item->id) ->orderBy('order_id ASC') ->all(); $sub = array(); foreach($child_items as $child) { $sub_row = $child->toArray(); $sub[] = $sub_row; } $row['children'] = $sub; $menus[] = $row; } } return $menus; } public function getAllMenus() { $menus = array(); $menu_items = MenuT::find() ->where('parent_id=0') ->orderBy('order_id ASC') ->all(); foreach($menu_items as $item) { $row = $item->toArray(); $child_items = MenuT::find() ->where('parent_id='.$item->id) ->orderBy('order_id ASC') ->all(); $sub = array(); foreach($child_items as $child) { $sub_row = $child->toArray(); $sub[] = $sub_row; } $row['children'] = $sub; $menus[] = $row; } return $menus; } public function getShowName() { return $this->username.'('.$this->name.')'; } public function getChildren($otherSql = '',$isAdmin=0) { if($otherSql != '') $otherSql = ' and '.$otherSql; if($this->id == 1 || $isAdmin == 1) { $items = UserT::find() ->where('is_delete=0'.$otherSql) ->orderBy('username ASC') ->all(); return $items; } else { $items = GroupT::getTree($this->group_id); $group_ids = array(); foreach($items as $item) { $group_ids[] = $item->id; } $items = UserT::find() ->where(['in','group_id',$group_ids]) ->andWhere('is_delete=0'.$otherSql) ->orderBy('username ASC') ->all(); return $items; } } public function getPhoneServer() { return $this->hasOne(PhoneServerT::className(),['id'=>'phone_server_id']); } public function getRole() { return $this->hasOne(RoleT::className(),['id'=>'role_id']); } public function getPermissions() { return $this->hasMany(PermissionsT::className(),['id'=>'permission_id']) ->viaTable('permissions_user_t',['user_id'=>'id']); } public function getMenus() { return $this->hasMany(MenuT::className(),['id'=>'menu_id']) ->viaTable('menu_user_t',['user_id'=>'id']); } public function getWorktype() { return $this->hasOne(WorktypeT::className(),['id'=>'worktype_id']); } public function getPay($pay_date) { $pay = PayT::findOne(['user_id'=>$this->id,'pay_date'=>$pay_date]); return $pay; } public function getChildrenUserIDs() { $user_ids = array(); $user_items = $this->getChildren(); if($user_items) { foreach($user_items as $item) { $user_ids[] = $item->id; } } // $user_ids[] = $this->my->id; return $user_ids; } public function getBusinessGroup() { return $this->hasOne(BusinessGroupT::className(),['id' => 'business_group_id']); } public function getDepartment() { return $this->hasOne(DepartmentT::className(),['id'=>'department_id']); } public function getCompany() { return $this->hasOne(CompanyT::className(),['id'=>'company_id']); } public function getChildrenClean($otherSql = '',$isAdmin=0) { if($otherSql != '') $otherSql = ' and '.$otherSql; if($this->id == 1 || $isAdmin == 1) { $items = UserT::find() ->where('is_delete=0'.$otherSql) ->andWhere('group_id in(123)') ->orderBy('username ASC') ->all(); return $items; } else { $items = GroupT::getTree($this->group_id); $group_ids = array(); foreach($items as $item) { $group_ids[] = $item->id; } $items = UserT::find() ->andWhere('group_id in(123)') // ->andWhere('id in(656,657,658,659,155)') ->andWhere('is_delete=0'.$otherSql) ->orderBy('username ASC') ->all(); return $items; } } }