diff --git a/app/api/controller/GoodsNew.php b/app/api/controller/GoodsNew.php index 80fd4f5c..8b288617 100644 --- a/app/api/controller/GoodsNew.php +++ b/app/api/controller/GoodsNew.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\common\service\GoodsEs; +use think\App; class GoodsNew extends Controller { @@ -13,4 +14,64 @@ class GoodsNew extends Controller $data = $goodsService->list([]); dd($data); } + + public function search() + { + $keyword = $this->request->param('keyword'); + $page = $this->request->param('page', 1); + $limit = $this->request->param('limit', 10); + if (!$keyword) { + $this->renderError('请输入搜索关键字'); + } + $params = ['goods_name' => $keyword]; + $goodsService = new GoodsEs(); + $list = $goodsService->list($params, $page, $limit); + $data['list'] = $list; + $data['total'] = $goodsService->count(); + + return $this->renderSuccess($data); + } + + + /** + * 添加商品 + */ + public function add() + { + $goods_id = 1; + $goods_data = \app\common\model\Goods::where('goods_id', '=', $goods_id) + ->order('goods_id desc') + ->find() + ->toArray(); + $goodsService = new GoodsEs(); + $data = $goodsService->createData($goods_id, $goods_data); + $this->renderSuccess($data); + } + + /** + * 更新商品 + */ + public function update() + { + $goods_id = 1; + $update = [ + 'goods_name' => '测试商品', + 'selling_point' => '测试商品', + 'goods_price_min' => 100, + 'goods_price_max' => 100, + ]; + $goodsService = new GoodsEs(); + $data = $goodsService->updateData($goods_id, $update); + $this->renderSuccess($data); + } + /** + * 删除 + */ + public function delete() + { + $goods_id = 1; + $goodsService = new GoodsEs(); + $data = $goodsService->delete($goods_id); + $this->renderSuccess($data); + } } \ No newline at end of file diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php index 402c180b..59335b64 100644 --- a/app/api/controller/Store.php +++ b/app/api/controller/Store.php @@ -125,7 +125,11 @@ class Store extends Controller $file = UploadFile::where('file_id', '=', $info['logo_image_id'])->find(); $info['logo_image'] = $file->preview_url; } - + $info['login_img'] = ""; + if ($info['login_img_id']) { + $file = UploadFile::where('file_id', '=', $info['login_img_id'])->find(); + $info['login_img'] = $file->preview_url; + } return $this->renderSuccess($info); } diff --git a/app/command/SyncGoodsToEs.php b/app/command/SyncGoodsToEs.php index 136cfedf..c952729e 100644 --- a/app/command/SyncGoodsToEs.php +++ b/app/command/SyncGoodsToEs.php @@ -21,7 +21,7 @@ class SyncGoodsToEs extends Command protected function execute(Input $input, Output $output) { $goodsService = new GoodsEs(); - $goods = $goodsService->list([]); + $goods = $goodsService->list(); var_dump($goods); } diff --git a/app/common/library/elasticsearch/Client.php b/app/common/library/elasticsearch/Client.php index 6686cac5..769e03a6 100644 --- a/app/common/library/elasticsearch/Client.php +++ b/app/common/library/elasticsearch/Client.php @@ -256,11 +256,13 @@ class Client } if (!empty($this->queryParams['order'])) { - $queryParams['body']['sort'] = [ - key($this->queryParams['order']) => [ - 'order' => current($this->queryParams['order']) - ] - ]; + foreach ($this->queryParams['order'] as $key => $row) { + $queryParams['body']['sort'][] = [ + key($row) => [ + 'order' => current($row) + ] + ]; + } } $queryParams['body']['query']['bool']['filter'] = $filter; @@ -349,7 +351,7 @@ class Client * @param string $index_name * @param string $type_name */ - public function addDoc($id, $doc, string $type_name = '_doc'): array + public function addDoc($id, $doc, string $type_name = '_doc') { $params = [ 'index' => $this->index, @@ -386,8 +388,8 @@ class Client protected function settings() { return [ - 'number_of_shards' => 5, - 'number_of_replicas' => 1 + 'number_of_shards' => 1, + 'number_of_replicas' => 0 ]; } @@ -484,9 +486,9 @@ class Client $check = $this->indices()->exists($params); - if ($check) { - throw new Exception('index: ' . $this->index . ' already exists'); - } +// if ($check) { +// throw new Exception('index: ' . $this->index . ' already exists'); +// } $params = [ 'index' => $this->index, @@ -655,12 +657,12 @@ class Client } /** - + * 更新索引 * @return array @todo */ - public function updateIndex() + public function updateIndex($mappings) { @@ -672,7 +674,7 @@ class Client 'body' => [ - 'properties' => $this->mappings() + 'properties' => $mappings ] diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index db2b2822..e8fb7fc1 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -505,7 +505,8 @@ class Goods extends BaseModel $filter[] = ['spec_type', '=', $params['spec_type']]; } //是否店内 - if (isset($param['is_in_store']) && $param['is_in_store'] !== '') { + //if (isset($param['is_in_store']) && $param['is_in_store'] !== '') { + if (isset($param['is_in_store']) && $param['is_in_store']) { $filter[] = ['is_in_store', '=', $params['is_in_store']]; } diff --git a/app/common/model/Store.php b/app/common/model/Store.php index 2b3d19c2..152aef65 100644 --- a/app/common/model/Store.php +++ b/app/common/model/Store.php @@ -92,6 +92,12 @@ class Store extends BaseModel } else { $list['rankingImg'] = null; } + if ($list['login_img_id']) { + $files = UploadFile::getFileList([$list['login_img_id']]); + $list['loginImg'] = $files ? $files[0] : null; + } else { + $list['loginImg'] = null; + } } return $list ?? null; } catch (\Exception $e) { diff --git a/app/common/service/GoodsEs.php b/app/common/service/GoodsEs.php index 56cc137f..aa5aabf2 100644 --- a/app/common/service/GoodsEs.php +++ b/app/common/service/GoodsEs.php @@ -8,68 +8,46 @@ class GoodsEs { private Client $esService; - private $index_name = 'goods_list'; + private string $index_name = 'goods_list'; public function __construct() { - $this->esService = Client::setEs('goods_list'); + $this->esService = Client::setEs($this->index_name); } /** * 查询商品列表 * @param $params - * @return */ - public function list($params) + public function list($params = [],$page = 1, $limit = 10) { - $page = 1; - $limit = 10; -// $body = [ -// 'query' => [ -// 'match_all' => [] -// ], -// 'from' => ($page - 1) * $limit, -// 'size' => $limit, -// 'sort' => [ -// 'id' => [ -// 'order' => 'desc' -// ] -// ] -// ]; - - $data = $this->esService + return $this->esService // ->setDebug() - ->equal(['intro' => '']) - ->from(1) - ->size(10) - ->order(['id' => 'desc']) + ->like($params) + ->from($page) + ->size($limit) + ->order(['goods_id' => 'desc']) ->query(); - - dd($data); } - + public function count($params = [],$page = 1, $limit = 10) + { + return $this->esService +// ->setDebug() + ->like($params) + ->from($page) + ->size($limit) + ->query(true); + } /** * 更新商品 */ - public function update($goods_id) + public function updateData($goods_id, $data) { - $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', - ]; - return $this->esService->update($goods_id, $doc); + return $this->esService->update($goods_id, $data); } /** @@ -77,32 +55,57 @@ class GoodsEs */ public function detail($goods_id) { - $goods_id = 1; - $res = $this->esService->getDoc($goods_id); - var_dump($res); + return $this->esService->getDoc($goods_id); } - /** * 创建商品 + */ + public function createData($goods_id, $goods_list) + { + $goods_list['create_time'] = $goods_list['create_time'] ? strtotime($goods_list['create_time']) * 1000 : time() * 1000; + $goods_list['update_time'] = $goods_list['update_time'] ? strtotime($goods_list['update_time']) * 1000 : time() * 1000; + $goods_list['delivery_type'] = implode(',', $goods_list['delivery_type']); + return $this->esService->addDoc($goods_id, $goods_list)->asArray(); + } + + + /** + * 批量创建商品 * @return */ - public function create($goods_id) + public function batchCreateData() { - $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); + for ($page = 1; $page<=134; $page++) + { + $this->addData($page); + sleep(1); + } + } + + public function addData($page) + { + $goods_list = \app\common\model\Goods::where('goods_id', '>', 368257) +// ->order('goods_id desc') + ->page($page) + ->limit(2000) + ->select() + ->toArray(); +// + $i = 0; + foreach ($goods_list as $value) + { + $value['create_time'] = strtotime($value['create_time']) * 1000; + $value['update_time'] = strtotime($value['update_time']) * 1000; + $value['delivery_type'] = implode(',', $value['delivery_type']); + $res = $this->esService->addDoc($value['goods_id'], $value)->asArray(); + if($res['result'] == 'created') + { + $i++; + } + } + + echo('同步成功'.$i.'条数据').PHP_EOL; } /** @@ -110,8 +113,15 @@ class GoodsEs */ public function delete($goods_id) { - $res = $this->esService->deleteDoc($goods_id); - var_dump($res); + return $this->esService->deleteDoc($goods_id); + } + + /** + * 删除索引 + */ + public function deleteIndex() + { + return $this->esService->deleteIndexNew(); } @@ -126,41 +136,255 @@ class GoodsEs $mapping = [ 'properties' => [ 'goods_id' => [ - 'type' => 'integer' + 'type' => 'keyword' ], 'goods_type' => [ 'type' => 'keyword' ], - 'director' => [ + 'goods_name' => [ 'type' => 'text', "analyzer" => "ik_smart" ], - 'intro' => [ + 'goods_no' => [ + 'type' => 'keyword', + ], + 'video_id' => [ + 'type' => 'integer' + ], + 'brand_id' => [ + 'type' => 'integer' + ], + 'video_cover_id' => [ + 'type' => 'integer' + ], + 'selling_point' => [ 'type' => 'text', "analyzer" => "ik_smart" ], - 'cover' => [ + 'spec_type' => [ + 'type' => 'integer' + ], + 'cost_price_min' => [ + 'type' => 'float' + ], + 'goods_price_min' => [ + 'type' => 'float' + ], + 'goods_price_max' => [ + 'type' => 'float' + ], + 'line_price_min' => [ + 'type' => 'float' + ], + 'line_price_max' => [ + 'type' => 'float' + ], + 'stock_total' => [ + 'type' => 'integer' + ], + 'deduct_stock_type' => [ + 'type' => 'integer' + ], + 'is_restrict' => [ + 'type' => 'integer' + ], + 'restrict_total' => [ + 'type' => 'integer' + ], + 'restrict_single' => [ + 'type' => 'integer' + ], + 'content' => [ + 'type' => 'text', + ], + 'sales_initial' => [ + 'type' => 'integer' + ], + 'delivery_id' => [ + 'type' => 'integer' + ], + 'is_points_gift' => [ + 'type' => 'integer' + ], + 'is_points_discount' => [ + 'type' => 'integer' + ], + 'is_alone_points_discount' => [ + 'type' => 'integer' + ], + 'points_discount_config' => [ + 'type' => 'text' + ], + 'is_enable_grade' => [ + 'type' => 'integer' + ], + 'is_alone_grade' => [ + 'type' => 'integer' + ], + 'alone_grade_equity' => [ + 'type' => 'text' + ], + 'is_ind_dealer' => [ + 'type' => 'integer' + ], + 'dealer_money_type' => [ + 'type' => 'integer' + ], + 'first_money' => [ + 'type' => 'float' + ], + 'second_money' => [ + 'type' => 'float' + ], + 'third_money' => [ + 'type' => 'float' + ], + 'is_ind_delivery_type' => [ + 'type' => 'integer' + ], + 'delivery_type' => [ + 'type' => 'keyword' + ], + 'status' => [ + 'type' => 'integer' + ], + 'sort' => [ + 'type' => 'integer' + ], + 'store_id' => [ + 'type' => 'keyword' + ], + 'merchant_id' => [ + 'type' => 'keyword' + ], + 'create_time' => [ + 'type' => 'date', + 'format' => 'yyyy-MM-dd HH:mm:ss' + ], + 'update_time' => [ + 'type' => 'date', + 'format' => 'yyyy-MM-dd HH:mm:ss' + ], + 'is_brand' => [ + 'type' => 'integer' + ], + 'is_new' => [ + 'type' => 'integer' + ], + 'paihang' => [ + 'type' => 'integer' + ], + 'remaizhishu' => [ + 'type' => 'integer' + ], + 'spu_id' => [ + 'type' => 'integer' + ], + 'channel' => [ + 'type' => 'keyword' + ], + 'unicode' => [ + 'type' => 'keyword' + ], + 'is_in_store' => [ + 'type' => 'integer' + ], + 'profit' => [ + 'type' => 'float' + ], + 'profit_rate' => [ + 'type' => 'float' + ], + 'cmmdty_model'=> [ + 'type' => 'keyword' + ], + 'remark' => [ + 'type' => 'text' + ], + 'sale_areas' => [ + 'type' => 'text' + ], + 'sale_areas_id' => [ 'type' => 'keyword' ], - 'episode_count' => [ + 'data_type' => [ + 'type' => 'integer' + ], + 'is_pool' => [ + 'type' => 'integer' + ], + 'is_self' => [ + 'type' => 'integer' + ], + 'link' => [ 'type' => 'keyword' ], - 'wechat_vid' => [ + 'origin_goods_id' => [ + 'type' => 'integer' + ], + 'link_other' => [ + 'type' => 'text' + ], + 'goods_no_other' => [ 'type' => 'keyword' ], - 'duration' => [ + 'region' => [ + 'type' => 'text' + ], + 'region_text' => [ + 'type' => 'text' + ], + 'specific_value' => [ 'type' => 'keyword' ], - 'service_types' => [ + 'cate_status' => [ + 'type' => 'integer' + ], + 'is_check' => [ + 'type' => 'integer' + ], + 'goods_source' => [ 'type' => 'keyword' ], + 'delivery_time' => [ + 'type' => 'integer' + ], + 'distribute_price' => [ + 'type' => 'float' + ], + 'shop_price' => [ + 'type' => 'float' + ], + 'is_has_banner' => [ + 'type' => 'integer' + ], + 'is_has_detail' => [ + 'type' => 'integer' + ], + 'is_jingpin' => [ + 'type' => 'integer' + ], + 'sale_time' => [ + 'type' => 'integer' + ], + 'markup_rate' => [ + 'type' => 'integer' + ] ] ]; - $res = $this->esService->createIndexNew($mapping); - var_dump($res); + return $this->esService->createIndexNew($mapping); + } + + /** + * 设置分词字段 + */ + public function analyze() + { + return $this->esService->analyze('goods_name'); } + } \ No newline at end of file diff --git a/app/store/controller/Store.php b/app/store/controller/Store.php index eb62d75e..c9695d12 100644 --- a/app/store/controller/Store.php +++ b/app/store/controller/Store.php @@ -16,6 +16,7 @@ use app\common\model\store\StoreSettle; use think\response\Json; use app\store\model\Store as StoreModel; use app\common\model\Channel; +use app\common\model\PriceSet; /** * 商家中心控制器 @@ -86,4 +87,63 @@ class Store extends Controller //$platformList = config('app.platformList'); return $this->renderSuccess($platformList); } + + public function setStorePrice(): Json + { + $params = $this->request->param(); + $storeid = $this->storeId; + // var_dump($params); + // exit(); + //先删除 + PriceSet::where('store_id', $storeid)->where('type', $params['type'] ?? 0)->delete(); + $inDatas = []; + foreach ($params['list'] as $value) { + $categorys = explode(",", $value['category']); + foreach ($categorys as $category) { + foreach ($value['price_list'] as $price) { + $temp = [ + 'category' => $value['category'], + 'code' => $category, + 'store_id' => $storeid, + 'type' => $params['type'], + 'min' => $price['min'], + 'max' => $price['max'], + 'add_price_rate' => $price['add_price_rate'], + 'create_time' => time(), + 'update_time' => time(), + ]; + $inDatas[] = $temp; + } + } + + + } + // echo "
"; + // print_r($inDatas); + // exit(); + $model = new PriceSet; + $model->addAll($inDatas); + return $this->renderSuccess('ok'); + } + + //加个设置回显 + public function getStorePriceInfo(int $type): Json + { + $storeid = $this->storeId; + $list = PriceSet::where('store_id', $storeid)->where('type', $type)->field('category,code,min,max,add_price_rate')->group("category, min")->select()->toArray(); + $data = []; + $arr = []; + foreach ($list as $value) { + $arr[$value['category']][] = $value; + } + foreach ($arr as $key => $item) { + $data['list'][] = [ + 'category' => $key, + 'price_list' => $item, + ]; + } + $data['type'] = $type; + return $this->renderSuccess($data); + } + }