格式化代码

This commit is contained in:
liyukun 2022-01-03 12:26:39 +08:00
parent 9ccfbe2500
commit 88e9a6a50f
30 changed files with 390 additions and 308 deletions

View File

@ -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;
}

View File

@ -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()
{

View File

@ -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 = [])
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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
{

View File

@ -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
*/

View File

@ -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

View File

@ -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
{

View File

@ -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();
}
}

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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 = [])
{

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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($i<count($id)){
$sql.=$val.$str;
}else{
$sql.=$val;
if ($i < count($id)) {
$sql .= $val . $str;
} else {
$sql .= $val;
}
}
return $sql;
}else{
return $sql;
} else {
return $id;
}
}
/**
* 条件切割
* @param string $order
* @param string $file
* @return string
*/
public static function setOrder($order,$file='-'){
if(empty($order)) return '';
return str_replace($file,' ',$order);
public static function setOrder($order, $file = '-')
{
if (empty($order)) return '';
return str_replace($file, ' ', $order);
}
/**
* 获取时间段之间的model
* @param int|string $time
* @param string $ceil
* @return array
*/
public static function getModelTime($where,$model=null,$prefix='add_time',$data='data',$field=' - '){
public static function getModelTime($where, $model = null, $prefix = 'add_time', $data = 'data', $field = ' - ')
{
if ($model == null) $model = new self;
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;
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"," ","&nbsp;"],'',htmlspecialchars_decode($str))));
public static function HtmlToMbStr($str)
{
return trim(strip_tags(str_replace(["\n", "\t", "\r", " ", "&nbsp;"], '', 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

View File

@ -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
{

View File

@ -4,8 +4,6 @@
namespace app\common\model;
use app\common\model\BaseModel;
class SystemConfigTab extends BaseModel
{
/**

View File

@ -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
*/

View File

@ -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
{

View File

@ -93,7 +93,7 @@ class Ape extends TagLib
}
$parse = '<?php ';
$parse .= '$__LIST__ = ' . "tpl_get_article_list($typeId,\"$row\",\"$orderBy\",\"$model\",\"$type\",\"$where\",$display,\"$ids\");";;
$parse .= '$__LIST__ = ' . "tpl_get_article_list($typeId,\"$row\",\"$orderBy\",\"$model\",\"$type\",\"$where\",$display,\"$ids\");";
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '"}';
$parse .= $content;

View File

@ -121,7 +121,7 @@
location.href = href;
clearInterval(interval);
}
;
}, 1000);
})();
</script>

View File

@ -1,13 +1,19 @@
<?php
use think\facade\Db;
use think\Exception;
use app\common\constant\Data;
use app\common\model\DocumentCategoryContent;
use app\common\model\DocumentCategory;
use app\common\model\Document;
use app\common\model\Comment;
use \app\common\model\FriendLink;
use app\common\model\Document;
use app\common\model\DocumentCategory;
use app\common\model\DocumentCategoryContent;
use app\common\model\FriendLink;
use app\common\model\Tag;
use think\App;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\facade\Db;
// 应用公共文件
/**
@ -122,11 +128,11 @@ function get_document_category_by_name($name, $field = false)
* @param int $row
* @param string $where
* @param string $orderby
* @return DocumentCategory[]|array|bool|\think\Collection
* @return DocumentCategory[]|array|bool|Collection
* @throws Exception
* @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-12 21:48
*/
@ -309,14 +315,14 @@ function tpl_get_prenext($get, $cid = false, $none)
* @param $pageSize int 每页显示的数据数目
* @param $cid int 栏目分类id
* @param $type string 读取数据的方式son:'获取栏目下文章以及所有子孙分类文章',self:'获取栏目下文章',search:'获取关键字搜索的文章',where:'根据自定义条件获取文章where语句'
* @param string $table 文章内容扩展表名默认article
* @param string $table 文章内容扩展表名默认article
* @param bool $where 自定义条件
* @param int $display
* @return array
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
function tpl_get_list($orderBy, $pageSize, $cid, $type, $table = 'article', $where = false, $display = 1)
{
@ -368,7 +374,7 @@ function tpl_get_list($orderBy, $pageSize, $cid, $type, $table = 'article', $whe
case 'tag':
//读取指定tag的文章
$tag = substr(input('t'), 0, strpos(input('t'), '.')); //搜索关键词
$tagModel = new \app\common\model\Tag();
$tagModel = new Tag();
$tagList = $tagModel->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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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()
{