Index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. //轮播图
  19. $where = [
  20. 'status' => 1,
  21. ];
  22. $banner = Db::name('banner')->field('id,title,type,image,video_file,url')->where($where)->order('weigh', 'desc')->select();
  23. $banner = list_domain_image($banner, ['image','video_file']);
  24. if(!empty($banner)){
  25. foreach($banner as $key => $val){
  26. $banner[$key]['thumb_image'] = '';
  27. if(!empty($val['video_file'])){
  28. $banner[$key]['thumb_image'] = $val['video_file'].'?x-oss-process=video/snapshot,t_100,f_png,m_fast';
  29. }
  30. }
  31. }
  32. //第一条公告
  33. $message = Db::name('message_sys')->where('is_show',1)->where('is_index',1)->order('weigh','desc')->find();
  34. $message = $this->info_lang($message,['title','info']);
  35. $message = info_domain_image($message,['avatar']);
  36. if($message){
  37. $message['createtime'] = $this->date_lang($message['sendtime']);
  38. }
  39. //留个好评
  40. $haoping = Db::name('appplat')->field('image,url,biglogo')->where('type',1)->order('weigh', 'desc')->select();
  41. $haoping = list_domain_image($haoping, ['image']);
  42. //关注我们
  43. $followus = Db::name('appplat')->field('image,url,biglogo')->where('type',2)->order('weigh', 'desc')->select();
  44. $followus = list_domain_image($followus, ['image']);
  45. $result = [
  46. 'banner' => $banner,
  47. 'message' => $message,
  48. 'haoping' => $haoping,
  49. 'followus' => $followus,
  50. 'contact_mobile' => config('site.contact_mobile'),
  51. 'contact_email' => config('site.contact_email'),
  52. 'index_middle_image' => localpath_to_netpath(config('site.index_middle_image')),
  53. 'index_bottom_image' => localpath_to_netpath(config('site.index_bottom_image')),
  54. 'map_longitude' => config('site.map_longitude'),
  55. 'map_latitude' => config('site.map_latitude'),
  56. ];
  57. $this->success(1,$result);
  58. }
  59. //搜索
  60. public function search(){
  61. $keyword = input('keyword','','trim');
  62. //搜课时表
  63. $where = [
  64. 'slot.status' => 0,//报名中
  65. 'slot.is_show' => 1,
  66. 'slot.starttime' => ['gt',time()],
  67. ];
  68. //模糊搜索
  69. $wherelike = '';
  70. if(!empty($keyword)){
  71. //搜课程名
  72. $wherelike .= "(lesson.name like '%".$keyword."%') or (lesson.name_en like '%".$keyword."%')";
  73. //搜教练ids
  74. $coach_where = [];
  75. $coach_where['nickname'] = ['LIKE','%'.$keyword.'%'];
  76. $coach_ids = Db::name('coach')->where($coach_where)->column('id');
  77. if(!empty($coach_ids))
  78. {
  79. $wherelike .= ' or ';
  80. foreach($coach_ids as $ck => $cv){
  81. $wherelike .= "(FIND_IN_SET('".$cv."',slot.coach_ids))";
  82. if($ck+1 < count($coach_ids)){
  83. $wherelike .= " or ";
  84. }
  85. }
  86. }
  87. }
  88. $list = Db::name('lesson_slot')->alias('slot')
  89. ->field('slot.*,lesson.name,lesson.name_en,lesson.image,lesson.price')
  90. ->join('lesson','slot.lesson_id = lesson.id','LEFT')
  91. ->where($where)->where($wherelike)->autopage()
  92. //->select(false);echo $list;exit;
  93. ->select();
  94. $list = list_domain_image($list,['image']);
  95. $list = $this->list_lang($list,['name']);
  96. //准备教练数据
  97. $coach_list = Db::name('coach')->column('id,nickname');
  98. foreach($list as $key => &$slot){
  99. //hours转换
  100. $slot['hours'] = floatval($slot['hours']);
  101. //放入教练
  102. $coach_text = '';
  103. $coach_ids = explode(',',$slot['coach_ids']);
  104. foreach($coach_ids as $coach_id){
  105. if(isset($coach_list[$coach_id])){
  106. $coach_text .= $coach_list[$coach_id].',';
  107. }
  108. }
  109. $slot['coach_text'] = substr($coach_text,0,-1);
  110. //组织时间
  111. if($this->lang == 'en'){
  112. $slot['slot_time'] = date('M d',$slot['starttime']).'('.date('D',$slot['starttime']).')'.','.date('H:i',$slot['starttime']).'-'.date('H:i',$slot['endtime']);
  113. }else{
  114. $slot['slot_time'] = date('n月d',$slot['starttime']).'(周'.date('N',$slot['starttime']).')'.','.date('H:i',$slot['starttime']).'-'.date('H:i',$slot['endtime']);
  115. }
  116. }
  117. $this->success(1,$list);
  118. }
  119. }