Builder.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. $this->view->assign("configList", get_addon_fullconfig("cms"));
  43. $this->view->assign("fieldList", $fieldList);
  44. $this->view->assign("channelFieldList", $channelFieldList);
  45. $this->view->assign("pageFieldList", $pageFieldList);
  46. $this->view->assign("pageTypeList", $pageTypeList);
  47. $this->view->assign("specialFieldList", $specialFieldList);
  48. $this->view->assign("blockFieldList", $blockFieldList);
  49. $this->view->assign("blockTypeList", $blockTypeList);
  50. $this->view->assign("blockNameList", $blockNameList);
  51. $this->view->assign("userFieldList", $userFieldList);
  52. $this->view->assign("channelList", $channelList);
  53. $this->view->assign("modelList", $modelList);
  54. return $this->view->fetch();
  55. }
  56. /**
  57. * 解析模板标签
  58. * @return string
  59. * @throws \think\Exception
  60. */
  61. public function parse()
  62. {
  63. $this->view->engine->layout(false);
  64. $tag = $this->request->post('tag');
  65. if (!config('app_debug')) {
  66. $this->error("只在开发模式下才可渲染");
  67. }
  68. $html = '';
  69. try {
  70. $html = $this->view->display($tag);
  71. } catch (\Exception $e) {
  72. $this->error("模板标签解析错误:" . $e->getMessage());
  73. }
  74. $this->success("", null, $html);
  75. return $this->view->fetch();
  76. }
  77. /**
  78. * 获取自定义字段列表HTML
  79. * @internal
  80. */
  81. public function get_model_fields()
  82. {
  83. $this->view->engine->layout(false);
  84. $id = $this->request->post('id/d');
  85. $model = Modelx::get($id);
  86. if ($model) {
  87. $fields = \app\admin\model\cms\Fields::where('source', 'model')->where('source_id', $model['id'])->column("id,name,title");
  88. $this->success('', null, ['fields' => array_values($fields)]);
  89. } else {
  90. $this->error(__('Please select model'));
  91. }
  92. $this->error(__('Parameter %s can not be empty', 'ids'));
  93. }
  94. }