| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\api\controller;
- use think\Db;
- use think\db\Expression;
- use app\common\controller\Api;
- use app\common\model\ProductLists;
- 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, ProductLists $productLists)
- {
- $item = $productsModel->where('status', 1)->column('id,'.$this->lan.'_title as title');
- $resp = array();
- foreach ($item as $kk =>$val) {
- $list= $productLists->where('type_id', $kk)->field('id,thum as img_url,'.$this->lan.'_name as name')->select();
- $i = 0;
- $proArr = array();
- foreach ($list as $key => &$item) {
- $pro =$productPopular
- ->field('id,product_id,price,cost_price,stock,(num+init_num) as num,start_time,end_time,status')
- ->where('product_id', $item['id'])
- ->where('status', '<', $productPopular::STOP)
- ->order('start_time')
- ->find();
- if(!empty($pro)){
- $proArr[$i] = $item;
- $proArr[$i]['pro'] = $pro;
- $i+=1;
- }
- }
- $resp[] = ['type_id'=>$kk,'title'=>$val, 'product'=>$proArr];
- }
- $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")
- ->join("product_area dr", "dr.id = a.area_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,dr.address')
- ->where('a.status', $productTransfer::NORMAL)
- ->where($map)
- ->order($order)
- ->paginate($this->pageSize);
- $this->success('', $list);
- }
- }
|