123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace app\model;
- use think\Model;
- class UsersRoles extends Model
- {
- protected $connection = 'mysql';
- protected $pk = 'id';
- protected $name = 'users_roles';
- public static function getsonid($id)
- {
- $data = self::where(['weid' => weid(), 'pid' => $id])
- ->select()->toArray();
- $returndata = '';
- if (!empty($data)) {
- foreach ($data as $vo) {
- if ($returndata) {
- $returndata = $returndata . "," . $vo['id'];
- } else {
- $returndata = $vo['id'];
- }
- }
- }
- if (!empty($returndata)) {
- return explode(',', $returndata);
- }
- }
- public static function getadminids()
- {
- $data = self::where(['weid' => weid(), 'sid' => 0, 'ocid' => 0])
- ->field('id,title')->select()->toArray();
- $returndata = '';
- if (!empty($data)) {
- foreach ($data as $vo) {
- if ($returndata) {
- $returndata = $returndata . "," . $vo['id'];
- } else {
- $returndata = $vo['id'];
- }
- }
- }
- if (!empty($returndata)) {
- return explode(',', $returndata);
- }
- }
- public static function getallarray($where = [])
- {
- $query = self::where([
- 'weid' => weid(),
- 'ocid' => (int) $where['ocid'],
- 'tzid' => (int) $where['tzid'],
- 'sid' => (int) $where['sid']
- ])->field('id,title')->order('id asc');
- $list = $query->select()->toArray();
- if (empty($list)) {
- UsersRoles::datainitial();
- $list = $list = $query->select()->toArray();
- }
- $array = [];
- foreach ($list as $k => $v) {
- $array[$k]['val'] = $v['id'];
- $array[$k]['key'] = $v['title'];
- }
- return $array;
- }
- public static function getpcarray($where = [])
- {
- $data = self::field('id,pid,title')->where([
- 'weid' => weid(),
- 'ocid' => (int) $where['ocid'],
- 'tzid' => (int) $where['tzid'],
- 'sid' => (int) $where['sid']
- ])->order('id asc')->select()->toArray();
- $datalist = [];
- foreach ($data as $key => $vo) {
- $datalist[$key]['val'] = $vo['id'];
- $datalist[$key]['key'] = $vo['title'];
- $datalist[$key]['pid'] = $vo['pid'];
- }
- return $datalist;
- }
- public static function getPid($id)
- {
- $data = self::find($id);
- if (!empty($data)) {
- return $data->pid;
- }
- }
- public static function getdatarules($role_id)
- {
- $UsersRoles = self::find($role_id);
- if (!empty($UsersRoles)) {
- return $UsersRoles->datarules;
- }
- }
- public static function getinfo($user)
- {
- $UsersRoles = [];
- if ($user['role_id'] == 0) {
- if ($user['username'] == 'admin') {
- $UsersRoles['title'] = '创始人';
- $UsersRoles['is_console'] = 1;
- $UsersRoles['is_allrole'] = 1;
- $UsersRoles['access'] = 'all';
- $UsersRoles['status'] = 1;
- } elseif (!empty($user['sid'])) {
- //店铺创始人
- $storeusers = Users::where(['sid' => $user['sid']])->order('id asc')->find();
- if ($storeusers->uuid == $user['uuid']) {
- $UsersRoles['title'] = '店铺创始人';
- $UsersRoles['is_allrole'] = 1;
- $UsersRoles['access'] = 'all';
- $UsersRoles['status'] = 1;
- }
- } elseif (!empty($user['ocid'])) {
- //城市代理创始人
- $storeusers = Users::where(['ocid' => $user['ocid']])->order('id asc')->find();
- if ($storeusers->uuid == $user['uuid']) {
- $UsersRoles['title'] = '城市代理创始人';
- $UsersRoles['is_allrole'] = 1;
- $UsersRoles['access'] = 'all';
- $UsersRoles['status'] = 1;
- }
- } elseif (!empty($user['tzid'])) {
- //社区
- $storeusers = Users::where(['tzid' => $user['tzid']])->order('id asc')->find();
- if ($storeusers->uuid == $user['uuid']) {
- $UsersRoles['title'] = '社区创始人';
- $UsersRoles['is_allrole'] = 1;
- $UsersRoles['access'] = 'all';
- $UsersRoles['status'] = 1;
- }
- } else {
- $group_access = \think\facade\Db::name('auth_group_access')->where('uid', $user['id'])->find();
- if (!empty($group_access)) {
- $group = \think\facade\Db::name('auth_group')->where('id', $group_access['group_id'])->find();
- if (!empty($group)) {
- $UsersRoles = self::where(['title' => $group['name']])->find();
- if (!empty($UsersRoles)) {
- Users::update(['id' => $user['id'], 'role_id' => $UsersRoles['id']]);
- }
- }
- }
- }
- } else {
- $UsersRoles = self::find($user['role_id']);
- if (!empty($UsersRoles)) {
- $UsersRoles = $UsersRoles->toArray();
- if ($UsersRoles['weid'] > 0) {
- $UsersRoles['is_console'] = 0;
- }
- if (weid() > 0 && $UsersRoles['is_console'] == 1) {
- $UsersRoles['access'] = 'all';
- }
- if ($UsersRoles['is_allrole'] == 1) {
- $UsersRoles['access'] = 'all';
- }
- }
- }
- return $UsersRoles;
- }
- public static function datainitial()
- {
- $weid = weid();
- self::create([
- 'weid' => $weid,
- 'title' => '超级管理员',
- 'access' => 'all',
- 'status' => 1
- ]);
- }
- }
|