creator = Admin::user()->id; }); } if(self::$mode == 'admin'){ static::updating(function ($model){ $model->updator = Admin::user()->id; }); } } public function setExtAttribute($ext) { if (is_array($ext)) { $this->attributes['ext'] = json_encode($ext); } } public function getExtAttribute($ext) { return json_decode($ext, true); } /** * 创建活动 * * * */ public static function store($data, $id = 0) { // var_dump($data['ext']);exit; self::$mode = 'api'; if($id) { $model = self::find($id); if(!$model) { throw new Exception('该信息不存在'); } }else { $model = new self(); } $model->organiz_type = $data['organiz_type']; $model->activity_range_id = $data['activity_range_id']; $model->organiz_name = $data['organiz_name']; $model->title = $data['title']; $model->member_num = $data['member_num']; $model->content = $data['content']; $model->active_time = $data['activity_time']??''; $model->belong = $data['belong']; $model->member = $data['member']; $model->ext = $data['ext']; $res = $model->save(); if($res) { return ["id" => $model->id]; } else { return []; } } public function creater() { return $this->belongsTo(Administrator::class, 'creator'); } public function updater() { return $this->belongsTo(Administrator::class, 'updator'); } public function range() { return $this->belongsTo(ActivityRange::class, 'activity_range_id'); } public function workstation() { return $this->belongsTo(ActivityWorkStation::class, 'belong','work_station_id'); } }