Browse Source

修改权重

wzq 5 years ago
parent
commit
7b6440ff17

+ 1 - 2
app/Console/Commands/UpdatePostInfo.php

@@ -73,8 +73,7 @@ class UpdatePostInfo extends Command
                     'available_bean', $post->data->available_bean,
                     'will_collect_bean', $post->data->will_collect_bean,
                     'create_bean', $post->data->create_bean,
-                    'collect_bean', $post->data->collect_bean,
-                    'weight', $post->data->weight);
+                    'collect_bean', $post->data->collect_bean);
             }
             usleep(100000);
         });

+ 6 - 8
app/Repositories/Post/PostRepository.php

@@ -103,6 +103,8 @@ class PostRepository
             }
         }
 
+        $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
+        $score = $fresh / 86400;
         $data = [
             'uid' => $userInfo['uid'],
             'username' => $userInfo['username'],
@@ -117,14 +119,12 @@ class PostRepository
             'content' => $request['content'],
             'location' => $request['location'] ?? '',
             'is_suggest' => $request['is_suggest'],
-            'is_hide' => 0
+            'is_hide' => 0,
+            'weight' => $score
         ];
 
         $date = date('Y-m-d H:i:s');
 
-        $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
-        $score = $fresh / 86400;
-
         DB::beginTransaction();
         try {
             $post = $this->post->create($data);
@@ -143,8 +143,7 @@ class PostRepository
                 'collect_real_count' => 0,
                 'available_bean' => $this->availableBean(),
                 'will_collect_bean' => rand(100, 200),
-                'collect_bean' => 0,
-                'weight' => $score
+                'collect_bean' => 0
             ]);
 
             $imgs = [];
@@ -207,8 +206,7 @@ class PostRepository
                 'available_bean', $postData->available_bean,
                 'will_collect_bean', $postData->will_collect_bean,
                 'create_bean', $postData->create_bean,
-                'collect_bean', $postData->collect_bean,
-                'weight', $postData->weight);
+                'collect_bean', $postData->collect_bean);
 
             return Response::create();
 

+ 37 - 0
database/migrations/2019_08_13_165505_add_weight_to_table_post.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddWeightToTablePost extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('post', function (Blueprint $table) {
+            $table->decimal('weight', 8, 2)
+                ->index('idx_weight')
+                ->after('location')
+                ->default(0)
+                ->comment('权重');
+            $table->index('is_suggest', 'idx_is_suggest');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 30 - 0
database/migrations/2019_08_13_171258_modify_weight_to_table_post_data.php

@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class ModifyWeightToTablePostData extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        DB::statement("ALTER TABLE `post_data` DROP COLUMN `weight`");
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('table_post_data', function (Blueprint $table) {
+            //
+        });
+    }
+}