|
|
|
@ -21,20 +21,24 @@ class GoodsCateEs |
|
|
|
|
$this->esService = Client::setEs($this->index_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询商品列表 |
|
|
|
|
* @param $params |
|
|
|
|
* 商品列表 |
|
|
|
|
* [list description] |
|
|
|
|
* @param array $params [description] |
|
|
|
|
* @param integer $page [description] |
|
|
|
|
* @param integer $limit [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function list(array $params = [],$page = 1, $limit = 10) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
$between = $ins = $orlike = $equal = []; |
|
|
|
|
//商品名称like查询 |
|
|
|
|
if (isset($params['goods_name']) && $params['goods_name']) { |
|
|
|
|
$orlike[] = ['goods_name' => $params['goods_name'] ?? '']; |
|
|
|
|
$orlike[] = ['goods_no' => $params['goods_name'] ?? '']; |
|
|
|
|
if (isset($params['keyword']) && $params['keyword']) { |
|
|
|
|
$orlike[] = ['goods_name' => $params['keyword'] ?? '']; |
|
|
|
|
$orlike[] = ['goods_no' => $params['keyword'] ?? '']; |
|
|
|
|
} |
|
|
|
|
$equal[] = ['is_delete' => 0]; |
|
|
|
|
//等于查询 |
|
|
|
|
if (isset($params['status']) && $params['status']) { |
|
|
|
|
$equal[] = ['status' => $params['status'] ?? 0]; |
|
|
|
@ -42,6 +46,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]; |
|
|
|
|
// } |
|
|
|
|
//between查询 |
|
|
|
|
if (isset($params['fliter_condition']) && $params['fliter_condition']) { |
|
|
|
|
$fliter_condition = json_decode($params['fliter_condition'], true); |
|
|
|
@ -59,9 +66,7 @@ class GoodsCateEs |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sort = $this->setQuerySort($params); |
|
|
|
|
|
|
|
|
|
//dd($sort); |
|
|
|
|
return $this->esService |
|
|
|
|
$data = $this->esService |
|
|
|
|
->select($this->field) |
|
|
|
|
->orlike($orlike) |
|
|
|
|
->hasChild($between) |
|
|
|
@ -72,6 +77,21 @@ class GoodsCateEs |
|
|
|
|
->order($sort) |
|
|
|
|
//->setDebug() |
|
|
|
|
->query(); |
|
|
|
|
if ($data['data']) { |
|
|
|
|
$model = new Goods; |
|
|
|
|
$goods_ids = array_column($data['data'], "goods_id"); |
|
|
|
|
$goods_list = array_column($data['data'], null, "goods_id"); |
|
|
|
|
$list = $model->getListByIds($goods_ids, 10); |
|
|
|
|
if ($list) { |
|
|
|
|
foreach ($list as &$value) { |
|
|
|
|
$value['highlight_goods_name'] = $goods_list[$value['goods_id']]['highlight_goods_name'] ?? ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['data'] = $list; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 检索排序条件 |
|
|
|
@ -97,6 +117,15 @@ class GoodsCateEs |
|
|
|
|
$sort[] = ["goods_id" => 'desc']; |
|
|
|
|
return $sort; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算总数 |
|
|
|
|
* [count description] |
|
|
|
|
* @param array $params [description] |
|
|
|
|
* @param integer $page [description] |
|
|
|
|
* @param integer $limit [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function count($params = [],$page = 1, $limit = 10) |
|
|
|
|
{ |
|
|
|
|
$between = $ins = []; |
|
|
|
@ -121,7 +150,7 @@ class GoodsCateEs |
|
|
|
|
unset($params['channels']); |
|
|
|
|
} |
|
|
|
|
return $this->esService |
|
|
|
|
// ->setDebug() |
|
|
|
|
//->setDebug() |
|
|
|
|
->like($like) |
|
|
|
|
->hasChild($between) |
|
|
|
|
->in($ins) |
|
|
|
@ -170,7 +199,7 @@ 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' => strtotime($value['create_time']), |
|
|
|
|
'cate_create_time' => $value['create_time'], |
|
|
|
|
'goods_category_field' => [ |
|
|
|
|
'name' => 'category', |
|
|
|
@ -188,10 +217,10 @@ class GoodsCateEs |
|
|
|
|
*/ |
|
|
|
|
public function batchCreateData() |
|
|
|
|
{ |
|
|
|
|
for ($page = 1; $page<=224; $page++) |
|
|
|
|
for ($page = 1; $page <= 224; $page++) |
|
|
|
|
{ |
|
|
|
|
$this->addData($page); |
|
|
|
|
// sleep(1); |
|
|
|
|
//sleep(1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -200,23 +229,21 @@ class GoodsCateEs |
|
|
|
|
$goods_cate_list = GoodsCategoryRel::where('category_id', '>', 0) |
|
|
|
|
->where('id', '>', 1628858) |
|
|
|
|
->where('goods_id', '>', 0) |
|
|
|
|
// ->order('goods_id desc') |
|
|
|
|
//->order('goods_id desc') |
|
|
|
|
->page($page) |
|
|
|
|
->limit(5000) |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
// dd($goods_cate_list); |
|
|
|
|
// |
|
|
|
|
// dd($goods_cate_list); |
|
|
|
|
$i = 0; |
|
|
|
|
if (!empty($goods_cate_list)){ |
|
|
|
|
foreach ($goods_cate_list as $value) |
|
|
|
|
{ |
|
|
|
|
foreach ($goods_cate_list as $value) { |
|
|
|
|
$parent_id = 'goods_'.$value['goods_id']; |
|
|
|
|
$doc = [ |
|
|
|
|
'id' => $value['id'], |
|
|
|
|
'category_id' => $value['category_id'], |
|
|
|
|
'cate_store_id' => $value['store_id'], |
|
|
|
|
// 'cate_create_time' => strtotime($value['create_time']), |
|
|
|
|
//'cate_create_time' => strtotime($value['create_time']), |
|
|
|
|
'cate_create_time' => $value['create_time'], |
|
|
|
|
'goods_category_field' => [ |
|
|
|
|
'name' => 'category', |
|
|
|
@ -224,7 +251,7 @@ class GoodsCateEs |
|
|
|
|
], |
|
|
|
|
|
|
|
|
|
]; |
|
|
|
|
// dd($doc); |
|
|
|
|
// dd($doc); |
|
|
|
|
$res = $this->esService->addChildDoc('category_'.$value['id'], $parent_id, $doc)->asArray(); |
|
|
|
|
if($res['result'] == 'created') |
|
|
|
|
{ |
|
|
|
@ -242,28 +269,27 @@ class GoodsCateEs |
|
|
|
|
*/ |
|
|
|
|
public function batchCreateGoodsData() |
|
|
|
|
{ |
|
|
|
|
for ($page = 1; $page<=173; $page++) |
|
|
|
|
for ($page = 1; $page <= 173; $page++) |
|
|
|
|
{ |
|
|
|
|
$this->addGoodsData($page); |
|
|
|
|
// sleep(1); |
|
|
|
|
//sleep(1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function addGoodsData($page) |
|
|
|
|
{ |
|
|
|
|
$goods_list = Goods::where('goods_id', '>', 0) |
|
|
|
|
// ->order('goods_id desc') |
|
|
|
|
//->order('goods_id desc') |
|
|
|
|
->page($page) |
|
|
|
|
->limit(2000) |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
// dd($goods_list); |
|
|
|
|
// |
|
|
|
|
// dd($goods_list); |
|
|
|
|
|
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($goods_list as $value) |
|
|
|
|
{ |
|
|
|
|
// $value['create_time'] = $value['create_time']; |
|
|
|
|
// $value['update_time'] = $value['update_time']; |
|
|
|
|
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' |
|
|
|
@ -277,7 +303,81 @@ class GoodsCateEs |
|
|
|
|
|
|
|
|
|
echo('同步成功'.$i.'条数据').PHP_EOL; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 批量创建商品分类 |
|
|
|
|
* [batchCreateGoodsCategory description] |
|
|
|
|
* @param integer $goods_cate_id [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function batchCreateGoodsCategory($goods_cate_id = 0){ |
|
|
|
|
while (TRUE) { |
|
|
|
|
$goods_cate_list = GoodsCategoryRel::where('id', '>', $goods_cate_id) |
|
|
|
|
->where('category_id', '>', 0) |
|
|
|
|
->where('goods_id', '>', 0) |
|
|
|
|
->order('id desc') |
|
|
|
|
->limit(1000) |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
if (!$goods_cate_list) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
foreach ($goods_cate_list as $value) { |
|
|
|
|
$parent_id = 'goods_'.$value['goods_id']; |
|
|
|
|
$doc = [ |
|
|
|
|
'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'], |
|
|
|
|
'goods_category_field' => [ |
|
|
|
|
'name' => 'category', |
|
|
|
|
'parent' => $parent_id |
|
|
|
|
], |
|
|
|
|
|
|
|
|
|
]; |
|
|
|
|
// dd($doc); |
|
|
|
|
$res = $this->esService->addChildDoc('category_'.$value['id'], $parent_id, $doc)->asArray(); |
|
|
|
|
if($res['result'] == 'created'){ |
|
|
|
|
echo('商品分类同步成功'.$value['id'].'条数据').PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$goods_cate_id = end($goods_cate_list)['id']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 批量创建商品 |
|
|
|
|
* [batchCreateGoods description] |
|
|
|
|
* @param integer $goods_id [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function batchCreateGoods($goods_id = 0){ |
|
|
|
|
while (TRUE) { |
|
|
|
|
$goods_list = Goods::where('goods_id', '>', $goods_id) |
|
|
|
|
->order('goods_id asc') |
|
|
|
|
->limit(1000) |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
// dd($goods_list); |
|
|
|
|
if (!$goods_list) { |
|
|
|
|
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'){ |
|
|
|
|
echo('商品同步成功'.$value['goods_id'].'条数据').PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$goods_id = end($goods_list)['goods_id']; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 删除商品 |
|
|
|
|
*/ |
|
|
|
|