Index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. $result = [
  39. 'banner' => $banner,
  40. 'top_category' => $top_category,
  41. 'buttom_category' => $buttom_category,
  42. ];
  43. $this->success(1,$result);
  44. }
  45. //是否有可领取的优惠券
  46. public function new_coupon(){
  47. //未领取的优惠券
  48. $coupon = (object)[];
  49. if($this->auth->isLogin()){
  50. //我拥有的
  51. $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->column('coupon_id');
  52. //我没有的,可领取的
  53. $coupon = Db::name('unishop_coupon')->field('id,title,least,value')
  54. ->where('id','NOTIN',$user_coupon)
  55. ->where('deletetime',NULL)
  56. ->where('switch',1)
  57. ->where('starttime','<',time())
  58. ->where('endtime','>',time())
  59. ->order('id asc')->find();
  60. if(empty($coupon)){ $coupon = (object)[];}
  61. }
  62. $this->success(1,$coupon);
  63. }
  64. //领取优惠券
  65. public function get_coupon(){
  66. $coupon_id = input('coupon_id',0);
  67. $coupon = Db::name('unishop_coupon')->field('id,title,least,value')
  68. ->where('id',$coupon_id)
  69. ->where('deletetime',NULL)
  70. ->where('switch',1)
  71. ->where('starttime','<',time())
  72. ->where('endtime','>',time())
  73. ->find();
  74. if($coupon){
  75. $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->where('coupon_id',$coupon_id)->find();
  76. if(empty($user_coupon)){
  77. $data = [
  78. 'coupon_id' => $coupon_id,
  79. 'user_id' => $this->auth->id,
  80. ];
  81. Db::name('unishop_coupon_user')->insertGetId($data);
  82. }
  83. }
  84. $this->success('领取成功');
  85. }
  86. //吃喝玩乐
  87. //列表
  88. public function chihewanle_list(){
  89. $list = Db::name('chihewanle')->field('id, title, info, image')->where(['status' => 1])->order('weigh', 'desc')->select();
  90. $list = list_domain_image($list, ['image']);
  91. $this->success(1,$list);
  92. }
  93. //吃喝玩乐
  94. //详情
  95. public function chihewanle_info(){
  96. $id = input('id',0);
  97. $info = Db::name('chihewanle')->field('id, title, info, image, content')->where('id',$id)->order('weigh', 'desc')->find();
  98. $info = info_domain_image($info, ['image']);
  99. $this->success(1,$info);
  100. }
  101. }