|
|
@@ -0,0 +1,91 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Api;
|
|
|
+
|
|
|
+
|
|
|
+use App\Http\Controllers\ApiController;
|
|
|
+use App\Models\Goods;
|
|
|
+use App\Models\GoodsCategory;
|
|
|
+use App\Servers\CommonServer;
|
|
|
+use App\Servers\GoodsSpecServer;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 外卖商品
|
|
|
+ */
|
|
|
+class GoodsController extends ApiController
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取商家分类
|
|
|
+ */
|
|
|
+ function getShopCategoryList()
|
|
|
+ {
|
|
|
+ $commonServer = CommonServer::creatServer();
|
|
|
+ $shop_id = $commonServer->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','type'])
|
|
|
+ ->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','is_infinite','stock'])
|
|
|
+ ->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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|