|
@@ -6,7 +6,6 @@ use app\admin\model\store\StoreProduct;
|
|
|
use app\admin\model\store\StoreProductAttr;
|
|
use app\admin\model\store\StoreProductAttr;
|
|
|
use app\admin\model\store\StoreProductAttrResult;
|
|
use app\admin\model\store\StoreProductAttrResult;
|
|
|
use app\admin\model\store\StoreProductAttrValue;
|
|
use app\admin\model\store\StoreProductAttrValue;
|
|
|
-use app\admin\model\system\SystemLog;
|
|
|
|
|
use app\models\store\StoreProductRule;
|
|
use app\models\store\StoreProductRule;
|
|
|
use think\console\Command;
|
|
use think\console\Command;
|
|
|
use think\console\Input;
|
|
use think\console\Input;
|
|
@@ -30,7 +29,7 @@ class Maintain extends Command
|
|
|
protected function configure()
|
|
protected function configure()
|
|
|
{
|
|
{
|
|
|
$this->setName('maintain')
|
|
$this->setName('maintain')
|
|
|
- ->addArgument('category', Argument::REQUIRED, 'act|prod|trash|reindex|none')
|
|
|
|
|
|
|
+ ->addArgument('category', Argument::REQUIRED, 'act|prod|trash|reindex|test_reindex|none')
|
|
|
->setDescription('maintain some application data.');
|
|
->setDescription('maintain some application data.');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -317,16 +316,86 @@ class Maintain extends Command
|
|
|
* 2.用于关键字搜索
|
|
* 2.用于关键字搜索
|
|
|
* 3.用于按价格/销量/好评度/上线时间排序
|
|
* 3.用于按价格/销量/好评度/上线时间排序
|
|
|
*
|
|
*
|
|
|
|
|
+ * TODO:
|
|
|
* - 新增/上架商品: 新增索引
|
|
* - 新增/上架商品: 新增索引
|
|
|
* - 删除/下架商品:删除索引
|
|
* - 删除/下架商品:删除索引
|
|
|
|
|
+ * - 編輯商品:重新索引
|
|
|
|
|
+ *
|
|
|
|
|
+ * cur: 當前新增的商品不會立即出現在搜索結果,而是每次都重新索引全部。
|
|
|
|
|
+ * 因为这样实现简单,另外商品总的数据量不会很大
|
|
|
|
|
+ *
|
|
|
*/
|
|
*/
|
|
|
protected function reindex()
|
|
protected function reindex()
|
|
|
{
|
|
{
|
|
|
|
|
+ $ml = new Client(config('meilisearch.addr'), config('meilisearch.key'));
|
|
|
|
|
+ // remove first
|
|
|
|
|
+ $ml->deleteIndex('products');
|
|
|
|
|
+ // rebuild
|
|
|
|
|
+ $idx = $ml->index('products', 'id');
|
|
|
|
|
+ // setup
|
|
|
|
|
+
|
|
|
|
|
+ $idx->updateSearchableAttributes([
|
|
|
|
|
+ 'store_name',
|
|
|
|
|
+ 'store_info',
|
|
|
|
|
+ 'keyword',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $idx->updateFilterableAttributes([
|
|
|
|
|
+ 'cate_id',
|
|
|
|
|
+ 'price',
|
|
|
|
|
+ 'is_hot',
|
|
|
|
|
+ 'is_benefit',
|
|
|
|
|
+ 'is_best',
|
|
|
|
|
+ 'is_new',
|
|
|
|
|
+ 'add_time',
|
|
|
|
|
+ 'is_good',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $idx->updateSortableAttributes([
|
|
|
|
|
+ 'price',
|
|
|
|
|
+ 'sales',
|
|
|
|
|
+ 'cost',
|
|
|
|
|
+ 'browse',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ // get all products
|
|
|
|
|
+ $page = 1;
|
|
|
|
|
+ $limit = 20;
|
|
|
|
|
+ $count = 0;
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ $products = StoreProduct::where('is_del', 0)
|
|
|
|
|
+ ->where('stock', '>', 0)
|
|
|
|
|
+ // ->where('is_show', 1)
|
|
|
|
|
+ ->field('id,image,slider_image,store_name,
|
|
|
|
|
+ store_info,keyword,cate_id,price,vip_price,ot_price,postage,
|
|
|
|
|
+ unit_name,sort,sales,stock,
|
|
|
|
|
+ is_hot,is_benefit,is_best,is_new,add_time,is_postage,
|
|
|
|
|
+ give_integral,cost,is_good,ficti,browse')
|
|
|
|
|
+ ->page($page, $limit)->select()->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ $count += count($products);
|
|
|
|
|
+
|
|
|
|
|
+ if (count($products) > 0) {
|
|
|
|
|
+ $idx->addDocuments($products, 'id');
|
|
|
|
|
+ }
|
|
|
|
|
+ // no more rows
|
|
|
|
|
+ if (count($products) < $limit) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ // loop
|
|
|
|
|
+ $page += 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ echo "re-index all products finished. total=$count" . PHP_EOL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function none()
|
|
|
|
|
|
|
+ protected function _all_products_on_sale()
|
|
|
|
|
+ {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected function test_reindex()
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ protected function none()
|
|
|
|
|
+ {
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|