xieruidong 2 lat temu
rodzic
commit
62da340c4a

+ 1 - 0
application/command.php

@@ -23,4 +23,5 @@ return [
     \app\admin\command\MobileImportCommand::class,
     \app\admin\command\MobileExportCommand::class,
     \app\common\command\EsImportCommand::class,
+    \app\common\command\EsMapCommand::class,
 ];

+ 4 - 3
application/common/command/EsImportCommand.php

@@ -15,9 +15,10 @@ class EsImportCommand extends Command{
 
     protected function execute(Input $input, Output $output)
     {
-        EsMobileService::mobile();
-        Mobile::where('type',1)->chunk(100,function ($mobile){
-
+        Mobile::where('type',1)->chunk(100,function ($mobiles){
+            foreach ($mobiles as $mobile){
+                EsMobileService::addIndex($mobile);
+            }
         });
     }
 }

+ 19 - 0
application/common/command/EsMapCommand.php

@@ -0,0 +1,19 @@
+<?php
+namespace app\common\command;
+
+use app\service\EsMobileService;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+
+class EsMapCommand extends Command{
+    protected function configure()
+    {
+        $this->setName('es:map')->setDescription('test');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        EsMobileService::mapping();
+    }
+}

+ 3 - 28
application/common/command/TestCommand.php

@@ -1,33 +1,10 @@
 <?php
 namespace app\common\command;
 
-use app\admin\command\Api\library\Builder;
-use app\api\controller\AdminAuth;
-use app\api\controller\AdminCoupon;
-use app\api\controller\AdminOrder;
-use app\api\controller\AdminUser;
-use app\api\controller\CommentController;
-use app\api\controller\Common;
-use app\api\controller\Ems;
-use app\api\controller\InfoController;
-use app\api\controller\Knowledge;
-use app\api\controller\NotificationController;
-use app\api\controller\Sender;
-use app\api\controller\SenderOrderController;
-use app\api\controller\Sms;
-use app\api\controller\Token;
-use app\api\controller\User;
-use app\api\controller\UserAddressController;
-use app\api\controller\UserCouponController;
-use app\api\controller\UserMoneyController;
-use app\api\controller\UserOrder;
-use app\api\controller\Validate;
-use app\common\model\Mobile;
-use app\common\model\UserRule;
+use app\service\EsMobileService;
 use think\console\Command;
 use think\console\Input;
 use think\console\Output;
-use think\Db;
 
 class TestCommand extends Command{
     protected function configure()
@@ -37,10 +14,8 @@ class TestCommand extends Command{
 
     protected function execute(Input $input, Output $output)
     {
-        Mobile::create([
-            'no'=>'13566662222',
-            'amount_base'=>100,
-            'amount_charge'=>0,
+        es()->search([
+            'index'=>EsMobileService::index(),
         ]);
     }
 }

+ 13 - 17
application/service/EsMobileService.php

@@ -1,15 +1,11 @@
 <?php
 namespace app\service;
 
+use app\common\model\Mobile;
 use traits\think\Instance;
 
 class EsMobileService{
     public static function mobile(){
-        self::mapping();
-        $resp=es()->indices()->get([
-            'index'=>self::index(),
-        ]);
-        dd($resp->getBody());
     }
     public static function index(){
         return 'mobiles';
@@ -144,17 +140,17 @@ class EsMobileService{
         ];
     }
     public static function mapping(){
-        try {
-            $res=es()->indices()->get([
-                'index'=>self::index(),
-                'type'=>self::type(),
-            ]);
-            dd(111);
-        }catch (\Exception $e){
-            es()->indices()->create([
-                'index'=>self::index(),
-                'body'=>self::body()
-            ]);
-        }
+        es()->indices()->create([
+            'index'=>self::index(),
+            'body'=>self::body()
+        ]);
+    }
+    public static function addMobile(Mobile $mobile){
+        $mobile->hidden([],true);
+        es()->index([
+            'index'=>self::index(),
+            'body'=>$mobile->toArray(),
+            'id'=>$mobile['id'],
+        ]);
     }
 }