Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
goods
Commits
2cfc1e9c
Commit
2cfc1e9c
authored
Jun 26, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:同步商品数据到es脚本准备
parent
ae54a12e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
7 deletions
+104
-7
GoodsToEs.php
application/modules/Cli/controllers/GoodsToEs.php
+61
-1
ElasticGoodService.php
application/services/goods/ElasticGoodService.php
+43
-6
No files found.
application/modules/Cli/controllers/GoodsToEs.php
View file @
2cfc1e9c
<?php
<?php
use
Api\PhpUtils\Http\Request
;
use
App\Base\Cli
;
use
App\Base\Cli
;
use
App\Exception\custom\InterfaceException
;
use
App\Models\goods\mysql\Category
;
use
\App\Models\goods\mysql\GoodsSku
;
use
\App\Models\goods\mysql\GoodsSku
;
use
\App\Services\goods\GoodsService
;
use
\App\Services\goods\GoodsService
;
use
\App\Services\goods\ElasticGoodService
;
use
Api\PhpUtils\Log\DaemonLog
;
use
Api\PhpUtils\Log\DaemonLog
;
use
Api\PhpServices\JwUser\JwUser
;
use
Api\PhpServices\JwUser\JwUser
;
use
App\Services\shop\ShopService
;
/**
/**
* 同步商品数据到es
* 同步商品数据到es
...
@@ -15,6 +20,8 @@ class GoodsToEsController extends Cli
...
@@ -15,6 +20,8 @@ class GoodsToEsController extends Cli
{
{
public
function
IndexAction
()
public
function
IndexAction
()
{
{
$this
->
initEsIndex
();
$goodsSkuIds
=
$this
->
getGoodsSkuIdList
();
$goodsSkuIds
=
$this
->
getGoodsSkuIdList
();
$this
->
toEs
(
$goodsSkuIds
);
$this
->
toEs
(
$goodsSkuIds
);
}
}
...
@@ -29,8 +36,61 @@ class GoodsToEsController extends Cli
...
@@ -29,8 +36,61 @@ class GoodsToEsController extends Cli
if
(
!
empty
(
$goodsSkuIds
))
{
if
(
!
empty
(
$goodsSkuIds
))
{
foreach
(
$goodsSkuIds
as
$goodsSkuId
)
{
foreach
(
$goodsSkuIds
as
$goodsSkuId
)
{
echo
"当前正在同步的商品sku_id:
$goodsSkuId
\n
"
;
echo
"当前正在同步的商品sku_id:
$goodsSkuId
\n
"
;
GoodsService
::
updateGoodsInfoToEs
(
$goodsSkuId
);
$this
->
updateGoodsInfoToEs
(
$goodsSkuId
);
}
}
}
private
function
initEsIndex
()
{
//删除原index
ElasticGoodService
::
deleteIndex
();
//创建空index
ElasticGoodService
::
createIndex
();
}
}
/**
* 写入到es
* @param $goodsSkuId
* @return array|callable
* @throws InterfaceException
*/
public
function
updateGoodsInfoToEs
(
$goodsSkuId
)
{
$goodsSkuInfoList
=
GoodsSku
::
getRecordMaster
([
"goods_sku_id"
=>
$goodsSkuId
]);
if
(
!
empty
(
$goodsSkuInfoList
))
{
$goodsSkuInfo
=
$goodsSkuInfoList
[
0
];
$nameList
=
Category
::
select
(
"name"
,
[
"category_id"
=>
[
$goodsSkuInfo
[
"category_1_id"
],
$goodsSkuInfo
[
"category_2_id"
]]]);
//生活号信息
$url
=
config
(
'interface'
,
'goods.public.get_life_account_by_id'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$lifeAccountRes
=
(
new
Request
())
->
get
(
$url
,
[
"life_account_id"
=>
$goodsSkuInfo
[
"life_account_id"
]]);
//门店信息
$subShopList
=
ShopService
::
getRelationShop
(
$goodsSkuId
);
$data
=
[
"id"
=>
$goodsSkuInfo
[
"goods_sku_id"
],
"goods_desc_pic_url"
=>
$goodsSkuInfo
[
"desc_pic_url"
],
"goods_name"
=>
$goodsSkuInfo
[
"goods_name"
],
"inventory_rest"
=>
$goodsSkuInfo
[
"inventory_rest"
],
"total_amount_sold"
=>
$goodsSkuInfo
[
"total_amount_sold"
],
"original_price"
=>
$goodsSkuInfo
[
"original_price"
]
/
100
,
"price"
=>
$goodsSkuInfo
[
"price"
]
/
100
,
"price_sort"
=>
(
int
)
$goodsSkuInfo
[
"price"
],
"audit_status"
=>
$goodsSkuInfo
[
"audit_status"
],
"online_status"
=>
$goodsSkuInfo
[
"online_status"
],
"desc"
=>
$goodsSkuInfo
[
"desc"
],
"category_1_name"
=>
$nameList
[
0
],
"category_2_name"
=>
$nameList
[
1
],
"life_account_name"
=>
empty
(
$lifeAccountRes
[
"response"
][
"result"
][
"life_account_name"
])
?
""
:
$lifeAccountRes
[
"response"
][
"result"
][
"life_account_name"
],
"life_account_icon"
=>
empty
(
$lifeAccountRes
[
"response"
][
"result"
][
"life_account_icon"
])
?
""
:
$lifeAccountRes
[
"response"
][
"result"
][
"life_account_icon"
],
"shop_name"
=>
empty
(
$subShopList
[
0
][
"shop_name"
])
?
""
:
$subShopList
[
0
][
"shop_name"
],
"shop_longitude"
=>
empty
(
$subShopList
[
0
][
"longitude"
])
?
""
:
$subShopList
[
0
][
"longitude"
],
"shop_latitude"
=>
empty
(
$subShopList
[
0
][
"latitude"
])
?
""
:
$subShopList
[
0
][
"latitude"
],
];
return
ElasticGoodService
::
indexDoc
(
$goodsSkuId
,
$data
);
}
}
}
}
...
...
application/services/goods/ElasticGoodService.php
View file @
2cfc1e9c
...
@@ -9,23 +9,60 @@ class ElasticGoodService
...
@@ -9,23 +9,60 @@ class ElasticGoodService
{
{
const
INDEX
=
"bp_goods"
;
const
INDEX
=
"bp_goods"
;
public
static
function
createIndex
(
$index
)
public
static
function
createIndex
()
{
{
$elasticClient
=
ElasticUtil
::
getInstance
();
$elasticClient
=
ElasticUtil
::
getInstance
();
$data
=
[
$data
=
[
"settings"
=>
[
"analysis"
=>
[
"analyzer"
=>
[
"default"
=>
[
"type"
=>
"ik_max_word"
,
]
]
]
],
'mappings'
=>
[
'mappings'
=>
[
'properties'
=>
[
'properties'
=>
[
'id'
=>
[
'goods_name'
=>
[
'type'
=>
'keyword'
,
'type'
=>
'text'
,
'analyzer'
=>
'ik_max_word'
,
],
'desc'
=>
[
'type'
=>
'text'
,
'analyzer'
=>
'ik_max_word'
,
],
'category_1_name'
=>
[
'type'
=>
'text'
,
'analyzer'
=>
'ik_max_word'
,
],
'category_2_name'
=>
[
'type'
=>
'text'
,
'analyzer'
=>
'ik_max_word'
,
],
],
'name'
=>
[
'
life_account_
name'
=>
[
'type'
=>
'text'
,
'type'
=>
'text'
,
'analyzer'
=>
'ik_max_word'
,
],
'shop_name'
=>
[
'type'
=>
'text'
,
'analyzer'
=>
'ik_max_word'
,
],
],
]
]
]
]
];
];
$res
=
$elasticClient
->
createIndex
(
$index
,
$data
);
return
$elasticClient
->
createIndex
(
self
::
INDEX
,
$data
);
var_export
(
$res
);
}
/**
* 删除
*/
public
static
function
deleteIndex
()
:
void
{
$elasticClient
=
ElasticUtil
::
getInstance
();
$res
=
$elasticClient
->
deleteIndex
(
self
::
INDEX
);
var_dump
(
$res
);
}
}
/**
/**
...
...
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