diff --git a/application/admin/command/Crud/stubs/controller.stub b/application/admin/command/Crud/stubs/controller.stub index 72a268e0ea09f886840525d9bfae466bb73ae56c..70525f70c94e4228751206528fe9632a7fb6d530 100644 --- a/application/admin/command/Crud/stubs/controller.stub +++ b/application/admin/command/Crud/stubs/controller.stub @@ -25,11 +25,6 @@ class {%controllerName%} extends Backend {%controllerAssignList%} } - public function import() - { - parent::import(); - } - /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 diff --git a/application/common/library/Ems.php b/application/common/library/Ems.php index 368278b548198831230bf6481aff240fe70acbaf..6cc01f16a60f7b98ec4b127461bf67c0f15f5c29 100644 --- a/application/common/library/Ems.php +++ b/application/common/library/Ems.php @@ -2,7 +2,12 @@ namespace app\common\library; +use PDOStatement; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; +use think\exception\DbException; use think\Hook; +use think\Model; /** * 邮箱验证码类 @@ -25,29 +30,32 @@ class Ems /** * 获取最后一次邮箱发送的数据 * - * @param int $email 邮箱 - * @param string $event 事件 - * @return Ems + * @param string $email 邮箱 + * @param string $event 事件 + * @return array|bool|PDOStatement|string|Model + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException */ - public static function get($email, $event = 'default') + public static function get(string $email, string $event = 'default') { $ems = \app\common\model\Ems:: where(['email' => $email, 'event' => $event]) ->order('id', 'DESC') ->find(); Hook::listen('ems_get', $ems, null, true); - return $ems ? $ems : null; + return $ems ?: null; } /** * 发送验证码 * - * @param int $email 邮箱 - * @param int $code 验证码,为空时将自动生成4位数字 - * @param string $event 事件 - * @return boolean + * @param string $email 邮箱 + * @param int|null $code 验证码,为空时将自动生成4位数字 + * @param string $event 事件 + * @return boolean */ - public static function send($email, $code = null, $event = 'default') + public static function send(string $email, int $code = null, string $event = 'default'): bool { $code = is_null($code) ? mt_rand(1000, 9999) : $code; $time = time(); @@ -64,12 +72,12 @@ class Ems /** * 发送通知 * - * @param mixed $email 邮箱,多个以,分隔 - * @param string $msg 消息内容 - * @param string $template 消息模板 + * @param string $email 邮箱,多个以,分隔 + * @param string $msg 消息内容 + * @param string|null $template 消息模板 * @return boolean */ - public static function notice($email, $msg = '', $template = null) + public static function notice(string $email, string $msg = '', string $template = null): bool { $params = [ 'email' => $email, @@ -77,18 +85,21 @@ class Ems 'template' => $template ]; $result = Hook::listen('ems_notice', $params, null, true); - return $result ? true : false; + return (bool)$result; } /** * 校验验证码 * - * @param int $email 邮箱 - * @param int $code 验证码 - * @param string $event 事件 - * @return boolean + * @param string $email 邮箱 + * @param int $code 验证码 + * @param string $event 事件 + * @return boolean + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ - public static function check($email, $code, $event = 'default') + public static function check(string $email, int $code, string $event = 'default'): bool { $time = time() - self::$expire; $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event]) @@ -102,7 +113,7 @@ class Ems $ems->save(); return false; } else { - $result = Hook::listen('ems_check', $ems, null, true); + Hook::listen('ems_check', $ems, null, true); return true; } } else { @@ -118,11 +129,11 @@ class Ems /** * 清空指定邮箱验证码 * - * @param int $email 邮箱 + * @param string $email 邮箱 * @param string $event 事件 * @return boolean */ - public static function flush($email, $event = 'default') + public static function flush(string $email, string $event = 'default'): bool { \app\common\model\Ems:: where(['email' => $email, 'event' => $event]) diff --git a/application/common/library/Sms.php b/application/common/library/Sms.php index 56ec56d82689ef1ff8bed7ac72138bf28314c7e2..0ef847ada52062d5e6517342e5d19751a88be0e1 100644 --- a/application/common/library/Sms.php +++ b/application/common/library/Sms.php @@ -2,7 +2,12 @@ namespace app\common\library; +use PDOStatement; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; +use think\exception\DbException; use think\Hook; +use think\Model; /** * 短信验证码类 @@ -25,29 +30,32 @@ class Sms /** * 获取最后一次手机发送的数据 * - * @param int $mobile 手机号 - * @param string $event 事件 - * @return Sms + * @param string $mobile 手机号 + * @param string $event 事件 + * @return array|bool|PDOStatement|string|Model + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException */ - public static function get($mobile, $event = 'default') + public static function get(string $mobile, string $event = 'default') { $sms = \app\common\model\Sms:: where(['mobile' => $mobile, 'event' => $event]) ->order('id', 'DESC') ->find(); Hook::listen('sms_get', $sms, null, true); - return $sms ? $sms : null; + return $sms ?: null; } /** * 发送验证码 * - * @param int $mobile 手机号 - * @param int $code 验证码,为空时将自动生成4位数字 - * @param string $event 事件 - * @return boolean + * @param string $mobile 手机号 + * @param int|null $code 验证码,为空时将自动生成4位数字 + * @param string $event 事件 + * @return boolean */ - public static function send($mobile, $code = null, $event = 'default') + public static function send(string $mobile, int $code = null, string $event = 'default'): bool { $code = is_null($code) ? mt_rand(1000, 9999) : $code; $time = time(); @@ -64,12 +72,12 @@ class Sms /** * 发送通知 * - * @param mixed $mobile 手机号,多个以,分隔 - * @param string $msg 消息内容 - * @param string $template 消息模板 + * @param string $mobile 手机号,多个以,分隔 + * @param string $msg 消息内容 + * @param string|null $template 消息模板 * @return boolean */ - public static function notice($mobile, $msg = '', $template = null) + public static function notice(string $mobile, string $msg = '', string $template = null): bool { $params = [ 'mobile' => $mobile, @@ -77,18 +85,21 @@ class Sms 'template' => $template ]; $result = Hook::listen('sms_notice', $params, null, true); - return $result ? true : false; + return (bool)$result; } /** * 校验验证码 * - * @param int $mobile 手机号 - * @param int $code 验证码 - * @param string $event 事件 - * @return boolean + * @param string $mobile 手机号 + * @param int|null $code 验证码 + * @param string $event 事件 + * @return boolean + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ - public static function check($mobile, $code, $event = 'default') + public static function check(string $mobile,int $code, string $event = 'default'): bool { $time = time() - self::$expire; $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event]) @@ -118,11 +129,11 @@ class Sms /** * 清空指定手机号验证码 * - * @param int $mobile 手机号 + * @param string $mobile 手机号 * @param string $event 事件 * @return boolean */ - public static function flush($mobile, $event = 'default') + public static function flush(string $mobile, string $event = 'default'): bool { \app\common\model\Sms:: where(['mobile' => $mobile, 'event' => $event])