Home.php 5.8 KB

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