|
@@ -3,6 +3,8 @@
|
|
|
namespace App\Model;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Schema;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -15,5 +17,53 @@ class BoxDetail extends Model
|
|
|
const CREATED_AT = 'crt_time';
|
|
|
const UPDATED_AT = 'upd_time';
|
|
|
protected $dateFormat = 'U';
|
|
|
+ protected $guarded = [];
|
|
|
|
|
|
+ protected $month = [
|
|
|
+ 1 => '01_03',
|
|
|
+ 2 => '01_03',
|
|
|
+ 3 => '01_03',
|
|
|
+ 4 => '04_06',
|
|
|
+ 5 => '04_06',
|
|
|
+ 6 => '04_06',
|
|
|
+ 7 => '07_09',
|
|
|
+ 8 => '07_09',
|
|
|
+ 9 => '07_09',
|
|
|
+ 10 => '10_12',
|
|
|
+ 11 => '10_12',
|
|
|
+ 12 => '10_12',
|
|
|
+ ];
|
|
|
+
|
|
|
+ public function __construct(array $attributes = [])
|
|
|
+ {
|
|
|
+ parent::__construct($attributes);
|
|
|
+ if (isset($attributes['channel']) && $attributes['channel'] > 0) {
|
|
|
+ $channel = $attributes['channel'];
|
|
|
+ $month = (int)substr($channel,4,2);
|
|
|
+ $channel = substr($channel,0,4).$this->month[$month];
|
|
|
+ $this->setTableById($channel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $channel
|
|
|
+ */
|
|
|
+ // 动态指定数据表
|
|
|
+ public function setTableById($channel)
|
|
|
+ {
|
|
|
+ if ($channel > 0) {
|
|
|
+ $tb = $this->table.'_' . (string)$channel;
|
|
|
+ $this->createTable($tb);
|
|
|
+ $this->setTable($tb);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function createTable($channel){
|
|
|
+// $table_name = 'box_detail_' . (string)$channel;
|
|
|
+ if(!Schema::hasTable($channel)){
|
|
|
+ DB::update('create table '.$channel.' like box_detail');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|