Commit 154ba0cd authored by hj's avatar hj

更新提交

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