Home.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\AnnouncementModel;
  5. use app\common\model\ProductTransfer;
  6. use app\common\model\ProductOrder;
  7. use app\common\model\ProductPopular;
  8. use app\common\model\ProductArea;
  9. use app\common\model\ProductsModel;
  10. use app\common\model\Region;
  11. use app\common\model\UserModel;
  12. use Exception;
  13. /**
  14. * 首页接口
  15. */
  16. class Home extends Api
  17. {
  18. protected array $noNeedLogin = ['*'];
  19. protected string $lan = '';
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->lan = $this->request->getLan();
  24. }
  25. /**
  26. * 首页基础数据
  27. */
  28. public function base(AnnouncementModel $announcement, ProductsModel $productsModel)
  29. {
  30. $resp = [
  31. 'system_name' => __("System name"),
  32. 'banner_list' => [],
  33. 'notice_list' => []
  34. ];
  35. // banner
  36. $resp['banner_list'] = $announcement
  37. ->field('id,title as title,img_url,createtime')
  38. ->where('type_id', $announcement::Banner)
  39. ->where('find_in_set(:id,sub_type_id)',['id'=>11])
  40. ->where('status', $announcement::Normal)
  41. ->where('is_show', $announcement::Normal)
  42. ->where('to_lang', $this->lan)
  43. ->limit(0,10)
  44. ->order('weigh desc,id DESC')
  45. ->select();
  46. // 最新公告
  47. $resp['notice_list'] = $announcement
  48. ->field('id,title as title,img_url,createtime')
  49. ->whereIn('type_id', $announcement::AnnounList)
  50. ->where('status', $announcement::Normal)
  51. ->where('is_show', $announcement::Normal)
  52. ->where('to_lang', $this->lan)
  53. ->limit(0,10)
  54. ->order('weigh desc,id DESC')
  55. ->select();
  56. //分类
  57. $resp['type_list'] = $productsModel->where('status', $productsModel::Normal)
  58. ->field('id,'.$this->lan.'_title as title')
  59. ->order('sort desc')
  60. ->select();
  61. $this->success('', $resp);
  62. }
  63. /**
  64. * 首页数据
  65. */
  66. public function all(ProductPopular $productPopular, ProductTransfer $productTransfer)
  67. {
  68. //更新库存
  69. $productPopular::setUpdateStatus();
  70. $resp['product_list'] = $productPopular->with('productsList')
  71. ->where('product_popular.status', '<', $productPopular::Stop)
  72. ->order('weigh desc,start_time asc')->select(); //$this->pageSize)
  73. $this->success('', $resp);
  74. }
  75. /**
  76. * 热销详情
  77. * @param int $uid
  78. * @param string $fee
  79. * @param string $txHsh
  80. * @return void
  81. */
  82. public function getPopularInfo(ProductPopular $productPopular, ProductOrder $productOrder)
  83. {
  84. try {
  85. $ids = $this->request->post('ids/d', 0);
  86. $product_id = $this->request->post('product_id/d', 0);
  87. if(empty($ids)) throw new Exception(__("Parameter error"));
  88. $times = array();
  89. $order = array();
  90. //详情
  91. $info = $productPopular::getProductInfo($product_id, $ids, $this->lan);
  92. if(!empty($info)) {
  93. $times = $productPopular
  94. ->where('product_id', $info['product_id'])
  95. ->field('title,price, start_time, end_time, status')
  96. ->order('weigh desc')->limit(10)->select();
  97. }
  98. if(!empty($info)) {
  99. $order = $productOrder->alias('a')
  100. ->join("user u", "a.user_id = u.id", "left")
  101. ->where('order_id', $ids)->field('u.address, u.avatar, a.create_time')
  102. ->order('a.id desc')->limit(10)->select();
  103. }
  104. } catch (Exception $e) {
  105. $this->error( $e->getMessage());
  106. }
  107. $this->success('', compact('info', 'times', 'order'));
  108. }
  109. /**
  110. * 获取地址
  111. * @return void
  112. * @throws Exception
  113. */
  114. public function getProductAddres(ProductArea $productarea)
  115. {
  116. $search = $this->request->post('search/s', '');
  117. $pid = $this->request->post('product_id/d', 0);
  118. if(empty($pid)) $this->error(__("Parameter error"));
  119. $map = array();
  120. if(!empty($search)) $map['address'] = ['like', '%'.$search.'%'];
  121. $list = $productarea
  122. ->field('id,province,city,area,county,address')
  123. ->where('product_id', $pid)
  124. ->where('status', $productarea::Normal)
  125. ->where($map)
  126. ->paginate($this->pageSize);
  127. // 提交事务
  128. $this->success('', $list);
  129. }
  130. //首页轮播图
  131. public function getBanner()
  132. {
  133. $this->success('ok', config('best_cha'));
  134. }
  135. }