Index.php 2.8 KB

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