| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\AnnouncementModel;
- use app\common\model\ProductTransfer;
- use app\common\model\ProductOrder;
- use app\common\model\ProductPopular;
- use app\common\model\ProductArea;
- use app\common\model\ProductsModel;
- use app\common\model\Region;
- use app\common\model\UserModel;
- use Exception;
- /**
- * 首页接口
- */
- class Home extends Api
- {
- protected array $noNeedLogin = ['*'];
- protected string $lan = '';
- public function _initialize()
- {
- parent::_initialize();
- $this->lan = $this->request->getLan();
- }
- /**
- * 首页基础数据
- */
- public function base(AnnouncementModel $announcement, ProductsModel $productsModel)
- {
- $resp = [
- 'system_name' => __("System name"),
- 'banner_list' => [],
- 'notice_list' => []
- ];
- // banner
- $resp['banner_list'] = $announcement
- ->field('id,'.$this->lan.'_title as title,img_url,createtime')
- ->where('type_id', $announcement::Banner)
- ->where('status', $announcement::NORMAL)
- ->limit(0,10)
- ->order('id DESC,weigh desc')
- ->select();
- // 最新公告
- $resp['notice_list'] = $announcement
- ->field('id,'.$this->lan.'_title as title,img_url,createtime')
- ->where('type_id', $announcement::Announ)
- ->where('status', $announcement::NORMAL)
- ->limit(0,10)
- ->order('id DESC,weigh desc')
- ->select();
- //分类
- $resp['type_list'] = $productsModel->where('status', $productsModel::NORMAL)
- ->field('id,'.$this->lan.'_title as title')
- ->order('sort desc')
- ->select();
- $this->success('', $resp);
- }
- /**
- * 首页数据
- */
- public function all(ProductPopular $productPopular, ProductTransfer $productTransfer)
- {
- //更新库存
- $productPopular::setUpdateStatus();
- $resp['product_list'] = $productPopular->with('productsList')->where('product_popular.status', '<', $productPopular::STOP)
- ->order('weigh desc,start_time asc')->select(); //$this->pageSize)
-
- // 转让
- $resp['transfer_list'] = $productTransfer->alias('a')
- ->join("product_list b", "a.product_id = b.id", "left")
- ->join("user u", "a.user_id = u.id", "left")
- ->join("products d", "b.type_id = d.id", "left")
- ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,price,u.nickname,d.'.$this->lan.'_title as title')
- ->where('a.status', $productTransfer::NORMAL)
- ->limit(2)
- ->order('a.id DESC')
- ->select();
- //抵押
- $resp['mortgage_list'] = array();
- $this->success('', $resp);
- }
- /**
- * 热销详情
- * @param int $uid
- * @param string $fee
- * @param string $txHsh
- * @return void
- */
- public function getPopularInfo(ProductPopular $productPopular, ProductOrder $productOrder)
- {
- try {
-
- $ids = $this->request->post('ids/d', 0);
- $product_id = $this->request->post('product_id/d', 0);
- if(empty($ids)) throw new Exception(__("Parameter error"));
- $times = array();
- $order = array();
- //详情
- $info = $productPopular::getProductInfo($product_id, $ids, $this->lan);
-
- if(!empty($info)) {
- $times = $productPopular
- ->where('product_id', $info['product_id'])
- ->field('title,price, start_time, end_time, status')
- ->order('weigh desc')->limit(10)->select();
- }
- if(!empty($info)) {
- $order = $productOrder->alias('a')
- ->join("user u", "a.user_id = u.id", "left")
- ->where('order_id', $ids)->field('u.address, u.avatar, a.create_time')
- ->order('a.id desc')->limit(10)->select();
- }
- } catch (Exception $e) {
- $this->error( $e->getMessage());
- }
- $this->success('', compact('info', 'times', 'order'));
- }
- /**
- * 转让详情
- * @param int $uid
- * @param string $fee
- * @param string $txHsh
- * @return void
- */
- public function getTransferInfo(ProductTransfer $productTransfer)
- {
- try {
- $ids = $this->request->post('ids/d', 0);
- if(empty($ids)) throw new Exception(__("Parameter error"));
-
- $info = $productTransfer->alias('a')
- ->join("product_list b", "a.product_id = b.id", "left")
- ->join("product_area d", "d.id = a.area_id", "left") //地区
- ->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')
- ->where('a.id', $ids)
- ->find();
-
- } catch (Exception $e) {
- $this->error( $e->getMessage());
- }
- $this->success('', $info);
- }
-
- /**
- * 获取地址
- * @return void
- * @throws Exception
- */
- public function getProductAddres(ProductArea $productarea)
- {
- $search = $this->request->post('search/s', '');
- $pid = $this->request->post('product_id/d', 0);
- if(empty($pid)) $this->error(__("Parameter error"));
- $map = array();
- if(!empty($search)) $map['address'] = ['like', '%'.$search.'%'];
- $list = $productarea
- ->field('id,province,city,area,county,address')
- ->where('product_id', $pid)
- ->where('status', $productarea::NORMAL)
- ->where($map)
- ->paginate($this->pageSize);
- // 提交事务
- $this->success('', $list);
- }
- }
|