DiypagelinkController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\BottomMenuOriginal;
  5. use app\model\Goods;
  6. use app\model\Category;
  7. use app\model\Technical;
  8. use app\model\Article;
  9. use app\model\ArticleCategory;
  10. use app\model\DiyPageLink;
  11. use app\model\DiyPage;
  12. use app\model\Tree;
  13. class DiypagelinkController extends Base
  14. {
  15. function getModel()
  16. {
  17. $ptype = input('post.ptype', '', 'serach_in');
  18. if ($ptype == 'pageslist') {
  19. return new BottomMenuOriginal;
  20. } else if ($ptype == 'diypageslist') {
  21. return new DiyPage;
  22. } else if ($ptype == 'servicelist' || $ptype == 'goodslist') {
  23. return new Category;
  24. } else if ($ptype == 'serviceDetail' || $ptype == 'goodsDetail') {
  25. return new Goods;
  26. } else if ($ptype == 'technicalDetail') {
  27. return new Technical;
  28. } else if ($ptype == 'articlelist') {
  29. return new ArticleCategory;
  30. } else if ($ptype == 'articleDetail') {
  31. return new Article;
  32. }
  33. }
  34. function index()
  35. {
  36. $page = input('post.page', 1, 'intval');
  37. $ptype = input('post.ptype', '', 'serach_in');
  38. $weid = weid();
  39. if ($ptype != 'custom') {
  40. $query = $this->setSearch();
  41. if ($ptype == 'servicelist' || $ptype == 'goodslist') {
  42. $res = $query->order('sort asc')->select()->toArray();
  43. } else {
  44. $res = $query->paginate(getpage())->toArray();
  45. }
  46. if (!empty($res['data'])) {
  47. foreach ($res['data'] as &$vo) {
  48. $vo['image'] = toimg($vo['image']);
  49. if ($ptype == 'serviceDetail') {
  50. $vo['cat_id'] = Category::getTitle($vo['cat_id']);
  51. }
  52. if ($ptype == 'articleDetail') {
  53. $vo['cid'] = ArticleCategory::getTitle($vo['cid']);
  54. }
  55. }
  56. }
  57. if ($ptype == 'servicelist' || $ptype == 'goodslist') {
  58. $data['data']['data'] = Tree::title($res, 0);
  59. } else {
  60. $data['data'] = $res;
  61. }
  62. if ($ptype == 'diypageslist') {
  63. if (!empty($data['data']['data'])) {
  64. foreach ($data['data']['data'] as &$vo) {
  65. $vo['url'] = "/pages/index/index?id=" . $vo['id'];
  66. }
  67. }
  68. }
  69. $data['field_data']['Fields'] = DiyPageLink::getFields($ptype);
  70. }
  71. return $this->json($data);
  72. }
  73. function setSearch()
  74. {
  75. $ptype = input('post.ptype', '', 'serach_in');
  76. $keyword = trim(input('post.keyword', '', 'serach_in'));
  77. $weid = weid();
  78. if ($ptype == 'pageslist') {
  79. $plwhere['weid'] = 0;
  80. if (config('database.app_name') == config('my.app_v2')) {
  81. $plwhere['is_v2'] = 1;
  82. }
  83. if (config('database.app_name') == config('my.app_v3')) {
  84. $plwhere['is_v3'] = 1;
  85. }
  86. if (config('database.app_name') == config('my.app_v6')) {
  87. $plwhere['is_v6'] = 1;
  88. }
  89. $query = $this->getModel()->where($plwhere)->order('id asc');
  90. } else {
  91. $query = $this->getModel()->where(['weid' => $weid])->order('id desc');
  92. }
  93. if ($ptype == 'goodslist') {
  94. $query->where('ptype', 1);
  95. }
  96. if ($ptype == 'servicelist') {
  97. $query->where('ptype', 2);
  98. }
  99. if (!empty($keyword)) {
  100. if ($ptype == 'serviceDetail' || $ptype == 'goodsDetail') {
  101. $query->where('name', 'like', '%' . $keyword . '%');
  102. } else {
  103. $query->where('title', 'like', '%' . $keyword . '%');
  104. }
  105. }
  106. return $query;
  107. }
  108. function linklist()
  109. {
  110. $linklist = DiyPageLink::linklist();
  111. $i = 0;
  112. foreach ($linklist as $key => $vo) {
  113. if ($vo['v3'] == 1 && config('database.app_name') != config('my.app_v3')) {
  114. } else {
  115. $vo['ptype'] = $key;
  116. $list[$i] = $vo;
  117. $i++;
  118. }
  119. }
  120. $data['data'] = $list;
  121. return $this->json($data);
  122. }
  123. }