控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Cms.php 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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. // | cms管理
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\cms;
  15. use addons\cms\library\Service;
  16. use app\admin\model\cms\Cms as CmsModel;
  17. use app\admin\model\cms\Page as PageModel;
  18. use app\common\controller\Adminbase;
  19. use think\Db;
  20. class Cms extends Adminbase
  21. {
  22. protected $searchFields = 'id,title';
  23. protected $noNeedRight = ['check_title', 'panl', 'classlist'];
  24. protected function initialize()
  25. {
  26. parent::initialize();
  27. $this->CmsModel = new CmsModel;
  28. $this->cmsConfig = get_addon_config("cms");
  29. $this->assign("cmsConfig", $this->cmsConfig);
  30. }
  31. public function index()
  32. {
  33. $isAdministrator = $this->auth->isAdministrator();
  34. $json = $priv_catids = [];
  35. if (0 !== (int) $this->cmsConfig['site_category_auth']) {
  36. //栏目权限 超级管理员例外
  37. if ($isAdministrator !== true) {
  38. $role_id = $this->auth->roleid;
  39. $priv_result = Db::name('CategoryPriv')->where(['roleid' => $role_id, 'action' => 'init'])->select();
  40. foreach ($priv_result as $_v) {
  41. $priv_catids[] = $_v['catid'];
  42. }
  43. }
  44. }
  45. $categorys = Db::name('Category')->order('listorder DESC, id DESC')->select();
  46. foreach ($categorys as $rs) {
  47. //剔除无子栏目外部链接
  48. if ($rs['type'] == 3 && $rs['child'] == 0) {
  49. continue;
  50. }
  51. if (0 !== (int) $this->cmsConfig['site_category_auth']) {
  52. //只显示有init权限的,超级管理员除外
  53. if ($isAdministrator !== true && !in_array($rs['id'], $priv_catids)) {
  54. $arrchildid = explode(',', $rs['arrchildid']);
  55. $array_intersect = array_intersect($priv_catids, $arrchildid);
  56. if (empty($array_intersect)) {
  57. continue;
  58. }
  59. }
  60. }
  61. $data = [
  62. 'id' => $rs['id'],
  63. 'parentid' => $rs['parentid'],
  64. 'catname' => $rs['catname'],
  65. 'type' => $rs['type'],
  66. ];
  67. //终极栏目
  68. if ($rs['child'] !== 0) {
  69. $data['isParent'] = true;
  70. }
  71. $data['target'] = 'right';
  72. if ($rs['type'] == 2) {
  73. $data['url'] = url('classlist', ['catid' => $rs['id']]);
  74. }
  75. //单页
  76. if ($rs['type'] == 1) {
  77. $data['target'] = 'right';
  78. $data['url'] = url('add', ['catid' => $rs['id']]);
  79. }
  80. $json[] = $data;
  81. }
  82. $this->assign('json', json_encode($json));
  83. return $this->fetch();
  84. }
  85. //栏目信息列表
  86. public function classlist()
  87. {
  88. $catid = $this->request->param('catid/d', 0);
  89. //当前栏目信息
  90. $catInfo = getCategory($catid);
  91. if (empty($catInfo)) {
  92. $this->error('该栏目不存在!');
  93. }
  94. //栏目所属模型
  95. $modelid = $catInfo['modelid'];
  96. if ($this->request->isAjax()) {
  97. //检查模型是否被禁用
  98. if (!getModel($modelid, 'status')) {
  99. $this->error('模型被禁用!');
  100. }
  101. $modelCache = cache("Model");
  102. $tableName = $modelCache[$modelid]['tablename'];
  103. $this->modelClass = Db::name($tableName);
  104. //如果发送的来源是Selectpage,则转发到Selectpage
  105. if ($this->request->request('keyField')) {
  106. return $this->selectpage();
  107. }
  108. list($page, $limit, $where) = $this->buildTableParames();
  109. $conditions = [
  110. ['catid', '=', $catid],
  111. ['status', 'in', [0, 1]],
  112. ];
  113. $total = Db::name($tableName)->where($where)->where($conditions)->count();
  114. $list = Db::name($tableName)->page($page, $limit)->where($where)->where($conditions)->order('listorder DESC, id DESC')->select();
  115. $_list = [];
  116. foreach ($list as $k => $v) {
  117. $v['update_time'] = date('Y-m-d H:i:s', $v['update_time']);
  118. $v['url'] = buildContentUrl($v['catid'], $v['id'], $v['url']);
  119. $_list[] = $v;
  120. }
  121. $result = ["code" => 0, "count" => $total, "data" => $_list];
  122. return json($result);
  123. }
  124. /*移动栏目 复制栏目*/
  125. $tree = new \util\Tree();
  126. $tree->icon = ['&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ '];
  127. $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
  128. $categorys = [];
  129. $result = Db::name('category')->order('listorder DESC, id DESC')->select();
  130. foreach ($result as $k => $v) {
  131. if ($v['type'] != 2) {
  132. $v['disabled'] = 'disabled';
  133. }
  134. if ($modelid && $modelid != $v['modelid']) {
  135. $v['disabled'] = 'disabled';
  136. }
  137. //$v['disabled'] = $v['child'] ? 'disabled' : '';
  138. $v['selected'] = $v['id'] == $catid ? 'selected' : '';
  139. $categorys[$k] = $v;
  140. }
  141. $str = "<option value=@id @selected @disabled>@spacer @catname</option>";
  142. $tree->init($categorys);
  143. $string = $tree->getTree(0, $str, $catid);
  144. $this->assign('string', $string);
  145. $this->assign('catid', $catid);
  146. return $this->fetch();
  147. }
  148. //移动文章
  149. public function remove()
  150. {
  151. $this->check_priv('remove');
  152. if ($this->request->isPost()) {
  153. $catid = $this->request->param('catid/d', 0);
  154. if (!$catid) {
  155. $this->error("请指定栏目!");
  156. }
  157. //需要移动的信息ID集合
  158. $ids = $this->request->param('ids/s');
  159. //目标栏目
  160. $tocatid = $this->request->param('tocatid/d', 0);
  161. if ($ids) {
  162. if ($tocatid == $catid) {
  163. $this->error('目标栏目和当前栏目是同一个栏目!');
  164. }
  165. $modelid = getCategory($tocatid, 'modelid');
  166. if (!$modelid) {
  167. $this->error('该模型不存在!');
  168. }
  169. $ids = array_filter(explode('|', $ids), 'intval');
  170. $tableName = Db::name('model')->where('id', $modelid)->where('status', 1)->value('tablename');
  171. if (!$tableName) {
  172. $this->error('模型被冻结不可操作~');
  173. }
  174. if (Db::name(ucwords($tableName))->where('id', 'in', $ids)->update(['catid' => $tocatid])) {
  175. Db::name('Category')->where('id', $catid)->setDec('items', count($ids));
  176. Db::name('Category')->where('id', $tocatid)->setInc('items', count($ids));
  177. $this->success('移动成功~');
  178. } else {
  179. $this->error('移动失败~');
  180. }
  181. } else {
  182. $this->error('请选择需要移动的信息!');
  183. }
  184. }
  185. }
  186. //添加信息
  187. public function add()
  188. {
  189. $this->check_priv('add');
  190. if ($this->request->isPost()) {
  191. $data = $this->request->post();
  192. $catid = intval($data['modelField']['catid']);
  193. if (empty($catid)) {
  194. $this->error("请指定栏目ID!");
  195. }
  196. $category = getCategory($catid);
  197. //dump($data['modelField']);die;
  198. if (empty($category)) {
  199. $this->error('该栏目不存在!');
  200. }
  201. if ($category['type'] == 2) {
  202. //模型类型
  203. if((int)$catid === 17){
  204. [$is_su,$msg] = $this->yzCid17($catid,$data,'add');
  205. if($is_su === 1){
  206. $this->error($msg);
  207. }
  208. }else if((int)$catid === 29){
  209. [$is_su,$msg] = $this->yzCid29($catid,$data,'add');
  210. if($is_su === 1){
  211. $this->error($msg);
  212. }
  213. }
  214. $data['modelFieldExt'] = $data['modelFieldExt'] ?? [];
  215. try {
  216. $this->CmsModel->addModelData($data['modelField'], $data['modelFieldExt']);
  217. } catch (\Exception $ex) {
  218. $this->error($ex->getMessage());
  219. }
  220. } elseif ($category['type'] == 1) {
  221. $PageModel = new PageModel;
  222. if (!$PageModel->savePage($data['modelField'])) {
  223. $error = $PageModel->getError();
  224. $this->error($error ? $error : '操作失败!');
  225. }
  226. }
  227. $this->success('操作成功!');
  228. } else {
  229. $catid = $this->request->param('catid/d', 0);
  230. $category = getCategory($catid);
  231. if (empty($category)) {
  232. $this->error('该栏目不存在!');
  233. }
  234. if ($category['type'] == 2) {
  235. $modelid = $category['modelid'];
  236. $fieldList = Service::getFieldList($modelid);
  237. $this->assign([
  238. 'catid' => $catid,
  239. 'fieldList' => $fieldList,
  240. ]);
  241. return $this->fetch();
  242. } elseif ($category['type'] == 1) {
  243. $PageModel = new PageModel;
  244. $info = $PageModel->getPage($catid);
  245. $this->assign([
  246. 'info' => $info,
  247. 'catid' => $catid,
  248. ]);
  249. return $this->fetch('singlepage');
  250. }
  251. }
  252. }
  253. //编辑信息
  254. public function edit()
  255. {
  256. $this->check_priv('edit');
  257. if ($this->request->isPost()) {
  258. $data = $this->request->post();
  259. $data['modelFieldExt'] = $data['modelFieldExt'] ?? [];
  260. //模型类型
  261. $catid = (int)$data['modelField']['catid'];
  262. if((int)$catid === 17){
  263. [$is_su,$msg] = $this->yzCid17($catid,$data,'edit');
  264. if($is_su === 1){
  265. $this->error($msg);
  266. }
  267. }else if((int)$catid === 29){
  268. [$is_su,$msg] = $this->yzCid29($catid,$data,'edit');
  269. if($is_su === 1){
  270. $this->error($msg);
  271. }
  272. }
  273. try {
  274. $this->CmsModel->editModelData($data['modelField'], $data['modelFieldExt']);
  275. } catch (\Exception $ex) {
  276. $this->error($ex->getMessage());
  277. }
  278. $this->success('编辑成功!');
  279. } else {
  280. $catid = $this->request->param('catid/d', 0);
  281. $id = $this->request->param('id/d', 0);
  282. $category = getCategory($catid);
  283. if (empty($category)) {
  284. $this->error('该栏目不存在!');
  285. }
  286. if ($category['type'] == 2) {
  287. $modelid = $category['modelid'];
  288. $fieldList = Service::getFieldList($modelid, $id);
  289. $this->assign([
  290. 'catid' => $catid,
  291. 'id' => $id,
  292. 'fieldList' => $fieldList,
  293. ]);
  294. return $this->fetch();
  295. } else {
  296. return $this->fetch('singlepage');
  297. }
  298. }
  299. }
  300. //删除
  301. public function del()
  302. {
  303. $this->check_priv('delete');
  304. $catid = $this->request->param('catid/d', 0);
  305. $ids = $this->request->param('id/a', null);
  306. if (empty($ids) || !$catid) {
  307. $this->error('参数错误!');
  308. }
  309. if (!is_array($ids)) {
  310. $ids = [0 => $ids];
  311. }
  312. $modelid = getCategory($catid, 'modelid');
  313. try {
  314. foreach ($ids as $id) {
  315. $this->CmsModel->deleteModelData($modelid, $id, $this->cmsConfig['web_site_recycle']);
  316. }
  317. } catch (\Exception $ex) {
  318. $this->error($ex->getMessage());
  319. }
  320. $this->success('删除成功!');
  321. }
  322. //清空回收站
  323. public function destroy()
  324. {
  325. $catid = $this->request->param('catid/d', 0);
  326. $ids = $this->request->param('id/a', null);
  327. if (empty($ids) || !$catid) {
  328. $this->error('参数错误!');
  329. }
  330. if (!is_array($ids)) {
  331. $ids = [0 => $ids];
  332. }
  333. $modelid = getCategory($catid, 'modelid');
  334. try {
  335. foreach ($ids as $id) {
  336. $this->CmsModel->deleteModelData($modelid, $id);
  337. }
  338. } catch (\Exception $ex) {
  339. $this->error($ex->getMessage());
  340. }
  341. $this->success('销毁成功!');
  342. }
  343. //面板
  344. public function panl()
  345. {
  346. if ($this->request->isPost()) {
  347. $date = $this->request->post('date');
  348. list($xAxisData, $seriesData) = $this->getAdminPostData($date);
  349. $this->success('', '', ['xAxisData' => $xAxisData, 'seriesData' => $seriesData]);
  350. } else {
  351. $info['category'] = Db::name('Category')->count();
  352. $info['model'] = Db::name('Model')->where(['module' => 'cms'])->count();
  353. $info['tags'] = Db::name('Tags')->count();
  354. $info['doc'] = Db::name('Category')->where('type', 2)->sum('items');
  355. list($xAxisData, $seriesData) = $this->getAdminPostData();
  356. $this->assign('xAxisData', $xAxisData);
  357. $this->assign('seriesData', $seriesData);
  358. $this->assign('info', $info);
  359. return $this->fetch();
  360. }
  361. }
  362. protected function getAdminPostData($date = '')
  363. {
  364. if ($date) {
  365. list($start, $end) = explode(' - ', $date);
  366. $start_time = strtotime($start);
  367. $end_time = strtotime($end);
  368. } else {
  369. $start_time = \util\Date::unixtime('day', 0, 'begin');
  370. $end_time = \util\Date::unixtime('day', 0, 'end');
  371. }
  372. $diff_time = $end_time - $start_time;
  373. $format = '%Y-%m-%d';
  374. if ($diff_time > 86400 * 30 * 2) {
  375. $format = '%Y-%m';
  376. } else {
  377. if ($diff_time > 86400) {
  378. $format = '%Y-%m-%d';
  379. } else {
  380. $format = '%H:00';
  381. }
  382. }
  383. //获取所有表名
  384. $models = Db::name('model')->where(['module' => 'cms', 'status' => 1])->select();
  385. $list = $xAxisData = $seriesData = [];
  386. if (count($models) > 0) {
  387. $table1 = $models[0]['tablename'];
  388. unset($models[0]);
  389. $field = 'a.username,uid,FROM_UNIXTIME(b.create_time, "' . $format . '") as create_times,COUNT(*) AS num';
  390. $dbObj = Db::name($table1)->alias('b')->field($field)->where('b.create_time', 'between time', [$start_time, $end_time])->join('admin a', 'a.id = b.uid');
  391. foreach ($models as $k => $v) {
  392. $dbObj->union(function ($query) use ($field, $start_time, $end_time, $v) {
  393. $query->name($v['tablename'])->alias('b')->field($field)->where('b.create_time', 'between time', [$start_time, $end_time])->join('admin a', 'a.id = b.uid')->group('uid,create_times');
  394. });
  395. };
  396. $res = $dbObj->group('uid,create_times')->select();
  397. if ($diff_time > 84600 * 30 * 2) {
  398. $start_time = strtotime('last month', $start_time);
  399. while (($start_time = strtotime('next month', $start_time)) <= $end_time) {
  400. $column[] = date('Y-m', $start_time);
  401. }
  402. } else {
  403. if ($diff_time > 86400) {
  404. for ($time = $start_time; $time <= $end_time;) {
  405. $column[] = date("Y-m-d", $time);
  406. $time += 86400;
  407. }
  408. } else {
  409. for ($time = $start_time; $time <= $end_time;) {
  410. $column[] = date("H:00", $time);
  411. $time += 3600;
  412. }
  413. }
  414. }
  415. $xAxisData = array_fill_keys($column, 0);
  416. foreach ($res as $k => $v) {
  417. if (!isset($list[$v['username']])) {
  418. $list[$v['username']] = $xAxisData;
  419. }
  420. $list[$v['username']][$v['create_times']] = $v['num'];
  421. }
  422. foreach ($list as $index => $item) {
  423. $seriesData[] = [
  424. 'name' => $index,
  425. 'type' => 'line',
  426. 'smooth' => true,
  427. 'areaStyle' => [],
  428. 'data' => array_values($item),
  429. ];
  430. }
  431. }
  432. return [array_keys($xAxisData), $seriesData];
  433. }
  434. /**
  435. * 排序
  436. */
  437. public function listorder()
  438. {
  439. $this->check_priv('listorder');
  440. $catid = $this->request->param('catid/d', 0);
  441. $id = $this->request->param('id/d', 0);
  442. $listorder = $this->request->param('value/d', 0);
  443. $modelid = getCategory($catid, 'modelid');
  444. $modelCache = cache("Model");
  445. if (empty($modelCache[$modelid])) {
  446. return false;
  447. };
  448. $tableName = $modelCache[$modelid]['tablename'];
  449. if (Db::name($tableName)->where('id', $id)->update(['listorder' => $listorder])) {
  450. $this->success("排序成功!");
  451. } else {
  452. $this->error("排序失败!");
  453. }
  454. }
  455. //回收站
  456. public function recycle()
  457. {
  458. $catid = $this->request->param('catid/d', 0);
  459. //当前栏目信息
  460. $catInfo = getCategory($catid);
  461. if (empty($catInfo)) {
  462. $this->error('该栏目不存在!');
  463. }
  464. //栏目所属模型
  465. $modelid = $catInfo['modelid'];
  466. if ($this->request->isAjax()) {
  467. $modelCache = cache("Model");
  468. $tableName = $modelCache[$modelid]['tablename'];
  469. $this->modelClass = Db::name($tableName);
  470. list($page, $limit, $where) = $this->buildTableParames();
  471. $conditions = [
  472. ['catid', '=', $catid],
  473. ['status', '=', -1],
  474. ];
  475. $total = Db::name($tableName)->where($where)->where($conditions)->count();
  476. $_list = Db::name($tableName)->where($where)->page($page, $limit)->where($conditions)->order('listorder DESC, id DESC')->select();
  477. $result = ["code" => 0, "count" => $total, "data" => $_list];
  478. return json($result);
  479. }
  480. $this->assign('catid', $catid);
  481. return $this->fetch();
  482. }
  483. //还原回收站
  484. public function restore()
  485. {
  486. $catid = $this->request->param('catid/d', 0);
  487. //当前栏目信息
  488. $catInfo = getCategory($catid);
  489. if (empty($catInfo)) {
  490. $this->error('该栏目不存在!');
  491. }
  492. //栏目所属模型
  493. $modelid = $catInfo['modelid'];
  494. $ids = $this->request->param('id/a');
  495. $modelInfo = cache('Model');
  496. $modelInfo = $modelInfo[$modelid];
  497. if ($ids) {
  498. if (!is_array($ids)) {
  499. $ids = [0 => $ids];
  500. }
  501. Db::name($modelInfo['tablename'])->where('id', 'in', $ids)->setField('status', 1);
  502. }
  503. $this->success('还原成功!');
  504. }
  505. //状态
  506. public function setstate()
  507. {
  508. $this->check_priv('status');
  509. $catid = $this->request->param('catid/d', 0);
  510. $id = $this->request->param('id/d', 0);
  511. $status = $this->request->param('value/d');
  512. $modelid = getCategory($catid, 'modelid');
  513. $modelCache = cache("Model");
  514. if (empty($modelCache[$modelid])) {
  515. return false;
  516. };
  517. $tableName = ucwords($modelCache[$modelid]['tablename']);
  518. if (Db::name($tableName)->where('id', $id)->update(['status' => $status])) {
  519. //更新栏目缓存
  520. cache('Category', null);
  521. getCategory($id, '', true);
  522. $data = Db::name($tableName)->where('id', $id)->find();
  523. //标签
  524. hook('content_edit_end', $data);
  525. $this->success('操作成功!');
  526. } else {
  527. $this->error('操作失败!');
  528. }
  529. }
  530. public function check_title()
  531. {
  532. $title = $this->request->param('data/s', '');
  533. $catid = $this->request->param('catid/d', 0);
  534. $id = $this->request->param('id/d', 0);
  535. if (empty($title)) {
  536. $this->success('标题没有重复!');
  537. return false;
  538. }
  539. $modelid = getCategory($catid, 'modelid');
  540. $modelCache = cache("Model");
  541. if (empty($modelCache[$modelid])) {
  542. $this->error('模型不存在!');
  543. return false;
  544. };
  545. $tableName = ucwords($modelCache[$modelid]['tablename']);
  546. $repeat = Db::name($tableName)->where('title', $title);
  547. empty($id) ?: $repeat->where('id', '<>', $id);
  548. if ($repeat->find()) {
  549. $this->error('标题有重复!');
  550. } else {
  551. $this->success('标题没有重复!');
  552. }
  553. }
  554. //批量更新
  555. public function multi()
  556. {
  557. // 管理员禁止批量操作
  558. $this->error();
  559. }
  560. protected function check_priv($action)
  561. {
  562. if ($this->auth->isAdministrator() !== true) {
  563. if (0 !== (int) $this->cmsConfig['site_category_auth']) {
  564. $catid = $this->request->param('catid/d', 0);
  565. $action = getCategory($catid, 'type') == 1 ? 'init' : $action;
  566. $priv_datas = Db::name('CategoryPriv')->where(['catid' => $catid, 'is_admin' => 1, 'roleid' => $this->auth->roleid, 'action' => $action])->find();
  567. if (empty($priv_datas)) {
  568. $this->error('您没有操作该项的权限!');
  569. }
  570. }
  571. }
  572. }
  573. public function yzCid29($catid,$data,$type='add')
  574. {
  575. //主词列表
  576. //判断是否唯一 不管status
  577. if($type == 'add'){
  578. $one = Db::name('options')->where([
  579. 'catid' => $catid,
  580. 'title' => $data['modelField']['title'],
  581. ])->find();
  582. }else{
  583. $one = Db::name('options')->where([
  584. 'catid' => $catid,
  585. 'title' => $data['modelField']['title'],
  586. ])->where('id','<>',$data['modelField']['id'])->find();
  587. }
  588. if(!empty($one)){
  589. //$this->error("该选项列表下此标题已存在!");
  590. return [1,'该选项列表下此标题已存在!'];
  591. }
  592. return [0,'success'];
  593. }
  594. public function yzCid17($catid,$data,$type='add'){
  595. //关键词栏目
  596. //进行判断标题是否存在
  597. //不用考虑状态还有指令类型
  598. if($type == 'add') {
  599. $one = Db::name('cms_zl')->where([
  600. 'catid' => $catid,
  601. 'gzxh' => $data['modelField']['gzxh'],
  602. 'title' => $data['modelField']['title'],
  603. ])->find();
  604. }else{
  605. $one = Db::name('cms_zl')->where([
  606. 'catid' => $catid,
  607. 'gzxh' => $data['modelField']['gzxh'],
  608. 'title' => $data['modelField']['title'],
  609. ])->where('id','<>',$data['modelField']['id'])->find();
  610. }
  611. if (!empty($one)) {
  612. //$this->error("该规则下此标题已存在!");
  613. return [1,'该规则下此标题已存在!'];
  614. }
  615. //为全局时 指令类型可以是其中一种
  616. if((int)$data['modelField']['is_qj'] === 1){
  617. //是全局
  618. $t_data = [
  619. '全局-非主非副','全局-主词类型','全局-副词类型'
  620. ];
  621. if(!in_array($data['modelField']['title'],$t_data)){
  622. //$this->error("标题必须是'全局-非主非副','全局-主词类型','全局-副词类型'其中一个!");
  623. return [1,"标题必须是'全局-非主非副','全局-主词类型','全局-副词类型'其中一个!"];
  624. }
  625. }else{
  626. //非全局时
  627. if((int)$data['modelField']['zllx'] === 0){
  628. //$this->error("非全局时,指令类型不能是(非主非副)!");
  629. return [1,"非全局时,指令类型不能是(非主非副)!"];
  630. }
  631. }
  632. //如果是主词类型时 且非全局
  633. if((int)$data['modelField']['is_qj'] === 0 && (int)$data['modelField']['zllx'] === 1){
  634. //验证是否存在主词
  635. $one = Db::name('options')->where([
  636. 'catid' => 29,
  637. 'title' => $data['modelField']['title'],
  638. ])->find();
  639. if(empty($one)){
  640. //$this->error("请先添加主词选项或选择正确的指令类型!");
  641. return [1,"请先添加主词选项或选择正确的指令类型!"];
  642. }
  643. //如果是
  644. if(!empty($one['fclb']) && (int)$data['modelField']['fclx'] === 0) {
  645. //自动获取副词 填入字段
  646. //自定义 就不覆盖 以当前填写为主 这是快照 = 新规则
  647. if (empty($data['modelField']['fclb']) || (string)$data['modelField']['fclb'] == '0') {
  648. $data['modelField']['fclb'] = $one['fclb'];
  649. }else{
  650. //可能选的是复用设置 但是这里确填写了
  651. //$this->error("请选择副词类型为自定义设置!");
  652. return [1,"请选择副词类型为自定义设置!"];
  653. }
  654. }
  655. }
  656. //如果是副词类型时 且非全局
  657. if((int)$data['modelField']['is_qj'] === 0 && (int)$data['modelField']['zllx'] === 2){
  658. if(empty($data['modelField']['zc']) || (string)$data['modelField']['zc'] == '0'){
  659. //$this->error("请填写主词字段!");
  660. return [1,"请填写主词字段!"];
  661. }else{
  662. //验证主词字段是否包含于标题
  663. if(strpos($data['modelField']['title'], $data['modelField']['zc']) !== false){
  664. } else {
  665. //$this->error("标题未包含主词,请检查!");
  666. return [1,"标题未包含主词,请检查!"];
  667. }
  668. //验证是否存在主词
  669. $one = Db::name('options')->where([
  670. 'catid' => 29,
  671. 'title' => $data['modelField']['zc'],
  672. ])->find();
  673. if(empty($one)){
  674. //$this->error("当前添加副词规则,请先添加主词选项!");
  675. return [1,"当前添加副词规则,请先添加主词选项!"];
  676. }
  677. //得到副词
  678. $fc = str_replace($data['modelField']['zc'], "", $data['modelField']['title']);
  679. //优先验证是否存在于主词规则里面
  680. $two = Db::name('cms_zl')->where([
  681. 'catid' => $catid,
  682. 'gzxh' => $data['modelField']['gzxh'],
  683. 'title' => $data['modelField']['zc'],
  684. ])->find();
  685. if(!empty($two)){
  686. if(strpos($two['fclb'], $fc) !== false){
  687. //存在于主词规则中 通过
  688. } else {
  689. //$this->error("主词规则中未找到当前副词!");
  690. //再次验证是否存在主词设置中
  691. if(strpos($one['fclb'], $fc) !== false){
  692. //存在 通过
  693. } else {
  694. //$this->error("主词规则存在但在该规则和主词设置两者中都未找到当前副词!");
  695. return [1,"主词规则存在但在该规则和主词设置两者中都未找到当前副词!"];
  696. }
  697. }
  698. }else{
  699. //不存在主词规则记录,再次验证是否存在主词设置中
  700. if(strpos($one['fclb'], $fc) !== false){
  701. //存在于主词规则记录中 通过
  702. } else {
  703. //$this->error("主词设置中未找到当前副词!");
  704. //$this->error("主词规则为空且主词设置中未找到当前副词!");
  705. return [1,"主词规则为空且主词设置中未找到当前副词!"];
  706. }
  707. }
  708. }
  709. }
  710. return [0,'success'];
  711. }
  712. }