88 lines
2.6 KiB
PHP
88 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年9月13日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common\auth;
|
|
|
|
use app\models\auth\Role;
|
|
use app\models\auth\RolePermission;
|
|
use app\models\Model;
|
|
use app\models\User;
|
|
use yii\data\Pagination;
|
|
use app\components\SiteHelper;
|
|
|
|
|
|
class CommonRoleListForm extends Model
|
|
{
|
|
public $keywords;
|
|
public $limit;
|
|
public $page;
|
|
|
|
public $cx_mch_id;
|
|
public $creator_user_id;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords'], 'trim'],
|
|
[['keywords'], 'string'],
|
|
[['page', 'limit', 'cx_mch_id', 'creator_user_id'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$query = Role::find()->alias('ar')
|
|
->leftJoin(['arp' => RolePermission::tableName()],'arp.role_id=ar.id')
|
|
->leftJoin(['u' => User::tableName()],'u.id=ar.creator_user_id')
|
|
->where([
|
|
'ar.cx_mch_id' => $this->cx_mch_id,
|
|
'ar.is_delete' => 0,
|
|
])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['LIKE', 'ar.name', $this->keywords],
|
|
['LIKE', 'ar.remark', $this->keywords],
|
|
])
|
|
->andFilterWhere([
|
|
'ar.creator_user_id' => $this->creator_user_id
|
|
])
|
|
->select('ar.id,ar.creator_user_id,ar.name,ar.remark,ar.created_at,ar.updated_at,u.nickname as creator_nickname');
|
|
$count_query = clone $query;
|
|
$count = $count_query->count();
|
|
$pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['ar.created_at' => SORT_DESC])->asArray()->all();
|
|
foreach ($list as $index => $item){
|
|
$item['created_at_cn'] = date('Y-m-d H:i:s',$item['created_at']);
|
|
$item['updated_at_cn'] = date('Y-m-d H:i:s',$item['updated_at']);
|
|
$list[$index] = $item;
|
|
}
|
|
//是否已经全部加载
|
|
$end_flag = $this->page > $pagination->pageCount ? true : false;
|
|
return [
|
|
'code' => 0,
|
|
'msg' => 'ok',
|
|
'data' => $list,
|
|
'count' => $count,
|
|
'page_size' => $this->limit,
|
|
'page_count' => $pagination->pageCount,
|
|
'page_no' => $this->page,
|
|
'end_flag' => $end_flag
|
|
];
|
|
}
|
|
}
|
|
|