lan = $this->request->getLan(); } /** * 热销列表 */ public function getPopularList(ProductsModel $productsModel, ProductPopular $productPopular, ProductLists $productLists) { $item = $productsModel::getProductTypeAll($this->lan); $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 &$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(ProductMarket $productMarket, OrderLogic $orderLogic) { $sort = $this->request->post('sort/d', ''); $type_id = $this->request->post('type_id/s', ''); $key_val = $this->request->post('key_val/s', ''); $order = 'a.price ASC'; if($sort == 1) $order = 'a.price DESC'; $map['product_market.status'] = $productMarket::Normal; if(!empty($type_id)) $map['product_market.type_id'] = $type_id; if(!empty($key_val)) $map['product_list.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%']; $list = $productMarket ->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,a.price,a.product_id,a.type_id') ->where('a.status', $productMarket::Normal) ->where($map) ->order($order) ->paginate($this->pageSize); $list = $this->getProductOrderList($list, $this->auth->id, true, $orderLogic); $this->success('', $list); } /** * 寄售转让收藏列表 * sort: 0 默认排序 1价格从高到低 2价格从低到高 * type_id 分类 * key_val 商品名称搜索 */ public function getTransferCollectList(ProductMarket $productMarket, OrderLogic $orderLogic) { $sort = $this->request->post('sort/d', ''); $type_id = $this->request->post('type_id/s', ''); $key_val = $this->request->post('key_val/s', ''); $order = 'a.price ASC'; if($sort == 1) $order = 'a.price DESC'; $map['a.status'] = $productMarket::Normal; if(!empty($type_id)) $map['b.type_id'] = $type_id; if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%']; $list = $productMarket->alias('a') ->join("product_list b", "a.product_id = b.id", "left") ->join("user_collect c", "c.market_id = a.id and c.user_id = {$this->auth->id}") ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id') ->where('a.status', $productMarket::Normal) ->where($map) ->order($order) ->paginate($this->pageSize); $list = $this->getProductOrderList($list, $this->auth->id, false, $orderLogic); $this->success('', $list); } /** * 寄售转让详情 * sort: 0 默认排序 1价格从高到低 2价格从低到高 * type_id 分类 * key_val 商品名称搜索 */ public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic) { $ids = $this->request->post('ids/d', ''); $list = $productMarket->with('products,producttransfer,collect') ->where('product_market.id', $ids) ->where('product_market.status', $productMarket::Normal) ->find(); if(empty($list)) $this->error('数据不存在'); $list->issue = $orderLogic::getProductIssue($list->product_id); //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的 $list->circulation = $orderLogic::getProductCirculation($list->product_id); //流通: 所有用户的持有量 $this->success('', $list); } private static function getProductOrderList(object $list, int $uid, bool $isCollect, OrderLogic $orderLogic): object { if($list){ $userCollect = Loader::model('UserCollect'); foreach ($list as &$item) { if($isCollect) $item['collect'] = $userCollect::where('user_id', $uid)->where('market_id', $item->id)->count(); $item['issue'] = $orderLogic::getProductIssue($item->product_id); //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的 $item['circulation'] = $orderLogic::getProductCirculation($item->product_id); //流通: 所有用户的持有量 } } return $list; } //获取分类 public function getPopularType() { return $this->success('', ProductsModel::getProductTypeById($this->lan)); } }