Index.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. public function index()
  13. {
  14. $this->success();
  15. }
  16. /**
  17. * 首页
  18. *
  19. */
  20. public function home(){
  21. //轮播图
  22. $banner = Db::name('banner')->field('id, title, image, url')->where(['status' => 1])->order('weigh', 'desc')->select();
  23. $banner = list_domain_image($banner, ['image']);
  24. //四个顶部分类
  25. $top_category = Db::name('unishop_category')->field('id, name, image')->where(['status' => 'normal','is_top' => 1])->order('weigh', 'asc')->limit(4)->select();
  26. $top_category = list_domain_image($top_category, ['image']);
  27. foreach($top_category as $key => $val){
  28. $val['type'] = 'product';
  29. if($key == 3){
  30. $val['type'] = 'news';
  31. }
  32. $top_category[$key] = $val;
  33. }
  34. //底部所有分类
  35. $buttom_category = Db::name('unishop_category')->field('id, name, image')->where(['status' => 'normal','is_top' => 0])->order('weigh', 'asc')->select();
  36. $buttom_category = list_domain_image($buttom_category, ['image']);
  37. //未领取的优惠券
  38. $coupon = (object)[];
  39. if($this->auth->isLogin()){
  40. //我拥有的
  41. $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->column('coupon_id');
  42. //我没有的,可领取的
  43. $coupon = Db::name('unishop_coupon')->field('id,title,least,value')
  44. ->where('id','NOTIN',$user_coupon)
  45. ->where('deletetime',NULL)
  46. ->where('switch',1)
  47. ->where('starttime','<',time())
  48. ->where('endtime','>',time())
  49. ->order('id asc')->find();
  50. if(empty($coupon)){ $coupon = (object)[];}
  51. }
  52. //
  53. $result = [
  54. 'banner' => $banner,
  55. 'top_category' => $top_category,
  56. 'buttom_category' => $buttom_category,
  57. 'coupon' => $coupon,
  58. ];
  59. $this->success(1,$result);
  60. }
  61. //吃喝玩乐
  62. //列表
  63. public function chihewanle_list(){
  64. $list = Db::name('chihewanle')->field('id, title, info, image')->where(['status' => 1])->order('weigh', 'desc')->select();
  65. $list = list_domain_image($list, ['image']);
  66. $this->success(1,$list);
  67. }
  68. //吃喝玩乐
  69. //详情
  70. public function chihewanle_info(){
  71. $id = input('id',0);
  72. $info = Db::name('chihewanle')->field('id, title, info, image, content')->where('id',$id)->order('weigh', 'desc')->find();
  73. $info = info_domain_image($info, ['image']);
  74. $this->success(1,$info);
  75. }
  76. }