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.
simple-yewu/common/models/UserT.php

294 lines
8.7 KiB

5 years ago
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "user_t".
*
* @property integer $id
* @property string $username
* @property string $password
* @property string $salt
* @property string $name
* @property string $phone
* @property integer $login_time
* @property string $login_ip
* @property integer $is_delete
* @property integer $is_locked
* @property integer $is_login
* @property integer $is_send
* @property integer $group_id
* @property integer $phone_server_id
* @property string $ext_phone
* @property integer $role_id
* @property string $enter_date
* @property string $job_date
* @property string $ext_pay
* @property string $try_pay
* @property string $try_rate
* @property integer $worktype_id
* @property integer $is_leave
* @property string $created_at
* @property string $updated_at
* @property integer $is_double
* @property string $business_group_id
* @property integer $department_id
* @property integer $company_id
* @property integer $is_outer
*/
class UserT extends \common\models\Base
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user_t';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'password', 'salt','role_id'], 'required'],
[['login_time', 'is_delete', 'is_locked', 'is_login', 'is_send', 'group_id','phone_server_id','role_id','worktype_id','is_leave','business_group_id', 'is_double','department_id','company_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['username', 'password', 'name'], 'string', 'max' => 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;
}
}
}