| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 07/03/2017
- * Time: 10:40
- */
- namespace app\common\models\user;
- use app\common\models\BaseModel;
- use app\platform\modules\application\models\AppUser;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class YzRole extends BaseModel
- {
- use SoftDeletes;
- public $table = 'yz_role';
- const ROLE_ENABLE = 2;
- const ROLE_DISABLE = 1;
- /**
- * 定义字段名
- * 可使
- * @return array */
- public function atributeNames() {
- return [
- 'name'=> '角色名称',
- ];
- }
- /**
- * 字段规则
- * @return array */
- public function rules() {
- return [
- 'name' => 'required',
- ];
- }
- //这个好像没有用,应该可以删除,待确认
- public function UserPermistions()
- {
- return $this->hasMany('app\common\models\user\YzPermission');
- }
- public function roleUser()
- {
- return $this->hasMany('app\common\models\user\YzUserRole', 'role_id');
- }
- public function rolePermission()
- {
- return $this->hasMany('app\common\models\user\YzPermission', 'item_id');
- }
- /**
- * @param int $pageSize
- * @return object
- */
- public static function getPageList($pageSize,$search)
- {
- $query = static::uniacid();
- if ($search['keyword']) {
- $query = $query->where('name', 'like', $search['keyword'] . '%');
- }
- if ($search['status']) {
- $query = $query->where('status', $search['status']);
- }
-
- $uids = AppUser::where('role','manager')->pluck('uid')->toArray();
-
- return $query->with(['roleUser'=>function($q) use ($uids){
- $q->whereNotIn('user_id',$uids);
- }])->paginate($pageSize);
- }
- public static function getRolelistToUser()
- {
- return static::select('id', 'name')->uniacid()->where('status', '=', "2")->get()->toArray();
- }
- /**
- * Get full role information and role permissions By roleId
- *
- * @param int $roleId
- * @return object
- */
- public static function getRoleById($roleId)
- {
- return static::where('id', $roleId)
- ->with(['rolePermission' => function($query) {
- return $query->select('id', 'item_id','permission')->where('type', '=', YzPermission::TYPE_ROLE);
- }])
- ->first();
- }
- /**
- * @param int $roleId
- * @return \mysqli_result
- */
- public static function deleteRole($roleId)
- {
- return static::where('id', $roleId)->delete();
- }
- }
|