WebStaticPageModel.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <?php
  2. namespace App\Web\Models;
  3. use App\Models\BaseModel;
  4. use Illuminate\Support\Facades\DB;
  5. class WebStaticPageModel extends BaseModel
  6. {
  7. /**
  8. * 状态字段
  9. */
  10. const DELETED_AT = 'status';
  11. /**
  12. * @var string
  13. */
  14. protected $table = 'web_static_page';
  15. /**
  16. * 检查路由地址是否唯一
  17. * */
  18. public function checkRoutePathUnique($routePath,$id=0){
  19. $where=[];
  20. if(!empty($id)){
  21. $where[]=['id', '<>', $id];
  22. }
  23. $where[]=['status', '<', 2];
  24. $where[]=['route_path', '=', trim($routePath)];
  25. return $this->checkFieldUnique('route_path',$where);
  26. }
  27. /**
  28. * 检查页面名称是否唯一
  29. * */
  30. public function checkPageNameUnique($pageName,$id=0){
  31. $where=[];
  32. if(!empty($id)){
  33. $where[]=['id', '<>', $id];
  34. }
  35. $where[]=['status', '<', 2];
  36. $where[]=['page_name', '=', trim($pageName)];
  37. return $this->checkFieldUnique('page_name',$where);
  38. }
  39. /**
  40. * 静态页面保存
  41. * @param array $data
  42. * */
  43. public function saveStaticPageData($data){
  44. if (!empty($data['id'])) {
  45. $id = $data['id'];
  46. $this->newInstance()->where('id', $data['id'])->update($data);
  47. } else {
  48. $id = $this->newInstance()->insertGetId($data);
  49. }
  50. return $id;
  51. }
  52. /**
  53. * 获取静态页面列表
  54. * */
  55. public function getStaticPageList($params,$fields='a.id,a.create_time,a.page_name,a.route_path,a.seo_id,a.sort,a.status,a.type
  56. ,a.update_time,b.seo_title,b.seo_describe,b.seo_keyword,b.urla,b.trans_status,b.track_code_head,b.track_code_body'){
  57. list($pageSize, $page, $skip) = $this->getPaginatorParams($params);
  58. $where=[];
  59. if(isset($params['status'])){
  60. $where[]=['a.status','=',$params['status']];
  61. }else{
  62. $where[]=['a.status','<',2];
  63. }
  64. $query= $this->newInstance()->alias('a')->leftJoin('web_seo as b', 'a.seo_id', '=', 'b.id')->where($where);
  65. if (!empty($params['keyword'])) {
  66. $keyword = $params['keyword'];
  67. $query->where('a.page_name', 'like', "%" . $keyword . "%");
  68. }
  69. $totalCount = $query->count();
  70. $list= $query->skip($skip)
  71. ->limit($pageSize)
  72. ->selectRaw($fields)
  73. ->orderBy('sort')
  74. ->get();
  75. if(!empty($list)){
  76. $list=$list->toArray();
  77. }else{
  78. $list=[];
  79. }
  80. $result = $this->buildPaginator($list, $skip, $page, $pageSize, $totalCount);
  81. return $result;
  82. }
  83. /**
  84. * 获取网页菜单
  85. * @param array $params
  86. * */
  87. public function getPageMenuInfo($params=[]) {
  88. if(!empty($params['route_path'])) {
  89. $where=[];
  90. $where[]=['status','<',2];
  91. $where['route_path']=$params['route_path'];
  92. $info= $this->newInstance()->where($where)->first();
  93. if(!empty($info)) {
  94. $info = $info->toArray();
  95. if(!empty($info['page_content'])) {
  96. $info['page_content'] = json_decode($info['page_content'],true);;
  97. }
  98. }
  99. return $info;
  100. }
  101. }
  102. /**
  103. * 获取静态页面详情
  104. * @param array $params
  105. * */
  106. public function getStaticPageInfo($params=[]){
  107. if(empty($params)){
  108. return [];
  109. }
  110. $where=[];
  111. $where[]=['status','<',2];
  112. if(!empty($params['id'])){
  113. // $where['id']=$params['id'];
  114. $where[] = ['id','=',$params['id']];
  115. }
  116. if(!empty($params['route_path'])){
  117. $where[] = ['route_path','=',$params['route_path']];
  118. // $where['route_path']=$params['route_path'];
  119. }
  120. if(isset($params['type'])){
  121. $where[] = ['type','=',empty($params['type'])?0:$params['type']];
  122. // $where['type']=empty($params['type'])?0:$params['type'];
  123. }
  124. $info= $this->newInstance()->where($where)->first();
  125. if(!empty($info)) {
  126. $info=$info->toArray();
  127. $info['page_content'] = json_decode($info['page_content'],true);
  128. //dd($info['page_content']);
  129. $page_content = [];
  130. if (!empty($info['page_content'])) {
  131. foreach ($info['page_content'] as $module_key => $module) {
  132. if (!isset($module['module']) && !is_int($module_key) && !empty($module['module_key'])) {
  133. $module_content = [$module_key=>[]];
  134. $module_content[$module_key] = ['module'=>[]];
  135. $module_content[$module_key]['module'] = $module;
  136. } elseif (!isset($module['module']) && is_int($module_key)) {
  137. $module_content = [$module['key']=>$module];
  138. } else {
  139. $module_content = [$module_key=>$module];
  140. }
  141. $page_content = array_merge($page_content,$module_content);
  142. }
  143. }
  144. $info['page_content'] = $page_content;
  145. //dd($page_content);
  146. //dd($page_content);
  147. /*if(!empty($info['page_content'])) {
  148. $moduleContent = json_decode($info['page_content'],true);
  149. $info['page_content'] = [];
  150. if (!empty($params['module_key_list'])) {
  151. $module_key_list = $params['module_key_list'];
  152. foreach ($module_key_list as $module_key) {
  153. if (isset($moduleContent[$module_key])) {
  154. $pageContent = mapByKey($moduleContent[$module_key],'key');
  155. $info['page_content'][$module_key] = $pageContent;
  156. }
  157. }
  158. } else {
  159. foreach ($moduleContent as $moduleKey => $moduleItem) {
  160. $moduleContent[$moduleKey] = mapByKey($moduleItem,'key');
  161. }
  162. $info['page_content'] = $moduleContent;
  163. }
  164. }*/
  165. return $info;
  166. }else{
  167. return ['page_content'=>[]];
  168. }
  169. }
  170. public function getStaticPageRenderData($params=[]){
  171. if(empty($params)){
  172. return [];
  173. }
  174. $where=[];
  175. $where['a.status']=0;
  176. $where['b.relation_table']=$this->table;
  177. if(!empty($params['page_name'])){
  178. $where['a.page_name']=$params['page_name'];
  179. }
  180. if(!empty($params['route_path'])){
  181. $where['a.route_path']=$params['route_path'];
  182. }
  183. $fields='a.*,b.urla,b.relation_table,b.relation_id,b.seo_title,b.seo_keyword,b.seo_describe';
  184. $info= $this->newInstance()->alias('a')
  185. ->leftJoin('web_seo as b', 'a.seo_id', '=', 'b.id')
  186. ->where($where)
  187. ->selectRaw($fields)
  188. ->first();
  189. if(!empty($info)){
  190. $info=$info->toArray();
  191. if(!empty($info['page_content'])){
  192. $pageContent=json_decode($info['page_content'],true);
  193. $pageContent=mapByKey($pageContent,'key');
  194. $info['page_content']=$pageContent;
  195. }
  196. return $info;
  197. }else{
  198. return [];
  199. }
  200. }
  201. public function getWebMenu(){
  202. $where=[];
  203. $where['a.status']=0;
  204. $where['b.relation_table']=$this->table;
  205. if(!empty($params['page_name'])){
  206. $where['a.page_name']=$params['page_name'];
  207. }
  208. if(!empty($params['route_path'])){
  209. $where['a.route_path']=$params['route_path'];
  210. }
  211. $fields='a.*,b.urla,b.relation_table,b.relation_id,b.seo_title,b.seo_keyword,b.seo_describe';
  212. $info= $this->newInstance()->alias('a')
  213. ->leftJoin('web_seo as b', 'a.seo_id', '=', 'b.id')
  214. ->where($where)
  215. ->selectRaw($fields)
  216. ->get();
  217. if(!empty($info)){
  218. return $info->toArray();
  219. }else{
  220. return [];
  221. }
  222. }
  223. public function downloadPageSEOQuery()
  224. {
  225. $query1 = DB::table('web_seo as a')
  226. ->select([
  227. 'b.id',
  228. 'b.page_name AS page_name',
  229. 'a.urla',
  230. 'a.seo_title',
  231. 'a.seo_keyword',
  232. 'a.seo_describe',
  233. DB::raw("'静态页' as relation_table")
  234. ])
  235. ->leftJoin('web_static_page as b', 'a.relation_id', '=', 'b.id')
  236. ->where('relation_table', 'web_static_page')
  237. ->where('b.status', 0)
  238. ->where('a.status', 0);
  239. $query2 = DB::table('web_seo as a')
  240. ->select([
  241. 'a.id',
  242. 'b.title AS page_name',
  243. 'a.urla',
  244. 'a.seo_title',
  245. 'a.seo_keyword',
  246. 'a.seo_describe',
  247. DB::raw("'新闻详情页' as relation_table")
  248. ])
  249. ->leftJoin('blog as b', 'a.relation_id', '=', 'b.id')
  250. ->where('relation_table', 'blog')
  251. ->where('b.status', 0)
  252. ->where('a.status', 0);
  253. $query3 = DB::table('web_seo as a')
  254. ->select([
  255. 'b.id',
  256. 'b.tag_name AS page_name',
  257. 'a.urla',
  258. 'a.seo_title',
  259. 'a.seo_keyword',
  260. 'a.seo_describe',
  261. DB::raw("'新闻标签页' as relation_table")
  262. ])
  263. ->leftJoin('blog_tag as b', 'a.relation_id', '=', 'b.id')
  264. ->where('relation_table', 'blog_tag')
  265. ->where('b.status', 0)
  266. ->where('a.status', 0);
  267. $query4 = DB::table('web_seo as a')
  268. ->select([
  269. 'b.id',
  270. 'b.type_name AS page_name',
  271. 'a.urla',
  272. 'a.seo_title',
  273. 'a.seo_keyword',
  274. 'a.seo_describe',
  275. DB::raw("'新闻分类页' as relation_table")
  276. ])
  277. ->leftJoin('blog_type as b', 'a.relation_id', '=', 'b.id')
  278. ->where('relation_table', 'blog_type')
  279. ->where('b.status', 0)
  280. ->where('a.status', 0);
  281. $query5 = DB::table('web_seo as a')
  282. ->select([
  283. 'b.id',
  284. 'b.title AS page_name',
  285. 'a.urla',
  286. 'a.seo_title',
  287. 'a.seo_keyword',
  288. 'a.seo_describe',
  289. DB::raw("'会议详情页' as relation_table")
  290. ])
  291. ->leftJoin('meeting as b', 'a.relation_id', '=', 'b.id')
  292. ->where('relation_table', 'meeting')
  293. ->where('b.status', 0)
  294. ->where('a.status', 0);
  295. $query6 = DB::table('web_seo as a')
  296. ->select([
  297. 'b.id',
  298. 'b.type_name AS page_name',
  299. 'a.urla',
  300. 'a.seo_title',
  301. 'a.seo_keyword',
  302. 'a.seo_describe',
  303. DB::raw("'会议分类页' as relation_table")
  304. ])
  305. ->leftJoin('meeting_type as b', 'a.relation_id', '=', 'b.id')
  306. ->where('relation_table', 'meeting_type')
  307. ->where('b.status', 0)
  308. ->where('a.status', 0);
  309. $query16 = DB::table('web_seo as a')
  310. ->select([
  311. 'b.id',
  312. 'b.tag_name AS page_name',
  313. 'a.urla',
  314. 'a.seo_title',
  315. 'a.seo_keyword',
  316. 'a.seo_describe',
  317. DB::raw("'会议标签页' as relation_table")
  318. ])
  319. ->leftJoin('meeting_tag as b', 'a.relation_id', '=', 'b.id')
  320. ->where('relation_table', 'meeting_tag')
  321. ->where('b.status', 0)
  322. ->where('a.status', 0);
  323. $query7 = DB::table('web_seo as a')
  324. ->select([
  325. 'b.id',
  326. 'b.title AS page_name',
  327. 'a.urla',
  328. 'a.seo_title',
  329. 'a.seo_keyword',
  330. 'a.seo_describe',
  331. DB::raw("'产品详情页' as relation_table")
  332. ])
  333. ->leftJoin('product as b', 'a.relation_id', '=', 'b.id')
  334. ->where('relation_table', 'product')
  335. ->where('b.status', 0)
  336. ->where('a.status', 0);
  337. $query8 = DB::table('web_seo as a')
  338. ->select([
  339. 'b.id',
  340. 'b.type_name AS page_name',
  341. 'a.urla',
  342. 'a.seo_title',
  343. 'a.seo_keyword',
  344. 'a.seo_describe',
  345. DB::raw("'产品分类页' as relation_table")
  346. ])
  347. ->leftJoin('product_type as b', 'a.relation_id', '=', 'b.id')
  348. ->where('relation_table', 'product_type')
  349. ->where('b.status', 0)
  350. ->where('a.status', 0);
  351. $query9 = DB::table('web_seo as a')
  352. ->select([
  353. 'b.id',
  354. 'b.tag_name AS page_name',
  355. 'a.urla',
  356. 'a.seo_title',
  357. 'a.seo_keyword',
  358. 'a.seo_describe',
  359. DB::raw("'产品标签页' as relation_table")
  360. ])
  361. ->leftJoin('product_tag as b', 'a.relation_id', '=', 'b.id')
  362. ->where('relation_table', 'product_tag')
  363. ->where('b.status', 0)
  364. ->where('a.status', 0);
  365. $result = $query1
  366. ->union($query2)
  367. ->union($query3)
  368. ->union($query4)
  369. ->union($query5)
  370. ->union($query6)
  371. ->union($query16)
  372. ->union($query7)
  373. ->union($query8)
  374. ->union($query9)
  375. ->limit(10000)
  376. ->get();
  377. return $result;
  378. }
  379. }