<?php
/**
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class MemberExtensionController extends BaseController
{
    public function index()
    {
        $map = array();
        $pid = I('pid');
        $sid = I('sid');
        if (!empty($pid)) {
            if (is_numeric($pid)) {
                $where_m['id|username'] = array(intval($pid), array('like', '%' . $pid . '%'), '_multi' => true);
            } else if (!empty($pid)) {
                $where_m['username'] = array('like', '%' . (string)$pid . '%');
            }
            $m_list = M('Member')->where($where_m)->field('id')->select();
            if (!empty($m_list)) {
                foreach ($m_list as $k => $v) {
                    $me_list[] = $v['id'];
                }
                $map['pid'] = array(array('in', $me_list));
            }
        }
        if (!empty($sid)) {
            if (is_numeric($sid)) {
                $where_u['id|username'] = array(intval($sid), array('like', '%' . $sid . '%'), '_multi' => true);
            } else if (!empty($sid)) {
                $where_u['username'] = array('like', '%' . (string)$sid . '%');
            }
            $user_list = M('Member')->where($where_u)->field('id')->select();
            if (!empty($user_list)) {
                foreach ($user_list as $k => $v) {
                    $u_list[] = $v['id'];
                }
                $map['sid'] = array(array('in', $u_list));
            }
        }
        $list = $this->lists('MemberExtension', $map);
        $this->assign('list', $list);
        $this->display();
    }
}
?>