Builder.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use addons\cms\library\Service;
  4. use app\admin\model\cms\Channel;
  5. use app\admin\model\cms\Modelx;
  6. use app\common\controller\Backend;
  7. use app\common\model\User;
  8. use fast\Tree;
  9. use think\Db;
  10. use think\db\Query;
  11. /**
  12. * 标签生成器
  13. *
  14. * @icon fa fa-file-text-o
  15. */
  16. class Builder extends Backend
  17. {
  18. protected $model = null;
  19. protected $noNeedRight = [];
  20. protected $channelIds = [];
  21. protected $isSuperAdmin = false;
  22. protected $searchFields = 'id,title';
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. $tree = Tree::instance();
  29. $tree->init(collection(Channel::where('status', 'normal')->order('weigh desc,id desc')->select())->toArray(), 'parent_id');
  30. $channelList = $tree->getTreeList($tree->getTreeArray(0), 'name');
  31. $modelList = \app\admin\model\cms\Modelx::order('id asc')->select();
  32. $prefix = \think\Config::get('database.prefix');
  33. $fieldList = Service::getTableFields("{$prefix}cms_archives");
  34. $channelFieldList = Service::getTableFields("{$prefix}cms_channel");
  35. $userFieldList = Service::getTableFields("{$prefix}user");
  36. $specialFieldList = Service::getTableFields("{$prefix}cms_special");
  37. $pageFieldList = Service::getTableFields("{$prefix}cms_page");
  38. $pageTypeList = \app\admin\model\cms\Page::distinct('type')->column("type");
  39. $blockTypeList = \app\admin\model\cms\Block::distinct('type')->column("type");
  40. $blockNameList = \app\admin\model\cms\Block::distinct('name')->column("name");
  41. $blockFieldList = Service::getTableFields("{$prefix}cms_block");
  42. $diyformList = \app\admin\model\cms\Diyform::all();
  43. $diyformFieldList = [];
  44. foreach ($diyformList as $index => $item) {
  45. $diyformFieldList[$item['id']] = Service::getTableFields($prefix . $item['table']);
  46. }
  47. $this->view->assign("configList", get_addon_fullconfig("cms"));
  48. $this->view->assign("fieldList", $fieldList);
  49. $this->view->assign("channelFieldList", $channelFieldList);
  50. $this->view->assign("pageFieldList", $pageFieldList);
  51. $this->view->assign("pageTypeList", $pageTypeList);
  52. $this->view->assign("specialFieldList", $specialFieldList);
  53. $this->view->assign("blockFieldList", $blockFieldList);
  54. $this->view->assign("blockTypeList", $blockTypeList);
  55. $this->view->assign("blockNameList", $blockNameList);
  56. $this->view->assign("userFieldList", $userFieldList);
  57. $this->view->assign("diyformList", $diyformList);
  58. $this->view->assign("diyformFieldList", $diyformFieldList);
  59. $this->view->assign("channelList", $channelList);
  60. $this->view->assign("modelList", $modelList);
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 解析模板标签
  65. * @return string
  66. */
  67. public function parse()
  68. {
  69. $this->view->engine->layout(false);
  70. $tag = $this->request->post('tag');
  71. if (!config('app_debug')) {
  72. $this->error("只在开发模式下才可渲染");
  73. }
  74. $html = '';
  75. try {
  76. $html = $this->view->display($tag);
  77. } catch (\Exception $e) {
  78. $this->error("模板标签解析错误:" . $e->getMessage());
  79. }
  80. $this->success("", null, $html);
  81. return $this->view->fetch();
  82. }
  83. /**
  84. * 获取自定义字段列表HTML
  85. * @internal
  86. */
  87. public function get_model_fields()
  88. {
  89. $this->view->engine->layout(false);
  90. $id = $this->request->post('id/d');
  91. $model = Modelx::get($id);
  92. if ($model) {
  93. $fields = \app\admin\model\cms\Fields::where('source', 'model')->where('source_id', $model['id'])->column("id,name,title");
  94. $this->success('', null, ['fields' => array_values($fields)]);
  95. } else {
  96. $this->error(__('Please select model'));
  97. }
  98. $this->error(__('Parameter %s can not be empty', 'ids'));
  99. }
  100. }