Parcourir la source

快应用改版

onlinetest il y a 5 ans
Parent
commit
51aa42cc2c

+ 65 - 0
app/Console/Commands/NewVersionPrepare.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Modules\User\Models\QappUser;
+use Illuminate\Console\Command;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+class NewVersionPrepare extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'new_viersion_prepare';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '新版本上线准备';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        if (!Schema::hasColumn('qapp_users', 'channel_id')) {
+            Schema::table('qapp_users', function (Blueprint $table) {
+                $table->unsignedInteger('channel_id');
+                $table->dropIndex('device_no');
+                $table->index(['device_no', 'channel_id'], 'idx_device_no');
+            });
+            DB::table('qapp_users')->update(['channel_id' => env('QUICKAPP_SITE')]);
+        }
+        if (!Schema::hasTable('qapp_package_info')) {
+            Schema::create('qapp_package_info', function (Blueprint $table) {
+                $table->increments('id');
+                $table->integer('channel_id');
+                $table->string('package', 255);
+                $table->string('company', 255);
+                $table->integer('app_pay_merchat_id');
+                $table->integer('h5_pay_merchat_id');
+                $table->integer('ali_pay_merchat_id');
+                $table->timestamps();
+            });
+        }
+    }
+}

+ 3 - 7
app/Console/Kernel.php

@@ -25,6 +25,7 @@ class Kernel extends ConsoleKernel
         Commands\channelCpcCode::class,
         Commands\updateFromNewYunqi::class,
         Commands\CheckOrderStatus::class,
+        Commands\NewVersionPrepare::class,
     ];
 
     /**
@@ -35,17 +36,12 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
-        //$schedule->command('book:update')->dailyAt('06:00');
-
-        //$schedule->command('book:update')->dailyAt('18:00');
-        $schedule->command('book:update')->hourly()->when(function (){
+        $schedule->command('book:update')->hourly()->when(function () {
             $now_hour = date('G');
-            if($now_hour %4 ==0){
+            if ($now_hour % 4 == 0) {
                 return true;
             }
             return false;
         });
-
-        //$schedule->command('checkOrderStatus')->everyMinute();
     }
 }

+ 1 - 1
app/Modules/User/Models/QappUser.php

@@ -7,5 +7,5 @@ use Illuminate\Database\Eloquent\Model;
 class QappUser extends Model
 {
     protected $table = 'qapp_users';
-    protected $fillable = ['uid', 'device_no', 'device_info', 'phone'];
+    protected $fillable = ['uid', 'channel_id', 'device_no', 'device_info', 'phone'];
 }

+ 7 - 5
app/Modules/User/Services/QappUserService.php

@@ -28,7 +28,8 @@ class QappUserService
     public function login(array $data)
     {
         $device_no = $data['device_no'];
-        $qapp_user = $this->getQAppUserByDeviceNo($device_no);
+        $channel_id = $this->findChannelId($data['package']);
+        $qapp_user = $this->getQAppUserByDeviceNo($device_no, $channel_id);
         if (!$qapp_user) {
             $qapp_user = $this->createQuickAppUser($data);
         }
@@ -95,9 +96,9 @@ class QappUserService
     /**
      * 根据设备号获取快应用用户信息
      */
-    public function getQAppUserByDeviceNo(string $device_no)
+    public function getQAppUserByDeviceNo(string $device_no, int $channel_id)
     {
-        $qapp_user = QappUser::where('device_no', $device_no)->first();
+        $qapp_user = QappUser::where('device_no', $device_no)->where('channel_id', $channel_id)->first();
         if ($qapp_user) {
             $user = User::find($qapp_user->uid);
             $qapp_user->user = $user;
@@ -133,10 +134,11 @@ class QappUserService
             DB::beginTransaction();
             $user = $this->createUser($data);
             $uid = $user->id;
+            $channel_id = $user->distribution_channel_id;
             $device_no = $data['device_no'];
             $device_info = $data['device_info'];
-            $data = compact('device_info');
-            $unique_key = compact('device_no', 'uid');
+            $data = compact('device_info', 'uid');
+            $unique_key = compact('device_no', 'channel_id');
             $qapp_user = QappUser::firstOrCreate($unique_key, $data);
             $qapp_user->user = $user;
             DB::commit();