<?php
namespace app\common\model\wxapp;
use app\common\model\BaseModel;
class Formid extends BaseModel
{
protected $name = 'wxapp_formid';
public function user()
{
$module = self::getCalledModule() ?: 'common';
return $this->belongsTo("app\\{$module}\\model\\User");
}
public static function getAvailable($userId)
{
return (new static)->where([
'user_id' => $userId,
'is_used' => 0,
'expiry_time' => ['>=', time()]
])->order(['create_time' => 'asc'])->find();
}
public static function setIsUsed($id)
{
return static::update(['is_used' => 1], compact('id'));
}
}