Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openApi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hj
openApi
Commits
bd604eec
Commit
bd604eec
authored
Dec 23, 2024
by
hj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新提交
parent
fb04dab5
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
320 additions
and
17 deletions
+320
-17
server/app/Console/Commands/WuxiLabNewJobCommand.php
server/app/Console/Commands/WuxiLabNewJobCommand.php
+1
-0
server/app/ImportExport/BaseImport.php
server/app/ImportExport/BaseImport.php
+44
-0
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabPackagesExportModel.php
...port/WuxiLab/Export/Models/WuxiLabPackagesExportModel.php
+1
-1
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabProductsExportModel.php
...port/WuxiLab/Export/Models/WuxiLabProductsExportModel.php
+1
-1
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabProductsShelvesExportModel.php
...xiLab/Export/Models/WuxiLabProductsShelvesExportModel.php
+1
-1
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabStocksExportModel.php
...Export/WuxiLab/Export/Models/WuxiLabStocksExportModel.php
+1
-1
server/app/ImportExport/WuxiLab/Export/WuxiLabExport.php
server/app/ImportExport/WuxiLab/Export/WuxiLabExport.php
+5
-5
server/app/ImportExport/WuxiLab/Import/Models/WuxiLabProductsImportModel.php
...port/WuxiLab/Import/Models/WuxiLabProductsImportModel.php
+33
-0
server/app/ImportExport/WuxiLab/Import/WuxiLabUpdateProductsImport.php
...portExport/WuxiLab/Import/WuxiLabUpdateProductsImport.php
+30
-0
server/app/Repositories/BaseRepository.php
server/app/Repositories/BaseRepository.php
+48
-0
server/app/Repositories/Contracts/WuxiLabUpdateProductsRepository.php
...epositories/Contracts/WuxiLabUpdateProductsRepository.php
+21
-0
server/app/Repositories/Eloquent/WuxiLabUpdateProductsRepositoryEloquent.php
...ries/Eloquent/WuxiLabUpdateProductsRepositoryEloquent.php
+25
-0
server/app/Repositories/Models/WuxiLabUpdateProducts.php
server/app/Repositories/Models/WuxiLabUpdateProducts.php
+31
-0
server/app/Services/ThirdPlatform/Api/WuxiApiNewService.php
server/app/Services/ThirdPlatform/Api/WuxiApiNewService.php
+3
-3
server/app/Services/ThirdPlatform/Api/WuxiApiService.php
server/app/Services/ThirdPlatform/Api/WuxiApiService.php
+1
-1
server/app/Services/ThirdPlatform/WuxiLabNewService.php
server/app/Services/ThirdPlatform/WuxiLabNewService.php
+24
-3
server/app/Services/ThirdPlatform/WuxiLabService.php
server/app/Services/ThirdPlatform/WuxiLabService.php
+1
-1
server/app/Services/ThirdPlatform/WuxiLabUpdateProductsService.php
...p/Services/ThirdPlatform/WuxiLabUpdateProductsService.php
+48
-0
server/app/Support/Traits/Helpers.php
server/app/Support/Traits/Helpers.php
+1
-0
No files found.
server/app/Console/Commands/WuxiLabNewJobCommand.php
View file @
bd604eec
...
...
@@ -63,6 +63,7 @@ class WuxiLabNewJobCommand extends Command
case
'batchUpdateProducts'
:
$service
->
batchUpdateProducts
(
$params
);
break
;
case
'batchUpdateProductPrice'
:
$service
->
batchUpdateProductPrice
(
$params
);
break
;
case
'batchUpdateProductStock'
:
$service
->
batchUpdateProductStock
(
$params
);
break
;
case
'initNeedUpdateProductsList'
:
$service
->
initNeedUpdateProductsList
(
$params
);
break
;
}
}
}
...
...
server/app/ImportExport/BaseImport.php
0 → 100644
View file @
bd604eec
<?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
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabPackagesExportModel.php
View file @
bd604eec
<?php
namespace
App\ImportExport\WuxiLab\Models
;
namespace
App\ImportExport\WuxiLab\
Export\
Models
;
use
Maatwebsite\Excel\Concerns\FromArray
;
use
Maatwebsite\Excel\Concerns\ShouldAutoSize
;
...
...
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabProductsExportModel.php
View file @
bd604eec
<?php
namespace
App\ImportExport\WuxiLab\Models
;
namespace
App\ImportExport\WuxiLab\
Export\
Models
;
use
Maatwebsite\Excel\Concerns\FromArray
;
use
Maatwebsite\Excel\Concerns\ShouldAutoSize
;
...
...
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabProductsShelvesExportModel.php
View file @
bd604eec
<?php
namespace
App\ImportExport\WuxiLab\Models
;
namespace
App\ImportExport\WuxiLab\
Export\
Models
;
use
Maatwebsite\Excel\Concerns\FromArray
;
use
Maatwebsite\Excel\Concerns\ShouldAutoSize
;
...
...
server/app/ImportExport/WuxiLab/Export/Models/WuxiLabStocksExportModel.php
View file @
bd604eec
<?php
namespace
App\ImportExport\WuxiLab\Models
;
namespace
App\ImportExport\WuxiLab\
Export\
Models
;
use
Maatwebsite\Excel\Concerns\FromArray
;
use
Maatwebsite\Excel\Concerns\ShouldAutoSize
;
...
...
server/app/ImportExport/WuxiLab/Export/WuxiLabExport.php
View file @
bd604eec
<?php
namespace
App\ImportExport\WuxiLab
;
namespace
App\ImportExport\WuxiLab
\Export
;
use
App\ImportExport\BaseExport
;
use
App\ImportExport\WuxiLab\Models\WuxiLabPackagesExportModel
;
use
App\ImportExport\WuxiLab\Models\WuxiLabProductsExportModel
;
use
App\ImportExport\WuxiLab\Models\WuxiLabProductsShelvesExportModel
;
use
App\ImportExport\WuxiLab\Models\WuxiLabStocksExportModel
;
use
App\ImportExport\WuxiLab\
Export\
Models\WuxiLabPackagesExportModel
;
use
App\ImportExport\WuxiLab\
Export\
Models\WuxiLabProductsExportModel
;
use
App\ImportExport\WuxiLab\
Export\
Models\WuxiLabProductsShelvesExportModel
;
use
App\ImportExport\WuxiLab\
Export\
Models\WuxiLabStocksExportModel
;
class
WuxiLabExport
extends
BaseExport
{
...
...
server/app/ImportExport/WuxiLab/Import/Models/WuxiLabProductsImportModel.php
0 → 100644
View file @
bd604eec
<?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
server/app/ImportExport/WuxiLab/Import/WuxiLabUpdateProductsImport.php
0 → 100644
View file @
bd604eec
<?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'
];
}
}
server/app/Repositories/BaseRepository.php
View file @
bd604eec
...
...
@@ -11,9 +11,12 @@
namespace
App\Repositories
;
use
App\Exceptions\ServerRunTimeException
;
use
Illuminate\Support\Arr
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Schema
;
use
Prettus\Repository\Eloquent\BaseRepository
as
BaseRepositoryEloquent
;
use
Prettus\Repository\Exceptions\RepositoryException
;
abstract
class
BaseRepository
extends
BaseRepositoryEloquent
{
...
...
@@ -51,4 +54,49 @@ abstract class BaseRepository extends BaseRepositoryEloquent
{
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
());
}
}
}
server/app/Repositories/Contracts/WuxiLabUpdateProductsRepository.php
0 → 100644
View file @
bd604eec
<?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
{
}
server/app/Repositories/Eloquent/WuxiLabUpdateProductsRepositoryEloquent.php
0 → 100644
View file @
bd604eec
<?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
));
}
}
server/app/Repositories/Models/WuxiLabUpdateProducts.php
0 → 100644
View file @
bd604eec
<?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'
];
}
server/app/Services/ThirdPlatform/Api/WuxiApiNewService.php
View file @
bd604eec
...
...
@@ -105,7 +105,7 @@ class WuxiApiNewService extends PlatformAbstractService
$mergeData
=
[];
foreach
(
$metaData
[
'rawList'
]
as
$datas
){
$tempData
[
'supplier_product_id'
]
=
$datas
[
'r_code'
];
/*
$tempData['supplier_product_id'] = $datas['r_code'];
$tempData['mdl'] = '';
$tempData['cas'] = $datas['c_cas'];
$tempData['nu'] = '';
...
...
@@ -118,7 +118,7 @@ class WuxiApiNewService extends PlatformAbstractService
$tempData['usually_ships_within_days'] = '';
$tempData['backorder_lead_time'] = '';*/
//储存条件
$tempData
[
'storage_condition'
]
=
0
;
/*
$tempData['storage_condition'] = 0;
switch($datas['c_cctj']){
case 1: $tempData['storage_condition'] = 0;break;
case 2: $tempData['storage_condition'] = 1;break;
...
...
@@ -148,7 +148,7 @@ Compounds,
7:Natural Products,
8:Impurity
*/
$tempData
[
'group_id'
]
=
6
;
/*
$tempData['group_id'] = 6;
//是否进口
$tempData['is_imported'] = false;
//是否推送电商
...
...
server/app/Services/ThirdPlatform/Api/WuxiApiService.php
View file @
bd604eec
...
...
@@ -11,7 +11,7 @@
namespace
App\Services\ThirdPlatform\Api
;
use
App\ImportExport\WuxiLab\WuxiLabExport
;
use
App\ImportExport\WuxiLab\
Export\
WuxiLabExport
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Services\ThirdPlatform\PlatformAbstractService
;
use
App\Support\Facades\SimpleLogs
;
...
...
server/app/Services/ThirdPlatform/WuxiLabNewService.php
View file @
bd604eec
...
...
@@ -2,6 +2,9 @@
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\Rhawn\Services\RhawnProductService
;
use
App\Services\ThirdPlatform\Api\WuxiApiNewService
;
...
...
@@ -10,7 +13,6 @@ use Illuminate\Support\Facades\DB;
class
WuxiLabNewService
{
public
function
__construct
()
{
$this
->
apiService
=
(
new
WuxiApiNewService
(
app
(
ThirdApiPlatformRepository
::
class
)));
...
...
@@ -224,8 +226,13 @@ class WuxiLabNewService
}
}
$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);
$baikeMysql = DB::connection('baike_mysql');
$casResult = $baikeMysql->table('tp_mol_data')->whereIn('cas', $noSmiles)->get()->toArray();
...
...
@@ -234,7 +241,7 @@ class WuxiLabNewService
$updateData['rawList'][$cas->cas]['c_smiles'] = $cas->smiles;
}
}
}
}
*/
$result
=
$this
->
apiService
->
pushBatchUpdateProduct
(
$updateData
,
$this
->
getToken
());
$this
->
processApiResponse
(
$result
);
...
...
@@ -315,4 +322,18 @@ class WuxiLabNewService
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
());
}
}
}
}
server/app/Services/ThirdPlatform/WuxiLabService.php
View file @
bd604eec
...
...
@@ -11,7 +11,7 @@
namespace
App\Services\ThirdPlatform
;
use
App\ImportExport\WuxiLab\WuxiLabExport
;
use
App\ImportExport\WuxiLab\
Export\
WuxiLabExport
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Rhawn\Services\RhawnProductService
;
use
App\Services\ThirdPlatform\Api\WuxiApiService
;
...
...
server/app/Services/ThirdPlatform/WuxiLabUpdateProductsService.php
0 → 100644
View file @
bd604eec
<?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
;
}
}
server/app/Support/Traits/Helpers.php
View file @
bd604eec
...
...
@@ -167,6 +167,7 @@ trait Helpers
function
stripHtml
(
$str
)
:
string
{
$str
=
str_replace
(
"<br>"
,
""
,
$str
);
$str
=
str_replace
(
"
\t
"
,
""
,
$str
);
//$str = htmlspecialchars($str);
$str
=
htmlspecialchars_decode
(
$str
);
return
strip_tags
(
$str
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment