Appversion.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Controller;
  5. use think\Request;
  6. /**
  7. *
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Appversion extends Backend
  12. {
  13. /**
  14. * AppVersion模型对象
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = model('AppVersion');
  21. $this->view->assign("typeList", $this->model->getTypeList());
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 编辑
  31. */
  32. public function edit($ids = null)
  33. {
  34. $row = $this->model->get($ids);
  35. if (!$row) {
  36. $this->error(__('No Results were found'));
  37. }
  38. $adminIds = $this->getDataLimitAdminIds();
  39. if (is_array($adminIds)) {
  40. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  41. $this->error(__('You have no permission'));
  42. }
  43. }
  44. if ($this->request->isPost()) {
  45. $params = $this->request->post("row/a");
  46. if ($params) {
  47. /*
  48. * 已经弃用,如果为了兼容老版可取消注释
  49. foreach ($params as $k => &$v)
  50. {
  51. $v = is_array($v) ? implode(',', $v) : $v;
  52. }
  53. */
  54. try {
  55. //是否采用模型验证
  56. if ($this->modelValidate) {
  57. $name = basename(str_replace('\\', '/', get_class($this->model)));
  58. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  59. $row->validate($validate);
  60. }
  61. if (version_compare($params['end_version'], $params['version_name'], '>=')) {
  62. $this->error('当前版本号必须大于结束版本号');
  63. }
  64. $filesize = filesize($_SERVER["DOCUMENT_ROOT"] . $params['apk_url']);
  65. $params['size'] = $filesize;
  66. $result = $row->allowField(true)->save($params);
  67. if ($result !== false) {
  68. $this->success();
  69. } else {
  70. $this->error($row->getError());
  71. }
  72. } catch (\think\exception\PDOException $e) {
  73. $this->error($e->getMessage());
  74. }
  75. }
  76. $this->error(__('Parameter %s can not be empty', ''));
  77. }
  78. $this->view->assign("row", $row);
  79. return $this->view->fetch();
  80. }
  81. /**
  82. * 失效
  83. * @param null $ids
  84. */
  85. public function setlose($ids = null)
  86. {
  87. $row = $this->model->get($ids);
  88. if (!$row) {
  89. $this->error(__('No Results were found'));
  90. }
  91. $adminIds = $this->getDataLimitAdminIds();
  92. if (is_array($adminIds)) {
  93. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  94. $this->error(__('You have no permission'));
  95. }
  96. }
  97. if ($this->request->isPost()) {
  98. $params = ['status' => 'hidden'];
  99. if ($params) {
  100. /*
  101. * 已经弃用,如果为了兼容老版可取消注释
  102. foreach ($params as $k => &$v)
  103. {
  104. $v = is_array($v) ? implode(',', $v) : $v;
  105. }
  106. */
  107. try {
  108. //是否采用模型验证
  109. if ($this->modelValidate) {
  110. $name = basename(str_replace('\\', '/', get_class($this->model)));
  111. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  112. $row->validate($validate);
  113. }
  114. $result = $row->allowField(true)->save($params);
  115. if ($result !== false) {
  116. $this->success();
  117. } else {
  118. $this->error($row->getError());
  119. }
  120. } catch (\think\exception\PDOException $e) {
  121. $this->error($e->getMessage());
  122. }
  123. }
  124. $this->error(__('Parameter %s can not be empty', ''));
  125. }
  126. }
  127. /**
  128. * 添加
  129. */
  130. public function add()
  131. {
  132. if ($this->request->isPost()) {
  133. $params = $this->request->post("row/a");
  134. if ($params) {
  135. /*
  136. * 已经弃用,如果为了兼容老版可取消注释
  137. foreach ($params as $k => &$v)
  138. {
  139. $v = is_array($v) ? implode(',', $v) : $v;
  140. }
  141. */
  142. if ($this->dataLimit) {
  143. $params[$this->dataLimitField] = $this->auth->id;
  144. }
  145. try {
  146. //是否采用模型验证
  147. if ($this->modelValidate) {
  148. $name = basename(str_replace('\\', '/', get_class($this->model)));
  149. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  150. $this->model->validate($validate);
  151. }
  152. if (version_compare($params['end_version'], $params['version_name'], '>=')) {
  153. $this->error('当前版本号必须大于结束版本号');
  154. }
  155. $filesize = filesize($_SERVER["DOCUMENT_ROOT"] . $params['apk_url']);
  156. $params['size'] = $filesize;
  157. $result = $this->model->allowField(true)->save($params);
  158. if ($result !== false) {
  159. $this->success();
  160. } else {
  161. $this->error($this->model->getError());
  162. }
  163. } catch (\think\exception\PDOException $e) {
  164. $this->error($e->getMessage());
  165. }
  166. }
  167. $this->error(__('Parameter %s can not be empty', ''));
  168. }
  169. return $this->view->fetch();
  170. }
  171. }