You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.0 KiB
PHP

<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends HomeController{
protected function _initialize()
{
parent::_initialize();
$this->login();
$map['id'] = get_pid();
$pro = M("promote", "tab_")->where($map)->find();
$pid = is_login_promote();
define('PLEVEL', $pro['parent_id']);
define('PID', $pid);
define('PROMOTE_ACCOUNT',session('promote_auth.account'));
if($pro['grand_id']>0) {/* 三级 */
define('PRO_GRADE',3);
} elseif($pro['parent_id']>0) {/* 二级 */
define('PRO_GRADE',2);
define('SETTLEMENT_GRADE','third_status'); /* 给三级结算 */
define('G_SETTLEMENT_GRADE','third_status');
} else {/* 一级 */
define('PRO_GRADE',1);
define('SETTLEMENT_GRADE','sub_status'); /* 给二级结算 */
define('G_SETTLEMENT_GRADE','sub_status,third_status');
}
$this->assign("parent_id", $pro['parent_id']);
$this->assign("grand_id", $pro['grand_id']);
$result = M('site_apply','tab_')->where("promote_id=$pid")->getField('status');
if($result['status'] == 1) {
$this -> assign('noapplysite', $result);
}
if (in_array(CONTROLLER_NAME,array('SiteBase','SiteGame','SiteGift','SiteGroup','SiteServer','SiteAdv'))) {
if ($result != 1) {
$this->redirect('SiteApply/index',array('msg'=>1));
}
}
}
/* 用户登录检测 */
protected function login(){
/* 用户登录检测 */
is_login_promote() || $this->error('您还没有登录,请先登录!', U('Index/index'));
}
/**
* 显示指定模型列表数据
* @param String $model 模型标识
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function lists($model = null, $p = 0, $extend_map = array(), \Closure $appendCallback = null){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//获取模型信息
$model = M('Model')->getByName($model);
$model || $this->error('模型不存在!');
//解析列表规则
$fields = array();
// 关键字搜索
$map = $extend_map;
$key = $model['search_key']?$model['search_key']:'title';
if(isset($_REQUEST[$key])){
$map[$key] = array('like','%'.$_GET[$key].'%');
unset($_REQUEST[$key]);
}
// 条件搜索
foreach($_REQUEST as $name=>$val){
if(in_array($name,$fields)){
$map[$name] = $val;
}
}
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$name = parse_name(get_table_name($model['id']), true);
$data = M($name,"tab_")
/* 查询指定字段,不指定则查询所有字段 */
->field(empty($fields) ? true : $fields)
// 查询条件
->where($map)
/* 默认通过id逆序排列 */
->order($model['need_pk']?'id DESC':'')
/* 数据分页 */
->page($page, $row)
/* 执行查询 */
->select();
/* 查询记录总数 */
$count = M($name,"tab_")->where($map)->count();
//分页
$parameter = $_POST;
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
$hasList = false;
if ($appendCallback) {
$appends = $appendCallback($data);
foreach ($appends as $key => $value) {
if ($key == 'list_data') {
$hasList = true;
}
$this->assign($key, $value);
}
}
$this->assign("count",$count);
$this->assign('model', $model);
$this->assign('list_grids', $grids);
if ($hasList == false) {
$this->assign('list_data', $data);
}
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function data_lists($p,$model,$extend=[]){
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$model = D($model);
// 条件搜索
$map = [];
foreach(I('get.') as $name=>$val){
$map[$name] = $val;
}
$map = array_merge($map,$extend['map']);
$lists_data = $model->where($map)->page($page,$row)->order($extend['order'])->select();
$count = $model->where($map)->count();
//分页
$parameter = $_POST;
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
$this->assign('lists_data',$lists_data);
$this->assign('count',$count);
$this->display();
}
/**
* @author ELF<360197197@qq.com>
* 分页方法(请勿擅自修改)
*/
public function paginate($query, $defaultPageSize = 10, $defaultPage = 1)
{
$page = I('get.p', $defaultPage);
$pageSize = I('get.row', $defaultPageSize);
$countQuery = clone $query;
$count = $countQuery->count();
$records = $query->page($page, $pageSize)->select();
$params = [
'p' => $page,
'row' => $pageSize
];
$params = array_merge($params, $_POST);
$params = array_merge($params, $_GET);
$pagination = set_pagination($count, $pageSize, $params);
return [$records, $pagination, $count];
}
public function getRecordsByIds($query, $ids, $params = [])
{
if (count($ids) == 0) {
return [];
}
$field = isset($params['field']) ? $params['field'] : 'id';
$indexBy = isset($params['indexBy']) ? $params['indexBy'] : '';
$items = $query->where([$field => ['in', $ids]])->select();
$records = [];
if ($indexBy) {
foreach ($items as $item) {
$records[$item[$field]] = $item;
}
return $records;
}
return $items;
}
public function getColumnsByIds($query, $ids, $column, $params = [])
{
if (count($ids) == 0) {
return [];
}
$field = isset($params['field']) ? $params['field'] : 'id';
$indexBy = isset($params['indexBy']) ? $params['indexBy'] : '';
$items = $query->where([$field => ['in', $ids]])->select();
$records = [];
if ($indexBy) {
foreach ($items as $item) {
$records[$item[$field]] = $item[$column];
}
} else {
foreach ($items as $item) {
$records[] = $item[$column];
}
}
return $records;
}
public function getLoginPromote()
{
$promoteId = session('promote_auth.pid');
return M('promote', 'tab_')->where(['id' => $promoteId])->find();
}
}