// +---------------------------------------------------------------------- namespace cmf\controller; use cmf\view\Filter; use huo\controller\agent\Agent; use huo\logic\agent\AgentLogic; use huo\logic\game\GameLogic; use huo\logic\member\CpLogic; use huo\model\conf\PaywayModel; use huo\model\conf\QqConfModel; use huo\model\game\GameModel; use huo\model\user\RoleModel; use huo\model\user\UserModel; use huolib\constant\AgentConst; use huolib\constant\CommonConst; use huolib\constant\GameConst; use huolib\constant\OrderConst; use huolib\status\CommonStatus; use huolib\tool\StrUtils; use huolib\tool\Time; class AdminBaseController extends BaseController { protected $role_type; protected $total_div; protected $admin_id; protected $page = 0; /* 页面 */ protected $list_rows = 0; /* 分页 */ protected $map = ['agent_id' => 0]; protected $back_url = ''; /*返回地址*/ protected $lang_index = ''; protected $lang_add = ''; protected $lang_edit = ''; protected $new_frame = 1; protected $app = 'admin'; public function _initialize() { // 监听admin_init hook('admin_init'); parent::_initialize(); $session_admin_id = session('ADMIN_ID'); if (!empty($session_admin_id)) { $user = (new UserModel())->where(['id' => $session_admin_id])->find(); if (!$this->checkAccess($session_admin_id)) { $this->error("您没有访问权限!"); } $this->assign("admin", $user); } else { if ($this->request->isPost()) { $this->error("您还没有登录!", url("admin/public/login")); } else { header("Location:".url("admin/public/login")); exit(); } } $this->page = $this->request->param('page/d', 1); $this->list_rows = $this->request->param('list_rows/d', config('paginate.list_rows')); $this->admin_id = cmf_get_current_admin_id(); $this->role_type = (new Agent())->getRoleType($this->admin_id); $this->total_div = ''; $this->assign('is_agent', $this->isAgent()); $this->assign('no_frame', ''); if (AgentConst::ROLE_TYPE_PC == $this->role_type || $this->isAgent()) { /* 查找拥有的渠道ID */ $_agent_ids = (new AgentLogic())->getAgentIds($this->admin_id, true); if (!empty($_agent_ids)) { $this->map['agent_id'] = ['in', $_agent_ids]; } } $_module = $this->request->module(); $_controller = $this->request->controller(); if (empty($this->lang_index)) { $this->lang_index = strtoupper($_module.'_'.$_controller.'_index'); } if (empty($this->lang_add)) { $this->lang_add = strtoupper($_module.'_'.$_controller.'_add'); } if (empty($this->lang_edit)) { $this->lang_edit = strtoupper($_module.'_'.$_controller.'_edit'); } $this->assign('lang_index', $this->lang_index); $this->assign('lang_add', $this->lang_add); $this->assign('lang_edit', $this->lang_edit); $this->new_frame = $this->request->param('new_frame/d', $this->new_frame); $this->assign('new_frame', $this->new_frame); } public function _initializeView() { $cmfAdminThemePath = config('cmf_admin_theme_path'); $cmfAdminDefaultTheme = config('cmf_admin_default_theme'); $themePath = "{$cmfAdminThemePath}{$cmfAdminDefaultTheme}"; $root = cmf_get_root(); //使cdn设置生效 $cdnSettings = cmf_get_option('cdn_settings'); if (empty($cdnSettings['cdn_static_root'])) { $viewReplaceStr = [ '__ROOT__' => $root, '__TMPL__' => "{$root}/{$themePath}", '__STATIC__' => STATICSITE.'/admin', '__WEB_ROOT__' => $root ]; } else { $cdnStaticRoot = rtrim($cdnSettings['cdn_static_root'], '/'); $viewReplaceStr = [ '__ROOT__' => $root, '__TMPL__' => "{$cdnStaticRoot}/{$themePath}", '__STATIC__' => "{$cdnStaticRoot}", '__WEB_ROOT__' => $cdnStaticRoot ]; } $viewReplaceStr = array_merge(config('view_replace_str'), $viewReplaceStr); config('template.view_base', "$themePath/"); config('view_replace_str', $viewReplaceStr); } /** * 初始化后台菜单 */ public function initMenu() { } /** * 检查后台用户访问权限 * * @param int $userId 后台用户id * * @return boolean 检查通过返回true */ private function checkAccess($userId) { // 如果用户id是1,则无需判断 if ($userId == 1) { return true; } $module = $this->request->module(); $controller = $this->request->controller(); $action = $this->request->action(); $rule = $module.$controller.$action; $notRequire = ["adminIndexindex", "adminMainindex"]; if (!in_array($rule, $notRequire)) { return cmf_auth_check($userId); } else { return true; } } /** * 获得QQ群列表 * * @param int $qq * * @return array * @author chenbingling * @date 2018/5/9 11:54 */ protected function _getQqGroups($qq = 0) { $_qqs = (new QqConfModel())->getQqIdName(GameConst::QQ_TYPE_QQ_GROUP); $this->assign('qqgroup_list', $_qqs); $_qqgroup_select = Filter::selectCommon($_qqs, 'qq_id', $qq); $this->assign('qqgroup_select', $_qqgroup_select); return $_qqs; } /** * 获得QQ列表 * * @param int $qq * * @return array * @author chenbingling * @date 2018/5/9 11:54 */ protected function _getQqs($qq = 0) { $_qqs = (new QqConfModel())->getQqIdName(GameConst::QQ_TYPE_QQ); $this->assign('qq_list', $_qqs); $_qq_select = Filter::selectCommon($_qqs, 'qq_id', $qq); $this->assign('qq_select', $_qq_select); return $_qqs; } /** * 游戏列表 * * @param int $app_id * @param int $status * @param int $is_delete * @param int $is_sdk * @param $classify * @param bool $game_flag * @param bool $add_plat * @param array $where * @param string $page * @param string $disable * * @param string $name * * @return array */ protected function _games($app_id = 0, $status = 0, $is_delete = 0, $is_sdk = 0, $classify = 0, $game_flag = false, $add_plat = true, $where = [], $page = '', $disable = '', $name = 'app_id') { if (is_numeric($status)) { $where['status'] = $status; } if (is_numeric($is_delete)) { $where['is_delete'] = $is_delete; } if (is_numeric($is_sdk)) { $where['is_sdk'] = $is_sdk; } if (is_numeric($classify) && $classify) { $where['classify'] = $classify; } elseif (is_array($classify)) { $where['classify'] = ['in', $classify]; } if (is_numeric($game_flag)) { $where['game_flag'] = $game_flag; } if (true == $add_plat) { $where['add_plat'] = $add_plat; } $_games = (new GameLogic())->getIdNames($where, $page); $this->assign('games', $_games); $_games_select = Filter::selectCommon($_games, $name, $app_id, 'select_2', $disable); $this->assign('games_select', $_games_select); return $_games; } /** * 获取所有一二级渠道 * * @param $agent_id * @param bool $inc_me * @param array $role_type * @param bool $inc_nice * * @return array */ protected function _agents($agent_id, $inc_me = false, $role_type = [3, 4], $inc_nice = true) { if (1 == count($role_type) && AgentConst::isGroup($role_type['0'])) { $_parents = (new AgentLogic())->getIdNames($this->admin_id, $inc_me, $role_type, $inc_nice); $_parents_select = Filter::selectCommon($_parents, 'parent_id', $agent_id); $this->assign('parents_select', $_parents_select); return $_parents; } else { $_agents[-1] = '官方渠道'; /* 添加官方渠道筛选 */ if (AgentConst::ROLE_TYPE_ADMIN != $this->role_type) { $_agents = (new AgentLogic())->getIdNames($this->admin_id, $inc_me, $role_type, $inc_nice); } else { $_agents += (new AgentLogic())->getIdNames($this->admin_id, $inc_me, $role_type, $inc_nice); } $this->assign('agents', $_agents); $_agents_select = Filter::selectCommon($_agents, 'agent_id', $agent_id); $this->assign('agents_select', $_agents_select); return $_agents; } } protected function _agentsByRoleId($agent_id, $role_id = []) { $_agents[-1] = '官方渠道'; /* 添加官方渠道筛选 */ $_agents += (new AgentLogic())->getIdNamesByRoleId($role_id, true); $this->assign('agents', $_agents); $_agents_select = Filter::selectCommon($_agents, 'agent_id', $agent_id); $this->assign('agents_select', $_agents_select); return $_agents; } /** * 获取cp * * @param $cp * @param bool $all * * @return array */ protected function _cp($cp, $all = false) { $_cpnames = (new CpLogic())->getNamesById(); /*搜索*/ $_cp_select = Filter::selectCommon($_cpnames, 'cp', $cp); $this->assign('cp_select', $_cp_select); $this->assign('cp', $_cpnames); if ($all) { return $_cpnames; } if (empty($_cpnames[$cp])) { return false; } return $_cpnames[$cp]; } /** * 时间选择器 * * @param string $start_time * @param string $end_time * @param bool $inc_month * @param bool $inc_end * * @return array */ protected function _time($start_time = '', $end_time = '', $inc_month = false, $inc_end = true) { $_time_range = $this->request->param('time_range/s', '', 'trim'); switch ($_time_range) { case 'today': $_start_time = date('Y-m-d'); $_end_time = date('Y-m-d'); break; case 'yesterday': $_start_time = date('Y-m-d', strtotime('-1 days')); $_end_time = date('Y-m-d', strtotime('-1 days')); break; case 'seven_days': $inc_end = true; list($_start_time, $_end_time) = Time::lastSeven(); $_start_time = date('Y-m-d', $_start_time); $_end_time = date('Y-m-d', $_end_time); break; case 'this_week': $inc_end = true; list($_start_time, $_end_time) = Time::week(); $_start_time = date('Y-m-d', $_start_time); $_end_time = date('Y-m-d', $_end_time); break; case 'last_week': $inc_end = true; list($_start_time, $_end_time) = Time::lastWeek(); $_start_time = date('Y-m-d', $_start_time); $_end_time = date('Y-m-d', $_end_time); break; case 'this_month': $inc_end = true; list($_start_time, $_end_time) = Time::month(); $_start_time = date('Y-m-d', $_start_time); $_end_time = date('Y-m-d', $_end_time); break; case 'last_month': $inc_end = true; list($_start_time, $_end_time) = Time::lastMonth(); $_start_time = date('Y-m-d', $_start_time); $_end_time = date('Y-m-d', $_end_time); break; case 'thirty_days': $inc_end = true; list($_start_time, $_end_time) = Time::lastThirty(); $_start_time = date('Y-m-d', $_start_time); $_end_time = date('Y-m-d', $_end_time); break; default: if ($inc_month) { $_start_time = $this->request->param('start_time', date('Y-m-d', strtotime('-1 month'))); } else { $_start_time = $this->request->param('start_time/s', $start_time, 'trim'); } $_end_time = $this->request->param('end_time/s', $end_time, 'trim'); break; } $this->assign('time_range', $_time_range); if (empty($_end_time)) { $_end_time = date('Y-m-d'); } if (true == $inc_end) { $_time_choose = Filter::timeChoose($_start_time, $_end_time, 'yyyy-mm-dd'); } else { $_end_time = $_start_time; $_time_choose = Filter::timeChoose2($_start_time, 'start_time', lang('END_TIME'), 'yyyy-mm-dd'); } $this->assign('time_choose', $_time_choose); return [$_start_time, $_end_time]; } /** * 日期转时间筛选 * * @param null $start_time * @param null $end_time * * @return array */ protected function _dateToTime($start_time = null, $end_time = null) { if (!empty($start_time) && !empty($end_time)) { return [ 'between', [ strtotime($start_time), strtotime($end_time.' +1 day') ] ]; } elseif (!empty($start_time)) { return ['egt', strtotime($start_time)]; } elseif (!empty($end_time)) { return ['elt', strtotime($end_time.' +1 day')]; } return []; } /** * 日期到日期筛选 * * @param null $start_time * @param null $end_time * * @return array */ protected function _dateToDate($start_time = null, $end_time = null) { if (!empty($start_time) && !empty($end_time)) { return [ 'between', [ $start_time, $end_time ] ]; } elseif (!empty($start_time)) { return ['egt', $start_time]; } elseif (!empty($end_time)) { return ['elt', $end_time]; } return []; } /** * 角色选择器 * * @param $role_id */ public function _roles($role_id) { $_map['role_type'] = ['in', [3, 4]]; $_roles = (new RoleModel())->getIdNames($_map, true); $this->assign('roles', $_roles); $this->assign('roles_select', Filter::selectCommon2($_roles, 'role_id', $role_id, 'name')); } /** * 角色类型选择器 * * @param int $role_type */ public function _roleTypes($role_type = 0) { $_role_types = AgentConst::getAgentRoleTypeMsg(0, true); $this->assign('role_types', $_role_types); $this->assign('role_types_select', Filter::selectCommon($_role_types, 'role_type', $role_type)); $this->assign('role_types_radio', Filter::radioCommon($_role_types, 'role_type', $role_type)); } /** * 推广状态选择器 * * @param $promote_switch */ public function _promotes($promote_switch) { $_promotes = GameConst::getPromotes(); $this->assign('promotes', $_promotes); $this->assign('promotes_select', Filter::selectCommon($_promotes, 'promote_switch', $promote_switch)); } /** * 获取所有的游戏客户端 * * @param $classify */ protected function _gameClassifies($classify) { $_classifies = GameConst::getClassifyMsg($classify, true); $this->assign('classifies', $_classifies); $_classifies_select = Filter::selectCommon($_classifies, 'classify', $classify); $this->assign('classifies_select', $_classifies_select); } /** * 支付方式选择器 * * @param string $payname */ public function _payways($payname) { $_payways = (new PaywayModel())->getPayWaysByPayName(); $this->assign('payways', $_payways); $this->assign('payways_select', Filter::selectCommon($_payways, 'payway', $payname)); } /** * 支付状态选择器 * * @param int $status */ public function _pay_statuses($status) { $_pay_statuses = OrderConst::getPayStatuss(); $this->assign('pay_statuses', $_pay_statuses); $this->assign('pay_statuses_select', Filter::selectCommon($_pay_statuses, 'status', $status)); } /** * 通用状态选中器 * * @param int $status * * @return array|bool|mixed */ public function _status($status = CommonConst::CONST_ZERO) { $_status_arr = CommonConst::getStatusMsg($status, true); $_status_select = Filter::selectCommon($_status_arr, 'status', $status); $this->assign('statuses', $_status_arr); $this->assign('status_select', $_status_select); return $_status_arr; } /** * * 校验操作员支付密码 * * @param string $pay_pwd * * @return bool */ protected function verifyPayPwd($pay_pwd = '') { if (empty($pay_pwd)) { $pay_pwd = $this->request->param('pay_pwd/s', ''); } $_rs = (new Agent())->checkPayPwd($this->admin_id, $pay_pwd); if (CommonStatus::NO_ERROR != $_rs['code']) { $this->adminError('支付密码错误'); } return true; } /** * 判断是否存在错误 * * @param $rs * * @return bool */ protected function hasError($rs) { if (!isset($rs['code'])) { return true; } if ($rs['code'] != CommonStatus::NO_ERROR) { return true; } return false; } /** * 遍历数组移除两边空格 * * @param $data * * @return array */ public function trimAll($data) { if (empty($data) || !is_array($data)) { return $data; } foreach ($data as $_k => $_v) { $data[$_k] = StrUtils::trimAll($_v); } return $data; } /** * 判断当前登陆是否为渠道 * * @return bool */ public function isAgent() { $role_type = [AgentConst::ROLE_TYPE_GROUP, AgentConst::ROLE_TYPE_AGENT]; if (in_array($this->role_type, $role_type)) { return true; } return false; } /** * 渠道类型 * * @param string $_type * * @return void */ public function _agentChargeType($_type = '') { $_agent_charge_type = AgentConst::getAgentChargeType(); $this->assign('agent_charge_type', $_agent_charge_type); $this->assign( 'agent_charge_type_select', Filter::selectCommon($_agent_charge_type, 'agent_charge_type', $_type) ); } protected function includeAgent($include_agent = '2') { $_include_agent_arr = [ '2' => '是', '1' => '否' ]; $_include_select = Filter::selectCommon($_include_agent_arr, 'include_agent', $include_agent); $this->assign('include_select', $_include_select); } /** * 判断当前登陆是否为渠道 * * @return bool */ public function isAdmin() { $role_type = [AgentConst::ROLE_TYPE_ADMIN, AgentConst::ROLE_TYPE_MANAGER]; if (in_array($this->role_type, $role_type)) { return true; } return false; } /** * 马甲包关联游戏列表 * * @param int $app_id * @param array $where * @param string $disable * * @return array */ protected function _mp_games( $app_id = 0, $where = [], $disable = '' ) { if (false == $this->isAdmin()) { return true; } $_app_ids = (new GameModel())->getMpVestReGameId(); $where['id'] = ['in', $_app_ids]; $_vest_re_games = (new GameLogic())->getIdNames($where); $this->assign('vest_re_games', $_vest_re_games); $_vest_re_games_select = Filter::selectCommon($_vest_re_games, 'vset_re_app_id', $app_id, 'select_2', $disable); $this->assign('vest_re_games_select', $_vest_re_games_select); return $_vest_re_games; } }