Archives.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace app\admin\controller\wwh;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. use think\Db;
  6. class Archives extends Base
  7. {
  8. /**
  9. * Archives模型对象
  10. * @var \app\admin\model\wwh\Archives
  11. */
  12. protected $model = null;
  13. protected $searchFields = 'title';
  14. protected $multiFields = ['weigh'];
  15. public function _initialize()
  16. {
  17. parent::_initialize();
  18. $this->model = new \app\admin\model\wwh\Archives;
  19. $columnList = [];
  20. $disabledIds = [];
  21. $all = collection(model('\app\admin\model\wwh\Column')->order('weigh desc,id desc')->select())->toArray();
  22. foreach ($all as $k => $v) {
  23. $state = ['opened' => true];
  24. if (($v['classify'] == 'none') or ($v['classify'] == 'link') or ($v['classify'] == 'service') or ($v['classify'] == 'partner') or ($v['classify'] == 'about') or ($v['classify'] == 'strength')) {
  25. $disabledIds[] = $v['id'];
  26. }
  27. if (($v['classify'] == 'none') or ($v['classify'] == 'link') or ($v['classify'] == 'service') or ($v['classify'] == 'partner') or ($v['classify'] == 'about') or ($v['classify'] == 'strength')) {
  28. $state['disabled'] = true;
  29. }
  30. $columnList[] = [
  31. 'id' => $v['id'],
  32. 'parent' => $v['parent_id'] ? $v['parent_id'] : '#',
  33. 'text' => $v['name'] . " <en> " . $v['e_name'] . "</en>",
  34. 'type' => $v['type'],
  35. 'state' => $state
  36. ];
  37. }
  38. $tree = Tree::instance()->init($all, 'parent_id');
  39. $columnOptions = $tree->getTree(0,
  40. "<option model='@model_id' value=@id @selected @disabled>@spacer@name @e_name</option>", '', $disabledIds);
  41. $this->view->assign('columnOptions', $columnOptions);
  42. $this->assignconfig('columnList', $columnList);
  43. $this->view->assign("typeList", $this->model->getTypeList());
  44. $this->view->assign("recDataList", $this->model->getRecDataList());
  45. $this->view->assign("langList", $this->model->getLangList());
  46. $this->view->assign("dTypeList", $this->model->getdTypeList());
  47. }
  48. /**
  49. * 查看
  50. */
  51. public function index()
  52. {
  53. //当前是否为关联查询
  54. $this->relationSearch = true;
  55. //设置过滤方法
  56. $this->request->filter(['strip_tags', 'trim']);
  57. if ($this->request->isAjax()) {
  58. //如果发送的来源是Selectpage,则转发到Selectpage
  59. if ($this->request->request('keyField')) {
  60. return $this->selectpage();
  61. }
  62. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  63. //获取是否启用英文配置
  64. $addon_config = get_addon_config("wwh");
  65. $switch_lang = $addon_config['switch_lang'];
  66. if ($switch_lang == 1) {
  67. $lang = '1,2';
  68. } else {
  69. $lang = '1';
  70. }
  71. $list = $this->model
  72. ->with(['column'])
  73. ->where($where)
  74. ->whereIn('lang', $lang)
  75. ->order($sort, $order)
  76. ->paginate($limit);
  77. $result = array("total" => $list->total(), "rows" => $list->items());
  78. return json($result);
  79. }
  80. return $this->view->fetch();
  81. }
  82. /**
  83. * 编辑
  84. */
  85. public function edit($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. return parent::edit($ids);
  99. }
  100. $column = \app\admin\model\wwh\Column::get($row['column_id']);
  101. if (!$column) {
  102. $this->error(__('No specified column found'));
  103. }
  104. $disabledIds = [];
  105. $all = collection(model('\app\admin\model\wwh\Column')->order('weigh desc,id desc')->select())->toArray();
  106. foreach ($all as $k => $v) {
  107. if ($v['type'] == 'link' || $v['classify'] != $column['classify']) {
  108. $disabledIds[] = $v['id'];
  109. }
  110. }
  111. $disabledIds = array_diff($disabledIds, [$row['column_id']]);
  112. $tree = Tree::instance()->init($all, 'parent_id');
  113. $columnOptions = $tree->getTree(0,
  114. "<option model='@model_id' value=@id @selected @disabled>@spacer@name @e_name</option>", $row['column_id'],
  115. $disabledIds);
  116. $this->view->assign('columnOptions', $columnOptions);
  117. $this->view->assign("row", $row);
  118. return $this->view->fetch();
  119. }
  120. /**
  121. * 删除
  122. */
  123. public function del($ids = "")
  124. {
  125. if (!$this->request->isPost()) {
  126. $this->error(__("Invalid parameters"));
  127. }
  128. $ids = $ids ? $ids : $this->request->post("ids");
  129. if ($ids) {
  130. $pk = $this->model->getPk();
  131. $adminIds = $this->getDataLimitAdminIds();
  132. if (is_array($adminIds)) {
  133. $this->model->where($this->dataLimitField, 'in', $adminIds);
  134. }
  135. $list = $this->model->where($pk, 'in', $ids)->select();
  136. $count = 0;
  137. Db::startTrans();
  138. try {
  139. foreach ($list as $k => $v) {
  140. $liststatus = $this->model->where(['status' => '1', 'id' => $ids])->limit(1)->select();
  141. if ($liststatus) {
  142. $this->error('该文章已审核,不能删除!');
  143. } else {
  144. $count += $v->delete();
  145. }
  146. }
  147. Db::commit();
  148. } catch (PDOException $e) {
  149. Db::rollback();
  150. $this->error($e->getMessage());
  151. } catch (Exception $e) {
  152. Db::rollback();
  153. $this->error($e->getMessage());
  154. }
  155. if ($count) {
  156. $this->success();
  157. } else {
  158. $this->error(__('No rows were deleted'));
  159. }
  160. }
  161. $this->error(__('Parameter %s can not be empty', 'ids'));
  162. }
  163. /**
  164. * 审核
  165. */
  166. public function audit($ids)
  167. {
  168. foreach ($ids as $k => $v) {
  169. $res = $this->model->where(['id' => ['in', $ids]])->update(['status' => 1]);
  170. if ($res == true) {
  171. $this->success('审核成功');
  172. } else {
  173. $this->error('未更新任何行');
  174. }
  175. }
  176. }
  177. /**
  178. * 反审核
  179. */
  180. public function faudit($ids)
  181. {
  182. $res = $this->model->where(['status' => '1', 'id' => $ids])->update(['status' => 0]);
  183. if ($res) {
  184. $this->success('反审核成功');
  185. } else {
  186. $this->error('未更新任何行');
  187. }
  188. }
  189. }