AdminPageController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\portal\controller;
  12. use app\admin\model\RouteModel;
  13. use cmf\controller\AdminBaseController;
  14. use app\portal\model\PortalPostModel;
  15. use app\portal\service\PostService;
  16. use app\admin\model\ThemeModel;
  17. use think\Db;
  18. class AdminPageController extends AdminBaseController
  19. {
  20. /**
  21. * 页面管理
  22. * @adminMenu(
  23. * 'name' => '页面管理',
  24. * 'parent' => 'portal/AdminIndex/default',
  25. * 'display'=> true,
  26. * 'hasView'=> true,
  27. * 'order' => 10000,
  28. * 'icon' => '',
  29. * 'remark' => '页面管理',
  30. * 'param' => ''
  31. * )
  32. */
  33. public function index()
  34. {
  35. $content = hook_one('portal_admin_page_index_view');
  36. if (!empty($content)) {
  37. return $content;
  38. }
  39. $param = $this->request->param();
  40. $postService = new PostService();
  41. $data = $postService->adminPageList($param);
  42. $data->appends($param);
  43. $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
  44. $this->assign('pages', $data->items());
  45. $this->assign('page', $data->render());
  46. return $this->fetch();
  47. }
  48. //排序
  49. public function listOrder() {
  50. $model = DB::name('portal_post');
  51. parent::listOrders($model);
  52. $this->success("排序更新成功!");
  53. }
  54. /**
  55. * 添加页面
  56. * @adminMenu(
  57. * 'name' => '添加页面',
  58. * 'parent' => 'index',
  59. * 'display'=> false,
  60. * 'hasView'=> true,
  61. * 'order' => 10000,
  62. * 'icon' => '',
  63. * 'remark' => '添加页面',
  64. * 'param' => ''
  65. * )
  66. */
  67. public function add()
  68. {
  69. $content = hook_one('portal_admin_page_add_view');
  70. if (!empty($content)) {
  71. return $content;
  72. }
  73. $themeModel = new ThemeModel();
  74. $pageThemeFiles = $themeModel->getActionThemeFiles('portal/Page/index');
  75. $this->assign('page_theme_files', $pageThemeFiles);
  76. return $this->fetch();
  77. }
  78. /**
  79. * 添加页面提交
  80. * @adminMenu(
  81. * 'name' => '添加页面提交',
  82. * 'parent' => 'index',
  83. * 'display'=> false,
  84. * 'hasView'=> false,
  85. * 'order' => 10000,
  86. * 'icon' => '',
  87. * 'remark' => '添加页面提交',
  88. * 'param' => ''
  89. * )
  90. */
  91. public function addPost()
  92. {
  93. $data = $this->request->param();
  94. $result = $this->validate($data['post'], 'AdminPage');
  95. if ($result !== true) {
  96. $this->error($result);
  97. }
  98. if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
  99. $data['post']['more']['photos'] = [];
  100. foreach ($data['photo_urls'] as $key => $url) {
  101. $photoUrl = cmf_asset_relative_url($url);
  102. array_push($data['post']['more']['photos'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
  103. }
  104. }
  105. if (!empty($data['file_names']) && !empty($data['file_urls'])) {
  106. $data['post']['more']['files'] = [];
  107. foreach ($data['file_urls'] as $key => $url) {
  108. $fileUrl = cmf_asset_relative_url($url);
  109. array_push($data['post']['more']['files'], ["url" => $fileUrl, "name" => $data['file_names'][$key]]);
  110. }
  111. }
  112. $portalPostModel = new PortalPostModel();
  113. $portalPostModel->adminAddPage($data['post']);
  114. $this->success(lang('ADD_SUCCESS'), url('AdminPage/edit', ['id' => $portalPostModel->id]));
  115. }
  116. /**
  117. * 编辑页面
  118. * @adminMenu(
  119. * 'name' => '编辑页面',
  120. * 'parent' => 'index',
  121. * 'display'=> false,
  122. * 'hasView'=> true,
  123. * 'order' => 10000,
  124. * 'icon' => '',
  125. * 'remark' => '编辑页面',
  126. * 'param' => ''
  127. * )
  128. */
  129. public function edit()
  130. {
  131. $content = hook_one('portal_admin_page_edit_view');
  132. if (!empty($content)) {
  133. return $content;
  134. }
  135. $id = $this->request->param('id', 0, 'intval');
  136. $portalPostModel = new PortalPostModel();
  137. $post = $portalPostModel->where('id', $id)->find();
  138. $themeModel = new ThemeModel();
  139. $pageThemeFiles = $themeModel->getActionThemeFiles('portal/Page/index');
  140. $routeModel = new RouteModel();
  141. $alias = $routeModel->getUrl('portal/Page/index', ['id' => $id]);
  142. $post['post_alias'] = $alias;
  143. $this->assign('page_theme_files', $pageThemeFiles);
  144. $this->assign('post', $post);
  145. return $this->fetch();
  146. }
  147. /**
  148. * 编辑页面提交
  149. * @adminMenu(
  150. * 'name' => '编辑页面提交',
  151. * 'parent' => 'index',
  152. * 'display'=> false,
  153. * 'hasView'=> false,
  154. * 'order' => 10000,
  155. * 'icon' => '',
  156. * 'remark' => '编辑页面提交',
  157. * 'param' => ''
  158. * )
  159. */
  160. public function editPost()
  161. {
  162. $data = $this->request->param();
  163. $result = $this->validate($data['post'], 'AdminPage');
  164. if ($result !== true) {
  165. $this->error($result);
  166. }
  167. if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
  168. $data['post']['more']['photos'] = [];
  169. foreach ($data['photo_urls'] as $key => $url) {
  170. $photoUrl = cmf_asset_relative_url($url);
  171. array_push($data['post']['more']['photos'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
  172. }
  173. }
  174. if (!empty($data['file_names']) && !empty($data['file_urls'])) {
  175. $data['post']['more']['files'] = [];
  176. foreach ($data['file_urls'] as $key => $url) {
  177. $fileUrl = cmf_asset_relative_url($url);
  178. array_push($data['post']['more']['files'], ["url" => $fileUrl, "name" => $data['file_names'][$key]]);
  179. }
  180. }
  181. $portalPostModel = new PortalPostModel();
  182. $portalPostModel->adminEditPage($data['post']);
  183. $this->success(lang('SAVE_SUCCESS'));
  184. }
  185. /**
  186. * 删除页面
  187. * @author iyting@foxmail.com
  188. * @adminMenu(
  189. * 'name' => '删除页面',
  190. * 'parent' => 'index',
  191. * 'display'=> false,
  192. * 'hasView'=> false,
  193. * 'order' => 10000,
  194. * 'icon' => '',
  195. * 'remark' => '删除页面',
  196. * 'param' => ''
  197. * )
  198. */
  199. public function delete()
  200. {
  201. $portalPostModel = new PortalPostModel();
  202. $data = $this->request->param();
  203. $result = $portalPostModel->adminDeletePage($data);
  204. if ($result) {
  205. $this->success(lang('DELETE_SUCCESS'));
  206. } else {
  207. $this->error(lang('DELETE_FAILED'));
  208. }
  209. }
  210. }