'integer', 'change' => 'integer', 'current' => 'integer', ]; protected function serializeDate(\DateTimeInterface $date) { return $date->format($this->dateFormat ?: 'Y-m-d H:i:s'); } public function user() { return $this->belongsTo(User::class, 'user_id', 'id'); } public function record($userId, $type, $change, $remark) { $record = new UserConsumeRecord(); $user = UserInfo::find($userId); $record->user_id = $user->user_id; $record->type = $type; $record->before = $user->integral; $record->change = $change; $record->current = $user->integral + $record->change; $record->remark = $remark; $record->save(); } }