SystemGroupData.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\setting;
  12. use app\admin\model\special\SpecialSubject;
  13. use app\admin\model\special\RecommendBanner;
  14. use app\admin\model\special\Special;
  15. use app\admin\model\special\Lecturer;
  16. use app\admin\model\system\Recommend;
  17. use app\admin\model\system\RecommendRelation;
  18. use app\admin\model\system\WebRecommend;
  19. use app\admin\model\system\WebRecommendRelation;
  20. use app\admin\model\user\Group;
  21. use service\FormBuilder as Form;
  22. use service\JsonService as Json;
  23. use service\UploadService as Upload;
  24. use think\Request;
  25. use think\Url;
  26. use app\admin\model\system\SystemGroup as GroupModel;
  27. use app\admin\model\system\SystemGroupData as GroupDataModel;
  28. use app\admin\controller\AuthController;
  29. use app\admin\model\system\SystemAttachment;
  30. use service\SystemConfigService;
  31. use app\admin\model\system\SystemConfig;
  32. use app\admin\model\download\DataDownload;
  33. /**
  34. * 数据列表控制器 在组合数据中
  35. * Class SystemGroupData
  36. * @package app\admin\controller\setting
  37. */
  38. class SystemGroupData extends AuthController
  39. {
  40. /**
  41. * 显示资源列表
  42. * @return \think\Response
  43. */
  44. public function index($gid)
  45. {
  46. $where = parent::getMore([
  47. ['status', '']
  48. ], $this->request);
  49. $this->assign('where', $where);
  50. $this->assign(compact("gid"));
  51. $this->assign(GroupModel::getField($gid));
  52. $where['gid'] = $gid;
  53. $this->assign(GroupDataModel::getList($where));
  54. return $this->fetch();
  55. }
  56. /**
  57. * 显示创建资源表单页.
  58. * @return \think\Response
  59. */
  60. public function create($gid)
  61. {
  62. $Fields = GroupModel::getField($gid);
  63. $f = array();
  64. foreach ($Fields["fields"] as $key => $value) {
  65. $info = [];
  66. if (!empty($value["param"])) {
  67. $value["param"] = str_replace("\r\n", "\n", $value["param"]);//防止不兼容
  68. $params = explode("\n", $value["param"]);
  69. if (is_array($params) && !empty($params)) {
  70. foreach ($params as $index => $v) {
  71. if (strstr($v, '=>') !== false) {
  72. list($left, $right) = explode('=>', $v);
  73. } else if (strstr($v, '=') !== false) {
  74. list($left, $right) = explode('=', $v);
  75. }
  76. $val["value"] = $left;
  77. $val["label"] = $right;
  78. $info[] = $val;
  79. }
  80. }
  81. }
  82. switch ($value["type"]) {
  83. case 'input':
  84. $f[] = Form::input($value["title"], $value["name"])->maxlength(90);
  85. break;
  86. case 'textarea':
  87. $f[] = Form::input($value["title"], $value["name"])->type('textarea')->placeholder($value['param']);
  88. break;
  89. case 'radio':
  90. $f[] = Form::radio($value["title"], $value["name"], isset($info[0]["value"]) ? $info[0]["value"] : '')->options($info);
  91. break;
  92. case 'checkbox':
  93. $f[] = Form::checkbox($value["title"], $value["name"], isset($info[0]) ? $info[0] : '')->options($info);
  94. break;
  95. case 'select':
  96. $f[] = Form::select($value["title"], $value["name"], isset($info[0]) ? $info[0] : '')->options($info)->multiple(false);
  97. break;
  98. case 'upload':
  99. $f[] = Form::frameImageOne($value["title"], $value["name"], Url::build('admin/widget.images/index', array('fodder' => $value["title"])))->icon('image')->width('100%')->height('500px');
  100. break;
  101. case 'uploads':
  102. $f[] = Form::frameImages($value["title"], $value["name"], Url::build('admin/widget.images/index', array('fodder' => $value["title"])))->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0);
  103. break;
  104. default:
  105. $f[] = Form::input($value["title"], $value["name"]);
  106. break;
  107. }
  108. }
  109. $f[] = Form::number('sort', '排序', 1)->min(0);
  110. $f[] = Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
  111. $form = Form::make_post_form('添加数据', $f, Url::build('save', compact('gid')), 2);
  112. $this->assign(compact('form'));
  113. return $this->fetch('public/form-builder');
  114. }
  115. /**
  116. * 保存新建的资源
  117. *
  118. * @param \think\Request $request
  119. * @return \think\Response
  120. */
  121. public function save(Request $request, $gid)
  122. {
  123. $Fields = GroupModel::getField($gid);
  124. $params = $request->post();
  125. $value = array();
  126. foreach ($params as $key => $param) {
  127. foreach ($Fields['fields'] as $index => $field) {
  128. if ($key == $field["title"]) {
  129. if ($param == "" || preg_replace("#(^( |\s)+|( |\s)+$)#", "", $param) == '')
  130. return Json::fail($field["name"] . "不能为空!");
  131. else {
  132. $value[$key]["type"] = $field["type"];
  133. $value[$key]["value"] = $param;
  134. }
  135. }
  136. }
  137. }
  138. $data = array("gid" => $gid, "add_time" => time(), "value" => json_encode($value), "sort" => $params["sort"], "status" => $params["status"]);
  139. GroupDataModel::set($data);
  140. return Json::successful('添加数据成功!');
  141. }
  142. /**
  143. * 显示编辑资源表单页.
  144. * @param int $id
  145. * @return \think\Response
  146. */
  147. public function edit($gid, $id)
  148. {
  149. $GroupData = GroupDataModel::get($id);
  150. $GroupDataValue = json_decode($GroupData["value"], true);
  151. $Fields = GroupModel::getField($gid);
  152. $f = array();
  153. foreach ($Fields['fields'] as $key => $value) {
  154. $info = [];
  155. if (!empty($value["param"])) {
  156. $value["param"] = str_replace("\r\n", "\n", $value["param"]);//防止不兼容
  157. $params = explode("\n", $value["param"]);
  158. if (is_array($params) && !empty($params)) {
  159. foreach ($params as $index => $v) {
  160. if (strstr($v, '=>') !== false) {
  161. list($left, $right) = explode('=>', $v);
  162. } else if (strstr($v, '=') !== false) {
  163. list($left, $right) = explode('=', $v);
  164. }
  165. $val["value"] = $left;
  166. $val["label"] = $right;
  167. $info[] = $val;
  168. }
  169. }
  170. }
  171. switch ($value['type']) {
  172. case 'input':
  173. $f[] = Form::input($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->maxlength(90);
  174. break;
  175. case 'textarea':
  176. $f[] = Form::input($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->type('textarea');
  177. break;
  178. case 'radio':
  179. $f[] = Form::radio($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->options($info);
  180. break;
  181. case 'checkbox':
  182. if (array_key_exists($value['title'], $GroupDataValue)) {
  183. $f[] = Form::checkbox($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->options($info);
  184. } else {
  185. $f[] = Form::checkbox($value["title"], $value["name"], isset($info[0]) ? $info[0] : '')->options($info);
  186. }
  187. break;
  188. case 'upload':
  189. if (!empty($GroupDataValue[$value['title']]['value'])) {
  190. $image = is_string($GroupDataValue[$value['title']]['value']) ? $GroupDataValue[$value['title']]['value'] : $GroupDataValue[$value['title']]['value'][0];
  191. } else {
  192. $image = '';
  193. }
  194. $f[] = Form::frameImageOne($value['title'], $value['name'], Url::build('admin/widget.images/index', array('fodder' => $value['title'])), $image)->icon('image')->width('100%')->height('500px');
  195. break;
  196. case 'uploads':
  197. $images = !empty($GroupDataValue[$value['title']]['value']) ? $GroupDataValue[$value['title']]['value'] : [];
  198. $f[] = Form::frameImages($value['title'], $value['name'], Url::build('admin/widget.images/index', array('fodder' => $value['title'])), $images)->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0);
  199. break;
  200. case 'select':
  201. $f[] = Form::select($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->setOptions($info);
  202. break;
  203. default:
  204. $f[] = Form::input($value['title'], $value['name'], $GroupDataValue[$value['title']]['value']);
  205. break;
  206. }
  207. }
  208. $f[] = Form::number('sort', '排序', $GroupData["sort"])->min(0);
  209. $f[] = Form::radio('status', '状态', $GroupData["status"])->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
  210. $form = Form::make_post_form('编辑', $f, Url::build('update', compact('id')), 2);
  211. $this->assign(compact('form'));
  212. return $this->fetch('public/form-builder');
  213. }
  214. /**
  215. * 保存更新的资源
  216. *
  217. * @param \think\Request $request
  218. * @param int $id
  219. * @return \think\Response
  220. */
  221. public function update(Request $request, $id)
  222. {
  223. $GroupData = GroupDataModel::get($id);
  224. $Fields = GroupModel::getField($GroupData["gid"]);
  225. $params = $request->post();
  226. foreach ($params as $key => $param) {
  227. foreach ($Fields['fields'] as $index => $field) {
  228. if ($key == $field["title"]) {
  229. if ($param == "" || preg_replace("#(^( |\s)+|( |\s)+$)#", "", $param) == '')
  230. return Json::fail($field["name"] . "不能为空!");
  231. else {
  232. $value[$key]["type"] = $field["type"];
  233. $value[$key]["value"] = $param;
  234. }
  235. }
  236. }
  237. }
  238. $data = array("value" => json_encode($value), "sort" => $params["sort"], "status" => $params["status"]);
  239. GroupDataModel::edit($data, $id);
  240. return Json::successful('修改成功!');
  241. }
  242. /**
  243. * 删除指定资源
  244. *
  245. * @param int $id
  246. * @return \think\Response
  247. */
  248. public function delete($id)
  249. {
  250. if (!GroupDataModel::del($id))
  251. return Json::fail(GroupDataModel::getErrorInfo('删除失败,请稍候再试!'));
  252. else
  253. return Json::successful('删除成功!');
  254. }
  255. public function upload()
  256. {
  257. $res = Upload::image('file', 'common');
  258. $thumbPath = Upload::thumb($res->dir);
  259. //产品图片上传记录
  260. $fileInfo = $res->fileInfo->getinfo();
  261. SystemAttachment::attachmentAdd($res->fileInfo->getSaveName(), $fileInfo['size'], $fileInfo['type'], $res->dir, $thumbPath, 6);
  262. if ($res->status == 200)
  263. return Json::successful('图片上传成功!', ['name' => $res->fileInfo->getSaveName(), 'url' => Upload::pathToUrl($thumbPath)]);
  264. else
  265. return Json::fail($res->error);
  266. }
  267. public function recommend()
  268. {
  269. $this->assign('fixedList', Recommend::fixedList());
  270. return $this->fetch();
  271. }
  272. public function recommend_list()
  273. {
  274. $where = parent::getMore([
  275. ['page', 1],
  276. ['limit', 20],
  277. ['order', ''],
  278. ['is_fixed', $this->request->param('is_fixed', 0)]
  279. ]);
  280. return Json::successlayui(Recommend::getRecommendList($where));
  281. }
  282. public function create_recemmend($id = 0)
  283. {
  284. if ($id) $this->assign('recemmend', Recommend::get($id));
  285. $this->assign('is_fixed', 1);
  286. $this->assign('grade_list', SpecialSubject::specialCategoryAll(1));
  287. $this->assign('id', $id);
  288. return $this->fetch();
  289. }
  290. public function create_recemmend_v1($id = 0)
  291. {
  292. if ($id) $this->assign('recemmend', Recommend::get($id));
  293. $this->assign('is_fixed', 0);
  294. $this->assign('grade_list', SpecialSubject::specialCategoryAll(1));
  295. $this->assign('is_fixed', 0);
  296. $this->assign('id', $id);
  297. return $this->fetch();
  298. }
  299. public function save_recemmend($id = 0)
  300. {
  301. $post = parent::postMore([
  302. ['icon', ''],
  303. ['image', ''],
  304. ['title', ''],
  305. ['type', ''],
  306. ['sort', 0],
  307. ['is_fixed', 0],
  308. ['is_show', 0],
  309. ['grade_id', 0],
  310. ['show_count', 0],
  311. ['typesetting', ''],
  312. ]);
  313. $post['is_show'] = $post['is_fixed'] ? 1 : $post['is_show'];
  314. if ($post['type'] == 14) {
  315. if ($post['typesetting'] == 1 || $post['typesetting'] == 4) return Json::fail('资料不能选择该排版');
  316. }
  317. if ($post['typesetting'] == 5) {
  318. unset($post['type'], $post['image'], $post['show_count']);
  319. }
  320. if ($id) {
  321. $rescomm = Recommend::get($id);
  322. if (!$rescomm) return Json::fail('修改的信息不存在');
  323. Recommend::update($post, ['id' => $id]);
  324. return Json::successful('修改成功');
  325. } else {
  326. $post['add_time'] = time();
  327. if (Recommend::set($post))
  328. return Json::successful('保存成功');
  329. else
  330. return Json::fail('保存失败');
  331. }
  332. }
  333. public function recemmend_content($id = 0)
  334. {
  335. if (!$id) return Json::fail('缺少参数');
  336. if ($this->request->isAjax()) {
  337. $where = parent::getMore([
  338. ['page', 1],
  339. ['limit', 20],
  340. ]);
  341. return Json::successlayui(RecommendRelation::getAll($where, $id));
  342. } else {
  343. $this->assign('id', $id);
  344. return $this->fetch();
  345. }
  346. }
  347. /**新闻\素材推荐内容
  348. * @param int $id
  349. * @return mixed
  350. */
  351. public function recemmend_article_content($id = 0)
  352. {
  353. $this->assign('id', $id);
  354. return $this->fetch();
  355. }
  356. /**练习/考试推荐内容
  357. * @param int $id
  358. * @return mixed
  359. */
  360. public function recemmend_test_content($id = 0)
  361. {
  362. $this->assign('id', $id);
  363. return $this->fetch();
  364. }
  365. /**商品推荐内容
  366. * @param int $id
  367. * @return mixed
  368. */
  369. public function recemmend_store_content($id = 0)
  370. {
  371. $this->assign('id', $id);
  372. return $this->fetch();
  373. }
  374. public function recemmed_delete($id = 0)
  375. {
  376. if (!$id) return Json::fail('缺少参数');
  377. if (RecommendRelation::del($id))
  378. return Json::successful('删除成功');
  379. else
  380. return Json::fail('删除失败');
  381. }
  382. /**
  383. * 设置单个产品上架|下架
  384. *
  385. * @return json
  386. */
  387. public function set_show($is_show = '', $id = '', $recommend = '')
  388. {
  389. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  390. if ($recommend == 'web') {
  391. $res = WebRecommend::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  392. } else {
  393. $res = Recommend::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  394. }
  395. if ($res) {
  396. return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  397. } else {
  398. return Json::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  399. }
  400. }
  401. public function set_show_banner($is_show = '', $id = '')
  402. {
  403. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  404. $res = RecommendBanner::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  405. if ($res) {
  406. return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  407. } else {
  408. return Json::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  409. }
  410. }
  411. /**
  412. * 快速编辑
  413. *
  414. * @return json
  415. */
  416. public function set_value($field = '', $id = '', $value = '', $recommend = '')
  417. {
  418. $field == '' || $id == '' || $value == '' && Json::fail('缺少参数');
  419. if ($recommend == 'web') {
  420. $res = WebRecommend::where(['id' => $id])->update([$field => $value]);
  421. } else {
  422. $res = Recommend::where(['id' => $id])->update([$field => $value]);
  423. }
  424. if ($res)
  425. return Json::successful('保存成功');
  426. else
  427. return Json::fail('保存失败');
  428. }
  429. /**
  430. * 快速编辑
  431. *
  432. * @return json
  433. */
  434. public function set_recemmend_value($field = '', $id = '', $value = '')
  435. {
  436. $field == '' || $id == '' || $value == '' && Json::fail('缺少参数');
  437. if (RecommendRelation::where(['id' => $id])->update([$field => $value]))
  438. return Json::successful('保存成功');
  439. else
  440. return Json::fail('保存失败');
  441. }
  442. public function set_value_banner($field = '', $id = '', $value = '')
  443. {
  444. $field == '' || $id == '' || $value == '' && Json::fail('缺少参数');
  445. if (RecommendBanner::where(['id' => $id])->update([$field => $value]))
  446. return Json::successful('保存成功');
  447. else
  448. return Json::fail('保存失败');
  449. }
  450. /**
  451. * 删除指定资源
  452. *
  453. * @param int $id
  454. * @return \think\Response
  455. */
  456. public function delete_recomm($id)
  457. {
  458. if (RecommendBanner::be(['recommend_id' => $id])) return Json::fail('删除失败,请先删除Banner图');
  459. if (RecommendRelation::be(['recommend_id' => $id])) return Json::fail('删除失败,请先删除内容管理里面的列表');
  460. if (!Recommend::del($id))
  461. return Json::fail('删除失败');
  462. else
  463. return Json::successful('删除成功!');
  464. }
  465. /**
  466. * 删除导航推荐
  467. * @param string $id
  468. */
  469. public function delete_banner($id = '')
  470. {
  471. if (!RecommendBanner::del($id))
  472. return Json::fail('删除失败');
  473. else
  474. return Json::successful('删除成功!');
  475. }
  476. public function recemmend_banner($id = '')
  477. {
  478. if ($id == '') return $this->failed('缺少参数');
  479. $this->assign('id', $id);
  480. $this->assign('type', 1);
  481. return $this->fetch();
  482. }
  483. public function recemmend_banner_list()
  484. {
  485. $where = parent::getMore([
  486. ['id', ''],
  487. ['page', ''],
  488. ['limit', ''],
  489. ]);
  490. if ($where['id'] == '') return Json::fail('缺少参数');
  491. return Json::successlayui(RecommendBanner::getRecemmodBannerList($where));
  492. }
  493. /*
  494. * 创建banner图
  495. * */
  496. public function create_recemmend_banner($id = '', $banner_id = 0)
  497. {
  498. $this->assign('id', $id);
  499. if ($banner_id) {
  500. $banner = RecommendBanner::get($banner_id);
  501. if (!$banner) return $this->failed('缺少修改的banner');
  502. $banner['pic_key'] = get_key_attr($banner['pic'], false);
  503. $this->assign('banner', $banner);
  504. }
  505. $this->assign('banner_id', (int)$banner_id);
  506. $this->assign('type', 2);
  507. return $this->fetch();
  508. }
  509. public function save_recemmend_banner($id = '', $banner_id = '')
  510. {
  511. $post = parent::postMore([
  512. ['url', ''],
  513. ['sort', ''],
  514. ['is_show', 0],
  515. ['pic', ''],
  516. ]);
  517. if ($id == '') return Json::fail('缺少参数');
  518. if ($post['pic'] == '') return Json::fail('请上传封面图!');
  519. if ($post['is_show'] == 'on') $post['is_show'] = 1;
  520. else $post['is_show'] = 0;
  521. $post['recommend_id'] = $id;
  522. if ($banner_id) {
  523. RecommendBanner::edit($post, $banner_id);
  524. return Json::successful('修改成功');
  525. } else {
  526. $post['add_time'] = time();
  527. RecommendBanner::set($post);
  528. return Json::successful('保存成功');
  529. }
  530. }
  531. /**
  532. * 首页导航固定跳转添加
  533. * @return mixed
  534. */
  535. public function navigation()
  536. {
  537. return $this->fetch();
  538. }
  539. /**
  540. * 个人中心题库菜单
  541. */
  542. public function center_menu_topic($gid = 0)
  543. {
  544. $this->assign('gid', $gid);
  545. return $this->fetch('center_menu1');
  546. }
  547. /**
  548. * 个人中心服务菜单
  549. */
  550. public function center_menu()
  551. {
  552. return $this->fetch('center_menu');
  553. }
  554. /**
  555. * pc端首页导航
  556. */
  557. public function center_web_menu()
  558. {
  559. return $this->fetch();
  560. }
  561. /**
  562. * pc端自定义跳转导航添加和修改页面
  563. * @param int $id
  564. * @return mixed|void
  565. * @throws \FormBuilder\exception\FormBuilderException
  566. * @throws \think\exception\DbException
  567. */
  568. public function create_web_recemmend_custom($id = 0, $is_fixed = 1)
  569. {
  570. if ($id) {
  571. $recommend = WebRecommend::get($id);
  572. if (!$recommend) {
  573. return $this->failed('您修改的导航不存在');
  574. }
  575. }
  576. $f[] = Form::input('title', '名称', isset($recommend) ? $recommend->title : '');
  577. $f[] = Form::input('link', '跳转路径', isset($recommend) ? $recommend->link : '');
  578. $f[] = Form::input('sort', '排序', isset($recommend) ? $recommend->sort : 0);
  579. $f[] = Form::radio('is_show', '状态', isset($recommend) ? $recommend->is_show : 0)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
  580. $form = Form::make_post_form('编辑', $f, Url::build('save_web_recemmend_custom', compact('id', 'is_fixed')), 2);
  581. $this->assign(compact('form'));
  582. return $this->fetch('public/form-builder');
  583. }
  584. /**
  585. * 保存pc端自定义导航链接
  586. * @param int $id
  587. */
  588. public function save_web_recemmend_custom($id = 0, $is_fixed = 1)
  589. {
  590. $data = parent::postMore([
  591. ['title', ''],
  592. ['link', ''],
  593. ['sort', 0],
  594. ['is_show', 0],
  595. ['type', 6],
  596. ['is_fixed', $is_fixed],
  597. ]);
  598. $data['title'] = preg_replace("#(^( |\s)+|( |\s)+$)#", "", $data['title']);
  599. $data['link'] = preg_replace("#(^( |\s)+|( |\s)+$)#", "", $data['link']);
  600. if (!$data['title']) {
  601. return Json::fail('请填写导航名称');
  602. }
  603. if (mb_strlen($data['title']) > 6) return Json::fail('标题不能超过6个字');
  604. if (!$data['link']) {
  605. return Json::fail('请填写导航跳转地址');
  606. }
  607. if ($id) {
  608. WebRecommend::edit($data, $id);
  609. return Json::successful('修改成功');
  610. } else {
  611. $data['add_time'] = time();
  612. if (WebRecommend::be(['title' => $data['title'], 'link' => $data['link']])) return Json::fail('名称已存在');
  613. $res = WebRecommend::set($data);
  614. if ($res) {
  615. return Json::successful('添加成功');
  616. } else {
  617. return Json::fail('修改失败');
  618. }
  619. }
  620. }
  621. /**
  622. * 自定义跳转导航添加和修改页面
  623. * @param int $id
  624. * @return mixed|void
  625. * @throws \FormBuilder\exception\FormBuilderException
  626. * @throws \think\exception\DbException
  627. */
  628. public function create_recemmend_custom($id = 0, $is_fixed = 1)
  629. {
  630. if ($id) {
  631. $recommend = Recommend::get($id);
  632. if (!$recommend) {
  633. return $this->failed('您修改的导航不存在');
  634. }
  635. }
  636. $f[] = Form::input('title', '名称', isset($recommend) ? $recommend->title : '');
  637. $f[] = Form::frameImageOne('icon', '图标(100*100px)', get_image_Url('icon'), isset($recommend) ? $recommend->icon : '')->icon('image')->width('100%')->height('500px');
  638. $f[] = Form::input('link', '跳转路径', isset($recommend) ? $recommend->link : '');
  639. $f[] = Form::number('sort', '排序', isset($recommend) ? $recommend->sort : 0)->min(0);
  640. if ($is_fixed == 2) {
  641. $f[] = Form::radio('is_promoter', '推广权限', isset($recommend) ? $recommend->is_promoter : 0)->options([['value' => 1, 'label' => '需要权限'], ['value' => 0, 'label' => '无需权限']]);
  642. $f[] = Form::radio('is_write_off', '核销权限', isset($recommend) ? $recommend->is_write_off : 0)->options([['value' => 1, 'label' => '需要权限'], ['value' => 0, 'label' => '无需权限']]);
  643. $f[] = Form::radio('is_lecturer', '讲师菜单', isset($recommend) ? $recommend->is_lecturer : 0)->options([['value' => 0, 'label' => '非讲师菜单'], ['value' => 1, 'label' => '讲师申请菜单'], ['value' => 2, 'label' => '讲师中心菜单']]);
  644. }
  645. $f[] = Form::radio('is_show', '状态', isset($recommend) ? $recommend->is_show : 0)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
  646. $form = Form::make_post_form('编辑', $f, Url::build('save_recemmend_custom', compact('id', 'is_fixed')), 2);
  647. $this->assign(compact('form'));
  648. return $this->fetch('public/form-builder');
  649. }
  650. /**
  651. * 保存自定义导航链接
  652. * @param int $id
  653. */
  654. public function save_recemmend_custom($id = 0, $is_fixed = 1)
  655. {
  656. $data = parent::postMore([
  657. ['title', ''],
  658. ['icon', ''],
  659. ['link', ''],
  660. ['sort', 0],
  661. ['is_show', 0],
  662. ['is_promoter', 0],
  663. ['is_write_off', 0],
  664. ['is_lecturer', 0],
  665. ['type', 3],
  666. ['is_fixed', $is_fixed],
  667. ]);
  668. $data['title'] = preg_replace("#(^( |\s)+|( |\s)+$)#", "", $data['title']);
  669. $data['link'] = preg_replace("#(^( |\s)+|( |\s)+$)#", "", $data['link']);
  670. if (!$data['title']) {
  671. return Json::fail('请填写导航名称');
  672. }
  673. if (!$data['icon']) {
  674. return Json::fail('请选择导航图标');
  675. }
  676. if (!$data['link']) {
  677. return Json::fail('请填写导航跳转地址');
  678. }
  679. if ($id) {
  680. Recommend::edit($data, $id);
  681. return Json::successful('修改成功');
  682. } else {
  683. $data['add_time'] = time();
  684. if (Recommend::be(['title' => $data['title'], 'link' => $data['link']])) return Json::fail('名称已存在');
  685. $res = Recommend::set($data);
  686. if ($res) {
  687. return Json::successful('添加成功');
  688. } else {
  689. return Json::fail('修改失败');
  690. }
  691. }
  692. }
  693. /**
  694. * 显示资源列表
  695. * @return \think\Response
  696. */
  697. public function index_v1($gid)
  698. {
  699. $is_show_or_hide = SystemConfigService::get('is_show_or_hide');
  700. $this->assign(compact("gid", 'is_show_or_hide'));
  701. return $this->fetch();
  702. }
  703. /**
  704. * 获取某个组合数据列表
  705. * @param int $gid
  706. * @param int $page
  707. * @param int $limit
  708. * @throws \think\Exception
  709. */
  710. public function get_group_data_list($gid = 0, $status = '', $page = 1, $limit = 10)
  711. {
  712. $model = GroupDataModel::where(function ($query) use ($gid, $status) {
  713. $query->where('gid', $gid);
  714. if ($status != '') {
  715. $query->where('status', $status);
  716. }
  717. });
  718. $data = $model->order('sort desc,id desc')->page($page, $limit)->select();
  719. $data = count($data) ? $data->toArray() : [];
  720. foreach ($data as &$item) {
  721. $value = json_decode($item['value'], true);
  722. foreach ($value as $key => $val) {
  723. $item[$key] = $value[$key]['value'];
  724. }
  725. }
  726. $count = count($data);
  727. return Json::successlayui(compact('data', 'count'));
  728. }
  729. /**
  730. * 修改某个字段
  731. * @param string $field
  732. * @param int $id
  733. * @param string $value
  734. */
  735. public function set_group_data($field = '', $id = 0, $value = '')
  736. {
  737. if ('id' == $field) {
  738. return Json::fail('修改失败,主键不允许修改');
  739. }
  740. if (!$field && !$value) {
  741. return Json::fail('缺少修改参数');
  742. }
  743. $info = GroupDataModel::where('id', $id)->find();
  744. if (!$info) {
  745. return Json::fail('修改的信息不存在');
  746. }
  747. if (in_array($field, ['sort', 'status'])) {
  748. $info->{$field} = $value;
  749. $res = $info->save();
  750. } else {
  751. $infoVale = json_decode($info->value, true);
  752. $infoVale[$field]['value'] = $value;
  753. $info->value = json_encode($infoVale);
  754. $res = $info->save();
  755. }
  756. if ($res) {
  757. return Json::successful('修改成功');
  758. } else {
  759. return Json::fail('修改失败');
  760. }
  761. }
  762. /**
  763. * 添加组合数据页面
  764. * @return mixed
  765. */
  766. public function create_v1($id = 0)
  767. {
  768. $this->assign([
  769. 'specialList' => json_encode(Special::PreWhere()->field(['id', 'title'])->order('sort desc,id desc')->select()),
  770. 'cateList' => json_encode(SpecialSubject::specialCategoryAll(1)),
  771. ]);
  772. if ($id) {
  773. $info = GroupDataModel::get($id);
  774. if ($info) {
  775. $infoValue = json_decode($info->value, true);
  776. $this->assign('data', [
  777. 'title' => isset($infoValue['title']['value']) ? $infoValue['title']['value'] : "",
  778. 'pic' => isset($infoValue['pic']['value']) ? $infoValue['pic']['value'] : "",
  779. 'info' => isset($infoValue['info']['value']) ? $infoValue['info']['value'] : '',
  780. 'sort' => $info->sort,
  781. 'status' => $info->status,
  782. 'type' => isset($infoValue['type']['value']) ? $infoValue['type']['value'] : "''",
  783. 'select_id' => isset($infoValue['select_id']['value']) ? $infoValue['select_id']['value'] : "''",
  784. 'id' => $id
  785. ]);
  786. }
  787. }
  788. return $this->fetch();
  789. }
  790. public function save_group_data($name = '')
  791. {
  792. $data = parent::postMore([
  793. ['title', ''],
  794. ['id', ''],
  795. ['image', ''],
  796. ['info', ''],
  797. ['type', 0],
  798. ['select_id', 0],
  799. ['sort', 0],
  800. ['status', 0],
  801. ]);
  802. $gid = GroupModel::where(['config_name' => $name])->value('id');
  803. if (!isset($data['id']) || !$data['id']) {
  804. if (GroupDataModel::where('gid', $gid)->count() >= 3) {
  805. return Json::fail('最多能添加3条信息');
  806. }
  807. }
  808. if (!$data['title']) {
  809. return Json::fail('请输入标题');
  810. }
  811. if (!$data['image']) {
  812. return Json::fail('请选择图片');
  813. }
  814. if (!$data['info']) {
  815. return Json::fail('请输入简介');
  816. }
  817. if (!$data['select_id']) {
  818. return Json::fail('请选择' . ($data['type'] ? '分类' : "专题"));
  819. }
  820. $info = '{"pic":{"type":"upload","value":""},"title":{"type":"input","value":""},"info":{"type":"input","value":""},"wap_link":{"type":"select","value":""}}';
  821. $info = json_decode($info, true);
  822. $info['pic']['value'] = $data['image'];
  823. $info['title']['value'] = $data['title'];
  824. $info['info']['value'] = $data['info'];
  825. $info['select_id']['value'] = $data['select_id'];
  826. $info['select_id']['type'] = 'select';
  827. $info['type']['type'] = 'radio';
  828. $info['type']['value'] = $data['type'];
  829. if ($data['type']) {
  830. $info['wap_link']['value'] = '/wap/special/special_cate?cate_id=' . $data['select_id'];
  831. } else {
  832. $is_light = Special::where('id', $data['select_id'])->value('is_light');
  833. if ($is_light) {
  834. $info['wap_link']['value'] = '/wap/special/single_details?id=' . $data['select_id'];
  835. } else {
  836. $info['wap_link']['value'] = '/wap/special/details?id=' . $data['select_id'];
  837. }
  838. }
  839. if (isset($data['id']) && $data['id']) {
  840. $res = GroupDataModel::update([
  841. 'gid' => $gid,
  842. 'value' => json_encode($info),
  843. 'sort' => $data['sort'],
  844. 'status' => $data['status'],
  845. ], ['id' => $data['id']]);
  846. } else {
  847. $res = GroupDataModel::set([
  848. 'gid' => $gid,
  849. 'value' => json_encode($info),
  850. 'add_time' => time(),
  851. 'sort' => $data['sort'],
  852. 'status' => $data['status'],
  853. ]);
  854. }
  855. if ($res) {
  856. return Json::successful('编辑成功');
  857. } else {
  858. return Json::fail('编辑失败');
  859. }
  860. }
  861. /**首页活动是否显示
  862. * @param $value
  863. */
  864. public function is_show_or_hide($value)
  865. {
  866. $res = SystemConfig::edit(['value' => json_encode($value)], 'is_show_or_hide', 'menu_name');
  867. if ($res) {
  868. return Json::successful('编辑成功');
  869. } else {
  870. return Json::fail('编辑失败');
  871. }
  872. }
  873. public function web_recommend()
  874. {
  875. return $this->fetch();
  876. }
  877. public function web_recommend_list()
  878. {
  879. $where = parent::getMore([
  880. ['page', 1],
  881. ['limit', 20],
  882. ['is_fixed', $this->request->param('is_fixed', 0)],
  883. ['order', '']
  884. ]);
  885. return Json::successlayui(WebRecommend::getRecommendList($where));
  886. }
  887. public function create_web_recemmend($id = 0)
  888. {
  889. if ($id) {
  890. $this->assign('recemmend', WebRecommend::get($id));
  891. }
  892. $this->assign('id', $id);
  893. return $this->fetch();
  894. }
  895. public function save_web_recemmend($id = 0)
  896. {
  897. $post = parent::postMore([
  898. ['title', ''],
  899. ['explain', ''],
  900. ['type', ''],
  901. ['sort', 0],
  902. ['is_show', 0],
  903. ['show_count', 0],
  904. ]);
  905. if (mb_strlen($post['title']) > 6) return Json::fail('标题不能超过6个字');
  906. if ($id) {
  907. $rescomm = WebRecommend::get($id);
  908. if (!$rescomm) return Json::fail('修改的信息不存在');
  909. WebRecommend::update($post, ['id' => $id]);
  910. return Json::successful('修改成功');
  911. } else {
  912. $post['add_time'] = time();
  913. if (WebRecommend::set($post))
  914. return Json::successful('保存成功');
  915. else
  916. return Json::fail('保存失败');
  917. }
  918. }
  919. public function data_download($id = 0)
  920. {
  921. $this->assign('id', $id);
  922. return $this->fetch();
  923. }
  924. public function article_list($id = 0)
  925. {
  926. $this->assign('id', $id);
  927. return $this->fetch();
  928. }
  929. public function test_list($id = 0)
  930. {
  931. $this->assign('id', $id);
  932. return $this->fetch();
  933. }
  934. public function recemmend_web_content($id = 0)
  935. {
  936. if (!$id) return Json::fail('缺少参数');
  937. if ($this->request->isAjax()) {
  938. $where = parent::getMore([
  939. ['page', 1],
  940. ['limit', 20],
  941. ]);
  942. return Json::successlayui(WebRecommendRelation::getAll($where, $id));
  943. } else {
  944. $this->assign('id', $id);
  945. return $this->fetch();
  946. }
  947. }
  948. /**关联资料
  949. * @param int $id
  950. * @param int $ids
  951. */
  952. public function addDataDownload($id = 0, $ids = '')
  953. {
  954. if (!$id || $ids == '') Json::fail('缺少参数');
  955. $res = WebRecommendRelation::addDataDownload($id, $ids);
  956. if ($res) {
  957. return Json::successful('关联成功');
  958. } else {
  959. return Json::fail('关联失败');
  960. }
  961. }
  962. /**专题关联试卷删除
  963. * @param int $id
  964. * @param int $data_id
  965. */
  966. public function delRecemmend($id, $data_id)
  967. {
  968. if (!$id || !$data_id) Json::fail('缺少参数');
  969. $res = WebRecommendRelation::userDelRecemmend($id, $data_id);
  970. if ($res)
  971. return Json::successful('删除成功');
  972. else
  973. return Json::fail('删除失败');
  974. }
  975. /**排序
  976. * @param int $id
  977. * @param int $link_id
  978. * @param $value
  979. */
  980. public function upRecemmendSort($id, $value)
  981. {
  982. if (!$id) Json::fail('缺少参数');
  983. $res = WebRecommendRelation::updateRecommendSort($id, $value);
  984. if ($res)
  985. return Json::successful('修改成功');
  986. else
  987. return Json::fail('修改失败');
  988. }
  989. /**
  990. * 获取资料列表
  991. */
  992. public function getDataDownloadList()
  993. {
  994. $where = parent::getMore([
  995. ['page', 1],
  996. ['limit', 20],
  997. ['recommend_id', 0],
  998. ['status', 1],
  999. ['title', '']
  1000. ]);
  1001. $data = [];
  1002. if (isset($where['recommend_id']) && $where['recommend_id']) {
  1003. $data = WebRecommendRelation::setWhere($where['recommend_id'])->column('link_id');
  1004. }
  1005. $download = DataDownload::dataDownloadLists($where, $data);
  1006. if (isset($download['data']) && $download['data']) {
  1007. foreach ($download['data'] as $k => $v) {
  1008. $download['data'][$k]['is_check'] = 0;
  1009. }
  1010. }
  1011. return Json::successlayui($download);
  1012. }
  1013. public function special_list($id = 0)
  1014. {
  1015. $this->assign('id', $id);
  1016. return $this->fetch();
  1017. }
  1018. /**
  1019. * 图文、音频、视频、专栏专题素材列表获取
  1020. * @return json
  1021. * */
  1022. public function source_list()
  1023. {
  1024. $where = parent::getMore([
  1025. ['page', 1],
  1026. ['limit', 20],
  1027. ['title', ''],
  1028. ['type', ''],
  1029. ['is_light', ''],
  1030. ['recommend_id', 0]
  1031. ]);
  1032. $rescomm = WebRecommend::get($where['recommend_id']);
  1033. $special_source = [];
  1034. if (isset($where['recommend_id']) && $where['recommend_id']) {
  1035. $special_source = WebRecommendRelation::setWhere($where['recommend_id'])->column('link_id');
  1036. }
  1037. $special_task = Special::getUserSpecialLists($where, $special_source, $rescomm['type']);
  1038. if (isset($special_task['data']) && $special_task['data']) {
  1039. foreach ($special_task['data'] as $k => $v) {
  1040. $special_task['data'][$k]['is_check'] = 0;
  1041. $special_task['data'][$k]['pay_status'] = PAY_MONEY;
  1042. if ($v['type'] == 6) $v['type'] = $v['light_type'];
  1043. $special_task['data'][$k]['types'] = parent::specialTaskType($v['type']);
  1044. }
  1045. }
  1046. return Json::successlayui($special_task);
  1047. }
  1048. public function lecturer_list($id = 0)
  1049. {
  1050. $this->assign('id', $id);
  1051. return $this->fetch();
  1052. }
  1053. public function get_lecturer_list()
  1054. {
  1055. $where = parent::getMore([
  1056. ['page', 1],
  1057. ['limit', 20],
  1058. ['title', ''],
  1059. ['is_show', 1],
  1060. ['recommend_id', 0]
  1061. ]);
  1062. $lecturer = [];
  1063. if (isset($where['recommend_id']) && $where['recommend_id']) {
  1064. $lecturer = WebRecommendRelation::setWhere($where['recommend_id'])->column('link_id');
  1065. }
  1066. $special_task = Lecturer::getRecommendLecturerList($where, $lecturer);
  1067. if (isset($special_task['data']) && $special_task['data']) {
  1068. foreach ($special_task['data'] as $k => $v) {
  1069. $special_task['data'][$k]['is_check'] = 0;
  1070. }
  1071. }
  1072. return Json::successlayui($special_task);
  1073. }
  1074. /**
  1075. * 删除指定资源
  1076. *
  1077. * @param int $id
  1078. * @return \think\Response
  1079. */
  1080. public function delete_web_recomm($id)
  1081. {
  1082. if (WebRecommendRelation::be(['recommend_id' => $id])) return Json::fail('删除失败,请先删除内容管理里面的列表');
  1083. if (!WebRecommend::del($id))
  1084. return Json::fail('删除失败');
  1085. else
  1086. return Json::successful('删除成功!');
  1087. }
  1088. }