<?php

namespace App\Modules\Trade\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class WechatOrderChargeDateStatistic extends Model
{
    protected $table = 'wechat_order_charge_date_statistic';
    protected $fillable = [
        'date',
        'platform',
        'app_id',
        'amount',
    ];

    public static function createTable()
    {
        if (!Schema::hasTable('wechat_order_charge_date_statistic')) {
            Schema::create('wechat_order_charge_date_statistic', function (Blueprint $table) {
                $table->increments('id');
                $table->string('date', 10);
                $table->string('platform', 50);
                $table->string('app_id', 64);
                $table->float('amount');
                $table->timestamps();
                $table->unique(['app_id', 'date', 'platform'], 'idx_month_appid');
            });
        }
    }
}
