Commit bd604eec authored by hj's avatar hj

更新提交

parent fb04dab5
...@@ -63,6 +63,7 @@ class WuxiLabNewJobCommand extends Command ...@@ -63,6 +63,7 @@ class WuxiLabNewJobCommand extends Command
case 'batchUpdateProducts': $service->batchUpdateProducts($params);break; case 'batchUpdateProducts': $service->batchUpdateProducts($params);break;
case 'batchUpdateProductPrice': $service->batchUpdateProductPrice($params);break; case 'batchUpdateProductPrice': $service->batchUpdateProductPrice($params);break;
case 'batchUpdateProductStock': $service->batchUpdateProductStock($params);break; case 'batchUpdateProductStock': $service->batchUpdateProductStock($params);break;
case 'initNeedUpdateProductsList': $service->initNeedUpdateProductsList($params);break;
} }
} }
} }
......
<?php
namespace App\ImportExport;
use App\Exceptions\ServerRunTimeException;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
use Maatwebsite\Excel\Excel as BaseExcel;
use Maatwebsite\Excel\Facades\Excel;
class BaseImport
{
protected $expand = '';
public function __construct()
{
$this->setFileExpand(BaseExcel::XLSX);
}
public function setFileExpand($name)
{
$this->expand = $name;
}
public function loadExcel($file, $importModel)
{
ini_set('memory_limit','3072M');
$importDataRows = [];
$filePath = config('filesystems.disks.local.root').'/'.$file;
if($filePath){
$importDataRows = Excel::toArray($importModel,$filePath);
$importDataRows = current($importDataRows);
if(empty($importDataRows)){
throw new ServerRunTimeException('导入文件数据为空');
}
/*if(count($importDataRows) > $importModel->chunkSize()){
throw new ServerRunTimeException('导入数据量超出'.$importModel->chunkSize().'条范围');
}*/
}
return $importDataRows;
}
}
\ No newline at end of file
<?php <?php
namespace App\ImportExport\WuxiLab\Models; namespace App\ImportExport\WuxiLab\Export\Models;
use Maatwebsite\Excel\Concerns\FromArray; use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\ShouldAutoSize;
......
<?php <?php
namespace App\ImportExport\WuxiLab\Models; namespace App\ImportExport\WuxiLab\Export\Models;
use Maatwebsite\Excel\Concerns\FromArray; use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\ShouldAutoSize;
......
<?php <?php
namespace App\ImportExport\WuxiLab\Models; namespace App\ImportExport\WuxiLab\Export\Models;
use Maatwebsite\Excel\Concerns\FromArray; use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\ShouldAutoSize;
......
<?php <?php
namespace App\ImportExport\WuxiLab\Models; namespace App\ImportExport\WuxiLab\Export\Models;
use Maatwebsite\Excel\Concerns\FromArray; use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\ShouldAutoSize;
......
<?php <?php
namespace App\ImportExport\WuxiLab; namespace App\ImportExport\WuxiLab\Export;
use App\ImportExport\BaseExport; use App\ImportExport\BaseExport;
use App\ImportExport\WuxiLab\Models\WuxiLabPackagesExportModel; use App\ImportExport\WuxiLab\Export\Models\WuxiLabPackagesExportModel;
use App\ImportExport\WuxiLab\Models\WuxiLabProductsExportModel; use App\ImportExport\WuxiLab\Export\Models\WuxiLabProductsExportModel;
use App\ImportExport\WuxiLab\Models\WuxiLabProductsShelvesExportModel; use App\ImportExport\WuxiLab\Export\Models\WuxiLabProductsShelvesExportModel;
use App\ImportExport\WuxiLab\Models\WuxiLabStocksExportModel; use App\ImportExport\WuxiLab\Export\Models\WuxiLabStocksExportModel;
class WuxiLabExport extends BaseExport class WuxiLabExport extends BaseExport
{ {
......
<?php
namespace App\ImportExport\WuxiLab\Import\Models;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithStartRow;
class WuxiLabProductsImportModel implements ToArray,WithChunkReading,SkipsEmptyRows,WithStartRow
{
use Importable;
public function array($row): array
{
return $row;
}
public function chunkSize(): int
{
return 5000;
}
public function startRow(): int
{
return 2;
}
public function getModelName(): string
{
return 'wuxiLabProductsImport';
}
}
\ No newline at end of file
<?php
namespace App\ImportExport\WuxiLab\Import;
use App\ImportExport\BaseImport;
use App\ImportExport\WuxiLab\Import\Models\WuxiLabProductsImportModel;
class WuxiLabUpdateProductsImport extends BaseImport
{
public function __construct()
{
parent::__construct();
}
public function loadImportExcel($file)
{
return parent::loadExcel($file, WuxiLabProductsImportModel::class);
}
public function getTitleHeader()
{
return [
'ProductId', 'CAS', 'MDL', 'MolecularFormula', 'MolecularWeight', 'ChemicalDissolveCas', 'SubCategory', 'UN', 'EnglishName', 'ChineseName', 'Brand', 'StorageCondition',
'TransportationCondition', 'IsImported', 'LeadTimeMinDays', 'LeadTimeMaxDays', 'LeadTimeBackOrderDays', 'Purity', 'ProductCategory',
'ShipsAdditionalDescription', 'Remark'
];
}
}
...@@ -11,9 +11,12 @@ ...@@ -11,9 +11,12 @@
namespace App\Repositories; namespace App\Repositories;
use App\Exceptions\ServerRunTimeException;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent; use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent;
use Prettus\Repository\Exceptions\RepositoryException;
abstract class BaseRepository extends BaseRepositoryEloquent abstract class BaseRepository extends BaseRepositoryEloquent
{ {
...@@ -51,4 +54,49 @@ abstract class BaseRepository extends BaseRepositoryEloquent ...@@ -51,4 +54,49 @@ abstract class BaseRepository extends BaseRepositoryEloquent
{ {
return DB::connection($this->getConnectionName()); return DB::connection($this->getConnectionName());
} }
public function createOrUpdate($params, $where = [], $autoUpdate = true)
{
$saveParams = $params;
$modelPrimaryKey = $this->makeModel()->getKeyName();
if(!empty($saveParams[$modelPrimaryKey])){
$saveParams['updated_at'] = date('Y-m-d H:i:s',time());
}else{
$saveParams['created_at'] = date('Y-m-d H:i:s',time());
$saveParams['updated_at'] = $saveParams['created_at'];
}
$attributes = array_keys($saveParams);
$tableColumns = Schema::getColumnListing($this->makeModel()->getTable());
foreach($attributes as $key => $attr){
if(!in_array($attr, $tableColumns)){
unset($attributes[$key]);
unset($saveParams[$attr]);
}
}
$updateWhere = $where;
if(!empty($params[$modelPrimaryKey])){
$updateWhere[$modelPrimaryKey] = $params[$modelPrimaryKey];
}
if(!$autoUpdate && !empty($where)){
$findResult = $this->findWhere($updateWhere)->first();
if($findResult){
throw new RepositoryException('保存的数据已存在');
}
}
try{
if(empty($updateWhere)){
return $this->create($saveParams);
}
return $this->updateOrCreate($updateWhere, $saveParams);
}catch(\Throwable $exception){
if($exception->getMessage() == ''){
throw new ServerRunTimeException('保存失败');
}
throw new ServerRunTimeException($exception->getMessage());
}
}
} }
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Contracts;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface WuxiLabUpdateProductsRepository extends RepositoryInterface
{
}
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\BaseRepository;
use App\Repositories\Contracts\WuxiLabUpdateProductsRepository;
use App\Repositories\Criteria\RequestCriteria;
use App\Repositories\Models\WuxiLabUpdateProducts;
/**
* Class UserRepositoryEloquent.
*/
class WuxiLabUpdateProductsRepositoryEloquent extends BaseRepository implements WuxiLabUpdateProductsRepository
{
public function model()
{
return WuxiLabUpdateProducts::class;
}
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Models;
class WuxiLabUpdateProducts extends Model
{
protected $connection = 'mysql';
protected $table = 'wuxilab_update_products';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'product_id', 'cas', 'mdl', 'smiles', 'molecular_formula', 'molecular_weight', 'chemical_dissolve_cas','un',
'english_name','chinese_name','brand','storage_condition','transportation_condition','is_imported','lead_time_min_days','lead_time_max_days',
'lead_time_back_order_days','purity','product_category','ships_additional_description','remark'
];
}
...@@ -105,7 +105,7 @@ class WuxiApiNewService extends PlatformAbstractService ...@@ -105,7 +105,7 @@ class WuxiApiNewService extends PlatformAbstractService
$mergeData = []; $mergeData = [];
foreach($metaData['rawList'] as $datas){ foreach($metaData['rawList'] as $datas){
$tempData['supplier_product_id'] = $datas['r_code']; /*$tempData['supplier_product_id'] = $datas['r_code'];
$tempData['mdl'] = ''; $tempData['mdl'] = '';
$tempData['cas'] = $datas['c_cas']; $tempData['cas'] = $datas['c_cas'];
$tempData['nu'] = ''; $tempData['nu'] = '';
...@@ -118,7 +118,7 @@ class WuxiApiNewService extends PlatformAbstractService ...@@ -118,7 +118,7 @@ class WuxiApiNewService extends PlatformAbstractService
$tempData['usually_ships_within_days'] = ''; $tempData['usually_ships_within_days'] = '';
$tempData['backorder_lead_time'] = '';*/ $tempData['backorder_lead_time'] = '';*/
//储存条件 //储存条件
$tempData['storage_condition'] = 0; /*$tempData['storage_condition'] = 0;
switch($datas['c_cctj']){ switch($datas['c_cctj']){
case 1: $tempData['storage_condition'] = 0;break; case 1: $tempData['storage_condition'] = 0;break;
case 2: $tempData['storage_condition'] = 1;break; case 2: $tempData['storage_condition'] = 1;break;
...@@ -148,7 +148,7 @@ Compounds, ...@@ -148,7 +148,7 @@ Compounds,
7:Natural Products, 7:Natural Products,
8:Impurity 8:Impurity
*/ */
$tempData['group_id'] = 6; /*$tempData['group_id'] = 6;
//是否进口 //是否进口
$tempData['is_imported'] = false; $tempData['is_imported'] = false;
//是否推送电商 //是否推送电商
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace App\Services\ThirdPlatform\Api; namespace App\Services\ThirdPlatform\Api;
use App\ImportExport\WuxiLab\WuxiLabExport; use App\ImportExport\WuxiLab\Export\WuxiLabExport;
use App\Repositories\Contracts\ThirdApiPlatformRepository; use App\Repositories\Contracts\ThirdApiPlatformRepository;
use App\Services\ThirdPlatform\PlatformAbstractService; use App\Services\ThirdPlatform\PlatformAbstractService;
use App\Support\Facades\SimpleLogs; use App\Support\Facades\SimpleLogs;
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
namespace App\Services\ThirdPlatform; namespace App\Services\ThirdPlatform;
use App\ImportExport\BaseImport;
use App\ImportExport\WuxiLab\Import\Models\WuxiLabProductsImportModel;
use App\ImportExport\WuxiLab\Import\WuxiLabUpdateProductsImport;
use App\Repositories\Contracts\ThirdApiPlatformRepository; use App\Repositories\Contracts\ThirdApiPlatformRepository;
use App\Rhawn\Services\RhawnProductService; use App\Rhawn\Services\RhawnProductService;
use App\Services\ThirdPlatform\Api\WuxiApiNewService; use App\Services\ThirdPlatform\Api\WuxiApiNewService;
...@@ -10,7 +13,6 @@ use Illuminate\Support\Facades\DB; ...@@ -10,7 +13,6 @@ use Illuminate\Support\Facades\DB;
class WuxiLabNewService class WuxiLabNewService
{ {
public function __construct() public function __construct()
{ {
$this->apiService = (new WuxiApiNewService(app(ThirdApiPlatformRepository::class))); $this->apiService = (new WuxiApiNewService(app(ThirdApiPlatformRepository::class)));
...@@ -224,8 +226,13 @@ class WuxiLabNewService ...@@ -224,8 +226,13 @@ class WuxiLabNewService
} }
} }
$updateData['rawList'] = array_column($updateData['rawList'], null, 'c_cas'); $updateData['rawList'] = array_column($updateData['rawList'], null, 'c_cas');
$productsIdsList = array_column($updateData['rawList'], 'product_id');
$productsList = app(WuxiLabUpdateProductsService::class)->getUpdateProductsListByProductIds($productsIdsList);
dd($productsList);
if(!empty($noSmiles)){ /*if(!empty($noSmiles)){
$noSmiles = array_unique($noSmiles); $noSmiles = array_unique($noSmiles);
$baikeMysql = DB::connection('baike_mysql'); $baikeMysql = DB::connection('baike_mysql');
$casResult = $baikeMysql->table('tp_mol_data')->whereIn('cas', $noSmiles)->get()->toArray(); $casResult = $baikeMysql->table('tp_mol_data')->whereIn('cas', $noSmiles)->get()->toArray();
...@@ -234,7 +241,7 @@ class WuxiLabNewService ...@@ -234,7 +241,7 @@ class WuxiLabNewService
$updateData['rawList'][$cas->cas]['c_smiles'] = $cas->smiles; $updateData['rawList'][$cas->cas]['c_smiles'] = $cas->smiles;
} }
} }
} }*/
$result = $this->apiService->pushBatchUpdateProduct($updateData, $this->getToken()); $result = $this->apiService->pushBatchUpdateProduct($updateData, $this->getToken());
$this->processApiResponse($result); $this->processApiResponse($result);
...@@ -315,4 +322,18 @@ class WuxiLabNewService ...@@ -315,4 +322,18 @@ class WuxiLabNewService
return false; return false;
} }
} }
public function initNeedUpdateProductsList($params)
{
$importService = app(WuxiLabUpdateProductsImport::class);
$importRowsList = $importService->loadImportExcel($params);
if($importRowsList){
foreach($importRowsList as $key => $row){
if($key == 0){
continue;
}
app(WuxiLabUpdateProductsService::class)->saveUpdateProducts($row, $importService->getTitleHeader());
}
}
}
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace App\Services\ThirdPlatform; namespace App\Services\ThirdPlatform;
use App\ImportExport\WuxiLab\WuxiLabExport; use App\ImportExport\WuxiLab\Export\WuxiLabExport;
use App\Repositories\Contracts\ThirdApiPlatformRepository; use App\Repositories\Contracts\ThirdApiPlatformRepository;
use App\Rhawn\Services\RhawnProductService; use App\Rhawn\Services\RhawnProductService;
use App\Services\ThirdPlatform\Api\WuxiApiService; use App\Services\ThirdPlatform\Api\WuxiApiService;
......
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Services\ThirdPlatform;
use App\Repositories\Contracts\WuxiLabUpdateProductsRepository;
use App\Support\Traits\Helpers;
class WuxiLabUpdateProductsService
{
use Helpers;
public function __construct(WuxiLabUpdateProductsRepository $wuxiLabUpdateProductsRepository)
{
$this->wuxiLabUpdateProductsRepository = $wuxiLabUpdateProductsRepository;
}
public function saveUpdateProducts($params, $title)
{
$saveProduct = [];
foreach($title as $key => $t){
$titleKey = $this->toUnderScore($t);
$saveProduct[$titleKey] = $this->stripHtml($params[$key]);
}
if(!empty($saveProduct)){
return $this->wuxiLabUpdateProductsRepository->createOrUpdate($saveProduct, ['product_id' => $saveProduct['product_id'], 'cas' => $saveProduct['cas']]);
}
return true;
}
public function getUpdateProductsListByProductIds($ids)
{
$productList = $this->wuxiLabUpdateProductsRepository->findWhereIn('product_id', (array)$ids);
if($productList){
return $productList->toArray();
}
return null;
}
}
...@@ -167,6 +167,7 @@ trait Helpers ...@@ -167,6 +167,7 @@ trait Helpers
function stripHtml($str): string function stripHtml($str): string
{ {
$str = str_replace("<br>", "", $str); $str = str_replace("<br>", "", $str);
$str = str_replace("\t", "", $str);
//$str = htmlspecialchars($str); //$str = htmlspecialchars($str);
$str = htmlspecialchars_decode($str); $str = htmlspecialchars_decode($str);
return strip_tags($str); return strip_tags($str);
......
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