Browse Source

分类包含失效商品

master
Lemon 5 years ago
parent
commit
7c60913dff
  1. 7
      app/Controller/v3/StoreController.php
  2. 25
      app/Service/v3/Implementations/CategoryService.php
  3. 2
      app/Service/v3/Interfaces/CategoryServiceInterface.php
  4. 1
      config/routes.php

7
app/Controller/v3/StoreController.php

@ -111,4 +111,11 @@ class StoreController extends BaseController
$res = $this->storeService->getList($personnel->market_id,$page,$pagesize); $res = $this->storeService->getList($personnel->market_id,$page,$pagesize);
return $this->success($res); return $this->success($res);
} }
public function getCategory()
{
$storeId = $this->request->input('store_id');
$res = $data['goods_types'] = $this->categoryService->allForStoreIncludeOff($storeId);
return $this->success($res);
}
} }

25
app/Service/v3/Implementations/CategoryService.php

@ -95,4 +95,29 @@ class CategoryService implements CategoryServiceInterface
return array_values($returnData); return array_values($returnData);
} }
public function allForStoreIncludeOff($storeId)
{
$goodsTypeIds = Goods::query()
->withoutGlobalScope('normal')
->where(['store_id' => $storeId])
->groupBy('category_id', 'id')
->pluck('category_id');
$categories = Category::query()
->with(['goodsCategory'])
->whereIn('id', $goodsTypeIds)
->orderBy('sort', 'DESC')
->orderBy('id', 'DESC')
->get()->toArray();
foreach ($categories as $key => &$item) {
$item['goods_category_ids'] = '';
if (isset($item['goods_category']) && $item['goods_category']) {
$item['goods_category_ids'] = implode(',', array_values(array_column($item['goods_category'], 'id')));
}
}
return $categories;
}
} }

2
app/Service/v3/Interfaces/CategoryServiceInterface.php

@ -11,5 +11,5 @@ interface CategoryServiceInterface
public function all(); public function all();
public function allForStore($storeId); public function allForStore($storeId);
public function allForAppletIndex(); public function allForAppletIndex();
public function allForStoreIncludeOff($storeId);
} }

1
config/routes.php

@ -154,6 +154,7 @@ Router::addGroup('/v3/', function () {
Router::post('goods/update', 'App\Controller\v3\GoodsController@update'); Router::post('goods/update', 'App\Controller\v3\GoodsController@update');
Router::post('store/getList', 'App\Controller\v3\StoreController@getList'); Router::post('store/getList', 'App\Controller\v3\StoreController@getList');
Router::post('goods/info', 'App\Controller\v3\GoodsController@info'); Router::post('goods/info', 'App\Controller\v3\GoodsController@info');
Router::post('store/getCategory', 'App\Controller\v3\StoreController@getCategory');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
// 微信支付回调 // 微信支付回调

Loading…
Cancel
Save