From d67479e07b6c3cf90d25612ac17507fa5ea738d6 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Thu, 29 Aug 2024 10:42:36 +0800 Subject: [PATCH] 1 --- doc/ActivationCode.py | 36 +++++++++++++ .../ActivationCodeController.class.php | 29 +++++++++++ webapp/models/ActivationCode.php | 50 ++++++++++++++++++- 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 doc/ActivationCode.py create mode 100644 webapp/controller/ActivationCodeController.class.php diff --git a/doc/ActivationCode.py b/doc/ActivationCode.py new file mode 100644 index 00000000..74fd3d0b --- /dev/null +++ b/doc/ActivationCode.py @@ -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:未激活'] + ] + } + ] + + diff --git a/webapp/controller/ActivationCodeController.class.php b/webapp/controller/ActivationCodeController.class.php new file mode 100644 index 00000000..9639cf13 --- /dev/null +++ b/webapp/controller/ActivationCodeController.class.php @@ -0,0 +1,29 @@ +_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 + )); + } + +} diff --git a/webapp/models/ActivationCode.php b/webapp/models/ActivationCode.php index 83bad239..18c39885 100644 --- a/webapp/models/ActivationCode.php +++ b/webapp/models/ActivationCode.php @@ -3,8 +3,54 @@ namespace models; - -class ActivationCode +use mt; +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; + } } \ No newline at end of file