VersionController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?php
  2. /**
  3. * VersionController.php UTF-8
  4. * APP版本管理
  5. *
  6. * @date : 2017/12/1 17:55
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace admin\admin\controller\app;
  13. use cmf\controller\AdminBaseController;
  14. use huo\controller\game\Gamepack;
  15. use huo\exception\HuoException;
  16. use huo\model\game\GameModel;
  17. use huo\model\game\GameversionModel;
  18. use huolib\constant\CommonConst;
  19. use huolib\constant\GameConst;
  20. use think\Lang;
  21. use think\Validate;
  22. class VersionController extends AdminbaseController {
  23. protected $app_id;
  24. function _initialize() {
  25. parent::_initialize();
  26. Lang::load(
  27. APP_PATH.'admin/lang'.DS.$this->lang.DS.'version'.EXT
  28. );
  29. $this->app_id = $this->request->param('app_id', config('app_app_id'));
  30. }
  31. /**
  32. * 游戏状态
  33. */
  34. public function _versionStatus() {
  35. $_version_status = [
  36. GameConst::GAME_STATUS_ACCESS => lang('not_line'),
  37. GameConst::GAME_STATUS_ON => lang('online'),
  38. GameConst::GAME_STATUS_OFF => lang('offline'),
  39. ];
  40. $this->assign('version_status', $_version_status);
  41. return $_version_status;
  42. }
  43. /**
  44. *
  45. */
  46. public function index() {
  47. $this->getAppInfo();
  48. $this->_versionStatus();
  49. $this->getList($this->app_id);
  50. return $this->fetch();
  51. }
  52. public function getAppInfo() {
  53. $_game_info = GameModel::useGlobalScope(false)
  54. ->where('id', $this->app_id)
  55. ->find()->toArray();
  56. $this->assign('icon', $_game_info['icon']);
  57. return $_game_info;
  58. }
  59. /**
  60. * 添加游戏母包
  61. */
  62. public function addPackageUrl() {
  63. $_ver_id = $this->request->param('id/d', 0);
  64. $_update = $this->request->param('update/d', 0);
  65. $this->assign('back_url', $this->request->server('HTTP_REFERER'));
  66. if (empty($_ver_id)) {
  67. $this->adminError(lang('param error'));
  68. }
  69. $_version_data = $this->getDetail($_ver_id);
  70. if (empty($_version_data)) {
  71. $this->adminError(lang('ERROR'));
  72. }
  73. if (empty($_update) && !empty($_version_data['package_url'])) {
  74. $this->adminSuccess(lang('SUCCESS'));
  75. }
  76. $this->assign($_version_data);
  77. $_game_info = $this->getAppInfo();
  78. if (empty($_game_info)) {
  79. $this->adminError(lang('ERROR'));
  80. }
  81. $this->assign('game', $_game_info);
  82. $_gp_class = new Gamepack($this->app_id);
  83. try {
  84. $_gp_class->setPinyin($_game_info['en_abbr']);
  85. $_gp_class->setAgentgame($_game_info['en_abbr']);
  86. $_gp_class->setVerId($_ver_id);
  87. $_gp_class->pack();
  88. $_data = $_gp_class->getData();
  89. } catch (HuoException $_he) {
  90. $_data = $_he->getData();
  91. }
  92. if (empty($_data)) {
  93. return $this->fetch('app/version/addpackageurl');
  94. }
  95. if (is_array($_data) && isset($_data['size'])) {
  96. $_gv_model = new GameversionModel();
  97. $_map['id'] = $_ver_id;
  98. $_gv_data['package_url'] = $_data['url'];
  99. $_gv_data['size'] = $_data['size'];
  100. $_gv_data['version'] = $_data['vername'];
  101. $_rs = $_gv_model->save($_gv_data, $_map);
  102. if (false !== $_rs) {
  103. $_game_model = new GameModel();
  104. $_g_data['package_name'] = $_data['pakagename'];
  105. $_g_map['id'] = $_version_data['app_id'];
  106. $_game_model->save($_g_data, $_g_map);
  107. $this->redirect($this->request->server('HTTP_REFERER'));
  108. }
  109. }
  110. return $this->fetch('app/version/addpackageurl');
  111. }
  112. /**
  113. * 获取对接参数
  114. */
  115. public function param() {
  116. $_ver_id = $this->request->param('id/d', 0);
  117. if (empty($_ver_id)) {
  118. $this->adminError(lang('param error'));
  119. }
  120. $this->assign($this->getDetail($_ver_id));
  121. return $this->fetch();
  122. }
  123. /**
  124. * @param int $ver_id
  125. *
  126. * @return array
  127. */
  128. public function getDetail($ver_id) {
  129. $_data = GameversionModel::useGlobalScope(false)
  130. ->cache('game_version_'.$ver_id)
  131. ->where('id', $ver_id)
  132. ->find()
  133. ->toArray();
  134. return $_data;
  135. }
  136. public function getList($app_id) {
  137. $_map['app_id'] = $app_id;
  138. $_items = GameversionModel::useGlobalScope(false)
  139. ->where($_map)
  140. ->useSoftDelete('delete_time', ['eq', 0])
  141. ->order('id', 'desc')
  142. ->paginate(10);
  143. $this->assign('page', $_items->render());
  144. $this->assign('items', $_items);
  145. return $_items;
  146. }
  147. /**
  148. * 添加APP
  149. *
  150. * @return string
  151. */
  152. public function addApp() {
  153. $_param['id'] = $this->app_id;
  154. $_param['is_sdk'] = GameConst::GAME_IS_NOT_SDK;
  155. $_param['is_online'] = GameConst::GAME_IS_ON_LINE;
  156. $_param['cp_id'] = 0;
  157. $_param['en_name'] = 'A P P';
  158. $_param['name'] = 'APP';
  159. $_param['is_delete'] = CommonConst::CONST_NOT_DELETE;
  160. $_param['status'] = GameConst::GAME_STATUS_ACCESS;
  161. $_param['delete_time'] = time();
  162. $_game_model = new GameModel();
  163. $_rs = $_game_model->addGames($_param);
  164. if ($_rs) {
  165. return 'success';
  166. }
  167. return 'error';
  168. }
  169. /**
  170. *添加
  171. */
  172. public function add() {
  173. $this->getAppInfo();
  174. return $this->fetch();
  175. }
  176. /**
  177. *添加提交
  178. */
  179. public function addPost() {
  180. if ($this->request->isPost()) {
  181. $_validate = new Validate(
  182. [
  183. 'version' => 'require|token',
  184. ]
  185. );
  186. $_param = $this->request->param();
  187. if (!$_validate->check($_param)) {
  188. $this->adminError($_validate->getError(), $this->request->server('HTTP_REFERER'));
  189. }
  190. $_param['app_id'] = $this->app_id;
  191. $_version_model = new GameversionModel();
  192. $_rs = $_version_model->addVersion($_param);
  193. if ($_rs) {
  194. $_g_data['icon'] = $this->request->param('icon');
  195. GameModel::update($_g_data, ['id' => $this->app_id], true);
  196. $this->adminSuccess(lang('ADD_SUCCESS'), url('admin/public/closeFrame'));
  197. } else {
  198. $this->adminSuccess(lang('ADD_FAILED'));
  199. }
  200. } else {
  201. $this->adminError(lang('REQUEST_ERROR'));
  202. }
  203. }
  204. /**
  205. *添加
  206. */
  207. public function edit() {
  208. $this->getAppInfo();
  209. $_ver_id = $this->request->param('id/d', 0);
  210. if (empty($_ver_id)) {
  211. $this->adminError(lang('param error'));
  212. }
  213. $this->assign($this->getDetail($_ver_id));
  214. return $this->fetch();
  215. }
  216. /**
  217. *添加提交
  218. */
  219. public function editPost() {
  220. if ($this->request->isPost()) {
  221. $_validate = new Validate(
  222. [
  223. 'id' => 'require|number',
  224. 'version' => 'require|token',
  225. ]
  226. );
  227. $_param = $this->request->param();
  228. if (!$_validate->check($_param)) {
  229. $this->adminError($_validate->getError(), $this->request->server('HTTP_REFERER'));
  230. }
  231. $_data['content'] = $this->request->post('content', '');
  232. $_data['version'] = $this->request->post('version', '');
  233. $_map['id'] = $_param['id'];
  234. $_rs = GameversionModel::update($_data, $_map);
  235. if ($_rs) {
  236. $_g_data['icon'] = $this->request->param('icon');
  237. GameModel::update($_g_data, ['id' => $this->app_id], true);
  238. $this->adminSuccess(lang('EDIT_SUCCESS'), url('admin/public/closeFrame'));
  239. } else {
  240. $this->adminSuccess(lang('EDIT_FAILED'));
  241. }
  242. } else {
  243. $this->adminError(lang('REQUEST_ERROR'));
  244. }
  245. }
  246. /**
  247. * 设置状态 上线 下线
  248. */
  249. public function setStatus() {
  250. $_ver_id = $this->request->param('id/d', 0);
  251. $_status = $this->request->param('is_default/d', 1);
  252. if (empty($_ver_id) || empty($_status)) {
  253. $this->adminError(lang('param error'));
  254. }
  255. $_version_data = $this->getDetail($_ver_id);
  256. if (2 == $_status) {
  257. if (empty($_version_data['package_url'])) {
  258. $this->adminError(lang('no_package'));
  259. }
  260. $_msg = lang('online');
  261. } else {
  262. $_msg = lang('offline');
  263. }
  264. $_data['is_default'] = $_status;
  265. $_map['app_id'] = $this->app_id;
  266. $_map['id'] = $_ver_id;
  267. $_version_model = new GameversionModel();
  268. $_rs = $_version_model->allowField(true)->isUpdate(true)->save($_data, $_map);
  269. if (false !== $_rs && 2 == $_status) {
  270. $_map['id'] = ['neq', $_ver_id];
  271. $_data['is_default'] = 3;
  272. $_rs = $_version_model->allowField(true)->isUpdate(true)->save($_data, $_map);
  273. }
  274. if (false === $_rs) {
  275. $this->adminError($_msg.lang('ERROR'));
  276. } else {
  277. $this->adminSuccess($_msg.lang('SUCCESS'));
  278. }
  279. }
  280. /**
  281. *下线
  282. */
  283. public function offline() {
  284. echo ' offline todo';
  285. exit;
  286. }
  287. /**
  288. *删除
  289. */
  290. public function delete() {
  291. $_ver_id = $this->request->param('id/d', 0);
  292. if (empty($_ver_id)) {
  293. $this->adminError(lang('param error'));
  294. }
  295. $_map['id'] = $_ver_id;
  296. $_data['is_delete'] = 1;
  297. $_data['delete_time'] = time();
  298. $_version_model = new GameversionModel();
  299. $_rs = $_version_model->allowField(true)->isUpdate(true)->save($_data, $_map);
  300. if (false === $_rs) {
  301. $this->adminError(lang('ERROR'));
  302. } else {
  303. $this->adminSuccess(lang('SUCCESS'));
  304. }
  305. }
  306. }