Commit c7e8ac1d authored by hangjun83's avatar hangjun83

百化产品接口更新

parent ffbf7469
......@@ -95,4 +95,24 @@ class ProductsController extends Controller
}
}
public function getProductsByBrand(Request $request)
{
$brandId = $request->get('brandId');
if(!$brandId){
return Response::ok('品牌id不存在!');
}
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
try{
$productsList = $this->bhuaProdcutService->getProductsByBrandId($requestParams);
if($productsList){
$productsList = $this->formatKeysfromArray($productsList,'toCamelCase');
}
return Response::success($productsList,'操作成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'获取品牌产品列表失败');
}
}
}
......@@ -48,4 +48,10 @@ class BhuaBrandsRepositoryEloquent extends BaseRepository implements BhuaBrandsR
return null;
}
public function getBrandById($id)
{
$brand = $this->findWhere(['id' => $id]);
return $brand;
}
}
......@@ -3,9 +3,9 @@
namespace App\Services\Api;
use App\Repositories\Transformers\Rhawn\Bhua\BrandsTransformer;
use App\Repositories\Transformers\Rhawn\Bhua\ProductsTransformer;
use App\Rhawn\Services\BhuaCustomerService;
use App\Rhawn\Services\BhuaProductService;
use App\Rhawn\Services\RhawnCustomerService;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
......@@ -46,4 +46,39 @@ class BhuaProductsService
}
}
public function getProductsByBrandId($params)
{
$offset = !isset($requestParams['page_size']) || empty($requestParams['page_size']) ? 2000 : $requestParams['page_size'];
if($offset > 200){
$offset = 200;
}
$pageNo = !isset($requestParams['page_no']) || empty($requestParams['page_no']) ? 1 : $requestParams['page_no'];
$limit = $pageNo == 1 ? 0 : $pageNo * $offset;
try{
$brand = $this->bhuaProductService->brandsRepository->getBrandById($params['brand_id']);
if(!$brand){
throw new \Exception('502','没找到相应品牌id');
}
$products = $this->bhuaProductService->productRepository->getProductsList(['bid' => $params['brand_id']], $offset, $limit);
$total = 0;
if($products){
$products = app(ProductsTransformer::class)->transform($products);
$brandsTotal = $this->bhuaProductService->brandsRepository->count(['bid' => $params['brand_id']]);
}
$dataReturn = [];
$dataReturn['data'] = $products;
$dataReturn['total_page'] = ceil($total / $offset);
$dataReturn['page_no'] = $pageNo;
return $dataReturn;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getAllBrands','error');
throw $exception;
}
}
}
......@@ -49,6 +49,7 @@ $api->version('v1', function($api) {
$api->group(['namespace'=>'App\Http\Controllers\Internal\V1\Bhua','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
$api->post('/openapi/internal/bhua/getAllBrands', ['permission' => 'orders.getAllBrands', 'uses'=>'ProductsController@getAllBrands']);
$api->post('/openapi/internal/bhua/getProductsByBrandId', ['permission' => 'orders.getProductsByBrandId', 'uses'=>'ProductsController@getProductsByBrand']);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment