<?php

namespace app\admin\model;

use think\Model;


/**
 * 分组模型
 */
class Users extends Model
{
    public function getByGroup($group = 0)
    {
        if ($group) {
            return $this->where(['group_id' => $group])->select();
        } else {
            return $this->all();
        }
    }

    public function groupinfo()
    {
        return $this->belongsTo('Groups', 'group_id', 'id');
    }

    public function getUidsBygid($groupid = 0, $pre = 0, $returnobj = 0)
    {
        $ret = $this->getByGroup($groupid);

        $return = [];
        if ($ret) {
            foreach ($ret as $val) {
                $return['uids'][] = $pre ? 'KF' . $val->id : $val->id;
                if ($returnobj) {
                    $return['objs'][$val->id] = $val;
                }
            }
            if (!$returnobj) {
                return $return['uids'];
            }
            return $return;
        } else {
            return false;
        }

    }

}
