params), ['page_no', 'page_size']); } /** * @note 首页商品列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author cjhao * @date 2021/7/26 16:47 */ public function lists(): array { $list = Goods::withSearch($this->setSearch(), $this->params) ->field('id,name,image,virtual_sales_num+sales_num as sales_num,min_price as sell_price,min_lineation_price as lineation_price') ->where(['status'=>GoodsEnum::STATUS_SELL]) ->limit($this->limitOffset, $this->limitLength) ->order('sort desc,id desc') ->select(); $showPrice = ConfigService::get('goods_set', 'show_price', 1); if(0 == $showPrice){ foreach ($list as $goods){ $goods->lineation_price = 0; } } $name = $this->params['name'] ?? ''; if ($name && $this->userId && $this->userInfo['terminal'] != UserTerminalEnum::PC) {//记录关键词 $this->recordKeyWord(trim($name), $this->userId); } return $list->toArray(); } /** * @notes 商品统计 * @return int * @author cjhao * @date 2021/7/26 16:48 */ public function count(): int { return Goods::withSearch($this->setSearch(), $this->params) ->where(['status'=>GoodsEnum::STATUS_SELL]) ->count(); } /** * @notes 记录商品搜索 * @param $name * @param $userId * @return bool * @author cjhao * @date 2021/8/11 17:43 */ public function recordKeyWord($name,$userId):bool { $searchRecord = SearchRecord::where(['user_id'=>$userId,'keyword'=>$name])->findOrEmpty(); if($searchRecord->isEmpty()){ $searchRecord->user_id = $userId; $searchRecord->keyword = $name; $searchRecord->save(); return true; } $searchRecord->count = Db::raw('count+1'); $searchRecord->save(); return true; } }