Field.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 字段管理
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\cms;
  15. use app\admin\model\cms\ModelField as ModelField;
  16. use app\admin\model\cms\Models;
  17. use app\common\controller\Backend;
  18. use think\facade\Db;
  19. class Field extends Backend
  20. {
  21. protected $ext_table = '_data';
  22. protected $multiFields = 'isadd,ifrequire,ifsearch,ifrequire';
  23. protected $modelClass = null;
  24. protected $modelValidate = true;
  25. //初始化
  26. protected function initialize()
  27. {
  28. parent::initialize();
  29. $filepath = app()->getAppPath() . "view" . DS . 'custom' . DS;
  30. $custom = str_replace($filepath . DS, '', glob($filepath . DS . 'custom*'));
  31. $this->assign('custom', $custom);
  32. $this->modelClass = new ModelField;
  33. }
  34. /**
  35. * 显示字段列表
  36. */
  37. public function index()
  38. {
  39. $modelid = $this->request->param('modelid/d', '');
  40. if (empty($modelid)) {
  41. $this->error('参数错误!');
  42. }
  43. $model = Models::find($modelid);
  44. if (empty($model)) {
  45. $this->error('该模型不存在!');
  46. }
  47. if ($this->request->isAjax()) {
  48. //根据模型读取字段列表
  49. $banFields = ['id', 'catid', 'did', 'user_id', 'admin_id'];
  50. list($page, $limit, $where) = $this->buildTableParames();
  51. $total = $this->modelClass
  52. ->where($where)
  53. ->where('modelid', $modelid)
  54. ->whereNotIn('name', $banFields)
  55. ->count();
  56. $data = $this->modelClass
  57. ->where($where)
  58. ->where('modelid', $modelid)
  59. ->whereNotIn('name', $banFields)
  60. ->order('listorder DESC, id DESC')
  61. ->page($page, $limit)
  62. ->select();
  63. $result = ["code" => 0, "count" => $total, "data" => $data];
  64. return json($result);
  65. }
  66. $this->assign([
  67. "modelid" => $modelid,
  68. "name" => $model['name'],
  69. ]);
  70. $this->assignconfig("modelid", $modelid);
  71. return $this->fetch();
  72. }
  73. /**
  74. * 增加字段
  75. */
  76. public function add()
  77. {
  78. $modelid = $this->request->param('modelid/d', '');
  79. $fieldType = Db::name('field_type')->order('listorder')->column('name,title,default_define,ifstring');
  80. $modelInfo = Models::find($modelid);
  81. $this->assign(
  82. [
  83. 'modelType' => $modelInfo['type'],
  84. "modelid" => $modelid,
  85. 'fieldType' => $fieldType,
  86. ]
  87. );
  88. return parent::add();
  89. }
  90. /**
  91. * 修改字段
  92. */
  93. public function edit()
  94. {
  95. $fieldType = Db::name('field_type')->order('listorder')->column('name,title,default_define,ifstring');
  96. $this->assign('fieldType', $fieldType);
  97. return parent::edit();
  98. }
  99. }