控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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\cms;
  15. use app\admin\model\cms\ModelField as ModelField;
  16. use app\common\controller\Adminbase;
  17. use think\Db;
  18. class Field extends Adminbase
  19. {
  20. protected $ext_table = '_data';
  21. //初始化
  22. protected function initialize()
  23. {
  24. parent::initialize();
  25. $filepath = APP_PATH . 'admin' . DS . "view" . DS . 'custom' . DS;
  26. $custom = str_replace($filepath . DS, '', glob($filepath . DS . 'custom*'));
  27. $this->assign('custom', $custom);
  28. $this->modelClass = new ModelField;
  29. }
  30. /**
  31. * 显示字段列表
  32. */
  33. public function index()
  34. {
  35. $modelid = $this->request->param('id/d', '');
  36. if (empty($modelid)) {
  37. $this->error('参数错误!');
  38. }
  39. $model = Db::name("Model")->where("id", $modelid)->find();
  40. if (empty($model)) {
  41. $this->error('该模型不存在!');
  42. }
  43. if ($this->request->isAjax()) {
  44. //根据模型读取字段列表
  45. $banFields = ['id', 'catid', 'did', 'uid'];
  46. list($page, $limit, $where) = $this->buildTableParames();
  47. $total = $this->modelClass->where($where)->where('modelid', $modelid)->whereNotIn('name', $banFields)->count();
  48. $data = $this->modelClass->where($where)->where('modelid', $modelid)->whereNotIn('name', $banFields)->order('listorder DESC, id DESC')->page($page, $limit)->select();
  49. $result = array("code" => 0, "count" => $total, "data" => $data);
  50. return json($result);
  51. }
  52. $this->assign([
  53. "modelid" => $modelid,
  54. "name" => $model['name'],
  55. ]);
  56. return $this->fetch();
  57. }
  58. /**
  59. * 增加字段
  60. */
  61. public function add()
  62. {
  63. $modelid = $this->request->param('modelid/d', '');
  64. if (empty($modelid)) {
  65. $this->error('参数错误!');
  66. }
  67. if ($this->request->isPost()) {
  68. //增加字段
  69. $data = $this->request->param();
  70. $result = $this->validate($data, 'app\admin\validate\cms\ModelField');
  71. if (true !== $result) {
  72. return $this->error($result);
  73. }
  74. try {
  75. $res = $this->modelClass->addField($data);
  76. } catch (\Exception $e) {
  77. $this->error($e->getMessage());
  78. }
  79. $this->success('新增成功');
  80. } else {
  81. $fieldType = Db::name('field_type')->order('listorder')->column('name,title,default_define,ifstring');
  82. $modelInfo = Db::name('model')->where('id', $modelid)->find();
  83. $this->assign(
  84. [
  85. 'modelType' => $modelInfo['type'],
  86. "modelid" => $modelid,
  87. 'fieldType' => $fieldType,
  88. ]
  89. );
  90. return $this->fetch();
  91. }
  92. }
  93. /**
  94. * 修改字段
  95. */
  96. public function edit()
  97. {
  98. //字段ID
  99. $fieldid = $this->request->param('id/d', 0);
  100. if (empty($fieldid)) {
  101. $this->error('字段ID不能为空!');
  102. }
  103. if ($this->request->isPost()) {
  104. $data = $this->request->param();
  105. $result = $this->validate($data, 'app\admin\validate\cms\ModelField');
  106. if (true !== $result) {
  107. return $this->error($result);
  108. }
  109. try {
  110. $this->modelClass->editField($data, $fieldid);
  111. } catch (\Exception $e) {
  112. $this->error($e->getMessage());
  113. }
  114. $this->success("更新成功!");
  115. } else {
  116. //字段信息
  117. $fieldData = ModelField::get($fieldid);
  118. //字段扩展配置
  119. $fieldData['setting'] = unserialize($fieldData['setting']);
  120. if (empty($fieldData)) {
  121. $this->error('该字段信息不存在!');
  122. }
  123. //模型信息
  124. $modedata = Db::name('model')->where('id', $fieldData->getAttr('modelid'))->find();
  125. if (empty($modedata)) {
  126. $this->error('该模型不存在!');
  127. }
  128. $fieldType = Db::name('field_type')->order('listorder')->column('name,title,default_define,ifstring');
  129. $this->assign([
  130. 'data' => $fieldData,
  131. //'fieldid' => $fieldid,
  132. 'fieldType' => $fieldType,
  133. ]);
  134. return $this->fetch();
  135. }
  136. }
  137. /**
  138. * 删除字段
  139. */
  140. public function del()
  141. {
  142. //字段ID
  143. $fieldid = $this->request->param('id/d', '');
  144. if (empty($fieldid)) {
  145. $this->error('字段ID不能为空!');
  146. }
  147. try {
  148. $this->modelClass->deleteField($fieldid);
  149. } catch (\Exception $e) {
  150. $this->error($e->getMessage());
  151. }
  152. $this->success("字段删除成功!");
  153. }
  154. /**
  155. * 菜单排序
  156. */
  157. public function listorder()
  158. {
  159. $id = $this->request->param('id/d', 0);
  160. $listorder = $this->request->param('value/d', 0);
  161. $rs = $this->modelClass->allowField(['listorder'])->isUpdate(true)->save(['id' => $id, 'listorder' => $listorder]);
  162. if ($rs) {
  163. $this->success("菜单排序成功!");
  164. } else {
  165. $this->error("菜单排序失败!");
  166. }
  167. }
  168. /**
  169. * 字段状态
  170. */
  171. public function setstate()
  172. {
  173. $id = $this->request->param('id/d');
  174. empty($id) && $this->error('参数不能为空!');
  175. $status = $this->request->param('value/d');
  176. if (ModelField::update(['status' => $status], ['id' => $id])) {
  177. $this->success("操作成功!");
  178. } else {
  179. $this->error('操作失败!');
  180. }
  181. }
  182. public function setsearch()
  183. {
  184. $id = $this->request->param('id/d');
  185. empty($id) && $this->error('参数不能为空!');
  186. $ifsearch = $this->request->param('value/d');
  187. if (ModelField::update(['ifsearch' => $ifsearch], ['id' => $id])) {
  188. $this->success("操作成功!");
  189. } else {
  190. $this->error('操作失败!');
  191. }
  192. }
  193. /**
  194. * 显示隐藏
  195. */
  196. public function setvisible()
  197. {
  198. $id = $this->request->param('id/d', 0);
  199. empty($id) && $this->error('参数不能为空!');
  200. $status = $this->request->param('value/d');
  201. $field = ModelField::get($id);
  202. if ($field->ifrequire && 0 == $status) {
  203. $this->error("必填字段不可以设置为隐藏!");
  204. }
  205. $field->isadd = $status;
  206. if ($field->save()) {
  207. $this->success("设置成功!");
  208. } else {
  209. $this->error("设置失败!");
  210. }
  211. }
  212. /**
  213. * 必须
  214. */
  215. public function setrequire()
  216. {
  217. $id = $this->request->param('id/d', 0);
  218. empty($id) && $this->error('参数不能为空!');
  219. $status = $this->request->param('value/d');
  220. $field = ModelField::get($id);
  221. if (!$field->isadd && $status) {
  222. $this->error("隐藏字段不可以设置为必填!");
  223. }
  224. $field->ifrequire = $status;
  225. if ($field->save()) {
  226. $this->success("设置成功!");
  227. } else {
  228. $this->error("设置失败!");
  229. }
  230. }
  231. }