| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\ProductsModel;
- use app\common\model\ProductPopular;
- use app\common\model\ProductTransfer;
- class Product extends Api
- {
- protected array $noNeedLogin = ['*'];
- protected string $lan = '';
- public function _initialize()
- {
- parent::_initialize();
- $this->lan = $this->request->getLan();
- }
- /**
- * 热销列表
- */
- public function getPopularList(ProductsModel $productsModel, ProductPopular $productPopular)
- {
- $list = $productsModel->where('status', 1)->column('id,'.$this->lan.'_title as title');
- $resp = array();
- foreach ($list as $kk =>$val) {
- $pro = $productPopular->alias('a')
- ->join("product_list b", "a.product_id = b.id", "left")
- ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
- ->where('a.status', '<', $productPopular::STOP)
- ->where('b.type_id', $kk)
- ->order('a.weigh desc')
- ->select();
- $resp[] = ['type_id'=>$kk,'title'=>$val, 'product'=>$pro];
- }
- $this->success('', $resp);
- }
- /**
- * 转让列表
- * sort: 0 默认排序 1价格从高到低 2价格从低到高
- * type_id 分类
- * key_val 商品名称搜索
- */
- public function getTransferList(ProductTransfer $productTransfer)
- {
- $sort = $this->request->post('sort/d', '');
- $type_id = $this->request->post('type_id/s', '');
- $key_val = $this->request->post('key_val/s', '');
- $order = 'a.id DESC';
- $map = [];
- if($sort == 1) $order = 'a.price DESC';
- if($sort == 2) $order = 'a.price ASC';
- if($type_id > 0) $map['b.type_id'] = ['=', $type_id];
- if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
- $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)
- ->where($map)
- ->order($order)
- ->paginate($this->pageSize);
- $this->success('', $list);
- }
- }
|