filtrationStr('shop_id');//商品id if (empty($shop_id)) return $this->apiResponseError('请选择商家'); $list = GoodsCategory::where('is_del',0) ->where('shop_id',$shop_id) ->select(['id as category_id','name']) ->orderBy('sort','desc') ->get(); return $this->apiResponseSuccess('成功',$list); } /** * 获取分类下商品 */ function getShopGoodsList() { $m_id = $this->getMemberId();//用户id $commonServer = CommonServer::creatServer(); $shop_id = $commonServer->filtrationStr('shop_id');//商品id if (empty($shop_id)) return $this->apiResponseError('请选择商家'); $category = GoodsCategory::where('is_del',0) ->where('shop_id',$shop_id) ->select(['id as type','name']) ->orderBy('sort','desc') ->get(); foreach ($category as $value){ $list = Goods::where('is_del',0) ->where('status',1) ->where('shop_id',$shop_id) ->where('category_id',$value['type']) ->select(['id as goods_id','category_id','goods_name','goods_desc','goods_image','price','spec_type','line_price','sales']) ->orderBy('sort','desc') ->get(); foreach ($list as $goods){ $goods->{'num'} = 0;//前端需要 } $value->{'list'} = $list; } return $this->apiResponseSuccess('成功',$category); } /** * 获取商品sku */ function getGoodsSpec() { $m_id = $this->getMemberId();//用户id $commonServer = CommonServer::creatServer(); $goods_id = $commonServer->filtrationStr('goods_id');//商品id if (empty($goods_id)) return $this->apiResponseError('请选择商品'); $spec_type = Goods::where('id',$goods_id)->where('is_del',0)->value('spec_type'); if ($spec_type == 2){ $sku = GoodsSpecServer::creatServer()->getGoodsSku($goods_id); }else{ $sku = []; } return $this->apiResponseSuccess('成功',$sku); } /** * 搜索商家商品 */ function getSearchGoodsList() { $m_id = $this->getMemberId();//用户id $commonServer = CommonServer::creatServer(); $search = $commonServer->filtrationStr('search');//搜索 $shop_id = $commonServer->filtrationStr('shop_id');//商品id if (empty($shop_id)) return $this->apiResponseError('请选择商家'); if (empty($search)) return $this->apiResponseSuccess('请输入搜索内容'); //记录搜索 GoodsServer::creatServer()->setSearch($m_id,$shop_id, $search); //查询该关键词下的商品 $list = Goods::where('is_del',0) ->where('status',1) ->where('shop_id',$shop_id) ->where('goods_name','like',"%$search%") ->select(['id as goods_id','category_id','goods_name','goods_desc','goods_image','price','spec_type','line_price','sales']) ->orderBy('sort','desc') ->paginate(10); return $this->apiResponseSuccess('获取成功', [ 'items' => $list->items(), 'total' => $list->total(), 'limit' => 10, ]); } /** * 获取搜索内容 */ function getSearchList() { $m_id = $this->getMemberId();//用户id $commonServer = CommonServer::creatServer(); $shop_id = $commonServer->filtrationStr('shop_id');//商品id if (empty($shop_id)) return $this->apiResponseError('请选择商家'); $data = GoodsServer::creatServer()->getSearch($m_id,$shop_id); return $this->apiResponseSuccess('获取数据成功', $data); } /** * 清除搜索记录 */ function delSearch() { $m_id = $this->getMemberId();//用户id $commonServer = CommonServer::creatServer(); $shop_id = $commonServer->filtrationStr('shop_id');//商品id if (empty($shop_id)) return $this->apiResponseError('请选择商家'); $res = GoodsSearch::where('m_id', $m_id)->where('shop_id',$shop_id)->delete(); if (!$res){ return $this->apiResponseError('清除失败'); } return $this->apiResponseSuccess('清除成功'); } }