Commit 2b7f9efb authored by hj's avatar hj

更新提交

parent a089f01d
...@@ -11,8 +11,12 @@ ...@@ -11,8 +11,12 @@
namespace App\Http\Controllers\V1\Chemicals; namespace App\Http\Controllers\V1\Chemicals;
use App\Exceptions\ServerRunTimeException;
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\RhawnOrdersService; use App\Services\Api\RhawnOrdersService;
use App\Services\CustomerService;
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;
...@@ -38,8 +42,28 @@ class MsdsController extends Controller ...@@ -38,8 +42,28 @@ class MsdsController extends Controller
public function getMsds(Request $request) public function getMsds(Request $request)
{ {
$companyCode = $request->get('company_code');
$cusNumber = $request->get('cus_number');
if(!$companyCode){
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('不是该经销商的客户');
}
$this->chemicalsMsdsService->getMsds('270912-72-6'); $platformCompanyInfo = app(CustomerService::class)->getPlatformCustomer(['cus_number' => $companyCode]);
$this->chemicalsMsdsService->getMsds('270912-72-6', 'cn', $platformCompanyInfo);
$customerCode = $request->get('customer_code'); $customerCode = $request->get('customer_code');
......
...@@ -27,8 +27,13 @@ class CustomersController extends Controller ...@@ -27,8 +27,13 @@ class CustomersController extends Controller
$this->validateRequest($request, $message); $this->validateRequest($request, $message);
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore'); $requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
try{ try{
if($requestParams['customer_type'] == 'chemsite'){
$requestParams['platform_params']['company_name'] = $requestParams['company_name'] ?? '';
$requestParams['platform_params']['company_address'] = $requestParams['company_adress'] ?? '';
$requestParams['platform_params']['company_fax'] = $requestParams['company_fax'] ?? '';
$requestParams['platform_params']['company_phone'] = $requestParams['company_phone'] ?? '';
}
$customer = $this->customerService->createPlatformCustomer($requestParams); $customer = $this->customerService->createPlatformCustomer($requestParams);
return Response::success($customer,'操作成功'); return Response::success($customer,'操作成功');
}catch(\Throwable $exception){ }catch(\Throwable $exception){
......
...@@ -3,31 +3,53 @@ ...@@ -3,31 +3,53 @@
namespace App\Services\Api; namespace App\Services\Api;
use App\Services\FileService; use App\Services\FileService;
use App\Services\Traits\Pdf\BasePdfTemplate;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
class ChemicalsMsdsService class ChemicalsMsdsService
{ {
public function __construct() use BasePdfTemplate;
{
}
public function getMsds($cas) public function getMsds($cas, $type = null, $comInfo = null)
{ {
$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;
} }
$msds_html = file_get_contents(env('MSDS_FILE_DIR').'/'.$cas.'/'.$cas.'_sds_cn.html');
dd($msds_html);
dd(Storage::exists(env('MSDS_FILE_DIR')));
if(Storage::exists(env('MSDS_FILE_DIR').'/'.$cas)){ $msds_html = file_get_contents(env('MSDS_FILE_DIR').'/'.$cas.'/'.$cas.'_sds_'.$type.'.html');
dd(123); if($msds_html){
if(!is_null($comInfo)){
$platformParams = json_decode($comInfo['platform_params'], true);
$msds_html = preg_replace('/<dt>企业名称:<\/dt>[\s\S]*?<dd>[\s\S]*?<\/dd>/i', '<dt>企业名称:<\/dt> <dd>'.$platformParams['company_name'].'<\/dd>', $msds_html);
$msds_html = preg_replace('/<dt>企业地址:<\/dt>[\s\S]*?<dd>[\s\S]*?<\/dd>/i', '<dt>企业地址:<\/dt> <dd>'.$platformParams['company_address'].'<\/dd>', $msds_html);
$msds_html = preg_replace('/<dt>传真:<\/dt>[\s\S]*?<dd>[\s\S]*?<\/dd>/i', '<dt>传真:<\/dt> <dd>'.$platformParams['company_fax'].'<\/dd>', $msds_html);
$msds_html = preg_replace('/<dt>联系电话:<\/dt>[\s\S]*?<dd>[\s\S]*?<\/dd>/i', '<dt>联系电话:<\/dt> <dd>'.$platformParams['company_phone'].'<\/dd>', $msds_html);
}
$this->getPdfApp()->loadHTML($msds_html, 'utf-8');
//echo $htmlTemp;
$this->getPdfApp()->render();
$pdf = $this->getPdfApp()->output();
$fileService = app(FileService::class);
if($pdf){
$fileName = $cas.'/'.$cas.'_msds.pdf';
$realPath = $fileService->getFileFolderPath().'/'.$fileName;
if($fileService->saveToFile($realPath, $pdf)){
$fileSave = [];
$fileSave['uniqueid'] = $fileService->getBase64Path($realPath);
$fileSave['type'] = 'file';
$fileSave['path'] = $realPath;
$fileSave['name'] = str_replace('.pdf','',$fileName);
$fileSave['extension'] = 'pdf';
$fileSave['mime_type'] = 'application/pdf';
$fileSave['byte_size'] = '';
$fileSave['model_name'] = $cas.'_msds';
$fileSave['model_data_id'] = 1;
$fileService->saveFileRecord($fileSave);
}
}
} }
$fileService = app(FileService::class);
dd($fileService->getFileFolderPath());
} }
} }
...@@ -73,7 +73,7 @@ class CustomerService ...@@ -73,7 +73,7 @@ class CustomerService
$newCustomer['company_name'] = $requestParams['customer_type'] == 'chemsite' ? $customer['com_name'] : $requestParams['customer_company']; $newCustomer['company_name'] = $requestParams['customer_type'] == 'chemsite' ? $customer['com_name'] : $requestParams['customer_company'];
$newCustomer['token'] = $this->randomFromDevice(16); $newCustomer['token'] = $this->randomFromDevice(16);
$newCustomer['cus_type'] = $requestParams['customer_type']; $newCustomer['cus_type'] = $requestParams['customer_type'];
$newCustomer['platform_params'] = isset($requestParams['platform_params']) ? $requestParams['platform_params'] : ''; $newCustomer['platform_params'] = isset($requestParams['platform_params']) ? json_encode($requestParams['platform_params'],JSON_UNESCAPED_UNICODE) : '';
$newCustomer['status'] = isset($requestParams['status']) ? $requestParams['status'] : 1; $newCustomer['status'] = isset($requestParams['status']) ? $requestParams['status'] : 1;
SimpleLogs::writeLog($newCustomer,__CLASS__.':createCustomer => params'); SimpleLogs::writeLog($newCustomer,__CLASS__.':createCustomer => params');
......
<?php
namespace App\Services\Traits\Pdf;
use App\Support\Traits\Helpers;
use Dompdf\Dompdf;
use Dompdf\Options;
trait BasePdfTemplate
{
use Helpers;
private $pdf = null;
public function getPdfApp(): Dompdf
{
if(!$this->pdf){
$options = new Options();
$options->setFontDir(app()->basePath('vendor/dompdf/dompdf/lib/fonts'));
$options->setDefaultFont('微软雅黑');
$options->setIsRemoteEnabled(true);
$options->setDefaultPaperSize('a4', 'landscape');
$options->setDpi(350);
$this->pdf = new Dompdf($options);
}
return $this->pdf;
}
/**
* 添加合同logo和公章图片
* @return void
*/
public function addImage($pdfApp)
{
$canvas = $pdfApp->getCanvas();
$w = $canvas->get_width();
$h = $canvas->get_height();
$y = $h -2 * 10 -24;
$logoImage = storage_path('app/public/images/contract/logo.png');
$canvas->page_script('
$logoImage="'.$logoImage.'";
$w="'.$w.'";
$h="'.$h.'";
$y="'.$y.'";
$pdf->line(160, $y, $w-160, $y, "black",1);
$pdf->set_opacity(1,"Multiply");
$pdf->image($logoImage, 35, 55, 110, 42);
'
);
}
public function returnTemplateHtml($body): string
{
return <<<EOF
<html lang="zh_CN no-js">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
body{
font-family: 'msyh';
font-size: 0.8rem;
font-weight: bold;
display: block;
}
.container {
position: relative;
z-index: 5;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
display: table;
width: 100%;
}
.search-group {
float: left;
width: 100%;
padding: 105px 0;
font-size: 80px;
font-weight: bold;
display: table;
}
.logo-group {
float: left;
width: 260px;;
height: 120px;
display: table;
}
.order_title {
float: left;
width: 100%;
height: 120px;
display: table;
text-indent: 10px;
}
.itemTable {
td {
height: 50px;
border: 1px solid #8a8888;
width: 100%;
}
.orderItemTd {
text-align: center;
background: #f2f2f2;
}
.orderItemTdContent {
text-align: center;
}
}
.orderTable {
td {
height: 50px;
}
}
</style><title></title>
</head><body><div class="container">$body</div></body>
</html>
EOF;
}
public function outputPdf($html, $addLogoImage = true): ?string
{
if($addLogoImage){
$this->addImage($this->getPdfApp());
}
$this->getPdfApp()->loadHTML($html, 'utf-8');
$this->getPdfApp()->render();
//$this->getPdfApp()->outputHtml();
return $this->getPdfApp()->output();
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddColumnFileManageTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('file_manage',function(Blueprint $table){
$table->integer('model_data_id')->nullable()->comment('模型数据id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
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