|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
|
|
|
use app\common\library\elasticsearch\Client;
|
|
|
|
|
|
|
|
class GoodsEs
|
|
|
|
{
|
|
|
|
private Client $esService;
|
|
|
|
|
|
|
|
private $index_name = 'goods_list';
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->esService = Client::setEs('goods_List');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询商品列表
|
|
|
|
* @param $params
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public function list($params)
|
|
|
|
{
|
|
|
|
$page = 1;
|
|
|
|
$limit = 10;
|
|
|
|
$body = [
|
|
|
|
'query' => [
|
|
|
|
'match_all' => []
|
|
|
|
],
|
|
|
|
'from' => ($page - 1) * $limit,
|
|
|
|
'size' => $limit,
|
|
|
|
'sort' => [
|
|
|
|
'id' => [
|
|
|
|
'order' => 'desc'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
return $this->esService
|
|
|
|
->equal(['title' => 1])
|
|
|
|
->from(0)
|
|
|
|
->size(10)
|
|
|
|
->order(['id' => 'desc'])
|
|
|
|
->query($body);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新商品
|
|
|
|
*/
|
|
|
|
public function update($goods_id)
|
|
|
|
{
|
|
|
|
$goods_id = 1;
|
|
|
|
$doc = [
|
|
|
|
'id' => $goods_id,
|
|
|
|
'video_title' => '少爷的甜蜜良药',
|
|
|
|
'director' => '吴宇森',
|
|
|
|
'intro' => '吴宇森导演的《少爷的甜蜜良药》是吴宇森导演的经典作品,讲述了一个boyfriend和girlfriend的故事,boyfriend因为工作原因,被拒了girlfriend的offer,然后boyfriend和girlfriend一起去一个地方,然后boyfriend和girlfriend',
|
|
|
|
'cover' => 'https://oss-duanju-file.luochen.com/cover/202404/62249c6a-5f57-45cf-90ac-be6de5890ce0.jpg?x-oss-process=image/resize,m_fixed,h_400,w_360',
|
|
|
|
'episode_count' => '12',
|
|
|
|
'wechat_vid' => 'wx_vid_1',
|
|
|
|
'duration' => '01:02:03',
|
|
|
|
'service_types' => '2,3',
|
|
|
|
];
|
|
|
|
$res = $this->esService->updateDoc($goods_id, $doc);
|
|
|
|
var_dump($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询商品详情
|
|
|
|
*/
|
|
|
|
public function detail($goods_id)
|
|
|
|
{
|
|
|
|
$goods_id = 1;
|
|
|
|
$res = $this->esService->getDoc($goods_id);
|
|
|
|
var_dump($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建商品
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public function create($goods_id)
|
|
|
|
{
|
|
|
|
$goods_id = 1;
|
|
|
|
$doc = [
|
|
|
|
'id' => $goods_id,
|
|
|
|
'video_title' => '少爷的甜蜜良药',
|
|
|
|
'director' => '吴宇森',
|
|
|
|
'intro' => '吴宇森导演的《少爷的甜蜜良药》是吴宇森导演的经典作品,讲述了一个boyfriend和girlfriend的故事,boyfriend因为工作原因,被拒了girlfriend的offer,然后boyfriend和girlfriend一起去一个地方,然后boyfriend和girlfriend',
|
|
|
|
'cover' => 'https://oss-duanju-file.luochen.com/cover/202404/62249c6a-5f57-45cf-90ac-be6de5890ce0.jpg?x-oss-process=image/resize,m_fixed,h_400,w_360',
|
|
|
|
'episode_count' => '12',
|
|
|
|
'wechat_vid' => 'wx_vid_1',
|
|
|
|
'duration' => '01:02:03',
|
|
|
|
'service_types' => '2,3',
|
|
|
|
];
|
|
|
|
$res = $this->esService->addDoc($goods_id, $doc);
|
|
|
|
var_dump($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除商品
|
|
|
|
*/
|
|
|
|
public function delete($goods_id)
|
|
|
|
{
|
|
|
|
$res = $this->esService->deleteDoc($goods_id);
|
|
|
|
var_dump($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建商品Index
|
|
|
|
* @return void
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
function createGoodsIndex()
|
|
|
|
{
|
|
|
|
$mapping = [
|
|
|
|
'properties' => [
|
|
|
|
'goods_id' => [
|
|
|
|
'type' => 'integer'
|
|
|
|
],
|
|
|
|
'goods_type' => [
|
|
|
|
'type' => 'keyword'
|
|
|
|
],
|
|
|
|
'director' => [
|
|
|
|
'type' => 'text',
|
|
|
|
"analyzer" => "ik_smart"
|
|
|
|
],
|
|
|
|
'intro' => [
|
|
|
|
'type' => 'text',
|
|
|
|
"analyzer" => "ik_smart"
|
|
|
|
],
|
|
|
|
'cover' => [
|
|
|
|
'type' => 'keyword'
|
|
|
|
],
|
|
|
|
'episode_count' => [
|
|
|
|
'type' => 'keyword'
|
|
|
|
],
|
|
|
|
'wechat_vid' => [
|
|
|
|
'type' => 'keyword'
|
|
|
|
],
|
|
|
|
'duration' => [
|
|
|
|
'type' => 'keyword'
|
|
|
|
],
|
|
|
|
'service_types' => [
|
|
|
|
'type' => 'keyword'
|
|
|
|
],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$res = $this->esService->createIndex($this->index_name, $mapping);
|
|
|
|
var_dump($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|