| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | <?phpnamespace Act\Lib;use Dever;class Form{    # 获取当前可用的formid    public function get($uid, $type = 1)    {        $where['uid'] = $uid;        if ($type > 0) {        	$where['type'] = $type;        	if ($type == 2) {        		# 支付表单有3次机会        		$where['num'] = 3;        	} else {        		# 普通表单只有一次机会        		$where['num'] = 1;        	}        }        $info = Dever::db('act/form_id')->getAll($where);        if ($info) {            $key = array_rand($info);            if (isset($info[$key])) {            	$update['where_id'] = $info[$key]['id'];            	$update['num'] = $info[$key]['num'] + 1;            	Dever::db('act/form_id')->update($update);            	return $info[$key]['form_id'];            }        } else {            return false;        }    }    # 提交formid    public function submit($uid, $id, $type = 1)    {        $where['uid'] = $uid;        $where['type'] = $type;        $where['form_id'] = $id;        $info = Dever::db('act/form_id')->one($where);        if (!$info) {        	$where['num'] = 0;            Dever::db('act/form_id')->insert($where);        }        return true;    }}
 |