123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- <?php
- /**
- * VersionController.php UTF-8
- * APP版本管理
- *
- * @date : 2017/12/1 17:55
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace admin\admin\controller\app;
- use cmf\controller\AdminBaseController;
- use huo\controller\game\Gamepack;
- use huo\exception\HuoException;
- use huo\model\game\GameModel;
- use huo\model\game\GameversionModel;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use think\Lang;
- use think\Validate;
- class VersionController extends AdminbaseController {
- protected $app_id;
- function _initialize() {
- parent::_initialize();
- Lang::load(
- APP_PATH.'admin/lang'.DS.$this->lang.DS.'version'.EXT
- );
- $this->app_id = $this->request->param('app_id', config('app_app_id'));
- }
- /**
- * 游戏状态
- */
- public function _versionStatus() {
- $_version_status = [
- GameConst::GAME_STATUS_ACCESS => lang('not_line'),
- GameConst::GAME_STATUS_ON => lang('online'),
- GameConst::GAME_STATUS_OFF => lang('offline'),
- ];
- $this->assign('version_status', $_version_status);
- return $_version_status;
- }
- /**
- *
- */
- public function index() {
- $this->getAppInfo();
- $this->_versionStatus();
- $this->getList($this->app_id);
- return $this->fetch();
- }
- public function getAppInfo() {
- $_game_info = GameModel::useGlobalScope(false)
- ->where('id', $this->app_id)
- ->find()->toArray();
- $this->assign('icon', $_game_info['icon']);
- return $_game_info;
- }
- /**
- * 添加游戏母包
- */
- public function addPackageUrl() {
- $_ver_id = $this->request->param('id/d', 0);
- $_update = $this->request->param('update/d', 0);
- $this->assign('back_url', $this->request->server('HTTP_REFERER'));
- if (empty($_ver_id)) {
- $this->adminError(lang('param error'));
- }
- $_version_data = $this->getDetail($_ver_id);
- if (empty($_version_data)) {
- $this->adminError(lang('ERROR'));
- }
- if (empty($_update) && !empty($_version_data['package_url'])) {
- $this->adminSuccess(lang('SUCCESS'));
- }
- $this->assign($_version_data);
- $_game_info = $this->getAppInfo();
- if (empty($_game_info)) {
- $this->adminError(lang('ERROR'));
- }
- $this->assign('game', $_game_info);
- $_gp_class = new Gamepack($this->app_id);
- try {
- $_gp_class->setPinyin($_game_info['en_abbr']);
- $_gp_class->setAgentgame($_game_info['en_abbr']);
- $_gp_class->setVerId($_ver_id);
- $_gp_class->pack();
- $_data = $_gp_class->getData();
- } catch (HuoException $_he) {
- $_data = $_he->getData();
- }
- if (empty($_data)) {
- return $this->fetch('app/version/addpackageurl');
- }
- if (is_array($_data) && isset($_data['size'])) {
- $_gv_model = new GameversionModel();
- $_map['id'] = $_ver_id;
- $_gv_data['package_url'] = $_data['url'];
- $_gv_data['size'] = $_data['size'];
- $_gv_data['version'] = $_data['vername'];
- $_rs = $_gv_model->save($_gv_data, $_map);
- if (false !== $_rs) {
- $_game_model = new GameModel();
- $_g_data['package_name'] = $_data['pakagename'];
- $_g_map['id'] = $_version_data['app_id'];
- $_game_model->save($_g_data, $_g_map);
- $this->redirect($this->request->server('HTTP_REFERER'));
- }
- }
- return $this->fetch('app/version/addpackageurl');
- }
- /**
- * 获取对接参数
- */
- public function param() {
- $_ver_id = $this->request->param('id/d', 0);
- if (empty($_ver_id)) {
- $this->adminError(lang('param error'));
- }
- $this->assign($this->getDetail($_ver_id));
- return $this->fetch();
- }
- /**
- * @param int $ver_id
- *
- * @return array
- */
- public function getDetail($ver_id) {
- $_data = GameversionModel::useGlobalScope(false)
- ->cache('game_version_'.$ver_id)
- ->where('id', $ver_id)
- ->find()
- ->toArray();
- return $_data;
- }
- public function getList($app_id) {
- $_map['app_id'] = $app_id;
- $_items = GameversionModel::useGlobalScope(false)
- ->where($_map)
- ->useSoftDelete('delete_time', ['eq', 0])
- ->order('id', 'desc')
- ->paginate(10);
- $this->assign('page', $_items->render());
- $this->assign('items', $_items);
- return $_items;
- }
- /**
- * 添加APP
- *
- * @return string
- */
- public function addApp() {
- $_param['id'] = $this->app_id;
- $_param['is_sdk'] = GameConst::GAME_IS_NOT_SDK;
- $_param['is_online'] = GameConst::GAME_IS_ON_LINE;
- $_param['cp_id'] = 0;
- $_param['en_name'] = 'A P P';
- $_param['name'] = 'APP';
- $_param['is_delete'] = CommonConst::CONST_NOT_DELETE;
- $_param['status'] = GameConst::GAME_STATUS_ACCESS;
- $_param['delete_time'] = time();
- $_game_model = new GameModel();
- $_rs = $_game_model->addGames($_param);
- if ($_rs) {
- return 'success';
- }
- return 'error';
- }
- /**
- *添加
- */
- public function add() {
- $this->getAppInfo();
- return $this->fetch();
- }
- /**
- *添加提交
- */
- public function addPost() {
- if ($this->request->isPost()) {
- $_validate = new Validate(
- [
- 'version' => 'require|token',
- ]
- );
- $_param = $this->request->param();
- if (!$_validate->check($_param)) {
- $this->adminError($_validate->getError(), $this->request->server('HTTP_REFERER'));
- }
- $_param['app_id'] = $this->app_id;
- $_version_model = new GameversionModel();
- $_rs = $_version_model->addVersion($_param);
- if ($_rs) {
- $_g_data['icon'] = $this->request->param('icon');
- GameModel::update($_g_data, ['id' => $this->app_id], true);
- $this->adminSuccess(lang('ADD_SUCCESS'), url('admin/public/closeFrame'));
- } else {
- $this->adminSuccess(lang('ADD_FAILED'));
- }
- } else {
- $this->adminError(lang('REQUEST_ERROR'));
- }
- }
- /**
- *添加
- */
- public function edit() {
- $this->getAppInfo();
- $_ver_id = $this->request->param('id/d', 0);
- if (empty($_ver_id)) {
- $this->adminError(lang('param error'));
- }
- $this->assign($this->getDetail($_ver_id));
- return $this->fetch();
- }
- /**
- *添加提交
- */
- public function editPost() {
- if ($this->request->isPost()) {
- $_validate = new Validate(
- [
- 'id' => 'require|number',
- 'version' => 'require|token',
- ]
- );
- $_param = $this->request->param();
- if (!$_validate->check($_param)) {
- $this->adminError($_validate->getError(), $this->request->server('HTTP_REFERER'));
- }
- $_data['content'] = $this->request->post('content', '');
- $_data['version'] = $this->request->post('version', '');
- $_map['id'] = $_param['id'];
- $_rs = GameversionModel::update($_data, $_map);
- if ($_rs) {
- $_g_data['icon'] = $this->request->param('icon');
- GameModel::update($_g_data, ['id' => $this->app_id], true);
- $this->adminSuccess(lang('EDIT_SUCCESS'), url('admin/public/closeFrame'));
- } else {
- $this->adminSuccess(lang('EDIT_FAILED'));
- }
- } else {
- $this->adminError(lang('REQUEST_ERROR'));
- }
- }
- /**
- * 设置状态 上线 下线
- */
- public function setStatus() {
- $_ver_id = $this->request->param('id/d', 0);
- $_status = $this->request->param('is_default/d', 1);
- if (empty($_ver_id) || empty($_status)) {
- $this->adminError(lang('param error'));
- }
- $_version_data = $this->getDetail($_ver_id);
- if (2 == $_status) {
- if (empty($_version_data['package_url'])) {
- $this->adminError(lang('no_package'));
- }
- $_msg = lang('online');
- } else {
- $_msg = lang('offline');
- }
- $_data['is_default'] = $_status;
- $_map['app_id'] = $this->app_id;
- $_map['id'] = $_ver_id;
- $_version_model = new GameversionModel();
- $_rs = $_version_model->allowField(true)->isUpdate(true)->save($_data, $_map);
- if (false !== $_rs && 2 == $_status) {
- $_map['id'] = ['neq', $_ver_id];
- $_data['is_default'] = 3;
- $_rs = $_version_model->allowField(true)->isUpdate(true)->save($_data, $_map);
- }
- if (false === $_rs) {
- $this->adminError($_msg.lang('ERROR'));
- } else {
- $this->adminSuccess($_msg.lang('SUCCESS'));
- }
- }
- /**
- *下线
- */
- public function offline() {
- echo ' offline todo';
- exit;
- }
- /**
- *删除
- */
- public function delete() {
- $_ver_id = $this->request->param('id/d', 0);
- if (empty($_ver_id)) {
- $this->adminError(lang('param error'));
- }
- $_map['id'] = $_ver_id;
- $_data['is_delete'] = 1;
- $_data['delete_time'] = time();
- $_version_model = new GameversionModel();
- $_rs = $_version_model->allowField(true)->isUpdate(true)->save($_data, $_map);
- if (false === $_rs) {
- $this->adminError(lang('ERROR'));
- } else {
- $this->adminSuccess(lang('SUCCESS'));
- }
- }
- }
|