From b4b97656e693674d5ec43a64f94393cde9bb8eed Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 1 Aug 2024 13:11:40 +0800 Subject: [PATCH] 1 --- webapp/controller/BaseController.class.php | 52 +++++++++++++++---- .../controller/BigwheelController.class.php | 5 ++ webapp/models/MidData.php | 2 + 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/webapp/controller/BaseController.class.php b/webapp/controller/BaseController.class.php index 76e90de3..5f73657f 100644 --- a/webapp/controller/BaseController.class.php +++ b/webapp/controller/BaseController.class.php @@ -10,7 +10,7 @@ class BaseController { private $relationDbConn = null; private $mailDbConn = null; private $timeOffset = 0; - private $serviceHash = array(); + private $moduleHash = array(); function __construct() { @@ -278,24 +278,56 @@ class BaseController { public function _getServiceConstant($serviceName, $name) { - $this->_mustBeLoadService($serviceName); - $reflectionConstant = new ReflectionClassConstant('services\\' . $serviceName, $name); - return $reflectionConstant->getValue();; + return $this->_internalGetModuleConstant('services', $serviceName, $name); } public function _callServiceStatic($serviceName, $funcName, ...$args) { - $this->_mustBeLoadService($serviceName); - $method = new ReflectionMethod('services\\' . $serviceName, $funcName); + return $this->_internalCallModuleStatic('services', $serviceName, $funcName, ... $args); + } + + public function _getModelConstant($modelName, $name) + { + return $this->_internalGetModuleConstant('models', $modelName, $name); + } + + public function _callModelStatic($modelName, $funcName, ...$args) + { + return $this->_internalCallModuleStatic('models', $modelName, $funcName, ... $args); + } + + public function _getMtConstant($modelName, $name) + { + return $this->_internalGetModuleConstant('mt', $modelName, $name); + } + + public function _callMtStatic($modelName, $funcName, ...$args) + { + return $this->_internalCallModuleStatic('mt', $modelName, $funcName, ... $args); + } + + private function _internalGetModuleConstant($dir, $moduleName, $name) + { + $fullName = $dir . '\\' . $moduleName; + $this->_internalMustBeLoadModule($fullName); + $reflectionConstant = new ReflectionClassConstant($fullName, $name); + return $reflectionConstant->getValue();; + } + + private function _internalCallModuleStatic($dir, $moduleName, $funcName, ...$args) + { + $fullName = $dir . '\\' . $moduleName; + $this->_internalMustBeLoadModule($fullName); + $method = new ReflectionMethod($fullName, $funcName); $ret = $method->invoke(null, ...$args); return $ret; } - private function _mustBeLoadService($serviceName) + private function _internalMustBeLoadModule($fullName) { - if (!array_key_exists($serviceName, $this->serviceHash)) { - require_once('services/' . $serviceName . '.php'); - $this->serviceHash[$serviceName] = $this->_getNowTime(); + if (!array_key_exists($fullName, $this->moduleHash)) { + require_once($fullName . '.php'); + $this->moduleHash[$fullName] = $this->_getNowTime(); } } diff --git a/webapp/controller/BigwheelController.class.php b/webapp/controller/BigwheelController.class.php index f2986488..0b344a0c 100644 --- a/webapp/controller/BigwheelController.class.php +++ b/webapp/controller/BigwheelController.class.php @@ -22,4 +22,9 @@ class BigwheelController extends BaseAuthedController public function buyS(){ } + private function getMidDataKey() + { + return myself()->_getServiceConstant(); + } + } diff --git a/webapp/models/MidData.php b/webapp/models/MidData.php index 8c5a61b0..f94aed26 100644 --- a/webapp/models/MidData.php +++ b/webapp/models/MidData.php @@ -7,6 +7,8 @@ use phpcommon\SqlHelper; class MidData extends BaseModel { + const BIG_WHEEL_TYPE = 'offer.reward.missions'; + public static function getData($type) { $row = SqlHelper::ormSelectOne(