Block.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\common\controller\Backend;
  4. /**
  5. * 区块表
  6. *
  7. * @icon fa fa-th-large
  8. */
  9. class Block extends Backend
  10. {
  11. /**
  12. * Block模型对象
  13. */
  14. protected $model = null;
  15. protected $noNeedRight = ['selectpage_type'];
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\cms\Block;
  20. $this->view->assign("statusList", $this->model->getStatusList());
  21. }
  22. public function index()
  23. {
  24. $typeArr = \app\admin\model\cms\Block::distinct('type')->column('type');
  25. $this->view->assign('typeList', $typeArr);
  26. $this->assignconfig('typeList', $typeArr);
  27. return parent::index();
  28. }
  29. public function selectpage_type()
  30. {
  31. $list = [];
  32. $word = (array)$this->request->request("q_word/a");
  33. $field = $this->request->request('showField');
  34. $keyValue = $this->request->request('keyValue');
  35. if (!$keyValue) {
  36. if (array_filter($word)) {
  37. foreach ($word as $k => $v) {
  38. $list[] = ['id' => $v, $field => $v];
  39. }
  40. }
  41. $typeArr = \app\admin\model\cms\Block::column('type');
  42. $typeArr = array_unique($typeArr);
  43. foreach ($typeArr as $index => $item) {
  44. $list[] = ['id' => $item, $field => $item];
  45. }
  46. } else {
  47. $list[] = ['id' => $keyValue, $field => $keyValue];
  48. }
  49. return json(['total' => count($list), 'list' => $list]);
  50. }
  51. /**
  52. * 添加
  53. */
  54. public function add()
  55. {
  56. if ($this->request->isPost()) {
  57. $row = $this->request->post("row/a", []);
  58. if (isset($row['parsetpl']) && $row['parsetpl']) {
  59. $this->token();
  60. }
  61. }
  62. $values = [];
  63. $fields = \addons\cms\library\Service::getCustomFields('block', 0, $values);
  64. $this->view->assign('fields', $fields);
  65. $this->view->assign('values', $values);
  66. return parent::add();
  67. }
  68. public function edit($ids = null)
  69. {
  70. if ($this->request->isPost()) {
  71. $row = $this->request->post("row/a", []);
  72. if (isset($row['parsetpl']) && $row['parsetpl']) {
  73. $this->token();
  74. }
  75. }
  76. $values = \app\admin\model\cms\Block::get($ids);
  77. if (!$values) {
  78. $this->error(__('No Results were found'));
  79. }
  80. $values = $values->toArray();
  81. $fields = \addons\cms\library\Service::getCustomFields('block', 0, $values);
  82. $this->view->assign('fields', $fields);
  83. $this->view->assign('values', $values);
  84. return parent::edit($ids);
  85. }
  86. public function import()
  87. {
  88. return parent::import();
  89. }
  90. }