Commit eb6c5aa4 authored by hj's avatar hj

更新提交00

parent b491f7ea
...@@ -115,6 +115,12 @@ class ProductsController extends Controller ...@@ -115,6 +115,12 @@ class ProductsController extends Controller
*/ */
public function getProductsByBrand(Request $request) public function getProductsByBrand(Request $request)
{ {
$customerCode = $request->get('customer_code');
if(!$customerCode){
return Response::ok('客户编号不存在!');
}
$this->checkCustomerType($customerCode,$this->controllerType);
$brandId = $request->get('brandId'); $brandId = $request->get('brandId');
if(!$brandId){ if(!$brandId){
return Response::ok('品牌id不存在!'); return Response::ok('品牌id不存在!');
...@@ -133,4 +139,31 @@ class ProductsController extends Controller ...@@ -133,4 +139,31 @@ class ProductsController extends Controller
} }
} }
public function getBrandProductDetail(Request $request)
{
$customerCode = $request->get('customer_code');
if(!$customerCode){
return Response::ok('客户编号不存在!');
}
$this->checkCustomerType($customerCode,$this->controllerType);
$brandId = $request->get('brandId');
if(!$brandId){
return Response::ok('品牌id不存在!');
}
$pCode = $request->get('productCode');
try{
$productDetail = $this->bhuaProdcutService->getBrandProductDetail($brandId, $pCode);
if($productDetail){
$productDetail = $this->formatKeysfromArray($productDetail,'toCamelCase');
}
return Response::success($productDetail,'操作成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'获取产品详情失败');
}
}
} }
...@@ -176,4 +176,22 @@ class BhuaProductRepositoryEloquent extends BaseRepository implements BhuaProduc ...@@ -176,4 +176,22 @@ class BhuaProductRepositoryEloquent extends BaseRepository implements BhuaProduc
} }
return null; return null;
} }
public function getProductsDetailByBrandId($brandId, $pCode)
{
$productsModel = $this->join('chemicals', 'chemicals.c_id','products.c_id');
$productsModel = $productsModel->where('products.b_id',$brandId)
->where('p_status',1)
->where('p_show',1);
if(!is_array($pCode)){
$productsModel->where('products.p_code',$pCode);
}else{
$productsModel->whereIn('products.p_code',$pCode);
}
$product = $productsModel->get();
if($product){
return $product->toArray();
}
return null;
}
} }
...@@ -97,6 +97,41 @@ class BhuaProductsService ...@@ -97,6 +97,41 @@ class BhuaProductsService
} }
} }
public function getBrandProductDetail($brandId, $pCode)
{
if(!is_numeric($brandId)){
throw new \Exception('品牌id类型错误',502);
}
if(!in_array($brandId,[40,1,10,108,161,7,188,5,4,32])){
throw new \Exception('品牌id不在授权范围之内',502);
}
try{
$brand = $this->bhuaProductService->brandsRepository->getBrandById($brandId);
if(!$brand){
throw new \Exception('没找到相应品牌id',502);
}
$products = $this->bhuaProductService->productRepository->getProductsDetailByBrandId($brandId, $pCode);
if($products){
$products = app(ProductsTransformer::class)->transform($products);
}
return $products;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getProductsByBrandId','error');
throw $exception;
}
}
private function checkCustomerExist($cusCode)
{
//查询用户是否存在
$customer = $this->bhuaCustomerService->getBhuaCustomerThroughtCusCode($cusCode);
if(!$customer){
throw new \Exception('客户编号为:['.$cusCode.']的用户不存在!',500);
}
return $customer;
}
} }
...@@ -42,7 +42,7 @@ class RhawnProductsService ...@@ -42,7 +42,7 @@ class RhawnProductsService
return $dataReturn; return $dataReturn;
}catch(\Throwable $exception){ }catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':cancelCustomerOrder','error'); SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getAllProducts','error');
throw $exception; throw $exception;
} }
} }
...@@ -57,7 +57,7 @@ class RhawnProductsService ...@@ -57,7 +57,7 @@ class RhawnProductsService
} }
return $products; return $products;
}catch(\Throwable $exception){ }catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':cancelCustomerOrder','error'); SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getProductDetail','error');
throw $exception; throw $exception;
} }
} }
...@@ -73,7 +73,7 @@ class RhawnProductsService ...@@ -73,7 +73,7 @@ class RhawnProductsService
} }
return $products; return $products;
}catch(\Throwable $exception){ }catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':cancelCustomerOrder','error'); SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getProductByCas','error');
throw $exception; throw $exception;
} }
} }
......
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