id = $this->getRandId($this->user_id); $this->expiry_time = strtotime('+30 days'); $this->create_time = time(); } public function beforeUpdate() { $this->update_time = time(); } protected function getRandId($userId, $prefix = 'RT') { return md5("{$prefix}-{$userId}" . time() . rand(1000, 9999)); } }