57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CreateSplitBandOriginSyn extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'table:band_origin_syns';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$month = date('m');
|
|
$year = date("Y");
|
|
if ($month == 12) {//下一年
|
|
$year += 1;
|
|
$month = 1;
|
|
}else {
|
|
$month += 1;
|
|
}
|
|
$month = str_pad($month, 2, '0', STR_PAD_LEFT);
|
|
$table_name = "band_origin_syns_{$year}{$month}";
|
|
if (!Schema::hasTable($table_name)) {
|
|
Schema::create($table_name, function (Blueprint $table) {
|
|
$table->id();
|
|
$table->integer('user_id')->unsigned()->comment("用户id");
|
|
$table->integer('band_id')->unsigned()->comment("手环id");
|
|
$table->timestamp('date')->nullable()->comment("时间");
|
|
$table->text("value")->nullable()->comment("数据");
|
|
$table->timestamps();
|
|
$table->unique(['user_id', 'band_id', 'date']);
|
|
$table->index('date');
|
|
});
|
|
}
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|