GameController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php
  2. /**
  3. * GameController.php UTF-8
  4. * 游戏管理
  5. *
  6. * @date : 2020/9/14 15:02
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : H5IOS 1.0
  11. */
  12. namespace huosdk\h5ios\admin\controller;
  13. use cmf\view\Filter;
  14. use huolib\status\CommonStatus;
  15. use huolib\tool\Page;
  16. use huosdk\h5ios\admin\validate\GameValidate;
  17. use huosdk\h5ios\core\constant\CommonConst;
  18. use huosdk\h5ios\core\constant\GameConst;
  19. use huosdk\h5ios\core\constant\OrderConst;
  20. use huosdk\h5ios\core\logic\GameLogic;
  21. use huosdk\h5ios\core\logic\GamePriceLogic;
  22. use huosdk\h5ios\core\model\CpModel;
  23. use huosdk\h5ios\core\model\GameModel;
  24. use huosdk\h5ios\core\model\GamePriceModel;
  25. use huosdk\h5ios\core\model\GameversionModel;
  26. use menu\controller\Menu;
  27. class GameController extends CommonController {
  28. protected $classify = GameConst::GAME_IOS_SWITCH_H5;
  29. protected $model_class_name = GameModel::class;
  30. protected $logic_class_name = GameLogic::class;
  31. protected $validate_class_name = GameValidate::class;
  32. protected $is_delete = CommonConst::CONST_NOT_DELETE;
  33. protected $class_name = 'game';
  34. protected $order = '+id';
  35. protected $app_ids = [];
  36. function _initialize() {
  37. $_url = $this->base_url.$this->class_name;
  38. $_game_price_url = $_url.'/gamePrice';
  39. $this->assign('game_price_url', $_game_price_url);
  40. $_param_url = $_url.'/param';
  41. $this->assign('param_url', $_param_url);
  42. $_edit_field_url = $_url.'/editField';
  43. $this->assign('edit_field_url', $_edit_field_url);
  44. $_edit_cp_url = $_url.'/cp';
  45. $this->assign('edit_cp_url', $_edit_cp_url);
  46. $_set_status_url = $_url.'/setStatus';
  47. $this->assign('set_status_url', $_set_status_url);
  48. parent::_initialize();
  49. }
  50. /**
  51. * 安卓游戏列表
  52. * adminh5ios/game/index
  53. *
  54. * @param string $template
  55. *
  56. * @return mixed
  57. */
  58. public function index($template = 'index') {
  59. return parent::index('game/index');
  60. }
  61. /**
  62. * 添加
  63. * adminh5ios/game/add
  64. *
  65. * @param string $template 模板文件
  66. *
  67. * @return mixed
  68. */
  69. public function add($template = 'add') {
  70. $this->_cps();
  71. $this->_games(
  72. 0, 0, CommonConst::CONST_NOT_DELETE, GameConst::GAME_IS_SDK, GameConst::GAME_H5
  73. );
  74. return parent::add('game/add');
  75. }
  76. /**
  77. * 添加操作函数
  78. * adminh5ios/game/addPost
  79. */
  80. public function addPost() {
  81. if ($this->request->isPost()) {
  82. /* 校验参数 */
  83. $_param = $this->request->param();
  84. /*校验参数*/
  85. $_validate = new $this->validate_class_name('add');
  86. if (!$_validate->check($_param)) {
  87. $this->adminError($_validate->getError());
  88. }
  89. /* 逻辑处理 */
  90. /* 转换 传入的H5游戏id */
  91. $_param['parent_id'] = get_val($_param, 'app_id', 0);
  92. $_param['classify'] = $this->classify;
  93. unset($_param['app_id']);
  94. $_rs = (new $this->model_class_name())->addData($_param);
  95. if (false === $_rs) {
  96. return $this->adminError(lang('ADD_FAILED'));
  97. }
  98. return $this->adminSuccess(lang('ADD_SUCCESS'));
  99. } else {
  100. $_code = CommonStatus::INVALID_PARAMS;
  101. return $this->adminError(CommonStatus::getMsg($_code));
  102. }
  103. }
  104. /**
  105. * 添加操作函数
  106. * adminh5ios/game/edit
  107. *
  108. * @param string $template 模板文件
  109. *
  110. * @return mixed
  111. */
  112. public function edit($template = 'edit') {
  113. return parent::edit($template);
  114. }
  115. /**
  116. * 编辑操作函数
  117. * adminh5ios/game/editPost
  118. */
  119. public function editPost() {
  120. return parent::editPost();
  121. }
  122. /**
  123. * 删除
  124. * adminh5ios/game/delete
  125. */
  126. public function delete() {
  127. return parent::delete();
  128. }
  129. /**
  130. * 排序 排序字段为list_orders数组 POST 排序字段为:list_order
  131. * adminh5ios/game/listOrders
  132. *
  133. * @param $model
  134. * @param string $field
  135. */
  136. public function listOrders($model = null, $field = 'list_order') {
  137. parent::listOrders($model, $field);
  138. }
  139. /**
  140. * 单个设置状态
  141. * adminh5ios/game/setStatus
  142. */
  143. public function setStatus() {
  144. parent::setStatus();
  145. }
  146. /**
  147. * 编辑字段值
  148. * adminh5ios/game/editField
  149. */
  150. public function editField() {
  151. $_field = $this->request->param('field/s', '');
  152. $_app_id = $this->request->param('id/d', 0);
  153. if (empty($_field) || empty($_app_id)) {
  154. $_code = CommonStatus::INVALID_PARAMS;
  155. return $this->adminError(CommonStatus::getMsg($_code));
  156. }
  157. $_data = (new GameModel())->getInfoById($_app_id);
  158. $this->assign('data', $_data);
  159. $this->assign('field', $_field);
  160. if ('parent_id' == $_field) {
  161. $this->_games(
  162. $_data['parent_id'], 0, CommonConst::CONST_NOT_DELETE, GameConst::GAME_IS_SDK, GameConst::GAME_H5
  163. );
  164. }
  165. return $this->fetch('game/edit_field');
  166. }
  167. /**
  168. * 编辑字段值提交
  169. * adminh5ios/game/editFieldPost
  170. */
  171. public function editFieldPost() {
  172. if ($this->request->isPost()) {
  173. /* 校验参数 */
  174. $_param = $this->request->param();
  175. $_field = $this->request->param('field/s', '');
  176. switch ($_field) {
  177. case 'apple_id':
  178. $_scene = 'editAppleId';
  179. break;
  180. case 'name':
  181. $_scene = 'editName';
  182. break;
  183. case 'cp_payback_url':
  184. $_scene = 'editCpPaybackUrl';
  185. break;
  186. case 'parent_id':
  187. $_scene = 'link_h5_game';
  188. $_param['parent_id'] = $this->request->param('app_id/d', 0);
  189. unset($_param['app_id']);
  190. break;
  191. default:
  192. $_code = CommonStatus::INVALID_PARAMS;
  193. return $this->adminError(CommonStatus::getMsg($_code));
  194. }
  195. /*校验参数*/
  196. $_validate = new GameValidate($_scene);
  197. if (!$_validate->check($_param)) {
  198. return $this->adminError($_validate->getError());
  199. }
  200. unset($_param['field']);
  201. /* 逻辑处理 */
  202. $_rs = (new GameModel())->updateData($_param, $_param['id']);
  203. if (false === $_rs) {
  204. return $this->adminError(lang('EDIT_FAILED'));
  205. }
  206. return $this->adminSuccess(lang('EDIT_SUCCESS'));
  207. } else {
  208. $_code = CommonStatus::INVALID_PARAMS;
  209. return $this->adminError(CommonStatus::getMsg($_code));
  210. }
  211. }
  212. /**
  213. * 编辑CP处理
  214. * adminh5ios/game/cp
  215. */
  216. public function cp() {
  217. $_app_id = $this->request->param('id/d', 0);
  218. if (empty($_app_id)) {
  219. $_code = CommonStatus::INVALID_PARAMS;
  220. return $this->adminError(CommonStatus::getMsg($_code));
  221. }
  222. $_data = (new GameModel())->getInfoById($_app_id);
  223. $this->assign('data', $_data);
  224. $this->_cps($_data['cp_id']);
  225. return $this->fetch('game/cp');
  226. }
  227. /**
  228. * 编辑CP提交
  229. * adminh5ios/game/cpPost
  230. */
  231. public function cpPost() {
  232. if ($this->request->isPost()) {
  233. /* 校验参数 */
  234. $_param = $this->request->param();
  235. /*校验参数*/
  236. $_validate = new GameValidate('cp');
  237. if (!$_validate->check($_param)) {
  238. return $this->adminError($_validate->getError());
  239. }
  240. /* 逻辑处理 */
  241. $_data['cp_id'] = $_param['cp_id'];
  242. $_rs = (new GameModel())->updateData($_data, $_param['id']);
  243. if (false === $_rs) {
  244. return $this->adminError(lang('EDIT_FAILED'));
  245. }
  246. return $this->adminSuccess(lang('EDIT_SUCCESS'));
  247. } else {
  248. $_code = CommonStatus::INVALID_PARAMS;
  249. return $this->adminError(CommonStatus::getMsg($_code));
  250. }
  251. }
  252. /**
  253. * 获取对接参数
  254. * adminh5ios/game/param
  255. */
  256. public function param() {
  257. $_app_id = $this->request->param('id/d', 0);
  258. if (empty($_app_id)) {
  259. $this->adminError(lang('PARAM_ERROR'));
  260. }
  261. $_game_data = (new $this->model_class_name())->getInfoById($_app_id);
  262. $_gv_data = (new GameversionModel())->getDefaultInfoByAppId($_app_id);
  263. $this->assign('game', $_game_data);
  264. $this->assign('gv', $_gv_data);
  265. return $this->fetch('game/param');
  266. }
  267. /**
  268. * 计费点设置列表
  269. * adminh5ios/game/gamePrice
  270. */
  271. public function gamePrice() {
  272. $_app_id = $this->request->param('id/d', 0);
  273. if (empty($_app_id)) {
  274. $_code = CommonStatus::INVALID_PARAMS;
  275. $this->adminError(CommonStatus::getMsg($_code));
  276. }
  277. $_game_data = (new GameModel())->getInfoById($_app_id);
  278. $this->assign('game', $_game_data);
  279. $_map['app_id'] = $_app_id;
  280. $_data = (new GamePriceLogic())->getAdminList($_map, '1,'.CommonConst::CONST_MAX_INT);
  281. $_items = (new Page())->paginate($_data['count'], $_data['list'], 1, CommonConst::CONST_MAX_INT);
  282. $this->assign('page', $_items->render());
  283. $this->assign('items', $_items->items());
  284. $this->assign('app_id', $_app_id);
  285. $this->assign('new_frame', 0);
  286. return $this->fetch('game/game_price');
  287. }
  288. /**
  289. * 计费点编辑
  290. * adminh5ios/game/gamePricePost
  291. */
  292. public function gamePricePost() {
  293. if ($this->request->isPost()) {
  294. $_param = $this->request->param();
  295. if (empty($_param['app_id'])
  296. || empty($_param['product_name'])
  297. || empty($_param['product_code'])
  298. || empty($_param['ch_product_code'])
  299. || empty($_param['product_price'])) {
  300. $_code = CommonStatus::INVALID_PARAMS;
  301. $this->adminError(CommonStatus::getMsg($_code));
  302. }
  303. $_data = [];
  304. foreach ($_param['product_code'] as $_k => $_v) {
  305. if (empty($_v) || empty($_param['product_price'][$_k]) || empty($_param['product_name'][$_k])) {
  306. continue;
  307. }
  308. $_data[] = [
  309. 'app_id' => $_param['app_id'],
  310. 'product_code' => $_v,
  311. 'ch_product_code' => $_param['ch_product_code'][$_k],
  312. 'product_price' => $_param['product_price'][$_k],
  313. 'product_name' => $_param['product_name'][$_k],
  314. ];
  315. }
  316. if (empty($_data)) {
  317. $_code = CommonStatus::INVALID_PARAMS;
  318. $this->adminError(CommonStatus::getMsg($_code));
  319. }
  320. /* 先删除原有计费点 */
  321. $_gp_model = new GamePriceModel();
  322. $_rs = $_gp_model->deleteDataByAppId($_param['app_id']);
  323. if (true == $_rs) {
  324. $_rs = (new GamePriceModel())->addDatas($_data);
  325. }
  326. if (false === $_rs) {
  327. $this->adminError(lang('ADD_FAILED'));
  328. }
  329. return $this->adminSuccess(lang('EDIT_SUCCESS'));
  330. } else {
  331. return $this->adminError(lang('PARAM_ERROR'));
  332. }
  333. }
  334. /**
  335. * 搜索参数
  336. * return array
  337. */
  338. protected function getSearchParam() {
  339. $_param = parent::getSearchParam();
  340. $_param['is_delete'] = $this->is_delete;
  341. /* 游戏搜索 */
  342. $_param['id'] = $this->request->param('app_id/d', 0);
  343. $this->_games(
  344. $_param['id'],
  345. 0,
  346. $this->is_delete,
  347. 0,
  348. $this->classify,
  349. false,
  350. true
  351. );
  352. /* 游戏状态搜索 */
  353. $_param['status'] = $this->request->param('status/d', 0);
  354. $this->_gameStatus();
  355. /* CP搜索 */
  356. $_param['cp_id'] = $this->request->param('cp_id/d', 0);
  357. $this->_cps($_param['cp_id']);
  358. /* 支付切换搜索 */
  359. $_param['pay_switch'] = $this->request->param('pay_switch/d', 0);
  360. $this->_paySwitch($_param['pay_switch']);
  361. /* 支付切换搜索 */
  362. $_param['classify'] = $this->request->param('classify/d', $this->classify);
  363. $this->_gameClassifies($_param['classify']);
  364. return $_param;
  365. }
  366. /**
  367. * 游戏状态
  368. */
  369. protected function _gameStatus() {
  370. $_game_status = [
  371. GameConst::GAME_STATUS_ACCESS => lang('GAME_STATUS_ACCESS'),
  372. GameConst::GAME_STATUS_ON => lang('GAME_STATUS_ON'),
  373. GameConst::GAME_STATUS_OFF => lang('GAME_STATUS_OFF'),
  374. ];
  375. $_game_status_select = Filter::selectCommon($_game_status, 'status', $this->request->get('status/d', 0));
  376. $this->assign('game_status', $_game_status);
  377. $this->assign('game_status_select', $_game_status_select);
  378. return $_game_status;
  379. }
  380. /**
  381. * 关联公司名称
  382. *
  383. * @param int $cp_id
  384. *
  385. * @return array
  386. */
  387. protected function _cps($cp_id = 0) {
  388. $_cps = (new CpModel())->getIdNames();
  389. $_cps_select = Filter::selectCommon($_cps, 'cp_id', $cp_id);
  390. $this->assign('cps_select', $_cps_select);
  391. $this->assign('cps', $_cps);
  392. return $_cps;
  393. }
  394. /**
  395. * 支付切换选择
  396. *
  397. * @param int $pay_switch 默认
  398. *
  399. * @return array
  400. */
  401. protected function _paySwitch($pay_switch = 0) {
  402. $_pay_switch_arr = [
  403. OrderConst::PAY_SWITCH_YES => lang('PAY_SWITCH_YES'),
  404. OrderConst::PAY_SWITCH_NO => lang('PAY_SWITCH_NO')
  405. ];
  406. $this->assign('pay_switch', $_pay_switch_arr);
  407. $_is_pay_switch = Filter::radioCommon($_pay_switch_arr, 'pay_switch', $pay_switch);
  408. $this->assign('is_pay_switch_radio', $_is_pay_switch);
  409. $_pay_switch_select = Filter::selectCommon($_pay_switch_arr, 'pay_switch', $pay_switch);
  410. $this->assign('pay_switch_select', $_pay_switch_select);
  411. return $_pay_switch_arr;
  412. }
  413. /**
  414. * 添加菜单
  415. * adminh5ios/game/addMenu
  416. *
  417. * @param int $parent_id
  418. * @param int $list_order
  419. *
  420. * @return int
  421. */
  422. public function addMenu($parent_id = 0, $list_order = 0) {
  423. $_controller = 'game';/* 控制器名 */
  424. $_name = 'IOS马甲'; /* 菜单名称 */
  425. $_en_name = 'Ios Vb'; /* 菜单英文名称 */
  426. $_icon = 'apple'; /* 菜单图标 */
  427. $_app = $this->app; /* 应用名 */
  428. $_menu_class = new Menu();
  429. $_menu_class->setApp($_app);
  430. /* 删除原有菜单 */
  431. $_menu_class->deleteMenu($_controller, $_app);
  432. /* 添加菜单入口 */
  433. $_manage_id = $_menu_class->addManage($_controller, $parent_id, $list_order, $_name, $_en_name, $_icon);
  434. /* 默认菜单 */
  435. $_index_id = $_menu_class->addDefaultMenu($_controller, $_manage_id, 1000, $_name, $_en_name, $_icon, 1, 1);
  436. {
  437. /* 修改字段 */
  438. $_menu_class->addTop(
  439. $_controller, $_index_id, 900, '修改字段', 'editField', '', 'editField', '', 1, 0
  440. );
  441. /* 修改字段提交 */
  442. $_menu_class->addTop(
  443. $_controller, $_index_id, 900, '修改字段提交', 'editFieldPost', '', 'editFieldPost', '', 1, 0
  444. );
  445. /* 修改CP */
  446. $_menu_class->addTop(
  447. $_controller, $_index_id, 800, '修改CP', 'cp', '', 'cp', '', 1, 0
  448. );
  449. /* 修改字段提交 */
  450. $_menu_class->addTop(
  451. $_controller, $_index_id, 800, '修改CP提交', 'cpPost', '', 'cpPost', '', 1, 0
  452. );
  453. /* 获取对接参数 */
  454. $_menu_class->addTop(
  455. $_controller, $_index_id, 700, '获取对接参数', 'Get Param', '', 'param', '', 1, 0
  456. );
  457. /* 计费点 */
  458. $_menu_class->addTop(
  459. $_controller, $_index_id, 600, '计费点', 'gamePrice', '', 'gamePrice', '', 1, 0
  460. );
  461. /* 计费点提交 */
  462. $_menu_class->addTop(
  463. $_controller, $_index_id, 600, '计费点提交', 'gamePricePost', '', 'gamePricePost', '', 1, 0
  464. );
  465. }
  466. (new PaySwitchController())->addMenu($_index_id, 500);
  467. /* 语言包 */
  468. (new \admin\admin\controller\MenuController())->exportMenuLang();
  469. return $_manage_id;
  470. }
  471. }