| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?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,title as title,img_url,createtime')
- ->where('type_id', $announcement::Banner)
- ->where('find_in_set(:id,sub_type_id)',['id'=>11])
- ->where('status', $announcement::Normal)
- ->where('is_show', $announcement::Normal)
- ->where('to_lang', $this->lan)
- ->limit(0,10)
- ->order('weigh desc,id DESC')
- ->select();
- // 最新公告
- $resp['notice_list'] = $announcement
- ->field('id,title as title,img_url,createtime')
- ->whereIn('type_id', $announcement::AnnounList)
- ->where('status', $announcement::Normal)
- ->where('is_show', $announcement::Normal)
- ->where('to_lang', $this->lan)
- ->limit(0,10)
- ->order('weigh desc,id 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)
-
- $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'));
- }
-
-
- /**
- * 获取地址
- * @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);
- }
- //首页轮播图
- public function getBanner()
- {
- $this->success('ok', config('best_cha'));
- }
- }
|