Index.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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,number')
  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)){
  61. $coupon = (object)[];
  62. }else{
  63. $coupon['value'] = intval($coupon['value']);
  64. }
  65. }
  66. $this->success(1,$coupon);
  67. }
  68. //领取优惠券
  69. public function get_coupon(){
  70. $coupon_id = input('coupon_id',0);
  71. $coupon = Db::name('unishop_coupon')->field('id,title,least,value,number')
  72. ->where('id',$coupon_id)
  73. ->where('deletetime',NULL)
  74. ->where('switch',1)
  75. ->where('starttime','<',time())
  76. ->where('endtime','>',time())
  77. ->find();
  78. $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->where('coupon_id',$coupon_id)->find();
  79. if($coupon && empty($user_coupon)){
  80. $data = [];
  81. for($i=1;$i<=$coupon['number'];$i++){
  82. $data[] = [
  83. 'coupon_id' => $coupon_id,
  84. 'user_id' => $this->auth->id,
  85. ];
  86. }
  87. Db::name('unishop_coupon_user')->insertAll($data);
  88. }
  89. $this->success('领取成功');
  90. }
  91. //吃喝玩乐
  92. //列表
  93. public function chihewanle_list(){
  94. $list = Db::name('chihewanle')->field('id, title, info, image')->where(['status' => 1])->order('weigh', 'desc')->select();
  95. $list = list_domain_image($list, ['image']);
  96. $this->success(1,$list);
  97. }
  98. //吃喝玩乐
  99. //详情
  100. public function chihewanle_info(){
  101. $id = input('id',0);
  102. $info = Db::name('chihewanle')->field('id, title, info, image, content')->where('id',$id)->order('weigh', 'desc')->find();
  103. $info = info_domain_image($info, ['image']);
  104. $this->success(1,$info);
  105. }
  106. }