Index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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'] = '1.jpg';
  27. }
  28. }
  29. //第一条公告
  30. $message = Db::name('message_sys')->where('is_show',1)->where('is_index',1)->order('weigh','desc')->find();
  31. $message = $this->info_lang($message,['title','info']);
  32. if($message){
  33. $message['createtime'] = get_last_time($message['createtime']);
  34. }
  35. //留个好评
  36. $haoping = Db::name('appplat')->field('image,url')->where('type',1)->order('weigh', 'desc')->select();
  37. $haoping = list_domain_image($haoping, ['image']);
  38. //关注我们
  39. $followus = Db::name('appplat')->field('image,url')->where('type',2)->order('weigh', 'desc')->select();
  40. $followus = list_domain_image($followus, ['image']);
  41. $result = [
  42. 'banner' => $banner,
  43. 'message' => $message,
  44. 'haoping' => $haoping,
  45. 'followus' => $followus,
  46. 'contact_mobile' => config('site.contact_mobile'),
  47. 'contact_email' => config('site.contact_email'),
  48. 'index_middle_image' => localpath_to_netpath(config('site.index_middle_image')),
  49. 'index_bottom_image' => localpath_to_netpath(config('site.index_bottom_image')),
  50. 'map_longitude' => '103.8014002',
  51. 'map_latitude' => '1.2763445',
  52. ];
  53. $this->success(1,$result);
  54. }
  55. //搜索
  56. public function search(){
  57. $keyword = input('keyword','','trim');
  58. if(empty($keyword)){
  59. $this->error();
  60. }
  61. //搜课时表
  62. $where = [
  63. 'lesson.name|lesson.name_en' => ['LIKE','%'.$keyword.'%'],
  64. 'slot.starttime' => ['gt',time()],//未开始
  65. 'slot.status' => 0,//报名中
  66. ];
  67. $list = Db::name('lesson_slot')->alias('slot')
  68. ->field('slot.*,lesson.name,lesson.name_en,lesson.image,lesson.price')
  69. ->join('lesson','slot.lesson_id = lesson.id','LEFT')
  70. ->where($where)->autopage()->select();
  71. $list = list_domain_image($list,['image']);
  72. $list = $this->list_lang($list,['name']);
  73. //准备教练数据
  74. $coach_list = Db::name('coach')->column('id,nickname');
  75. foreach($list as $key => &$slot){
  76. //放入教练
  77. $coach_text = '';
  78. $coach_ids = explode(',',$slot['coach_ids']);
  79. foreach($coach_ids as $coach_id){
  80. $coach_text .= $coach_list[$coach_id].',';
  81. }
  82. $slot['coach_text'] = substr($coach_text,0,-1);
  83. }
  84. $this->success(1,$list);
  85. }
  86. }