Commit 154ba0cd authored by hj's avatar hj

更新提交

parent 2b7f9efb
...@@ -70,7 +70,7 @@ class CompanyAuthController extends Controller ...@@ -70,7 +70,7 @@ class CompanyAuthController extends Controller
{ {
$message = [ $message = [
'companyToken.required' => "公司token必传", 'companyToken.required' => "公司token必传",
'cusNumber.required' => "客户编号必传", //'cusNumber.required' => "客户编号必传",
]; ];
$this->validateRequest($request, $message); $this->validateRequest($request, $message);
......
...@@ -15,22 +15,13 @@ use App\Exceptions\ServerRunTimeException; ...@@ -15,22 +15,13 @@ use App\Exceptions\ServerRunTimeException;
use App\Rhawn\Services\Chemsite\ChemsiteCompanyService; use App\Rhawn\Services\Chemsite\ChemsiteCompanyService;
use App\Services\Api\ChemicalsMsdsService; use App\Services\Api\ChemicalsMsdsService;
use App\Services\Api\Chemsite\ChemsiteCustomerService; use App\Services\Api\Chemsite\ChemsiteCustomerService;
use App\Services\Api\RhawnOrdersService;
use App\Services\CustomerService; use App\Services\CustomerService;
use App\Services\FileService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response; use Jiannei\Response\Laravel\Support\Facades\Response;
use App\Http\Controllers\V1\Controller; use App\Http\Controllers\V1\Controller;
use App\Support\Traits\Helpers; use App\Support\Traits\Helpers;
use OpenApi\Annotations\Post;
use OpenApi\Annotations\RequestBody;
use OpenApi\Annotations\MediaType;
use OpenApi\Annotations\Schema;
use OpenApi\Annotations\Property;
use OpenApi\Annotations\Response as AnnotationResponse;
use OpenApi\Annotations as OA;
class MsdsController extends Controller class MsdsController extends Controller
{ {
use Helpers; use Helpers;
...@@ -42,51 +33,58 @@ class MsdsController extends Controller ...@@ -42,51 +33,58 @@ class MsdsController extends Controller
public function getMsds(Request $request) public function getMsds(Request $request)
{ {
$companyCode = $request->get('company_code'); try{
$cusNumber = $request->get('cus_number'); $companyCode = $request->get('company_code');
if(!$companyCode){ $cusNumber = $request->get('cus_number');
return Response::ok('验证失败,参数缺少!');
}
$companyInfo = app(ChemsiteCompanyService::class)->getCompanyThroughCusCode($companyCode); $params = $this->formatKeysfromArray($request->all(),'toUnderScore');
if(!$companyInfo){ $cas = $params['cas'];
throw new ServerRunTimeException('经销商不存在'); $msdsType = $params['msds_type'];
}
if($cusNumber){ if(!$companyCode){
$customer = app(ChemsiteCustomerService::class)->getCustomerByNumber($cusNumber); return Response::ok('验证失败,参数缺少!');
if(!$customer){ }
throw new ServerRunTimeException('客户不存在'); if(!$cas){
return Response::ok('验证失败,缺少cas参数!');
}
if(!$msdsType){
return Response::ok('验证失败,缺少msds类型参数!');
} }
}
if($customer['com_id'] != $companyInfo['com_id']){
throw new ServerRunTimeException('不是该经销商的客户');
}
$platformCompanyInfo = app(CustomerService::class)->getPlatformCustomer(['cus_number' => $companyCode]); if(!in_array($msdsType, ['cn', 'en'])){
$this->chemicalsMsdsService->getMsds('270912-72-6', 'cn', $platformCompanyInfo); return Response::ok('验证失败,获取类型错误!');
}
$companyInfo = app(ChemsiteCompanyService::class)->getCompanyThroughCusCode($companyCode);
if(!$companyInfo){
throw new ServerRunTimeException('经销商不存在');
}
if($cusNumber){
$customer = app(ChemsiteCustomerService::class)->getCustomerByNumber($cusNumber);
if(!$customer){
throw new ServerRunTimeException('客户不存在');
}
if($customer['com_id'] != $companyInfo['com_id']){
throw new ServerRunTimeException('不是该经销商的客户');
}
}
$customerCode = $request->get('customer_code'); $platformCompanyInfo = app(CustomerService::class)->getPlatformCustomer(['cus_number' => $companyCode]);
$companyCode = $request->get('company_code'); $pdf = $this->chemicalsMsdsService->getMsds($cas, $msdsType, $platformCompanyInfo);
$cusNumber = $request->get('cus_number');
if(!$companyCode){ return Response::success($this->formatKeysfromArray(['download' => $pdf]),'操作成功');
return Response::ok('验证失败,参数缺少!'); }catch(\Throwable $exception){
} return $this->returnErrorExecptionResponse($exception,'获取msds失败');
if(!$customerCode){
return Response::ok('客户编号不存在!');
} }
$this->checkCustomerType($customerCode,$this->controllerType); }
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore'); public function downloadFile($path)
$requestParams = array_merge($requestParams,['customer_code' => $customerCode]); {
try{ try{
$orderList = $this->rhawnOrdersService->getCustomerRhawnOrdersList($requestParams); ob_end_clean();
if($orderList){ return app(FileService::class)->download($path);
$orderList = $this->formatKeysfromArray($orderList,'toCamelCase');
}
return Response::success($orderList,'操作成功');
}catch(\Throwable $exception){ }catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'获取订单列表失败'); $this->returnErrorExecptionResponse($exception);
} }
} }
......
...@@ -12,6 +12,12 @@ class ChemicalsMsdsService ...@@ -12,6 +12,12 @@ class ChemicalsMsdsService
public function getMsds($cas, $type = null, $comInfo = null) public function getMsds($cas, $type = null, $comInfo = null)
{ {
$fileService = app(FileService::class);
$msdPdf = $fileService->getFileListByModelData($comInfo['cus_type'].'_'.$cas.'_msds', $comInfo['cus_number']);
if($msdPdf){
return $fileService->getDownloadUrl(current($msdPdf)['uniqueid']);
}
$findResult = shell_exec('find '.env('MSDS_FILE_DIR').' -iname \''.$cas.'\' -print'); $findResult = shell_exec('find '.env('MSDS_FILE_DIR').' -iname \''.$cas.'\' -print');
if(is_null($findResult)){ if(is_null($findResult)){
return null; return null;
...@@ -31,10 +37,8 @@ class ChemicalsMsdsService ...@@ -31,10 +37,8 @@ class ChemicalsMsdsService
$this->getPdfApp()->render(); $this->getPdfApp()->render();
$pdf = $this->getPdfApp()->output(); $pdf = $this->getPdfApp()->output();
$fileService = app(FileService::class);
if($pdf){ if($pdf){
$fileName = $cas.'/'.$cas.'_msds.pdf'; $fileName = $cas.'/'.$comInfo['cus_number'].'_'.$cas.'_'.$comInfo['cus_type'].'_msds.pdf';
$realPath = $fileService->getFileFolderPath().'/'.$fileName; $realPath = $fileService->getFileFolderPath().'/'.$fileName;
if($fileService->saveToFile($realPath, $pdf)){ if($fileService->saveToFile($realPath, $pdf)){
$fileSave = []; $fileSave = [];
...@@ -45,11 +49,15 @@ class ChemicalsMsdsService ...@@ -45,11 +49,15 @@ class ChemicalsMsdsService
$fileSave['extension'] = 'pdf'; $fileSave['extension'] = 'pdf';
$fileSave['mime_type'] = 'application/pdf'; $fileSave['mime_type'] = 'application/pdf';
$fileSave['byte_size'] = ''; $fileSave['byte_size'] = '';
$fileSave['model_name'] = $cas.'_msds'; $fileSave['model_name'] = $comInfo['cus_type'].'_'.$cas.'_msds';
$fileSave['model_data_id'] = 1; $fileSave['model_data_id'] = $comInfo['cus_number'];
$fileService->saveFileRecord($fileSave); if($fileService->saveFileRecord($fileSave)){
return $fileService->getDownloadUrl($fileSave['uniqueid']);
}
} }
} }
} }
return null;
} }
} }
...@@ -44,7 +44,7 @@ class AuthService ...@@ -44,7 +44,7 @@ class AuthService
$platformCustomer = current($platformCustomer->toArray()); $platformCustomer = current($platformCustomer->toArray());
if($platformCustomer['cus_type'] == 'chemsite'){ if($platformCustomer['cus_type'] == 'chemsite'){
$token['company_token'] = $requestParams['customer_token']; $token['company_token'] = $requestParams['customer_token'];
$token['cus_number'] = $requestParams['cus_number']; $token['cus_number'] = $requestParams['cus_number'] ?? '';
}else{ }else{
$token['customer_token'] = $requestParams['customer_token']; $token['customer_token'] = $requestParams['customer_token'];
} }
......
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