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

116 lines
4.2 KiB

<?php
namespace apps\base\controllers;
use base\Config;
use classes\ecshop;
use classes\mysql;
use classes\error;
use classes\session;
use classes\session_memcached;
abstract class BackendController extends BaseController
{
public function __construct()
{
parent::__construct();
define('__TPL__', __ROOT__ . 'data/assets/console/');
// 全局常量
require BASE_PATH . 'config/constant.php';
// 加载helper文件
$helper_list = array('time', 'base', 'common', 'main', 'insert', 'goods');
$this->load_helper($helper_list);
// 全局对象
$this->db_config = Config::get('DB.default');
$this->ecs = $GLOBALS['ecs'] = new ecshop($this->db_config['DB_NAME'], $this->db_config['DB_PREFIX']);
$this->db = $GLOBALS['db'] = new mysql();
if (!defined('INIT_NO_USERS')) {
$this->sess = $GLOBALS['sess'] = new session($this->db, $this->ecs->table('sessions'), $this->ecs->table('sessions_data'));
/*if($this->cache->cache == 'memcached' && C('CACHE.memcached.CACHE_TYPE') == 'Memcached'){
$this->sess = $GLOBALS['sess'] = new session_memcached($this->db, $this->ecs->table('sessions'), $this->ecs->table('sessions_data'));
}
else{
$this->sess = $GLOBALS['sess'] = new session($this->db, $this->ecs->table('sessions'), $this->ecs->table('sessions_data'));
}*/
define('SESS_ID', $this->sess->get_session_id());
}
$this->checkLogin();
}
public function display($tpl = '', $return = false, $isTpl = true)
{
$tpl = $this->getTpl($tpl, $isTpl);
return parent::display($tpl, $return, $isTpl);
}
/**
* 操作成功之后跳转,默认三秒钟跳转
*
* @param unknown $msg
* @param unknown $url
* @param string $type
* @param number $waitSecond
*/
public function message($msg, $url = NULL, $type = '1', $waitSecond = 3)
{
if ($url == NULL)
$url = 'javascript:history.back();';
if ($type == '2') {
$title = '错误信息';
} else {
$title = '提示信息';
}
$data['title'] = $title;
$data['message'] = $msg;
$data['type'] = $type;
$data['url'] = $url;
$data['second'] = $waitSecond;
$this->assign('data', $data);
$this->display('admin/message');
exit();
}
//上传文件
protected function ectouchUpload($key = '', $upload_dir = 'images') {
$config = array(
'maxSize' => 1024 * 1024 * 2,
'allowExts' => explode(',', 'jpg,jpeg,gif,png,bmp,mp3,amr,mp4'),
'rootPath' => ROOT_PATH,
'savePath' => 'data/attached/' . $upload_dir . "/",
);
$upload = new \libraries\Upload($config);
if (!$upload->upload($key)) {
return array('error' => 1, 'message' => $upload->getError());
}
else{
//$fileInfo = $upload->getUploadFileInfo();
return array('error' => 0, 'message' => $upload->getUploadFileInfo());
}
}
private function checkLogin()
{
$condition['user_id'] = isset($_SESSION['admin_id']) ? intval($_SESSION['admin_id']):0;
$action_list = $this->model->table('admin_user')->field('action_list')->where($condition)->one();
//手机端权限
if(empty($action_list) && strpos(APP_NAME, $actin_list) === FALSE && $action_list != 'all'){
$this->redirect('../admin/index.php?act=main');
}
}
private function getTpl($tpl = '', $isTpl = false)
{
if ($isTpl) {
$tpl = empty($tpl) ? strtolower(CONTROLLER_NAME) . C('TPL.TPL_DEPR') . strtolower(ACTION_NAME) : $tpl;
$base_themes = ROOT_PATH . 'source/apps/base/views/';
if (file_exists($base_themes . $tpl . C('TPL.TPL_SUFFIX'))) {
$tpl = 'source/apps/base/views/' . $tpl;
} else {
$tpl = 'source/apps/' . APP_NAME . '/views/' . $tpl;
}
}
return $tpl;
}
}