This commit is contained in:
hujiabin 2024-08-29 10:42:36 +08:00
parent 618ab1ce61
commit d67479e07b
3 changed files with 113 additions and 2 deletions

36
doc/ActivationCode.py Normal file
View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
import _common
class ActivationCode(object):
def __init__(self):
self.apis = [
{
'name': 'bindActivationCode',
'desc': '绑定激活码',
'group': 'ActivationCode',
'url': 'webapp/index.php?c=ActivationCode&a=bindActivationCode',
'params': [
_common.ReqHead(),
['code', 0, '激活码']
],
'response': [
_common.RspHead(),
]
},{
'name': 'getActivationCodeBindState',
'desc': '激活码绑定状态',
'group': 'ActivationCode',
'url': 'webapp/index.php?c=ActivationCode&a=getActivationCodeBindState',
'params': [
_common.ReqHead(),
],
'response': [
_common.RspHead(),
['state', 0, '1:已激活 0:未激活']
]
}
]

View File

@ -0,0 +1,29 @@
<?php
require_once('models/ActivationCode.php');
use models\ActivationCode;
use phpcommon\SqlHelper;
class ActivationCodeController extends BaseAuthedController {
public function bindActivationCode(){
$code = getReqVal('code', 0);
if (!ActivationCode::verifyCode($code)){
$this->_rspErr(1, "activation code error");
return;
}
if (ActivationCode::verifyAccountBind()){
$this->_rspErr(1, "The activation code has been bind");
return;
}
ActivationCode::addBindCode($code);
$this->_rspOk();
}
public function getActivationCodeBindState(){
$state = ActivationCode::verifyAccountBind() ? 1 :0;
$this->_rspData(array(
'state' => $state
));
}
}

View File

@ -3,8 +3,54 @@
namespace models; namespace models;
use mt;
class ActivationCode use phpcommon\SqlHelper;
class ActivationCode extends BaseModel
{ {
public static function verifyCode($code){
$row = SqlHelper::ormSelectOne(
myself()->_getAccountMysql(),
't_activation_code',
array(
'activation_code' => $code,
)
);
if ($row){
return true;
}
return false;
}
public static function addBindCode($code){
SqlHelper::upsert(
myself()->_getAccountMysql(),
't_activation_code_bind',
array(
'account_id' => myself()->_getAccountId(),
),
array(
),
array(
'account_id' => myself()->_getAccountId(),
'activation_code' =>$code,
'createtime' =>myself()->_getNowTime(),
'modifytime' =>myself()->_getNowTime(),
)
);
}
public static function verifyAccountBind(){
$row = SqlHelper::ormSelectOne(
myself()->_getAccountMysql(),
't_activation_code_bind',
array(
'account_id' => myself()->_getAccountId(),
)
);
if ($row){
return true;
}
return false;
}
} }