private function _uploadImage($field_name) { $upload = $this->getLibrary('upload'); $folder = server_upload_path(); $upload_path = server_upload_abs_path($folder); //添加文件夹 if (!file_exists($upload_path)) { mkdir($upload_path, DIR_WRITE_MODE, true); } //$allowed_types = '*'; //$config['max_size'] = '2048'; $file_name = time() . rand(1000, 9999); // $this->upload->initialize($config); $upload = $upload->upload($field_name, $file_name, $upload_path, array('allowFileType' => '*')); if (is_int($upload)) { $this->controller->json_return(array('msg' => '', 'state' => 'FAILURE', 'imageid' => 0)); } $abs_path = file_abs_path($folder, $upload['newName']); $hash = md5(file_get_contents($abs_path)); $relative_path = $folder . $upload['newName']; $sizeAry = getimagesize($abs_path); list($width, $height, $type) = $sizeAry; $imageModel = InitPHP::getMysqlDao('image'); //判断图片是否存在 $exists = $imageModel->checkHash($hash); if (!empty($exists)) { //如果存在 $this->controller->json_return(array('url' => upload_url($exists['path']), 'state' => 'SUCCESS', 'imageid' => $exists['id'])); } $image = array('path' => $relative_path, 'size' => $upload['size'], 'width' => $width, 'height' => $height, 'type' => $type, 'hash' => $hash, 'create_time' => time()); $image_id = $imageModel->insert($image); $this->controller->json_return(array('url' => upload_url($relative_path), 'state' => 'SUCCESS', 'imageid' => $image_id)); }
public function __construct() { parent::__construct(); $this->controller_name = $this->getC(); $this->action_name = $this->getA(); $this->module_name = $this->getM(); //访问参数日志记录 $this->_logVisit(); //API统一接口为post提交 if (!$this->controller->is_post()) { $this->outputCom(constHelper::API_STATUS_NEED_POST, '必须为POST请求'); } /** * 请求参数示例 * __ua=Android 4.4.4//MI 3W//26//2.0//865645022129866//////WIFI& * __timestamp=1441854121116& * mobile=13800138000& * __version=2.0& * __device=android&type=2& * __key=67543fd413ce4d281fc93306597acb66 */ $device = $this->p('__device'); //客户端名称 $timestamp = $this->p('__timestamp'); //客户端时间戳 $key = $this->p('__key'); //客户端加密指纹 $session = $this->p('__session'); //客户端SESSION $version = substr($this->p('__version'), 0, 5); //客户端版本 //客户端最低版本号要求 if (strnatcmp($version, constHelper::MIN_VERSION_ALLOWED) < 0) { //客户端需要升级 $this->outputCom(constHelper::API_STATUS_NEED_UPGRADE, '客户端需要升级'); } //检查密钥 $this->_checkSecretKey($device, $timestamp, $key); //判断是否需要验证登录 $needCheck = $this->_checkLogin(); if ($needCheck && empty($session)) { $this->outputCom(constHelper::API_STATUS_NEED_LOGIN, '请先登录'); } //根据session获取用户信息 if (!empty($session)) { $memberModel = InitPHP::getMysqlDao('member'); $this->member = $memberModel->getMemberBySession($session); } //session没有获取到相关信息 也要做跳转 if ($needCheck && empty($this->member)) { $this->outputCom(constHelper::API_STATUS_NEED_LOGIN, '请先登录'); } }
/** * ajax登录 * @author pwstrick */ public function ajaxlogin() { $account = $this->p('name'); $pwd = $this->p('pwd'); $pwd = md5($pwd . constHelper::PWD_KEY); $userModel = InitPHP::getMysqlDao('user', 'mysql/sys'); $account = $userModel->login($account, $pwd); if (empty($account)) { $this->ajaxFailureOutput('用户名或密码不正确'); return; } //保存到session中 $session = $this->getUtil('session'); $session->set(constHelper::ADMIN_SESSION, $account); $this->ajaxSuccessOutput('登录成功'); }
/** * 分组删除 * @author pwstrick */ public function grouplistdel() { $id = (int) $this->p('id'); $groupModel = InitPHP::getMysqlDao('group', 'mysql/sys'); $affected = $groupModel->updateStatusById($id, constHelper::STATUS_DEL); if ($affected > 0) { $this->ajaxSuccessOutput('关闭分组成功'); } else { $this->ajaxFailureOutput('关闭分组失败'); } }
/** * 获取可访问的菜单 */ private function _getMenu() { //提取模块 $moduleModel = InitPHP::getMysqlDao('module', 'mysql/sys'); $rows = $moduleModel->getListByStatus(); $modules = array(); foreach ($rows as $row) { $row['actions'] = array(); $modules[$row['module_key']] = $row; } //提取功能 $actionModel = InitPHP::getMysqlDao('action', 'mysql/sys'); $rows = $actionModel->getMenuList(); $actions = array(); foreach ($rows as $row) { $actions[$row['action_id']] = $row; } $uid = $this->userID(); //提取用户组 $groupUserModel = InitPHP::getMysqlDao('groupUser', 'mysql/sys'); $rows = $groupUserModel->getListByUid($uid); $myGIDs = array(); foreach ($rows as $row) { $myGIDs[$row['group_id']] = $row['group_id']; } //提取用户组权限 $aclGroupModel = InitPHP::getMysqlDao('aclGroup', 'mysql/sys'); $gAcls = array(); foreach ($myGIDs as $gid) { $rows = $aclGroupModel->getListByGroupId($gid); foreach ($rows as $row) { $gAcls[$gid][$row['action_id']] = $row['access']; } } //提取用户权限 $aclUserModel = InitPHP::getMysqlDao('aclUser', 'mysql/sys'); $rows = $aclUserModel->getListByUserId($uid); $userAcls = array(); foreach ($rows as $row) { $userAcls[$row['action_id']] = $row['access']; } //功能清算 - 个人设置 $allowedActions = array(); foreach ($userAcls as $aid => $access) { if (0 == $access) { //清楚用户被禁止的功能 if (array_key_exists($aid, $actions)) { unset($actions[$aid]); } } if (1 == $access) { //保留被允许的功能 if (array_key_exists($aid, $actions)) { $allowedActions[$aid] = $actions[$aid]; } } } //功能清算 - 分组设置, 同一个功能在不同分组中权限设置. 只要有一个分组允许访问. 那么该组内的用户都有权访问. foreach ($gAcls as $gid => $acls) { foreach ($acls as $aid => $access) { if (1 == $access) { if (array_key_exists($aid, $actions)) { $allowedActions[$aid] = $actions[$aid]; } } } } //组织菜单 foreach ($allowedActions as $aid => $row) { if (array_key_exists($row['module_key'], $modules)) { $modules[$row['module_key']]['actions'][$aid] = $row; } } $basic = array('index' => array('action' => 'index', 'icon' => 'home', 'text' => '控制面板')); //将菜单组织成可以当前结构 foreach ($modules as &$module) { $module['text'] = $module['module_name']; if (!empty($module['actions'])) { $module['action'] = '#'; $module['sub'] = []; foreach ($module['actions'] as $action) { $module['sub'][] = array('action' => $action['action_key'], 'text' => $action['action_name'], 'sort' => (int) $action['sort']); } } } $basic = array_merge($basic, $modules); $sorts = array_column($basic, 'sort'); array_multisort($sorts, SORT_ASC, SORT_NUMERIC, $basic); //排序 foreach ($basic as &$menu) { if (empty($menu['sub'])) { continue; } $sorts = array_column($menu['sub'], 'sort'); array_multisort($sorts, SORT_ASC, SORT_NUMERIC, $menu['sub']); //排序 } return $basic; }
public function getUser() { $userModel = InitPHP::getMysqlDao('member'); return 'seec'; }