|
|
|
@ -16,9 +16,10 @@ class GoodsCateEs |
|
|
|
|
|
|
|
|
|
private string $field = 'goods_name,goods_id,category_id,goods_price_min,profit,profit_rate,status,create_time,goods_no,sort,store_id'; |
|
|
|
|
|
|
|
|
|
public function __construct() |
|
|
|
|
public function __construct($index_name = "") |
|
|
|
|
{ |
|
|
|
|
$this->esService = Client::setEs($this->index_name); |
|
|
|
|
$index_name = $index_name ? $index_name : $this->index_name; |
|
|
|
|
$this->esService = Client::setEs($index_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -46,9 +47,9 @@ class GoodsCateEs |
|
|
|
|
if (isset($params['store_id']) && $params['store_id']) { |
|
|
|
|
$equal[] = ['store_id' => $params['store_id'] ?? 0]; |
|
|
|
|
} |
|
|
|
|
// if (isset($params['categoryId']) && $params['categoryId']) { |
|
|
|
|
// $equal[] = ['store_id' => $params['categoryId'] ?? 0]; |
|
|
|
|
// } |
|
|
|
|
if (isset($params['merchantId']) && $params['merchantId']) { |
|
|
|
|
$equal[] = ['merchant_id' => $params['merchantId'] ?? 0]; |
|
|
|
|
} |
|
|
|
|
//between查询 |
|
|
|
|
if (isset($params['fliter_condition']) && $params['fliter_condition']) { |
|
|
|
|
$fliter_condition = json_decode($params['fliter_condition'], true); |
|
|
|
@ -81,6 +82,8 @@ class GoodsCateEs |
|
|
|
|
$model = new Goods; |
|
|
|
|
$goods_ids = array_column($data['data'], "goods_id"); |
|
|
|
|
$goods_list = array_column($data['data'], null, "goods_id"); |
|
|
|
|
// var_dump($goods_ids); |
|
|
|
|
// exit(); |
|
|
|
|
$list = $model->getListByIds($goods_ids, 10); |
|
|
|
|
if ($list) { |
|
|
|
|
foreach ($list as &$value) { |
|
|
|
@ -110,7 +113,7 @@ class GoodsCateEs |
|
|
|
|
if ($params['sortType'] === 'all') { |
|
|
|
|
$sort[] = ['sort' => 'asc']; |
|
|
|
|
} elseif ($params['sortType'] === 'sales') { |
|
|
|
|
$sort[] = ['goods_sales' => 'desc']; |
|
|
|
|
$sort[] = ['sales_actual' => 'desc']; |
|
|
|
|
} elseif ($params['sortType'] === 'price') { |
|
|
|
|
$sort[] = $params['sortPrice'] ? ['goods_price_min' => 'desc'] : ['goods_price_min' => 'asc']; |
|
|
|
|
} |
|
|
|
@ -180,12 +183,12 @@ class GoodsCateEs |
|
|
|
|
/** |
|
|
|
|
* 创建商品 |
|
|
|
|
*/ |
|
|
|
|
public function createData($goods_id, $list) |
|
|
|
|
public function createData($goods_id, $goods) |
|
|
|
|
{ |
|
|
|
|
$list['goods_category_field'] = [ |
|
|
|
|
'name' => 'goods' |
|
|
|
|
]; |
|
|
|
|
return $this->esService->addDoc('goods_'.$goods_id, $list)->asArray(); |
|
|
|
|
return $this->esService->addDoc('goods_'.$goods_id, $goods)->asArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -243,8 +246,8 @@ class GoodsCateEs |
|
|
|
|
'id' => $value['id'], |
|
|
|
|
'category_id' => $value['category_id'], |
|
|
|
|
'cate_store_id' => $value['store_id'], |
|
|
|
|
//'cate_create_time' => strtotime($value['create_time']), |
|
|
|
|
'cate_create_time' => $value['create_time'], |
|
|
|
|
'cate_create_time' => strtotime($value['create_time']), |
|
|
|
|
//'cate_create_time' => $value['create_time'], |
|
|
|
|
'goods_category_field' => [ |
|
|
|
|
'name' => 'category', |
|
|
|
|
'parent' => $parent_id |
|
|
|
@ -309,16 +312,23 @@ class GoodsCateEs |
|
|
|
|
* @param integer $goods_cate_id [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function batchCreateGoodsCategory($goods_cate_id = 0){ |
|
|
|
|
public function batchCreateGoodsCategory($goods_cate_id = 0, $storeId = 0){ |
|
|
|
|
$where = []; |
|
|
|
|
if ($storeId) { |
|
|
|
|
$where['store_id'] = $storeId; |
|
|
|
|
} |
|
|
|
|
while (TRUE) { |
|
|
|
|
echo $goods_cate_id.PHP_EOL; |
|
|
|
|
$goods_cate_list = GoodsCategoryRel::where('id', '>', $goods_cate_id) |
|
|
|
|
->where($where) |
|
|
|
|
->where('category_id', '>', 0) |
|
|
|
|
->where('goods_id', '>', 0) |
|
|
|
|
->order('id desc') |
|
|
|
|
->order('id asc') |
|
|
|
|
->limit(1000) |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
if (!$goods_cate_list) { |
|
|
|
|
echo "没有商品分类了".PHP_EOL; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
foreach ($goods_cate_list as $value) { |
|
|
|
@ -337,7 +347,7 @@ class GoodsCateEs |
|
|
|
|
]; |
|
|
|
|
// dd($doc); |
|
|
|
|
$res = $this->esService->addChildDoc('category_'.$value['id'], $parent_id, $doc)->asArray(); |
|
|
|
|
if($res['result'] == 'created'){ |
|
|
|
|
if($res['result'] == 'created' || $res['result'] == 'updated'){ |
|
|
|
|
echo('商品分类同步成功'.$value['id'].'条数据').PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -350,27 +360,33 @@ class GoodsCateEs |
|
|
|
|
* @param integer $goods_id [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function batchCreateGoods($goods_id = 0){ |
|
|
|
|
public function batchCreateGoods($goods_id = 0, $storeId = 0){ |
|
|
|
|
$where = []; |
|
|
|
|
if ($storeId) { |
|
|
|
|
$where['store_id'] = $storeId; |
|
|
|
|
} |
|
|
|
|
while (TRUE) { |
|
|
|
|
echo $goods_id.PHP_EOL; |
|
|
|
|
$goods_list = Goods::where('goods_id', '>', $goods_id) |
|
|
|
|
->where($where) |
|
|
|
|
//->field("goods_id,goods_name,goods_no,content,cost_price_min,goods_price_min,sort,sales_actual,profit,profit_rate,channel,store_id,is_delete,status,create_time") |
|
|
|
|
->order('goods_id asc') |
|
|
|
|
->limit(1000) |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
// dd($goods_list); |
|
|
|
|
//dd($goods_list); |
|
|
|
|
if (!$goods_list) { |
|
|
|
|
echo "没有商品了".PHP_EOL; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($goods_list as $value) { |
|
|
|
|
//$value['create_time'] = $value['create_time']; |
|
|
|
|
//$value['update_time'] = $value['update_time']; |
|
|
|
|
$value['delivery_type'] = implode(',', $value['delivery_type']); |
|
|
|
|
|
|
|
|
|
$value['goods_category_field'] = [ |
|
|
|
|
'name' => 'goods' |
|
|
|
|
]; |
|
|
|
|
$res = $this->esService->addDoc('goods_'.$value['goods_id'], $value)->asArray(); |
|
|
|
|
if($res['result'] == 'created'){ |
|
|
|
|
//var_dump($res); |
|
|
|
|
if($res['result'] == 'created' || $res['result'] == 'updated'){ |
|
|
|
|
echo('商品同步成功'.$value['goods_id'].'条数据').PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -378,6 +394,25 @@ class GoodsCateEs |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 添加或者更新商品 |
|
|
|
|
* [addOrUpdateGoodsAndGoodsCate description] |
|
|
|
|
* @param [type] $goods_list [description] |
|
|
|
|
*/ |
|
|
|
|
public function addOrUpdateGoodsAndGoodsCate($goods_list){ |
|
|
|
|
if (!$goods_list) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
foreach ($goods_list as $goods) { |
|
|
|
|
$this->createData($goods['goods_id'], $goods); |
|
|
|
|
$goods_cate_list = GoodsCategoryRel::where('goods_id', $goods['goods_id'])->select()->toArray(); |
|
|
|
|
foreach ($goods_cate_list as $goods_cate) { |
|
|
|
|
$this->createCateData($goods_cate['id'], $goods_cate); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 删除商品 |
|
|
|
|
*/ |
|
|
|
@ -410,10 +445,11 @@ class GoodsCateEs |
|
|
|
|
], |
|
|
|
|
'goods_name' => [ |
|
|
|
|
'type' => 'text', |
|
|
|
|
"analyzer" => "ik_smart" |
|
|
|
|
"analyzer" => "ik_max_word", |
|
|
|
|
"search_analyzer" => "ik_smart" |
|
|
|
|
], |
|
|
|
|
'goods_no' => [ |
|
|
|
|
'type' => 'keyword', |
|
|
|
|
'type' => 'keyword' |
|
|
|
|
], |
|
|
|
|
'video_id' => [ |
|
|
|
|
'type' => 'integer' |
|
|
|
@ -425,8 +461,7 @@ class GoodsCateEs |
|
|
|
|
'type' => 'integer' |
|
|
|
|
], |
|
|
|
|
'selling_point' => [ |
|
|
|
|
'type' => 'text', |
|
|
|
|
"analyzer" => "ik_smart" |
|
|
|
|
'type' => 'keyword', |
|
|
|
|
], |
|
|
|
|
'spec_type' => [ |
|
|
|
|
'type' => 'integer' |
|
|
|
@ -647,7 +682,8 @@ class GoodsCateEs |
|
|
|
|
'type' => 'integer' |
|
|
|
|
], |
|
|
|
|
'cate_create_time' => [ |
|
|
|
|
'type' => 'integer' |
|
|
|
|
'type' => 'date', |
|
|
|
|
'format' => 'yyyy-MM-dd HH:mm:ss' |
|
|
|
|
], |
|
|
|
|
'goods_category_field' => [ |
|
|
|
|
'type' => 'join', |
|
|
|
@ -657,7 +693,8 @@ class GoodsCateEs |
|
|
|
|
] |
|
|
|
|
] |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
//var_dump($mapping); |
|
|
|
|
//exit(); |
|
|
|
|
return $this->esService->createIndexNew($mapping); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|