Exemplo n.º 1
0
function HasAdmin($uid, $post_id)
{
    //圈主可对圈子里面的说说进行管理
    //判断方法  member_post.community_id > community.table_id > school.id > school.group_member_id
    $post = M('member_post')->where(array('id' => $post_id))->find();
    if (!$post) {
        if (IsDebug()) {
            echo '//说说不存在';
        }
        return false;
    }
    if (0 != $post['pid']) {
        $post = M('member_post')->where(array('id' => $post['pid']))->find();
    }
    if (0 == $post['community_id']) {
        if (IsDebug()) {
            echo '//说说不属于任何圈子';
        }
        return false;
    }
    $community = M('community')->where(array('id' => $post['community_id']))->find();
    if (!$community) {
        if (IsDebug()) {
            echo '圈子不存在';
        }
        return false;
    }
    $school = M('school')->where(array('id' => $community['table_id']))->find();
    if (!$school) {
        if (IsDebug()) {
            echo '学校不存在';
        }
        return false;
    }
    if ($uid == $school['group_member_id']) {
        return true;
    } else {
        if (3 == $school['type']) {
        }
        if (IsDebug()) {
            echo '不是学校的圈主uid: ' . $uid . 'group_member_id: ' . $school['group_member_id'];
        }
        return false;
    }
}
 /**
  * 通用分页列表数据集获取方法
  *
  * 可以通过url参数传递where条件,例如:  index.html?name=asdfasdfasdfddds
  * 可以通过url空值排序字段和方式,例如: index.html?_field=id&_order=asc
  * 可以通过url参数r指定每页数据条数,例如: index.html?r=5
  *
  * @param sting|Model  $model   模型名或模型实例
  * @param array        $where   where查询条件(优先级: $where>$_REQUEST>模型设定)
  * @param array|string $order   排序条件,传入null时使用sql默认排序或模型属性(优先级最高);
  * 请求参数中如果指定了_order和_field则据此排序(优先级第二);
  * 否则使用$order参数(如果$order参数,且模型也没有设定过order,则取主键降序);
  *
  * @param array        $base    基本的查询条件
  * @param boolean      $field   单表模型用不到该参数,要用在多表join时为field()方法指定参数
  * @author 朱亚杰 <*****@*****.**>
  *
  * @return array|false
  * 返回数据集
  */
 protected function lists($model, $where = array(), $order = '', $base = array('status' => array('egt', 0)), $field = true, $page_num = 1)
 {
     $options = array();
     $REQUEST = (array) I('request.');
     if (is_string($model)) {
         $model = M($model);
     }
     $OPT = new \ReflectionProperty($model, 'options');
     $OPT->setAccessible(true);
     $pk = $model->getPk();
     if ($order === null) {
         //order置空
     } else {
         if (isset($REQUEST['_order']) && isset($REQUEST['_field']) && in_array(strtolower($REQUEST['_order']), array('desc', 'asc'))) {
             $options['order'] = '`' . $REQUEST['_field'] . '` ' . $REQUEST['_order'];
         } elseif ($order === '' && empty($options['order']) && !empty($pk)) {
             $options['order'] = $pk . ' desc';
         } elseif ($order) {
             $options['order'] = $order;
         }
     }
     unset($REQUEST['_order'], $REQUEST['_field']);
     $options['where'] = array_filter(array_merge((array) $base, (array) $where), function ($val) {
         if ($val === '' || $val === null) {
             return false;
         } else {
             return true;
         }
     });
     if (empty($options['where'])) {
         unset($options['where']);
     }
     $options = array_merge((array) $OPT->getValue($model), $options);
     $total = $model->where($options['where'])->count();
     $pageCount = ceil($total / $this->pageSize);
     if ($pageCount < $_GET['p']) {
         $_GET['p'] = $pageCount;
     }
     $page = new \Think\Page($total, $this->pageSize);
     $options['limit'] = $page->firstRow . ',' . $page->listRows;
     $model->setProperty('options', $options);
     $result = $model->field($field)->select();
     if (IsDebug()) {
         echo $model->getLastSql();
     }
     //echo $model->getLastSql();
     return array($page->totalRows, $page->listRows, $pageCount, $result);
 }