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
27225ca5
Commit
27225ca5
authored
Aug 08, 2022
by
hangjun83
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
openapi
parent
14278aec
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
429 additions
and
11 deletions
+429
-11
server/app/Console/Commands/BideJobCommand.php
server/app/Console/Commands/BideJobCommand.php
+70
-0
server/app/Export/WuxiLab/Models/WuxiLabPackagesExportModel.php
.../app/Export/WuxiLab/Models/WuxiLabPackagesExportModel.php
+3
-2
server/app/Export/WuxiLab/Models/WuxiLabProductsExportModel.php
.../app/Export/WuxiLab/Models/WuxiLabProductsExportModel.php
+1
-0
server/app/Jobs/BideJob.php
server/app/Jobs/BideJob.php
+38
-0
server/app/Providers/AppServiceProvider.php
server/app/Providers/AppServiceProvider.php
+1
-0
server/app/Services/BhProductsService.php
server/app/Services/BhProductsService.php
+118
-0
server/app/Services/BideService.php
server/app/Services/BideService.php
+61
-0
server/app/Services/ThirdPlatform/Api/BideApiService.php
server/app/Services/ThirdPlatform/Api/BideApiService.php
+88
-0
server/app/Services/ThirdPlatform/PlatformAbstractService.php
...er/app/Services/ThirdPlatform/PlatformAbstractService.php
+1
-1
server/app/Services/WuxiLabService.php
server/app/Services/WuxiLabService.php
+0
-5
server/app/Support/Traits/Helpers.php
server/app/Support/Traits/Helpers.php
+17
-0
server/app/Support/Traits/HttpClientHelpers.php
server/app/Support/Traits/HttpClientHelpers.php
+13
-2
server/database/seeds/local/ThridApiPlatformSeeder.php
server/database/seeds/local/ThridApiPlatformSeeder.php
+18
-1
No files found.
server/app/Console/Commands/BideJobCommand.php
0 → 100644
View file @
27225ca5
<?php
namespace
App\Console\Commands
;
use
App\Jobs\BideJob
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\ConfirmableTrait
;
class
BideJobCommand
extends
Command
{
use
ConfirmableTrait
;
/**
* 命令行的名称及用法。
*
* @var string
*/
protected
$signature
=
'bide:job
{--action_type= : 任务操作类型}
{--params= : 任务参数}'
;
/**
* 命令行的概述。
*
* @var string
*/
protected
$description
=
'bide更新cas数据'
;
/**
* 创建新的命令实例。
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* 运行命令。
* @throws \Exception
*/
public
function
handle
()
{
if
(
!
$this
->
confirmToProceed
())
{
return
1
;
}
if
(
$this
->
hasArgument
(
'help'
)){
$this
->
help
();
}
else
{
$action_type
=
$this
->
option
(
'action_type'
);
$params
=
$this
->
option
(
'params'
);
if
(
empty
(
$action_type
)){
$this
->
error
(
'缺少命令参数,请输入具体的参数命令.如需帮助请输入 --help'
);
exit
;
}
$productUpdateJob
=
(
new
BideJob
(
$action_type
,
$params
))
->
delay
(
100
)
->
onQueue
(
'slow'
);
app
(
'Illuminate\Contracts\Bus\Dispatcher'
)
->
dispatch
(
$productUpdateJob
);
}
}
public
function
help
()
{
$helpStr
=
"参数帮助说明"
;
$this
->
comment
(
$this
->
setHelp
(
$helpStr
)
->
getProcessedHelp
());
$this
->
line
(
"action_type: 具体动作参数
\n\n
initProductToExcel => 初始化批量商品
\n
batchUpdateProduct => 批量更新商品
\n\n
params : 操作需要传入的参数.非必填项"
);
}
}
server/app/Export/WuxiLab/Models/WuxiLabPackagesExportModel.php
View file @
27225ca5
...
...
@@ -29,10 +29,11 @@ class WuxiLabPackagesExportModel implements FromArray,WithHeadings, ShouldAutoSi
public
function
toMap
(
$rows
)
:
array
{
$exportRows
=
[];
array_push
(
$exportRows
,[
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
]);
foreach
(
$rows
as
$key
=>
$row
){
array_push
(
$exportRows
,[
$row
[
'r_code'
],
''
,
$row
[
'p_pack'
]
.
'/'
.
$row
[
'p_pack_unit'
],
$row
[
'p_stock'
]
==
0
?
'0'
:
$row
[
'p_stock'
],
'CN-SH'
,
$row
[
'p_price'
],
$row
[
'p_avg_cost'
]
,
'RMB'
,
'CN'
,
'0.00'
$row
[
'r_code'
],
''
,
$row
[
'p_pack'
]
.
'/'
.
$row
[
'p_pack_unit'
],
$row
[
'p_stock'
]
==
0
?
'0'
:
$row
[
'p_stock'
],
'CN-SH'
,
$row
[
'p_price'
],
'0.5'
,
'RMB'
,
'CN'
,
$row
[
'p_price'
]
*
0.5
]);
}
...
...
server/app/Export/WuxiLab/Models/WuxiLabProductsExportModel.php
View file @
27225ca5
...
...
@@ -29,6 +29,7 @@ class WuxiLabProductsExportModel implements FromArray,WithHeadings, ShouldAutoSi
public
function
toMap
(
$rows
)
:
array
{
$exportRows
=
[];
array_push
(
$exportRows
,[
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
]);
foreach
(
$rows
as
$key
=>
$row
){
array_push
(
$exportRows
,[
$row
[
'r_code'
],
$row
[
'c_cas'
],
$row
[
'c_mdl'
],
$row
[
'c_fzs'
],
$row
[
'c_fzl'
],
'N/A'
,
''
,
...
...
server/app/Jobs/BideJob.php
0 → 100644
View file @
27225ca5
<?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\Jobs
;
use
App\Services\BideService
;
class
BideJob
extends
Job
{
protected
$actionType
=
null
;
protected
$params
=
null
;
public
function
__construct
(
$actionType
,
$params
)
{
$this
->
actionType
=
$actionType
;
$this
->
params
=
$params
;
}
public
function
handle
()
{
$service
=
app
(
BideService
::
class
);
switch
(
$this
->
actionType
){
case
'batchUpdateProduct'
:
default
:
$service
->
batchUpdateProducts
(
$this
->
params
);
break
;
}
}
}
server/app/Providers/AppServiceProvider.php
View file @
27225ca5
...
...
@@ -47,6 +47,7 @@ class AppServiceProvider extends ServiceProvider
$this
->
commands
([
\App\Console\Commands\IntegleJobCommand
::
class
,
\App\Console\Commands\WuxiLabJobCommand
::
class
,
\App\Console\Commands\BideJobCommand
::
class
,
\App\Console\Commands\KafkaConsumerCommand
::
class
]);
...
...
server/app/Services/BhProductsService.php
0 → 100644
View file @
27225ca5
<?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
;
use
Illuminate\Support\Facades\DB
;
class
BhProductsService
{
/**
* 保存bide平台的产品数据
*/
public
function
storeBideProducts
(
$bideProducts
)
{
if
(
!
is_array
(
$bideProducts
)
||
empty
(
$bideProducts
))
{
return
false
;
}
try
{
$id
=
0
;
$dbConnect
=
DB
::
connection
(
'bh_mysql'
);
$dbConnect
->
beginTransaction
();
$chemicalsRow
=
$dbConnect
->
table
(
'chemicals'
)
->
where
(
'c_cas'
,
$bideProducts
[
0
][
'CASNumber'
])
->
get
()
->
toArray
();
if
(
empty
(
$chemicalsRow
))
{
return
false
;
}
$chemicalsRow
=
current
(
$chemicalsRow
);
foreach
(
$bideProducts
as
$product
)
{
if
(
$product
[
'Weight'
]
>
0
)
{
$p_tod
=
'现货'
;
}
else
{
$p_tod
=
'无货,请咨询'
;
}
$p_code
=
$product
[
'ProductNum'
]
.
'-'
.
$product
[
'PackSize'
];
$productRow
=
$dbConnect
->
table
(
'products'
)
->
where
(
'b_id'
,
10
)
->
where
(
'c_id'
,
$chemicalsRow
->
c_id
)
->
where
(
'p_code'
,
'like'
,
$p_code
)
->
get
()
->
toArray
();
$pro_data
=
[];
if
(
empty
(
$productRow
))
{
$pro_data
[
'b_id'
]
=
10
;
$pro_data
[
'c_id'
]
=
$chemicalsRow
->
c_id
;
$pro_data
[
'p_code'
]
=
$p_code
;
if
(
!
$product
[
'ProductCName'
])
{
$pro_data
[
'p_cn_name'
]
=
''
;
}
else
{
$pro_data
[
'p_cn_name'
]
=
$product
[
'ProductCName'
];
}
if
(
!
$product
[
'ProductEName'
])
{
$pro_data
[
'p_en_name'
]
=
''
;
}
else
{
$pro_data
[
'p_en_name'
]
=
$product
[
'ProductEName'
];
}
$pro_data
[
'p_level'
]
=
$product
[
'Purity'
];
$pro_data
[
'p_pack'
]
=
$product
[
'PackSize'
];
$pro_data
[
'p_price'
]
=
$product
[
'PriceB'
];
$pro_data
[
'p_tod'
]
=
$p_tod
;
$pro_data
[
'p_weight'
]
=
'0.01'
;
$pro_data
[
'p_status'
]
=
1
;
$pro_data
[
'p_show'
]
=
1
;
$pro_data
[
'prom_from'
]
=
0
;
$pro_data
[
'prom_to'
]
=
0
;
$id
=
$dbConnect
->
table
(
'products'
)
->
insertGetId
(
$pro_data
);
}
else
{
$productRow
=
current
(
$productRow
);
$pro_data
[
'p_status'
]
=
1
;
$pro_data
[
'p_show'
]
=
1
;
$pro_data
[
'p_price'
]
=
$product
[
'PriceB'
];
$pro_data
[
'p_tod'
]
=
$p_tod
;
$pro_data
[
'modifytime'
]
=
time
();
$dbConnect
->
table
(
'products'
)
->
where
(
'p_id'
,
$productRow
->
p_id
)
->
update
(
$pro_data
);
$id
=
$productRow
->
p_id
;
}
}
$dbConnect
->
table
(
'products'
)
->
where
(
'c_id'
,
$chemicalsRow
->
c_id
)
->
where
(
'b_id'
,
10
)
->
update
([
'p_status'
=>
0
,
'p_show'
=>
0
,
'modifytime'
=>
time
()]);
$dbConnect
->
commit
();
app
(
SysLogService
::
class
)
->
addApiLogs
(
$id
.
' 更新成功,更新时间:'
.
date
(
'Y-m-d H:i:s'
,
time
()));
return
$id
;
}
catch
(
\Exception
$exception
){
$dbConnect
->
rollback
();
throw
$exception
;
}
}
}
server/app/Services/BideService.php
0 → 100644
View file @
27225ca5
<?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
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Services\Kafka\KafkaService
;
use
App\Services\ThirdPlatform\Api\BideApiService
;
use
App\Services\ThirdPlatform\PlatformAbstractService
;
use
App\Support\Traits\Helpers
;
class
BideService
extends
PlatformAbstractService
{
public
function
__construct
(
ThirdApiPlatformRepository
$thirdApiPlatformRepository
)
{
$this
->
setPlatformName
(
'bide'
);
parent
::
__construct
(
$thirdApiPlatformRepository
);
}
public
function
batchUpdateProducts
(
$params
=
null
){
$path
=
config
(
'filesystems.disks.local.root'
)
.
'/upload/'
.
$params
;
$generator
=
Helpers
::
yieldLoadCsv
(
$path
);
// yield 循环逐行读取csv内容
while
(
$generator
->
valid
())
{
$content
=
$generator
->
current
();
app
(
KafkaService
::
class
)
->
produerSend
(
[
'params'
=>
[
'cas'
=>
current
(
$content
)],
'consumer'
=>
__CLASS__
,
'method'
=>
'batchUpdateApi'
]
);
$generator
->
next
();
}
$generator
->
rewind
();
}
public
function
batchUpdateApi
(
$params
)
{
$result
=
app
(
BideApiService
::
class
)
->
pushBatchUpdateProduct
(
$params
[
'cas'
]);
if
(
!
$result
){
return
;
}
try
{
$result
=
app
(
BhProductsService
::
class
)
->
storeBideProducts
(
$result
);
}
catch
(
\Exception
$exception
){
app
(
SysLogService
::
class
)
->
addApiLogs
([
'error'
=>
$exception
->
getMessage
()]);
}
}
}
server/app/Services/ThirdPlatform/Api/BideApiService.php
0 → 100644
View file @
27225ca5
<?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\Api
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Support\Traits\HttpClientHelpers
;
class
BideApiService
{
use
HttpClientHelpers
;
protected
$platformInfo
=
null
;
public
function
__construct
()
{
$this
->
platformInfo
=
app
(
ThirdApiPlatformRepository
::
class
)
->
getPlatformInfoByPlatformName
(
'bide'
);
$this
->
platformInfo
[
'platform_params'
]
=
json_decode
(
$this
->
platformInfo
[
'platform_params'
],
true
);
}
/**
* 批量更新商品信息
* @param $product
* @return bool
*/
public
function
pushBatchUpdateProduct
(
$product
){
if
(
!
$this
->
platformInfo
){
throw
new
\LogicException
(
'第三方平台信息无法获取!'
,
500
);
}
try
{
$params
=
[];
$params
[
'CASNumber'
]
=
$this
->
mergeApiMetaData
(
$product
);
$uri
=
$this
->
platformInfo
[
'platform_url'
]
.
'/api/Product/GetStockPriceData_CN_RealBottles_Ten'
;
$response
=
$this
->
getPostClient
(
$uri
,
$params
,
null
,[
'Client_id'
=>
$this
->
platformInfo
[
'platform_params'
][
'Client_id'
],
'Client_secret'
=>
$this
->
platformInfo
[
'platform_params'
][
'Client_secret'
]
],
false
);
return
$this
->
apiResponse
(
$response
);
}
catch
(
\Exception
$e
){
return
$this
->
requestError
(
$e
);
}
}
/**
* 整理组装 api 数据
* @param $metaData
* @return array
*/
public
function
mergeApiMetaData
(
$metaData
)
{
return
$metaData
;
}
protected
function
apiResponse
(
$response
)
{
$decodeResponse
=
json_decode
(
$response
,
true
);
if
(
$decodeResponse
[
'status'
]
==
'1'
&&
$decodeResponse
[
'code'
]
==
'0'
){
if
(
!
empty
(
$decodeResponse
[
'data'
])){
return
$decodeResponse
[
'data'
];
}
}
elseif
(
$decodeResponse
[
'status'
]
==
'0'
){
if
(
!
is_array
(
$decodeResponse
[
'data'
])){
return
false
;
}
}
return
false
;
}
protected
function
requestError
(
$err
)
{
return
false
;
}
}
server/app/Services/ThirdPlatform/PlatformAbstractService.php
View file @
27225ca5
...
...
@@ -57,7 +57,7 @@ abstract class PlatformAbstractService
return
$this
->
platformInfo
;
}
protected
function
batchUpdateProducts
()
protected
function
batchUpdateProducts
(
$params
=
null
)
{
}
...
...
server/app/Services/WuxiLabService.php
View file @
27225ca5
...
...
@@ -96,11 +96,6 @@ class WuxiLabService extends PlatformAbstractService
}
unset
(
$result
[
'status'
]);
$logsContent
=
[
'apiParams'
=>
$updateData
,
'apiReturn'
=>
$result
];
app
(
SysLogService
::
class
)
->
addApiLogs
(
$logsContent
);
}
/**
...
...
server/app/Support/Traits/Helpers.php
View file @
27225ca5
...
...
@@ -125,4 +125,21 @@ trait Helpers
return
$newArr
;
}
/**
* 使用协程的方式返回大内容的csv数据
* @param $file
* @return bool|\Generator
*/
public
static
function
yieldLoadCsv
(
$file
,
$maxLen
=
99999999
){
if
(
!
is_file
(
$file
)
&&!
file_exists
(
$file
))
{
return
false
;
}
$cvs_file
=
fopen
(
$file
,
'rb'
);
//开始读取csv文件数据
while
(
feof
(
$cvs_file
)
===
false
){
yield
fgetcsv
(
$cvs_file
);
}
fclose
(
$cvs_file
);
}
}
server/app/Support/Traits/HttpClientHelpers.php
View file @
27225ca5
...
...
@@ -2,21 +2,27 @@
namespace
App\Support\Traits
;
use
App\Services\SysLogService
;
use
Illuminate\Support\Str
;
trait
HttpClientHelpers
{
protected
function
getPostClient
(
$uri
,
$paramsBody
,
$auth
=
null
,
$json
=
true
)
protected
function
getPostClient
(
$uri
,
$paramsBody
,
$auth
=
null
,
$
header
=
null
,
$
json
=
true
)
{
$client
=
app
(
\GuzzleHttp\Client
::
class
);
$options
=
[];
if
(
!
is_null
(
$header
)){
$options
[
'headers'
]
=
$header
;
}
if
(
$json
)
{
$options
[
'headers'
]
=
[
'Content-type'
=>
'application/json'
,
"Accept"
=>
"application/json"
];
$options
[
'json'
]
=
$paramsBody
;
}
else
{
...
...
@@ -30,6 +36,11 @@ trait HttpClientHelpers
$options
[
'debug'
]
=
env
(
'API_DEBUG'
);
$response
=
$client
->
request
(
'post'
,
$uri
,
$options
);
return
$response
->
getBody
()
->
getContents
();
$responseContent
=
$response
->
getBody
()
->
getContents
();
app
(
SysLogService
::
class
)
->
addApiLogs
(
$responseContent
);
return
$responseContent
;
}
}
server/database/seeds/local/ThridApiPlatformSeeder.php
View file @
27225ca5
...
...
@@ -10,7 +10,7 @@ class ThridApiPlatformSeeder extends Seeder
use
\App\Support\Traits\Helpers
;
protected
$thirdapiplatform
=
[
[
/*
[
'platform_name' => 'integle',
'platform_title' => 'integle',
'platform_url' => 'http://suppliers.integle.com',
...
...
@@ -31,6 +31,17 @@ class ThridApiPlatformSeeder extends Seeder
'platform_type' => 'third',
'platform_status' => '1',
'platform_token' => '',
],*/
[
'platform_name'
=>
'bide'
,
'platform_title'
=>
'bide'
,
'platform_url'
=>
'http://220.248.71.110:9000'
,
'platform_desc'
=>
'bide 接口'
,
'platform_icon'
=>
''
,
'platform_params'
=>
''
,
'platform_type'
=>
'third'
,
'platform_status'
=>
'1'
,
'platform_token'
=>
''
,
],
];
...
...
@@ -59,6 +70,12 @@ class ThridApiPlatformSeeder extends Seeder
'batchNums'
=>
'500'
]);
break
;
case
"bide"
:
$platform
[
'platform_params'
]
=
json_encode
([
'Client_id'
=>
'bide_bssw'
,
'Client_secret'
=>
'83643588AE356CBFF84227C178DAE900'
,
]);
break
;
}
$platform
[
'platform_type'
]
=
'third'
;
$platform
[
'platform_status'
]
=
'1'
;
...
...
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