Home.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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,'.$this->lan.'_title as title,img_url,createtime')
  38. ->where('type_id', $announcement::Banner)
  39. ->where('status', $announcement::NORMAL)
  40. ->limit(0,10)
  41. ->order('id DESC,weigh desc')
  42. ->select();
  43. // 最新公告
  44. $resp['notice_list'] = $announcement
  45. ->field('id,'.$this->lan.'_title as title,img_url,createtime')
  46. ->where('type_id', $announcement::Announ)
  47. ->where('status', $announcement::NORMAL)
  48. ->limit(0,10)
  49. ->order('id DESC,weigh desc')
  50. ->select();
  51. //分类
  52. $resp['type_list'] = $productsModel->where('status', $productsModel::NORMAL)
  53. ->field('id,'.$this->lan.'_title as title')
  54. ->order('sort desc')
  55. ->select();
  56. $this->success('', $resp);
  57. }
  58. /**
  59. * 首页数据
  60. */
  61. public function all(ProductPopular $productPopular, ProductTransfer $productTransfer)
  62. {
  63. //更新库存
  64. $productPopular::setUpdateStatus();
  65. $resp['product_list'] = $productPopular->with('productsList')->where('product_popular.status', '<', $productPopular::STOP)
  66. ->order('weigh desc,start_time asc')->select(); //$this->pageSize)
  67. // 转让
  68. $resp['transfer_list'] = $productTransfer->alias('a')
  69. ->join("product_list b", "a.product_id = b.id", "left")
  70. ->join("user u", "a.user_id = u.id", "left")
  71. ->join("products d", "b.type_id = d.id", "left")
  72. ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,price,u.nickname,d.'.$this->lan.'_title as title')
  73. ->where('a.status', $productTransfer::NORMAL)
  74. ->limit(2)
  75. ->order('a.id DESC')
  76. ->select();
  77. //抵押
  78. $resp['mortgage_list'] = array();
  79. $this->success('', $resp);
  80. }
  81. /**
  82. * 热销详情
  83. * @param int $uid
  84. * @param string $fee
  85. * @param string $txHsh
  86. * @return void
  87. */
  88. public function getPopularInfo(ProductPopular $productPopular, ProductOrder $productOrder)
  89. {
  90. try {
  91. $ids = $this->request->post('ids/d', 0);
  92. $product_id = $this->request->post('product_id/d', 0);
  93. if(empty($ids)) throw new Exception(__("Parameter error"));
  94. $times = array();
  95. $order = array();
  96. //详情
  97. $info = $productPopular::getProductInfo($product_id, $ids, $this->lan);
  98. if(!empty($info)) {
  99. $times = $productPopular
  100. ->where('product_id', $info['product_id'])
  101. ->field('title,price, start_time, end_time, status')
  102. ->order('weigh desc')->limit(10)->select();
  103. }
  104. if(!empty($info)) {
  105. $order = $productOrder->alias('a')
  106. ->join("user u", "a.user_id = u.id", "left")
  107. ->where('order_id', $ids)->field('u.address, u.avatar, a.create_time')
  108. ->order('a.id desc')->limit(10)->select();
  109. }
  110. } catch (Exception $e) {
  111. $this->error( $e->getMessage());
  112. }
  113. $this->success('', compact('info', 'times', 'order'));
  114. }
  115. /**
  116. * 转让详情
  117. * @param int $uid
  118. * @param string $fee
  119. * @param string $txHsh
  120. * @return void
  121. */
  122. public function getTransferInfo(ProductTransfer $productTransfer)
  123. {
  124. try {
  125. $ids = $this->request->post('ids/d', 0);
  126. if(empty($ids)) throw new Exception(__("Parameter error"));
  127. $info = $productTransfer->alias('a')
  128. ->join("product_list b", "a.product_id = b.id", "left")
  129. ->join("product_area d", "d.id = a.area_id", "left") //地区
  130. ->field('a.id,a.product_id,a.area_id,'.'b.'.$this->lan.'_name as name,b.images as img_url,price,fees,b.details,d.address')
  131. ->where('a.id', $ids)
  132. ->find();
  133. } catch (Exception $e) {
  134. $this->error( $e->getMessage());
  135. }
  136. $this->success('', $info);
  137. }
  138. /**
  139. * 获取地址
  140. * @return void
  141. * @throws Exception
  142. */
  143. public function getProductAddres(ProductArea $productarea)
  144. {
  145. $search = $this->request->post('search/s', '');
  146. $pid = $this->request->post('product_id/d', 0);
  147. if(empty($pid)) $this->error(__("Parameter error"));
  148. $map = array();
  149. if(!empty($search)) $map['address'] = ['like', '%'.$search.'%'];
  150. $list = $productarea
  151. ->field('id,province,city,area,county,address')
  152. ->where('product_id', $pid)
  153. ->where('status', $productarea::NORMAL)
  154. ->where($map)
  155. ->paginate($this->pageSize);
  156. // 提交事务
  157. $this->success('', $list);
  158. }
  159. }