From 88e9a6a50f652ca2ac230a4541866c6e4666228e Mon Sep 17 00:00:00 2001 From: liyukun <1099438829@qq.com> Date: Mon, 3 Jan 2022 12:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/extend/Jwt.php | 12 +- app/common/model/Admin.php | 29 ++-- app/common/model/AdminAuth.php | 34 ++--- app/common/model/AdminLog.php | 4 +- app/common/model/AdminNotify.php | 15 ++- app/common/model/AdminRole.php | 28 ++-- app/common/model/Advert.php | 10 +- app/common/model/Attachment.php | 3 - app/common/model/AttachmentCategory.php | 22 ++-- app/common/model/BaseModel.php | 65 +++++---- app/common/model/Comment.php | 10 +- app/common/model/Document.php | 10 +- app/common/model/DocumentArticle.php | 10 +- app/common/model/DocumentCategory.php | 16 ++- app/common/model/DocumentCategoryContent.php | 10 +- app/common/model/DocumentProduct.php | 10 +- app/common/model/FriendLink.php | 10 +- app/common/model/InvitationCode.php | 10 +- app/common/model/MessageForm.php | 10 +- app/common/model/ModelTrait.php | 131 +++++++++++-------- app/common/model/SystemConfig.php | 28 ++-- app/common/model/SystemConfigTab.php | 2 - app/common/model/Tag.php | 22 ++-- app/common/model/User.php | 32 ++--- app/common/taglib/Ape.php | 2 +- app/common/tpl/dispatch_jump.tpl | 2 +- app/index/common.php | 69 +++++----- app/index/controller/Article.php | 46 ++++--- app/index/controller/Index.php | 23 ++-- app/index/controller/Login.php | 23 ++-- 30 files changed, 390 insertions(+), 308 deletions(-) diff --git a/app/common/extend/Jwt.php b/app/common/extend/Jwt.php index b65e602..8edfb52 100644 --- a/app/common/extend/Jwt.php +++ b/app/common/extend/Jwt.php @@ -3,7 +3,11 @@ namespace app\common\extend; +use Exception; +use Firebase\JWT\BeforeValidException; +use Firebase\JWT\ExpiredException; use Firebase\JWT\JWT as jt; +use Firebase\JWT\SignatureInvalidException; /** * Class Jwt @@ -42,16 +46,16 @@ class Jwt $data = jt::decode(trim(ltrim($token, 'Bearer')), $salt, ["HS256"]); $data = (array)$data; return (array)$data['data']; - } catch (\Firebase\JWT\SignatureInvalidException $e) { + } catch (SignatureInvalidException $e) { $status['msg'] = "签名不正确"; return $status; - } catch (\Firebase\JWT\BeforeValidException $e) { + } catch (BeforeValidException $e) { $status['msg'] = "token失效"; return $status; - } catch (\Firebase\JWT\ExpiredException $e) { + } catch (ExpiredException $e) { $status['msg'] = "token失效"; return $status; - } catch (\Exception $e) { + } catch (Exception $e) { $status['msg'] = "未知错误"; return $status; } diff --git a/app/common/model/Admin.php b/app/common/model/Admin.php index 7bcba7a..27464bf 100644 --- a/app/common/model/Admin.php +++ b/app/common/model/Admin.php @@ -3,8 +3,9 @@ namespace app\common\model; -use app\common\model\BaseModel; -use think\facade\Cache; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; use think\facade\Session; /** @@ -19,9 +20,9 @@ class Admin extends BaseModel * @param $username * @param $pwd * @return bool - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function login(string $username, string $pwd): bool { @@ -72,9 +73,9 @@ class Admin extends BaseModel * 列表 * @param array $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function systemPage(array $where): array { @@ -103,9 +104,9 @@ class Admin extends BaseModel * @param int $id * @param string $field * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getAdminInfoById(int $id, string $field = '*'): array { @@ -120,9 +121,9 @@ class Admin extends BaseModel /** * 人员列表 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function lst() { diff --git a/app/common/model/AdminAuth.php b/app/common/model/AdminAuth.php index 0ef3dba..9f2acdb 100644 --- a/app/common/model/AdminAuth.php +++ b/app/common/model/AdminAuth.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * 操作权限 @@ -43,9 +45,9 @@ class AdminAuth extends BaseModel * @param int $pid * @param array $auth * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getMenu(int $pid = 0, array $auth = []): array { @@ -68,9 +70,9 @@ class AdminAuth extends BaseModel * 权限列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function systemPage($where): array { @@ -88,9 +90,9 @@ class AdminAuth extends BaseModel * @param int $pid * @param array $auth * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function lst(int $pid = 0, array $auth = []): array { @@ -153,9 +155,9 @@ class AdminAuth extends BaseModel /** * 返回选择项 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function returnOptions(): array { @@ -186,9 +188,9 @@ class AdminAuth extends BaseModel * @param array $auth * @param array $list * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function selectAndBuildTree(int $pid = 0, array $auth = [], array $list = []) { diff --git a/app/common/model/AdminLog.php b/app/common/model/AdminLog.php index e4ee39c..e01018a 100644 --- a/app/common/model/AdminLog.php +++ b/app/common/model/AdminLog.php @@ -4,7 +4,7 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DbException; /** * 操作日志 @@ -40,7 +40,7 @@ class AdminLog extends BaseModel * 日志列表 * @param $where * @return array - * @throws \think\db\exception\DbException + * @throws DbException */ public static function systemPage($where) { diff --git a/app/common/model/AdminNotify.php b/app/common/model/AdminNotify.php index aad6044..1c008e9 100644 --- a/app/common/model/AdminNotify.php +++ b/app/common/model/AdminNotify.php @@ -4,7 +4,10 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\Paginator; /** * 消息通知 @@ -16,8 +19,8 @@ class AdminNotify extends BaseModel /** * 系统分页 * @param array $where - * @return \think\Paginator - * @throws \think\db\exception\DbException + * @return Paginator + * @throws DbException */ public static function systemPage(array $where) { @@ -47,9 +50,9 @@ class AdminNotify extends BaseModel * 后台首页获取通知信息 * @param int $num * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function pageList(int $num) { diff --git a/app/common/model/AdminRole.php b/app/common/model/AdminRole.php index 95a7906..11afd3c 100644 --- a/app/common/model/AdminRole.php +++ b/app/common/model/AdminRole.php @@ -4,8 +4,10 @@ namespace app\common\model; -use app\common\model\BaseModel; use FormBuilder\Factory\Elm; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * 操作角色 @@ -27,9 +29,9 @@ class AdminRole extends BaseModel /** * 获取所有角色ids * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getAuthLst(): array { @@ -52,9 +54,9 @@ class AdminRole extends BaseModel * @param int $pid * @param array $auth * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function systemPage(int $pid = -1): array { @@ -71,9 +73,9 @@ class AdminRole extends BaseModel * @param int $pid * @param array $auth * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function lst(int $pid = 0, array $auth = []): array { @@ -107,9 +109,9 @@ class AdminRole extends BaseModel /** * 返回选择项 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function returnOptions(): array { diff --git a/app/common/model/Advert.php b/app/common/model/Advert.php index 6792f8d..193b25c 100644 --- a/app/common/model/Advert.php +++ b/app/common/model/Advert.php @@ -3,6 +3,10 @@ namespace app\common\model; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + /** * Class Advert * @package app\common\model @@ -15,9 +19,9 @@ class Advert extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/Attachment.php b/app/common/model/Attachment.php index 2815a5e..abdaf4f 100644 --- a/app/common/model/Attachment.php +++ b/app/common/model/Attachment.php @@ -4,9 +4,6 @@ namespace app\common\model; -use app\common\model\BaseModel; -use app\common\model\SystemConfig; - /** * Class attachment * @package app\admin\model\widget diff --git a/app/common/model/AttachmentCategory.php b/app/common/model/AttachmentCategory.php index c43fc1c..f9002e7 100644 --- a/app/common/model/AttachmentCategory.php +++ b/app/common/model/AttachmentCategory.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class AttachmentCategory @@ -18,9 +20,9 @@ class AttachmentCategory extends BaseModel * @param int $pid * @param bool $lower * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getCategoryLst(string $type = "image", int $pid = 0, bool $lower = false) { @@ -52,9 +54,9 @@ class AttachmentCategory extends BaseModel * @param int $pid * @param string $title * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function buildNodes(string $type = "images", int $pid = 0, string $title = "") { @@ -90,9 +92,9 @@ class AttachmentCategory extends BaseModel /** * 返回选择项 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function returnOptions(): array { diff --git a/app/common/model/BaseModel.php b/app/common/model/BaseModel.php index 39084c4..9891e7f 100644 --- a/app/common/model/BaseModel.php +++ b/app/common/model/BaseModel.php @@ -11,25 +11,10 @@ class BaseModel extends Model { use ModelTrait; - private static $errorMsg; - - private static $transaction = 0; - - private static $DbInstance = []; - const DEFAULT_ERROR_MSG = '操作失败,请稍候再试!'; - - /** - * 设置错误信息 - * @param string $errorMsg - * @return bool - */ - protected static function setErrorInfo($errorMsg = self::DEFAULT_ERROR_MSG, $rollback = false) - { - if ($rollback) self::rollbackTrans(); - self::$errorMsg = $errorMsg; - return false; - } + private static $errorMsg; + private static $transaction = 0; + private static $DbInstance = []; /** * 获取错误信息 @@ -49,22 +34,6 @@ class BaseModel extends Model Db::startTrans(); } - /** - * 提交事务 - */ - public static function commitTrans() - { - Db::commit(); - } - - /** - * 关闭事务 - */ - public static function rollbackTrans() - { - Db::rollback(); - } - /** * 根据结果提交滚回事务 * @param $res @@ -78,4 +47,32 @@ class BaseModel extends Model } } + /** + * 提交事务 + */ + public static function commitTrans() + { + Db::commit(); + } + + /** + * 设置错误信息 + * @param string $errorMsg + * @return bool + */ + protected static function setErrorInfo($errorMsg = self::DEFAULT_ERROR_MSG, $rollback = false) + { + if ($rollback) self::rollbackTrans(); + self::$errorMsg = $errorMsg; + return false; + } + + /** + * 关闭事务 + */ + public static function rollbackTrans() + { + Db::rollback(); + } + } \ No newline at end of file diff --git a/app/common/model/Comment.php b/app/common/model/Comment.php index ebd8724..84fcfe4 100644 --- a/app/common/model/Comment.php +++ b/app/common/model/Comment.php @@ -3,6 +3,10 @@ namespace app\common\model; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + /** * Class Comment * @package app\common\model @@ -15,9 +19,9 @@ class Comment extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/Document.php b/app/common/model/Document.php index 13cfb96..e6cf180 100644 --- a/app/common/model/Document.php +++ b/app/common/model/Document.php @@ -3,6 +3,10 @@ namespace app\common\model; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + /** * Class Document * @package app\admin\model\system @@ -15,9 +19,9 @@ class Document extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/DocumentArticle.php b/app/common/model/DocumentArticle.php index 6785fcf..b1d6872 100644 --- a/app/common/model/DocumentArticle.php +++ b/app/common/model/DocumentArticle.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class DocumentArticle @@ -18,9 +20,9 @@ class DocumentArticle extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/DocumentCategory.php b/app/common/model/DocumentCategory.php index 8eb1e21..27611c8 100644 --- a/app/common/model/DocumentCategory.php +++ b/app/common/model/DocumentCategory.php @@ -3,7 +3,9 @@ namespace app\common\model; -use think\facade\Db; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class DocumentCategory @@ -17,9 +19,9 @@ class DocumentCategory extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-11-08 0:25 */ @@ -37,9 +39,9 @@ class DocumentCategory extends BaseModel * @param int $type * @param array $ids * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function selectByType(int $type = 0, array $ids = []) { diff --git a/app/common/model/DocumentCategoryContent.php b/app/common/model/DocumentCategoryContent.php index 10be76a..a8330bd 100644 --- a/app/common/model/DocumentCategoryContent.php +++ b/app/common/model/DocumentCategoryContent.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class DocumentCategoryContent @@ -18,9 +20,9 @@ class DocumentCategoryContent extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/DocumentProduct.php b/app/common/model/DocumentProduct.php index 4af7873..a5b0d41 100644 --- a/app/common/model/DocumentProduct.php +++ b/app/common/model/DocumentProduct.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class DocumentProduct @@ -18,9 +20,9 @@ class DocumentProduct extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/FriendLink.php b/app/common/model/FriendLink.php index 1cefaab..d465d9e 100644 --- a/app/common/model/FriendLink.php +++ b/app/common/model/FriendLink.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class FriendLink @@ -18,9 +20,9 @@ class FriendLink extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/InvitationCode.php b/app/common/model/InvitationCode.php index 6b6b682..475a47c 100644 --- a/app/common/model/InvitationCode.php +++ b/app/common/model/InvitationCode.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * Class InvitationCode @@ -18,9 +20,9 @@ class InvitationCode extends BaseModel * 邀请码列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/MessageForm.php b/app/common/model/MessageForm.php index 20cb4d4..9037652 100644 --- a/app/common/model/MessageForm.php +++ b/app/common/model/MessageForm.php @@ -3,6 +3,10 @@ namespace app\common\model; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + /** * Class Document * @package app\admin\model\system @@ -15,9 +19,9 @@ class MessageForm extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/ModelTrait.php b/app/common/model/ModelTrait.php index 9ad1d2a..8c16efd 100644 --- a/app/common/model/ModelTrait.php +++ b/app/common/model/ModelTrait.php @@ -4,6 +4,7 @@ namespace app\common\model; +use think\db\Raw; use think\Model; trait ModelTrait @@ -33,7 +34,8 @@ trait ModelTrait } } - public static function all($function){ + public static function all($function) + { $query = self::newQuery(); $function($query); return $query->select(); @@ -153,9 +155,10 @@ trait ModelTrait * @param string $like 模糊查找 关键字 * @return array */ - public static function setWherePage($model=null,$where=[],$field=[],$fieldOr=[],$fun=null,$like='LIKE'){ - if(!is_array($where) || !is_array($field)) return false; - if($model===null) $model=new self(); + public static function setWherePage($model = null, $where = [], $field = [], $fieldOr = [], $fun = null, $like = 'LIKE') + { + if (!is_array($where) || !is_array($field)) return false; + if ($model === null) $model = new self(); //处理等于行查询 foreach ($field as $key => $item) { if (($count = strpos($item, '.')) === false) { @@ -194,59 +197,68 @@ trait ModelTrait * @param string $str * @return string */ - private static function get_field($id,$str='|'){ - if(is_array($id)){ - $sql=""; - $i=0; - foreach($id as $val){ + private static function get_field($id, $str = '|') + { + if (is_array($id)) { + $sql = ""; + $i = 0; + foreach ($id as $val) { $i++; - if($iwhereTime($prefix,$where[$data]); - break; + if (!isset($where[$data])) return $model; + switch ($where[$data]) { + case 'today': + case 'week': + case 'month': + case 'year': + case 'yesterday': + $model = $model->whereTime($prefix, $where[$data]); + break; case 'quarter': - list($startTime,$endTime)=self::getMonth(); + list($startTime, $endTime) = self::getMonth(); $model = $model->where($prefix, '>', strtotime($startTime)); $model = $model->where($prefix, '<', strtotime($endTime)); break; case 'lately7': - $model = $model->where($prefix,'between',[strtotime("-7 day"),time()]); + $model = $model->where($prefix, 'between', [strtotime("-7 day"), time()]); break; case 'lately30': - $model = $model->where($prefix,'between',[strtotime("-30 day"),time()]); + $model = $model->where($prefix, 'between', [strtotime("-30 day"), time()]); break; default: - if(strstr($where[$data],$field)!==false){ + if (strstr($where[$data], $field) !== false) { list($startTime, $endTime) = explode($field, $where[$data]); $model = $model->where($prefix, '>', strtotime($startTime)); $model = $model->where($prefix, '<', strtotime($endTime)); @@ -255,14 +267,17 @@ trait ModelTrait } return $model; } + /** * 获取去除html去除空格去除软回车,软换行,转换过后的字符串 * @param string $str * @return string */ - public static function HtmlToMbStr($str){ - return trim(strip_tags(str_replace(["\n","\t","\r"," "," "],'',htmlspecialchars_decode($str)))); + public static function HtmlToMbStr($str) + { + return trim(strip_tags(str_replace(["\n", "\t", "\r", " ", " "], '', htmlspecialchars_decode($str)))); } + /** * 截取中文指定字节 * @param string $str @@ -271,27 +286,31 @@ trait ModelTrait * @param string $file * @return string */ - public static function getSubstrUTf8($str,$utf8len=100,$chaet='UTF-8',$file='....'){ - if(mb_strlen($str,$chaet)>$utf8len){ - $str=mb_substr($str,0,$utf8len,$chaet).$file; + public static function getSubstrUTf8($str, $utf8len = 100, $chaet = 'UTF-8', $file = '....') + { + if (mb_strlen($str, $chaet) > $utf8len) { + $str = mb_substr($str, 0, $utf8len, $chaet) . $file; } return $str; } + /** * 获取本季度 time * @param int|string $time * @param string $ceil * @return array */ - public static function getMonth($time='',$ceil=0){ - if($ceil!=0) - $season = ceil(date('n') /3)-$ceil; + public static function getMonth($time = '', $ceil = 0) + { + if ($ceil != 0) + $season = ceil(date('n') / 3) - $ceil; else - $season = ceil(date('n') /3); - $firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y'))); - $lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y'))); - return array($firstday,$lastday); + $season = ceil(date('n') / 3); + $firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y'))); + $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y'))); + return array($firstday, $lastday); } + /** * 高精度 加法 * @param int|string $uid id @@ -301,15 +320,15 @@ trait ModelTrait * @param int $acc 精度 * @return bool */ - public static function bcInc($key, $incField, $inc, $keyField = null, $acc=2) + public static function bcInc($key, $incField, $inc, $keyField = null, $acc = 2) { - if(!is_numeric($inc)) return false; + if (!is_numeric($inc)) return false; $model = new self(); - if($keyField === null) $keyField = $model->getPk(); - $result = self::where($keyField,$key)->find(); - if(!$result) return false; - $new = bcadd($result[$incField],$inc,$acc); - return false !== $model->where($keyField,$key)->update([$incField=>$new]); + if ($keyField === null) $keyField = $model->getPk(); + $result = self::where($keyField, $key)->find(); + if (!$result) return false; + $new = bcadd($result[$incField], $inc, $acc); + return false !== $model->where($keyField, $key)->update([$incField => $new]); } @@ -323,16 +342,16 @@ trait ModelTrait * @param int $acc 精度 * @return bool */ - public static function bcDec($key, $decField, $dec, $keyField = null, $minus = false, $acc=2) + public static function bcDec($key, $decField, $dec, $keyField = null, $minus = false, $acc = 2) { - if(!is_numeric($dec)) return false; + if (!is_numeric($dec)) return false; $model = new self(); - if($keyField === null) $keyField = $model->getPk(); - $result = self::where($keyField,$key)->find(); - if(!$result) return false; - if(!$minus && $result[$decField] < $dec) return false; - $new = bcsub($result[$decField],$dec,$acc); - return false !== $model->where($keyField,$key)->update([$decField=>$new]); + if ($keyField === null) $keyField = $model->getPk(); + $result = self::where($keyField, $key)->find(); + if (!$result) return false; + if (!$minus && $result[$decField] < $dec) return false; + $new = bcsub($result[$decField], $dec, $acc); + return false !== $model->where($keyField, $key)->update([$decField => $new]); } /** @@ -346,7 +365,7 @@ trait ModelTrait /** * 数据个数 - * @param string|\think\db\Raw $model + * @param string|Raw $model * @return int */ public static function counts($model): int diff --git a/app/common/model/SystemConfig.php b/app/common/model/SystemConfig.php index 3f31294..4ffe76e 100644 --- a/app/common/model/SystemConfig.php +++ b/app/common/model/SystemConfig.php @@ -4,7 +4,9 @@ namespace app\common\model; -use app\common\model\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * 系统配置 @@ -17,9 +19,9 @@ class SystemConfig extends BaseModel * 列表 * @param int $tab_id * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function lst($where): array { @@ -36,9 +38,9 @@ class SystemConfig extends BaseModel * 获取字段值 * @param string $formName * @return string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getValueByFormName(string $formName): string { @@ -63,9 +65,9 @@ class SystemConfig extends BaseModel * 获取字段值 * @param string $formNames * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getValuesByFormNames(array $formNames): array { @@ -80,9 +82,9 @@ class SystemConfig extends BaseModel * 获取参数 * @param int $tab_id * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function getLstByTabId(int $tab_id = 0): array { diff --git a/app/common/model/SystemConfigTab.php b/app/common/model/SystemConfigTab.php index 3982f8a..108056d 100644 --- a/app/common/model/SystemConfigTab.php +++ b/app/common/model/SystemConfigTab.php @@ -4,8 +4,6 @@ namespace app\common\model; -use app\common\model\BaseModel; - class SystemConfigTab extends BaseModel { /** diff --git a/app/common/model/Tag.php b/app/common/model/Tag.php index 47a338c..15acf73 100644 --- a/app/common/model/Tag.php +++ b/app/common/model/Tag.php @@ -3,6 +3,12 @@ namespace app\common\model; +use Exception; +use think\Collection; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + /** * Class Tag * @package app\common\model @@ -15,9 +21,9 @@ class Tag extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ @@ -41,8 +47,8 @@ class Tag extends BaseModel * @param $tags * @param $document_id * @param $user_id - * @return \think\Collection - * @throws \Exception + * @return Collection + * @throws Exception * @author 李玉坤 * @date 2021-11-08 0:53 */ @@ -69,9 +75,9 @@ class Tag extends BaseModel * 列表 * @param $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-02-15 23:24 */ diff --git a/app/common/model/User.php b/app/common/model/User.php index 89ba085..7cbd479 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -3,7 +3,9 @@ namespace app\common\model; -use think\facade\Cache; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; use think\facade\Session; /** @@ -15,7 +17,7 @@ use think\facade\Session; */ class User extends BaseModel { - public static $adminColumn = [ "username", "nickname", "password", "avatar", "mail", "tel", + public static $adminColumn = ["username", "nickname", "password", "avatar", "mail", "tel", "ip", "status", "remark", "is_admin", "create_time", "update_time"]; /** @@ -23,9 +25,9 @@ class User extends BaseModel * @param $name * @param $pwd * @return bool - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function login(string $name, string $pwd): bool { @@ -60,15 +62,15 @@ class User extends BaseModel public static function addAdminUser($data) { $insertData = []; - foreach (self::$adminColumn as $key){ + foreach (self::$adminColumn as $key) { if (isset($data[$key])) { $insertData[$key] = $data[$key]; } } - if (!empty($insertData)){ + if (!empty($insertData)) { //标识后台用户 $insertData['is_admin'] = 1; - return self::insert($insertData,true); + return self::insert($insertData, true); } return false; } @@ -81,16 +83,16 @@ class User extends BaseModel * @author 李玉坤 * @date 2022-01-03 3:48 */ - public static function updateAdminUser($id ,$data) + public static function updateAdminUser($id, $data) { $updateData = []; - foreach (self::$adminColumn as $key){ + foreach (self::$adminColumn as $key) { if (isset($data[$key])) { $updateData[$key] = $data[$key]; } } - if (!empty($updateData)){ - return self::update($updateData,['id'=>$id]); + if (!empty($updateData)) { + return self::update($updateData, ['id' => $id]); } return false; } @@ -119,9 +121,9 @@ class User extends BaseModel * 列表 * @param array $where * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public static function systemPage(array $where): array { diff --git a/app/common/taglib/Ape.php b/app/common/taglib/Ape.php index 255406a..f59407b 100644 --- a/app/common/taglib/Ape.php +++ b/app/common/taglib/Ape.php @@ -93,7 +93,7 @@ class Ape extends TagLib } $parse = ''; $parse .= '{volist name="__LIST__" id="' . $void . '"}'; $parse .= $content; diff --git a/app/common/tpl/dispatch_jump.tpl b/app/common/tpl/dispatch_jump.tpl index e6fc6af..d70b404 100644 --- a/app/common/tpl/dispatch_jump.tpl +++ b/app/common/tpl/dispatch_jump.tpl @@ -121,7 +121,7 @@ location.href = href; clearInterval(interval); } - ; + }, 1000); })(); diff --git a/app/index/common.php b/app/index/common.php index ad1d367..80c7cf5 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -1,13 +1,19 @@ where('name', $tag)->select()->toArray(); $documentListModel = $documentListModel->where('a.id', 'in', array_column($tagList, 'document_id')); break; @@ -563,10 +569,10 @@ function tpl_get_friend_link($type, $row) * 广告 * @param $type * @param $row - * @return array|mixed|object|\think\App|\think\Collection|Db[] - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @return array|mixed|object|App|Collection|Db[] + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-07-26 23:24 */ @@ -658,16 +664,17 @@ function tpl_get_position($dc, $positionList = array()) return tpl_get_position($parentDc, $positionList); } -function get_comment_children($parentIds){ - $list = $commentModel = Comment::where('status', 1)->where('pid','in', $parentIds)->select()->toArray(); - if (empty($list)){ +function get_comment_children($parentIds) +{ + $list = $commentModel = Comment::where('status', 1)->where('pid', 'in', $parentIds)->select()->toArray(); + if (empty($list)) { return $list; } - foreach ($list as &$item){ - $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();; + foreach ($list as &$item) { + $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build(); } unset($item); - return array_merge($list,get_comment_children(array_column($list,'id'))); + return array_merge($list, get_comment_children(array_column($list, 'id'))); } /** @@ -677,7 +684,7 @@ function get_comment_children($parentIds){ * @param int $pageSize * @param string $orderBy * @return array - * @throws \think\db\exception\DbException + * @throws DbException * @author 李玉坤 * @date 2021-12-05 23:54 */ @@ -706,7 +713,7 @@ function tpl_get_comment_list($id, $type, $pageSize, $orderBy) } $lists = []; foreach ($commentModel as $key => $item) { - $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();; + $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build(); $lists[$key] = $item; } return [ @@ -745,10 +752,10 @@ function get_comment_count($documentId, $type = 'top') * @param $documentId * @param $row * @param string $table - * @return Document[]|array|\think\Collection - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @return Document[]|array|Collection + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-11-28 1:02 */ diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 6a5ab6b..b108341 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -3,14 +3,18 @@ namespace app\index\controller; use app\admin\extend\Util as Util; -use app\common\model\Document; -use app\common\model\DocumentCategory; -use app\common\model\DocumentCategoryContent; +use app\common\constant\Data; use app\common\model\Comment as commentModel; +use app\common\model\Document; +use app\common\model\DocumentCategory; +use app\common\model\DocumentCategoryContent; use app\common\model\Tag as TagModel; use app\Request; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\Exception; use think\facade\Log; -use app\common\constant\Data; /** * 应用入口 @@ -22,10 +26,10 @@ class Article extends Base /** * 列表页 * @return string - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws Exception + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-10-29 0:17 */ @@ -101,10 +105,10 @@ class Article extends Base /** * 详情页 * @return string - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws Exception + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-10-29 0:17 */ @@ -140,7 +144,7 @@ class Article extends Base $article['position'] = tpl_get_position($dc); //更新浏览次数 $documentModel->where('id', $article['id'])->inc('view')->update(); - $templateFile = config('view.view_path') . 'article/' . $articleType.'.html'; + $templateFile = config('view.view_path') . 'article/' . $articleType . '.html'; if (!is_file($templateFile)) { $this->error('模板文件不存在!'); } @@ -188,10 +192,10 @@ class Article extends Base if ($data['email'] == "") $this->error("邮箱不能为空"); if ($data['url'] == "") $this->error("url不能为空"); if ($data['content'] == "") $this->error("内容能为空"); - $data['status'] = web_config('comment_review')?0:1; + $data['status'] = web_config('comment_review') ? 0 : 1; $res = commentModel::create($data); if ($res) { - $this->success('提交成功',url('detail',['id'=>$data['document_id']])); + $this->success('提交成功', url('detail', ['id' => $data['document_id']])); } else { $this->error('提交失败,请联系站长查看', null); } @@ -200,9 +204,9 @@ class Article extends Base /** * 文章标签页面 * @return string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-10-29 0:19 */ @@ -258,9 +262,9 @@ class Article extends Base /** * 搜索页面 * @return string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-10-29 0:18 */ diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 37acf76..412b2f6 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -3,11 +3,14 @@ namespace app\index\controller; use app\admin\extend\Util as Util; -use app\common\model\FriendLink as friendLinkModel; -use app\common\validate\MessageForm as MessageformValidate; -use app\common\model\MessageForm as MessageFormModel; -use app\Request; use app\common\constant\Data; +use app\common\model\FriendLink as friendLinkModel; +use app\common\model\MessageForm as MessageFormModel; +use app\common\validate\MessageForm as MessageformValidate; +use app\Request; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * 应用入口 @@ -38,9 +41,9 @@ class Index extends Base * 友链申请 * @param Request $request * @return string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-10-17 1:03 */ @@ -83,9 +86,9 @@ class Index extends Base * 留言 * @param Request $request * @return string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @author 李玉坤 * @date 2021-10-17 1:03 */ diff --git a/app/index/controller/Login.php b/app/index/controller/Login.php index 874f64e..801c220 100644 --- a/app/index/controller/Login.php +++ b/app/index/controller/Login.php @@ -6,15 +6,20 @@ namespace app\index\controller; -use app\common\model\User as userModel; use app\admin\extend\Util; +use app\common\model\User as userModel; +use Exception; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\Response; class Login extends Base { /** * 登录 * @return string - * @throws \Exception + * @throws Exception */ public function login() { @@ -25,9 +30,9 @@ class Login extends Base /** * 验证登录 * @return mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public function verify() { @@ -43,7 +48,7 @@ class Login extends Base /** * 注册 * @return string - * @throws \Exception + * @throws Exception */ public function register() { @@ -53,7 +58,7 @@ class Login extends Base /** * 忘记密码 * @return string - * @throws \Exception + * @throws Exception */ public function forget() { @@ -63,7 +68,7 @@ class Login extends Base /** * 退出登陆 * @return mixed - * @throws \Exception + * @throws Exception */ public function logout() { @@ -78,7 +83,7 @@ class Login extends Base /** * 验证码 - * @return \think\Response + * @return Response */ public function captcha() {