AdminBaseController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +---------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace cmf\controller;
  12. use cmf\view\Filter;
  13. use huo\controller\agent\Agent;
  14. use huo\logic\agent\AgentLogic;
  15. use huo\logic\game\GameLogic;
  16. use huo\logic\member\CpLogic;
  17. use huo\model\conf\PaywayModel;
  18. use huo\model\conf\QqConfModel;
  19. use huo\model\game\GameModel;
  20. use huo\model\user\RoleModel;
  21. use huo\model\user\UserModel;
  22. use huolib\constant\AgentConst;
  23. use huolib\constant\CommonConst;
  24. use huolib\constant\GameConst;
  25. use huolib\constant\OrderConst;
  26. use huolib\status\CommonStatus;
  27. use huolib\tool\StrUtils;
  28. use huolib\tool\Time;
  29. class AdminBaseController extends BaseController {
  30. protected $role_type;
  31. protected $total_div;
  32. protected $admin_id;
  33. protected $page = 0; /* 页面 */
  34. protected $list_rows = 0; /* 分页 */
  35. protected $map = ['agent_id' => 0];
  36. protected $back_url = ''; /*返回地址*/
  37. protected $lang_index = '';
  38. protected $lang_add = '';
  39. protected $lang_edit = '';
  40. protected $new_frame = 1;
  41. protected $app = 'admin';
  42. public function _initialize() {
  43. // 监听admin_init
  44. hook('admin_init');
  45. parent::_initialize();
  46. $session_admin_id = session('ADMIN_ID');
  47. if (!empty($session_admin_id)) {
  48. $user = (new UserModel())->where(['id' => $session_admin_id])->find();
  49. if (!$this->checkAccess($session_admin_id)) {
  50. $this->error("您没有访问权限!");
  51. }
  52. $this->assign("admin", $user);
  53. } else {
  54. if ($this->request->isPost()) {
  55. $this->error("您还没有登录!", url("admin/public/login"));
  56. } else {
  57. header("Location:".url("admin/public/login"));
  58. exit();
  59. }
  60. }
  61. $this->page = $this->request->param('page/d', 1);
  62. $this->list_rows = $this->request->param('list_rows/d', config('paginate.list_rows'));
  63. $this->admin_id = cmf_get_current_admin_id();
  64. $this->role_type = (new Agent())->getRoleType($this->admin_id);
  65. $this->total_div = '';
  66. $this->assign('is_agent', $this->isAgent());
  67. $this->assign('no_frame', '');
  68. if (AgentConst::ROLE_TYPE_PC == $this->role_type || $this->isAgent()) {
  69. /* 查找拥有的渠道ID */
  70. $_agent_ids = (new AgentLogic())->getAgentIds($this->admin_id, true);
  71. if (!empty($_agent_ids)) {
  72. $this->map['agent_id'] = ['in', $_agent_ids];
  73. }
  74. }
  75. $_module = $this->request->module();
  76. $_controller = $this->request->controller();
  77. if (empty($this->lang_index)) {
  78. $this->lang_index = strtoupper($_module.'_'.$_controller.'_index');
  79. }
  80. if (empty($this->lang_add)) {
  81. $this->lang_add = strtoupper($_module.'_'.$_controller.'_add');
  82. }
  83. if (empty($this->lang_edit)) {
  84. $this->lang_edit = strtoupper($_module.'_'.$_controller.'_edit');
  85. }
  86. $this->assign('lang_index', $this->lang_index);
  87. $this->assign('lang_add', $this->lang_add);
  88. $this->assign('lang_edit', $this->lang_edit);
  89. $this->new_frame = $this->request->param('new_frame/d', $this->new_frame);
  90. $this->assign('new_frame', $this->new_frame);
  91. }
  92. public function _initializeView() {
  93. $cmfAdminThemePath = config('cmf_admin_theme_path');
  94. $cmfAdminDefaultTheme = config('cmf_admin_default_theme');
  95. $themePath = "{$cmfAdminThemePath}{$cmfAdminDefaultTheme}";
  96. $root = cmf_get_root();
  97. //使cdn设置生效
  98. $cdnSettings = cmf_get_option('cdn_settings');
  99. if (empty($cdnSettings['cdn_static_root'])) {
  100. $viewReplaceStr = [
  101. '__ROOT__' => $root,
  102. '__TMPL__' => "{$root}/{$themePath}",
  103. '__STATIC__' => STATICSITE.'/admin',
  104. '__WEB_ROOT__' => $root
  105. ];
  106. } else {
  107. $cdnStaticRoot = rtrim($cdnSettings['cdn_static_root'], '/');
  108. $viewReplaceStr = [
  109. '__ROOT__' => $root,
  110. '__TMPL__' => "{$cdnStaticRoot}/{$themePath}",
  111. '__STATIC__' => "{$cdnStaticRoot}",
  112. '__WEB_ROOT__' => $cdnStaticRoot
  113. ];
  114. }
  115. $viewReplaceStr = array_merge(config('view_replace_str'), $viewReplaceStr);
  116. config('template.view_base', "$themePath/");
  117. config('view_replace_str', $viewReplaceStr);
  118. }
  119. /**
  120. * 初始化后台菜单
  121. */
  122. public function initMenu() {
  123. }
  124. /**
  125. * 检查后台用户访问权限
  126. *
  127. * @param int $userId 后台用户id
  128. *
  129. * @return boolean 检查通过返回true
  130. */
  131. private function checkAccess($userId) {
  132. // 如果用户id是1,则无需判断
  133. if ($userId == 1) {
  134. return true;
  135. }
  136. $module = $this->request->module();
  137. $controller = $this->request->controller();
  138. $action = $this->request->action();
  139. $rule = $module.$controller.$action;
  140. $notRequire = ["adminIndexindex", "adminMainindex"];
  141. if (!in_array($rule, $notRequire)) {
  142. return cmf_auth_check($userId);
  143. } else {
  144. return true;
  145. }
  146. }
  147. /**
  148. * 获得QQ群列表
  149. *
  150. * @param int $qq
  151. *
  152. * @return array
  153. * @author chenbingling <cbl@huosdk.com>
  154. * @date 2018/5/9 11:54
  155. */
  156. protected function _getQqGroups($qq = 0) {
  157. $_qqs = (new QqConfModel())->getQqIdName(GameConst::QQ_TYPE_QQ_GROUP);
  158. $this->assign('qqgroup_list', $_qqs);
  159. $_qqgroup_select = Filter::selectCommon($_qqs, 'qq_id', $qq);
  160. $this->assign('qqgroup_select', $_qqgroup_select);
  161. return $_qqs;
  162. }
  163. /**
  164. * 获得QQ列表
  165. *
  166. * @param int $qq
  167. *
  168. * @return array
  169. * @author chenbingling <cbl@huosdk.com>
  170. * @date 2018/5/9 11:54
  171. */
  172. protected function _getQqs($qq = 0) {
  173. $_qqs = (new QqConfModel())->getQqIdName(GameConst::QQ_TYPE_QQ);
  174. $this->assign('qq_list', $_qqs);
  175. $_qq_select = Filter::selectCommon($_qqs, 'qq_id', $qq);
  176. $this->assign('qq_select', $_qq_select);
  177. return $_qqs;
  178. }
  179. /**
  180. * 游戏列表
  181. *
  182. * @param int $app_id
  183. * @param int $status
  184. * @param int $is_delete
  185. * @param int $is_sdk
  186. * @param $classify
  187. * @param bool $game_flag
  188. * @param bool $add_plat
  189. * @param array $where
  190. * @param string $page
  191. * @param string $disable
  192. *
  193. * @param string $name
  194. *
  195. * @return array
  196. */
  197. 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')
  198. {
  199. if (is_numeric($status)) {
  200. $where['status'] = $status;
  201. }
  202. if (is_numeric($is_delete)) {
  203. $where['is_delete'] = $is_delete;
  204. }
  205. if (is_numeric($is_sdk)) {
  206. $where['is_sdk'] = $is_sdk;
  207. }
  208. if (is_numeric($classify) && $classify) {
  209. $where['classify'] = $classify;
  210. } elseif (is_array($classify)) {
  211. $where['classify'] = ['in', $classify];
  212. }
  213. if (is_numeric($game_flag)) {
  214. $where['game_flag'] = $game_flag;
  215. }
  216. if (true == $add_plat) {
  217. $where['add_plat'] = $add_plat;
  218. }
  219. $_games = (new GameLogic())->getIdNames($where, $page);
  220. $this->assign('games', $_games);
  221. $_games_select = Filter::selectCommon($_games, $name, $app_id, 'select_2', $disable);
  222. $this->assign('games_select', $_games_select);
  223. return $_games;
  224. }
  225. /**
  226. * 获取所有一二级渠道
  227. *
  228. * @param $agent_id
  229. * @param bool $inc_me
  230. * @param array $role_type
  231. * @param bool $inc_nice
  232. *
  233. * @return array
  234. */
  235. protected function _agents($agent_id, $inc_me = false, $role_type = [3, 4], $inc_nice = true) {
  236. if (1 == count($role_type) && AgentConst::isGroup($role_type['0'])) {
  237. $_parents = (new AgentLogic())->getIdNames($this->admin_id, $inc_me, $role_type, $inc_nice);
  238. $_parents_select = Filter::selectCommon($_parents, 'parent_id', $agent_id);
  239. $this->assign('parents_select', $_parents_select);
  240. return $_parents;
  241. } else {
  242. $_agents[-1] = '官方渠道'; /* 添加官方渠道筛选 */
  243. if (AgentConst::ROLE_TYPE_ADMIN != $this->role_type) {
  244. $_agents = (new AgentLogic())->getIdNames($this->admin_id, $inc_me, $role_type, $inc_nice);
  245. } else {
  246. $_agents += (new AgentLogic())->getIdNames($this->admin_id, $inc_me, $role_type, $inc_nice);
  247. }
  248. $this->assign('agents', $_agents);
  249. $_agents_select = Filter::selectCommon($_agents, 'agent_id', $agent_id);
  250. $this->assign('agents_select', $_agents_select);
  251. return $_agents;
  252. }
  253. }
  254. protected function _agentsByRoleId($agent_id, $role_id = []) {
  255. $_agents[-1] = '官方渠道'; /* 添加官方渠道筛选 */
  256. $_agents += (new AgentLogic())->getIdNamesByRoleId($role_id, true);
  257. $this->assign('agents', $_agents);
  258. $_agents_select = Filter::selectCommon($_agents, 'agent_id', $agent_id);
  259. $this->assign('agents_select', $_agents_select);
  260. return $_agents;
  261. }
  262. /**
  263. * 获取cp
  264. *
  265. * @param $cp
  266. * @param bool $all
  267. *
  268. * @return array
  269. */
  270. protected function _cp($cp, $all = false) {
  271. $_cpnames = (new CpLogic())->getNamesById();
  272. /*搜索*/
  273. $_cp_select = Filter::selectCommon($_cpnames, 'cp', $cp);
  274. $this->assign('cp_select', $_cp_select);
  275. $this->assign('cp', $_cpnames);
  276. if ($all) {
  277. return $_cpnames;
  278. }
  279. if (empty($_cpnames[$cp])) {
  280. return false;
  281. }
  282. return $_cpnames[$cp];
  283. }
  284. /**
  285. * 时间选择器
  286. *
  287. * @param string $start_time
  288. * @param string $end_time
  289. * @param bool $inc_month
  290. * @param bool $inc_end
  291. *
  292. * @return array
  293. */
  294. protected function _time($start_time = '', $end_time = '', $inc_month = false, $inc_end = true) {
  295. $_time_range = $this->request->param('time_range/s', '', 'trim');
  296. switch ($_time_range) {
  297. case 'today':
  298. $_start_time = date('Y-m-d');
  299. $_end_time = date('Y-m-d');
  300. break;
  301. case 'yesterday':
  302. $_start_time = date('Y-m-d', strtotime('-1 days'));
  303. $_end_time = date('Y-m-d', strtotime('-1 days'));
  304. break;
  305. case 'seven_days':
  306. $inc_end = true;
  307. list($_start_time, $_end_time) = Time::lastSeven();
  308. $_start_time = date('Y-m-d', $_start_time);
  309. $_end_time = date('Y-m-d', $_end_time);
  310. break;
  311. case 'this_week':
  312. $inc_end = true;
  313. list($_start_time, $_end_time) = Time::week();
  314. $_start_time = date('Y-m-d', $_start_time);
  315. $_end_time = date('Y-m-d', $_end_time);
  316. break;
  317. case 'last_week':
  318. $inc_end = true;
  319. list($_start_time, $_end_time) = Time::lastWeek();
  320. $_start_time = date('Y-m-d', $_start_time);
  321. $_end_time = date('Y-m-d', $_end_time);
  322. break;
  323. case 'this_month':
  324. $inc_end = true;
  325. list($_start_time, $_end_time) = Time::month();
  326. $_start_time = date('Y-m-d', $_start_time);
  327. $_end_time = date('Y-m-d', $_end_time);
  328. break;
  329. case 'last_month':
  330. $inc_end = true;
  331. list($_start_time, $_end_time) = Time::lastMonth();
  332. $_start_time = date('Y-m-d', $_start_time);
  333. $_end_time = date('Y-m-d', $_end_time);
  334. break;
  335. case 'thirty_days':
  336. $inc_end = true;
  337. list($_start_time, $_end_time) = Time::lastThirty();
  338. $_start_time = date('Y-m-d', $_start_time);
  339. $_end_time = date('Y-m-d', $_end_time);
  340. break;
  341. default:
  342. if ($inc_month) {
  343. $_start_time = $this->request->param('start_time', date('Y-m-d', strtotime('-1 month')));
  344. } else {
  345. $_start_time = $this->request->param('start_time/s', $start_time, 'trim');
  346. }
  347. $_end_time = $this->request->param('end_time/s', $end_time, 'trim');
  348. break;
  349. }
  350. $this->assign('time_range', $_time_range);
  351. if (empty($_end_time)) {
  352. $_end_time = date('Y-m-d');
  353. }
  354. if (true == $inc_end) {
  355. $_time_choose = Filter::timeChoose($_start_time, $_end_time, 'yyyy-mm-dd');
  356. } else {
  357. $_end_time = $_start_time;
  358. $_time_choose = Filter::timeChoose2($_start_time, 'start_time', lang('END_TIME'), 'yyyy-mm-dd');
  359. }
  360. $this->assign('time_choose', $_time_choose);
  361. return [$_start_time, $_end_time];
  362. }
  363. /**
  364. * 日期转时间筛选
  365. *
  366. * @param null $start_time
  367. * @param null $end_time
  368. *
  369. * @return array
  370. */
  371. protected function _dateToTime($start_time = null, $end_time = null) {
  372. if (!empty($start_time) && !empty($end_time)) {
  373. return [
  374. 'between',
  375. [
  376. strtotime($start_time),
  377. strtotime($end_time.' +1 day')
  378. ]
  379. ];
  380. } elseif (!empty($start_time)) {
  381. return ['egt', strtotime($start_time)];
  382. } elseif (!empty($end_time)) {
  383. return ['elt', strtotime($end_time.' +1 day')];
  384. }
  385. return [];
  386. }
  387. /**
  388. * 日期到日期筛选
  389. *
  390. * @param null $start_time
  391. * @param null $end_time
  392. *
  393. * @return array
  394. */
  395. protected function _dateToDate($start_time = null, $end_time = null) {
  396. if (!empty($start_time) && !empty($end_time)) {
  397. return [
  398. 'between',
  399. [
  400. $start_time,
  401. $end_time
  402. ]
  403. ];
  404. } elseif (!empty($start_time)) {
  405. return ['egt', $start_time];
  406. } elseif (!empty($end_time)) {
  407. return ['elt', $end_time];
  408. }
  409. return [];
  410. }
  411. /**
  412. * 角色选择器
  413. *
  414. * @param $role_id
  415. */
  416. public function _roles($role_id) {
  417. $_map['role_type'] = ['in', [3, 4]];
  418. $_roles = (new RoleModel())->getIdNames($_map, true);
  419. $this->assign('roles', $_roles);
  420. $this->assign('roles_select', Filter::selectCommon2($_roles, 'role_id', $role_id, 'name'));
  421. }
  422. /**
  423. * 角色类型选择器
  424. *
  425. * @param int $role_type
  426. */
  427. public function _roleTypes($role_type = 0) {
  428. $_role_types = AgentConst::getAgentRoleTypeMsg(0, true);
  429. $this->assign('role_types', $_role_types);
  430. $this->assign('role_types_select', Filter::selectCommon($_role_types, 'role_type', $role_type));
  431. $this->assign('role_types_radio', Filter::radioCommon($_role_types, 'role_type', $role_type));
  432. }
  433. /**
  434. * 推广状态选择器
  435. *
  436. * @param $promote_switch
  437. */
  438. public function _promotes($promote_switch) {
  439. $_promotes = GameConst::getPromotes();
  440. $this->assign('promotes', $_promotes);
  441. $this->assign('promotes_select', Filter::selectCommon($_promotes, 'promote_switch', $promote_switch));
  442. }
  443. /**
  444. * 获取所有的游戏客户端
  445. *
  446. * @param $classify
  447. */
  448. protected function _gameClassifies($classify) {
  449. $_classifies = GameConst::getClassifyMsg($classify, true);
  450. $this->assign('classifies', $_classifies);
  451. $_classifies_select = Filter::selectCommon($_classifies, 'classify', $classify);
  452. $this->assign('classifies_select', $_classifies_select);
  453. }
  454. /**
  455. * 支付方式选择器
  456. *
  457. * @param string $payname
  458. */
  459. public function _payways($payname) {
  460. $_payways = (new PaywayModel())->getPayWaysByPayName();
  461. $this->assign('payways', $_payways);
  462. $this->assign('payways_select', Filter::selectCommon($_payways, 'payway', $payname));
  463. }
  464. /**
  465. * 支付状态选择器
  466. *
  467. * @param int $status
  468. */
  469. public function _pay_statuses($status) {
  470. $_pay_statuses = OrderConst::getPayStatuss();
  471. $this->assign('pay_statuses', $_pay_statuses);
  472. $this->assign('pay_statuses_select', Filter::selectCommon($_pay_statuses, 'status', $status));
  473. }
  474. /**
  475. * 通用状态选中器
  476. *
  477. * @param int $status
  478. *
  479. * @return array|bool|mixed
  480. */
  481. public function _status($status = CommonConst::CONST_ZERO) {
  482. $_status_arr = CommonConst::getStatusMsg($status, true);
  483. $_status_select = Filter::selectCommon($_status_arr, 'status', $status);
  484. $this->assign('statuses', $_status_arr);
  485. $this->assign('status_select', $_status_select);
  486. return $_status_arr;
  487. }
  488. /**
  489. *
  490. * 校验操作员支付密码
  491. *
  492. * @param string $pay_pwd
  493. *
  494. * @return bool
  495. */
  496. protected function verifyPayPwd($pay_pwd = '') {
  497. if (empty($pay_pwd)) {
  498. $pay_pwd = $this->request->param('pay_pwd/s', '');
  499. }
  500. $_rs = (new Agent())->checkPayPwd($this->admin_id, $pay_pwd);
  501. if (CommonStatus::NO_ERROR != $_rs['code']) {
  502. $this->adminError('支付密码错误');
  503. }
  504. return true;
  505. }
  506. /**
  507. * 判断是否存在错误
  508. *
  509. * @param $rs
  510. *
  511. * @return bool
  512. */
  513. protected function hasError($rs) {
  514. if (!isset($rs['code'])) {
  515. return true;
  516. }
  517. if ($rs['code'] != CommonStatus::NO_ERROR) {
  518. return true;
  519. }
  520. return false;
  521. }
  522. /**
  523. * 遍历数组移除两边空格
  524. *
  525. * @param $data
  526. *
  527. * @return array
  528. */
  529. public function trimAll($data) {
  530. if (empty($data) || !is_array($data)) {
  531. return $data;
  532. }
  533. foreach ($data as $_k => $_v) {
  534. $data[$_k] = StrUtils::trimAll($_v);
  535. }
  536. return $data;
  537. }
  538. /**
  539. * 判断当前登陆是否为渠道
  540. *
  541. * @return bool
  542. */
  543. public function isAgent() {
  544. $role_type = [AgentConst::ROLE_TYPE_GROUP, AgentConst::ROLE_TYPE_AGENT];
  545. if (in_array($this->role_type, $role_type)) {
  546. return true;
  547. }
  548. return false;
  549. }
  550. /**
  551. * 渠道类型
  552. *
  553. * @param string $_type
  554. *
  555. * @return void
  556. */
  557. public function _agentChargeType($_type = '') {
  558. $_agent_charge_type = AgentConst::getAgentChargeType();
  559. $this->assign('agent_charge_type', $_agent_charge_type);
  560. $this->assign(
  561. 'agent_charge_type_select', Filter::selectCommon($_agent_charge_type, 'agent_charge_type', $_type)
  562. );
  563. }
  564. protected function includeAgent($include_agent = '2') {
  565. $_include_agent_arr = [
  566. '2' => '是',
  567. '1' => '否'
  568. ];
  569. $_include_select = Filter::selectCommon($_include_agent_arr, 'include_agent', $include_agent);
  570. $this->assign('include_select', $_include_select);
  571. }
  572. /**
  573. * 判断当前登陆是否为渠道
  574. *
  575. * @return bool
  576. */
  577. public function isAdmin() {
  578. $role_type = [AgentConst::ROLE_TYPE_ADMIN, AgentConst::ROLE_TYPE_MANAGER];
  579. if (in_array($this->role_type, $role_type)) {
  580. return true;
  581. }
  582. return false;
  583. }
  584. /**
  585. * 马甲包关联游戏列表
  586. *
  587. * @param int $app_id
  588. * @param array $where
  589. * @param string $disable
  590. *
  591. * @return array
  592. */
  593. protected function _mp_games(
  594. $app_id = 0,
  595. $where = [],
  596. $disable = ''
  597. ) {
  598. if (false == $this->isAdmin()) {
  599. return true;
  600. }
  601. $_app_ids = (new GameModel())->getMpVestReGameId();
  602. $where['id'] = ['in', $_app_ids];
  603. $_vest_re_games = (new GameLogic())->getIdNames($where);
  604. $this->assign('vest_re_games', $_vest_re_games);
  605. $_vest_re_games_select = Filter::selectCommon($_vest_re_games, 'vset_re_app_id', $app_id, 'select_2', $disable);
  606. $this->assign('vest_re_games_select', $_vest_re_games_select);
  607. return $_vest_re_games;
  608. }
  609. }