IndexController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * 首页
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\admin\model\SlideItemModel;
  8. use app\portal\model\PortalPostModel;
  9. use app\weixin\model\Member;
  10. use app\weixin\service\Article;
  11. use app\weixin\model\Wechat;
  12. use app\weixin\service\PRedis;
  13. use cmf\controller\HomeBaseController;
  14. use think\db\Query;
  15. use function AlibabaCloud\Client\value;
  16. class IndexController extends HomeBaseController
  17. {
  18. /**
  19. * 获取轮播图
  20. * @throws \think\db\exception\DataNotFoundException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. * @throws \think\exception\DbException
  23. */
  24. public function getBanners(){
  25. $cacheKey = "cache:banners:index";
  26. $datas = PRedis::get($cacheKey);
  27. if($datas){
  28. showJson(1005, 1001, $datas);
  29. }
  30. $datas = SlideItemModel::where(['slide_id'=>1, 'status'=>1])
  31. ->field('id,title,image,url')
  32. ->order('list_order asc,id asc')
  33. ->select();
  34. $datas = $datas? $datas->toArray() : [];
  35. if($datas){
  36. foreach ($datas as &$v){
  37. $v['image'] = $v['image']? cmf_get_image_preview_url($v['image']) : '';
  38. }
  39. unset($v);
  40. PRedis::set($cacheKey, $datas, rand(10, 300));
  41. }
  42. showJson(1005, 1001, $datas);
  43. }
  44. /**
  45. * 图文
  46. * @throws \think\exception\DbException
  47. */
  48. public function getPicList(){
  49. $page = input('page', 1);
  50. $type = input('type', 1);
  51. $pageSize = input('pageSize', 1);
  52. $cacheKey = "cache:pics:index:{$type}_{$page}_{$pageSize}";
  53. $datas = PRedis::get($cacheKey);
  54. if($datas){
  55. showJson(1005, 1001, $datas);
  56. }
  57. $datas = PortalPostModel::alias('p')
  58. ->leftJoin('sg_user u','u.id=p.user_id')
  59. ->where(['p.post_status'=>1,'p.post_type'=>3])
  60. ->where(function (Query $query) use ($type) {
  61. if($type){
  62. $query->where('p.type', $type);
  63. }
  64. })
  65. ->field('p.id,p.post_title,p.post_type,p.type,p.user_id,p.published_time,p.post_excerpt,p.thumbnail,p.albums,p.post_status,u.user_nickname,u.avatar')
  66. ->order("p.is_top DESC,p.published_time DESC")
  67. ->paginate($pageSize)
  68. ->each(function($item, $k){
  69. $albums = isset($item['albums']) && $item['albums']? explode(',', $item['albums']) : [];
  70. foreach ($albums as &$v){
  71. $v = $v? cmf_get_image_preview_url($v) : '';
  72. }
  73. unset($v);
  74. $item['avatar'] = $item['avatar']? cmf_get_image_preview_url($item['avatar']) : '';
  75. $item['published_time_text'] = $item['published_time']? date('Y-m-d H:i:s',$item['published_time']) : '';
  76. $item['albums'] = $albums;
  77. return $item;
  78. });
  79. if($datas){
  80. PRedis::set($cacheKey, $datas, rand(10, 30));
  81. }
  82. showJson(1005, 1001, $datas);
  83. }
  84. /**
  85. * 获取JSSDK参数
  86. */
  87. public function getJssdkParams(){
  88. $url = input('url', '');
  89. $jssdkParams = Wechat::getJssdkParams($url);
  90. $siteInfo = $siteInfo = cmf_get_site_info();
  91. $jssdkParams['mapKey'] = isset($siteInfo['map_key'])? trim($siteInfo['map_key']) : '';
  92. PRedis::set('shares:'.date('YmdHis'), ['url'=> $url,'params'=> $jssdkParams], 600);
  93. showJson(1005,1001, $jssdkParams);
  94. }
  95. /**
  96. * 获取微信信息
  97. */
  98. public function getWxInfo(){
  99. $wxInfo = session('wxInfo');
  100. showJson(1005,1001, $wxInfo);
  101. }
  102. /**
  103. * 获取条件参数
  104. */
  105. public function params(){
  106. $type = input('type', 1);
  107. if($type == 1){
  108. $params['ages'] = config('weixin.ages');
  109. $params['heights'] = config('weixin.heights');
  110. $params['weights'] = config('weixin.weights');
  111. $params['incomes'] = config('weixin.incomes');
  112. $params['educations'] = config('weixin.educations');
  113. $params['positions'] = config('weixin.positions');
  114. $params['marrieds'] = config('weixin.marrieds');
  115. $params['propertys'] = config('weixin.propertys');
  116. $params['tags'] = config('weixin.tags');
  117. $params['incomeTypes'] = config('weixin.incomeTypes');
  118. }else if($type == 2){
  119. $params['complainTypes'] = config('weixin.complainTypes');
  120. }else if($type == 3){
  121. $params['adviceTypes'] = config('weixin.adviceTypes');
  122. }
  123. showJson(1005,1001, $params);
  124. }
  125. /**
  126. * 获取网站信息
  127. */
  128. public function getSiteInfo(){
  129. $siteInfo = $siteInfo = cmf_get_site_info();
  130. $chooseNum = isset($siteInfo['choose_num'])? intval($siteInfo['choose_num']) : 0;
  131. $data = [
  132. 'site_name'=> isset($siteInfo['site_name'])? $siteInfo['site_name'] : '',
  133. 'site_seo_title'=> isset($siteInfo['site_seo_title'])? $siteInfo['site_seo_title'] : '',
  134. 'site_seo_keywords'=> isset($siteInfo['site_seo_keywords'])? $siteInfo['site_seo_keywords'] : '',
  135. 'site_seo_description'=> isset($siteInfo['site_seo_description'])? $siteInfo['site_seo_description'] : '',
  136. 'choose_num'=> $chooseNum? $chooseNum : 3,
  137. 'contact_type'=> isset($siteInfo['contact_type'])? $siteInfo['contact_type'] : 1,
  138. 'custom_intro'=> isset($siteInfo['custom_intro'])? htmlspecialchars_decode($siteInfo['custom_intro']) : '',
  139. ];
  140. showJson(1005,1001, $data);
  141. }
  142. /**
  143. * 获取广告列表
  144. */
  145. public function getAdvertList(){
  146. $id = input('type', 1);
  147. $pages = config('config.pages');
  148. $slideNum = isset($pages['slideNum'])? intval($pages['slideNum']) : 0;
  149. $dataList = db('slide')->alias('s')
  150. ->join('slide_item si','si.slide_id=s.id','left')
  151. ->where(['s.id'=> $id,'s.status'=> 1])
  152. ->field('si.id,si.title,si.image,si.url,si.description')
  153. ->order('si.list_order')
  154. ->limit($slideNum? $slideNum :6)
  155. ->select()
  156. ->toArray();
  157. foreach($dataList as &$item){
  158. $item['image'] = $item['image']? cmf_get_image_preview_url($item['image']) : '';
  159. }
  160. showJson(1005,1001, $dataList);
  161. }
  162. /**
  163. * 获取单页文章内容
  164. */
  165. public function getPage(){
  166. $info = [];
  167. $type = input('type', 'about');
  168. $articles = config('weixin.articles');
  169. $articleId = isset($articles[$type])? intval($articles[$type]) : 0;
  170. if($articleId){
  171. $field = 'id,thumbnail,post_title,post_excerpt,post_content,published_time,post_source,user_id';
  172. $info = PortalPostModel::where(['id'=> $articleId,'post_type'=> 2,'post_status'=>1])
  173. ->field($field)
  174. ->find();
  175. if($info){
  176. $info['post_content'] = htmlspecialchars_decode($info['post_content']);
  177. }
  178. }
  179. $info['version'] = config('weixin.version');
  180. showJson(1005,1001, $info);
  181. }
  182. /**
  183. * 获取客服列表
  184. */
  185. public function getCustomList(){
  186. $params = input();
  187. $pageSize = input('pageSize', 20);
  188. $dataList = Article::getList($params, $pageSize);
  189. showJson(1005, 1001, $dataList);
  190. }
  191. }
  192. ?>