控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Field.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 表单字段后台管理
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\formguide;
  15. use app\admin\model\formguide\ModelField as ModelField;
  16. use app\common\controller\Adminbase;
  17. use think\Db;
  18. class Field extends AdminBase
  19. {
  20. public $fields, $banfie;
  21. protected $modelClass = null;
  22. //初始化
  23. protected function initialize()
  24. {
  25. parent::initialize();
  26. //允许使用的字段列表
  27. $this->banfie = array("text", "checkbox", "textarea", "radio", "select", "image", "number", "Ueditor", "color", "file", "datetime");
  28. $this->modelClass = new ModelField;
  29. }
  30. //首页
  31. public function index()
  32. {
  33. $fieldid = $this->request->param('id/d', 0);
  34. if ($this->request->isAjax()) {
  35. list($page, $limit, $where) = $this->buildTableParames();
  36. $count = $this->modelClass->where($where)->where(['modelid' => $fieldid])->count();
  37. $data = $this->modelClass->where($where)->where(['modelid' => $fieldid])->page($page, $limit)->order(['listorder' => 'DESC', 'id' => 'DESC'])->select();
  38. return json(["code" => 0, 'count' => $count, "data" => $data]);
  39. } else {
  40. $this->assign("id", $fieldid);
  41. return $this->fetch();
  42. }
  43. }
  44. //添加
  45. public function add()
  46. {
  47. if ($this->request->isPost()) {
  48. //增加字段
  49. $data = $this->request->post();
  50. $result = $this->validate($data, 'app\admin\validate\formguide\ModelField');
  51. if (true !== $result) {
  52. return $this->error($result);
  53. }
  54. try {
  55. $res = $this->modelClass->addField($data);
  56. } catch (\Exception $e) {
  57. $this->error($e->getMessage());
  58. }
  59. $this->success('新增成功');
  60. } else {
  61. $fieldid = $this->request->param('id/d', 0);
  62. $fieldType = Db::name('field_type')->where('name', 'in', $this->banfie)->order('listorder')->column('name,title,default_define,ifoption,ifstring');
  63. $modelInfo = Db::name('model')->where('id', $fieldid)->find();
  64. $this->assign(
  65. [
  66. 'modelType' => $modelInfo['type'],
  67. "modelid" => $fieldid,
  68. 'fieldType' => $fieldType,
  69. ]
  70. );
  71. return $this->fetch();
  72. }
  73. }
  74. //编辑
  75. public function edit()
  76. {
  77. $fieldid = $this->request->param('id/d', 0);
  78. if ($this->request->isPost()) {
  79. $data = $this->request->post();
  80. $result = $this->validate($data, 'app\admin\validate\formguide\ModelField');
  81. if (true !== $result) {
  82. return $this->error($result);
  83. }
  84. try {
  85. $this->modelClass->editField($data, $fieldid);
  86. } catch (\Exception $e) {
  87. $this->error($e->getMessage());
  88. }
  89. $this->success("更新成功!");
  90. } else {
  91. //字段信息
  92. $fieldData = ModelField::get($fieldid);
  93. //字段扩展配置
  94. $fieldData['setting'] = unserialize($fieldData['setting']);
  95. if (empty($fieldData)) {
  96. $this->error('该字段信息不存在!');
  97. }
  98. //模型信息
  99. $modedata = Db::name('model')->where('id', $fieldData->getAttr('modelid'))->find();
  100. if (empty($modedata)) {
  101. $this->error('该模型不存在!');
  102. }
  103. $fieldType = Db::name('field_type')->where('name', 'in', $this->banfie)->order('listorder')->column('name,title,default_define,ifoption,ifstring');
  104. $this->assign([
  105. 'data' => $fieldData,
  106. 'fieldid' => $fieldid,
  107. 'fieldType' => $fieldType,
  108. ]);
  109. return $this->fetch();
  110. }
  111. }
  112. //删除
  113. public function del()
  114. {
  115. $fieldid = $this->request->param('id/d', 0);
  116. if (empty($fieldid)) {
  117. $this->error('字段ID不能为空!');
  118. }
  119. try {
  120. $this->modelClass->deleteField($fieldid);
  121. } catch (\Exception $e) {
  122. $this->error($e->getMessage());
  123. }
  124. $this->success("字段删除成功!");
  125. }
  126. }