SpecialIssue.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\admin\model\cms\Participate;
  4. use app\common\controller\Backend;
  5. use think\Db;
  6. use think\exception\DbException;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 特刊管理
  11. *
  12. * @icon fa fa-cny
  13. */
  14. class SpecialIssue extends Backend
  15. {
  16. /**
  17. * Issue模型对象
  18. * @var \app\admin\model\cms\Issue
  19. */
  20. protected $model = null;
  21. protected $searchFields = 'id';
  22. protected $noNeedRight = ['is_adopt'];
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->model = new \app\admin\model\cms\Issue();
  27. }
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags']);
  35. if ($this->request->isAjax()) {
  36. $this->relationSearch = true;
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $total = $this->model->with(['user', 'journal'])
  43. ->where($where)
  44. ->order($sort, $order)
  45. ->count();
  46. $list = $this->model->with(['user', 'journal'])
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->limit($offset, $limit)
  50. ->select();
  51. foreach ($list as $value) {
  52. $editor_email_arr = [];
  53. $editor_arr = json_decode($value['editor'],true);
  54. foreach ($editor_arr as $item) {
  55. $editor_email_arr[] = $item['email'];
  56. }
  57. $value['editor'] = $editor_email_arr;
  58. }
  59. $result = array("total" => $total, "rows" => $list);
  60. return json($result);
  61. }
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 编辑
  66. *
  67. * @param $ids
  68. * @return string
  69. * @throws DbException
  70. * @throws \think\Exception
  71. */
  72. public function edit($ids = null)
  73. {
  74. $row = $this->model->get($ids);
  75. if (!$row) {
  76. $this->error(__('No Results were found'));
  77. }
  78. $adminIds = $this->getDataLimitAdminIds();
  79. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  80. $this->error(__('You have no permission'));
  81. }
  82. if (false === $this->request->isPost()) {
  83. $row['editor'] = json_decode($row['editor'], true);
  84. $this->view->assign('row', $row);
  85. return $this->view->fetch();
  86. }
  87. $params = $this->request->post('row/a');
  88. if (empty($params)) {
  89. $this->error(__('Parameter %s can not be empty', ''));
  90. }
  91. $params = $this->preExcludeFields($params);
  92. $result = false;
  93. Db::startTrans();
  94. try {
  95. //是否采用模型验证
  96. if ($this->modelValidate) {
  97. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  98. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  99. $row->validateFailException()->validate($validate);
  100. }
  101. $result = $row->allowField(true)->save($params);
  102. Db::commit();
  103. } catch (ValidateException|PDOException|Exception $e) {
  104. Db::rollback();
  105. $this->error($e->getMessage());
  106. }
  107. if (false === $result) {
  108. $this->error(__('No rows were updated'));
  109. }
  110. $this->success();
  111. }
  112. /**
  113. * 特刊申请操作
  114. *
  115. * @param $ids
  116. * @param $status
  117. * @return void
  118. * @throws \think\db\exception\DataNotFoundException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. * @throws \think\exception\DbException
  121. */
  122. public function is_adopt($ids = null, $status = null)
  123. {
  124. $row = $this->model->get($ids);
  125. if (!$row) {
  126. $this->error(__('No Results were found'));
  127. }
  128. $result = false;
  129. Db::startTrans();
  130. try {
  131. //是否采用模型验证
  132. if ($this->modelValidate) {
  133. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  134. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  135. $row->validateFailException()->validate($validate);
  136. }
  137. $result = $row->allowField(true)->save(['status' => $status]);
  138. Db::commit();
  139. } catch (ValidateException|PDOException|Exception $e) {
  140. Db::rollback();
  141. $this->error($e->getMessage());
  142. }
  143. if (false === $result) {
  144. $this->error(__('No rows were updated'));
  145. }
  146. $this->success();
  147. }
  148. }