格式化代码

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; namespace app\common\extend;
use Exception;
use Firebase\JWT\BeforeValidException;
use Firebase\JWT\ExpiredException;
use Firebase\JWT\JWT as jt; use Firebase\JWT\JWT as jt;
use Firebase\JWT\SignatureInvalidException;
/** /**
* Class Jwt * Class Jwt
@ -42,16 +46,16 @@ class Jwt
$data = jt::decode(trim(ltrim($token, 'Bearer')), $salt, ["HS256"]); $data = jt::decode(trim(ltrim($token, 'Bearer')), $salt, ["HS256"]);
$data = (array)$data; $data = (array)$data;
return (array)$data['data']; return (array)$data['data'];
} catch (\Firebase\JWT\SignatureInvalidException $e) { } catch (SignatureInvalidException $e) {
$status['msg'] = "签名不正确"; $status['msg'] = "签名不正确";
return $status; return $status;
} catch (\Firebase\JWT\BeforeValidException $e) { } catch (BeforeValidException $e) {
$status['msg'] = "token失效"; $status['msg'] = "token失效";
return $status; return $status;
} catch (\Firebase\JWT\ExpiredException $e) { } catch (ExpiredException $e) {
$status['msg'] = "token失效"; $status['msg'] = "token失效";
return $status; return $status;
} catch (\Exception $e) { } catch (Exception $e) {
$status['msg'] = "未知错误"; $status['msg'] = "未知错误";
return $status; return $status;
} }

View File

@ -3,8 +3,9 @@
namespace app\common\model; namespace app\common\model;
use app\common\model\BaseModel; use think\db\exception\DataNotFoundException;
use think\facade\Cache; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Session; use think\facade\Session;
/** /**
@ -19,9 +20,9 @@ class Admin extends BaseModel
* @param $username * @param $username
* @param $pwd * @param $pwd
* @return bool * @return bool
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function login(string $username, string $pwd): bool public static function login(string $username, string $pwd): bool
{ {
@ -72,9 +73,9 @@ class Admin extends BaseModel
* 列表 * 列表
* @param array $where * @param array $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function systemPage(array $where): array public static function systemPage(array $where): array
{ {
@ -103,9 +104,9 @@ class Admin extends BaseModel
* @param int $id * @param int $id
* @param string $field * @param string $field
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getAdminInfoById(int $id, string $field = '*'): array public static function getAdminInfoById(int $id, string $field = '*'): array
{ {
@ -120,9 +121,9 @@ class Admin extends BaseModel
/** /**
* 人员列表 * 人员列表
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function lst() public static function lst()
{ {

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 int $pid
* @param array $auth * @param array $auth
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getMenu(int $pid = 0, array $auth = []): array public static function getMenu(int $pid = 0, array $auth = []): array
{ {
@ -68,9 +70,9 @@ class AdminAuth extends BaseModel
* 权限列表 * 权限列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function systemPage($where): array public static function systemPage($where): array
{ {
@ -88,9 +90,9 @@ class AdminAuth extends BaseModel
* @param int $pid * @param int $pid
* @param array $auth * @param array $auth
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function lst(int $pid = 0, array $auth = []): array public static function lst(int $pid = 0, array $auth = []): array
{ {
@ -153,9 +155,9 @@ class AdminAuth extends BaseModel
/** /**
* 返回选择项 * 返回选择项
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function returnOptions(): array public static function returnOptions(): array
{ {
@ -186,9 +188,9 @@ class AdminAuth extends BaseModel
* @param array $auth * @param array $auth
* @param array $list * @param array $list
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function selectAndBuildTree(int $pid = 0, array $auth = [], array $list = []) public static function selectAndBuildTree(int $pid = 0, array $auth = [], array $list = [])
{ {

View File

@ -4,7 +4,7 @@
namespace app\common\model; namespace app\common\model;
use app\common\model\BaseModel; use think\db\exception\DbException;
/** /**
* 操作日志 * 操作日志
@ -40,7 +40,7 @@ class AdminLog extends BaseModel
* 日志列表 * 日志列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DbException * @throws DbException
*/ */
public static function systemPage($where) public static function systemPage($where)
{ {

View File

@ -4,7 +4,10 @@
namespace app\common\model; 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 * @param array $where
* @return \think\Paginator * @return Paginator
* @throws \think\db\exception\DbException * @throws DbException
*/ */
public static function systemPage(array $where) public static function systemPage(array $where)
{ {
@ -47,9 +50,9 @@ class AdminNotify extends BaseModel
* 后台首页获取通知信息 * 后台首页获取通知信息
* @param int $num * @param int $num
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function pageList(int $num) public static function pageList(int $num)
{ {

View File

@ -4,8 +4,10 @@
namespace app\common\model; namespace app\common\model;
use app\common\model\BaseModel;
use FormBuilder\Factory\Elm; 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 * 获取所有角色ids
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getAuthLst(): array public static function getAuthLst(): array
{ {
@ -52,9 +54,9 @@ class AdminRole extends BaseModel
* @param int $pid * @param int $pid
* @param array $auth * @param array $auth
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function systemPage(int $pid = -1): array public static function systemPage(int $pid = -1): array
{ {
@ -71,9 +73,9 @@ class AdminRole extends BaseModel
* @param int $pid * @param int $pid
* @param array $auth * @param array $auth
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function lst(int $pid = 0, array $auth = []): array public static function lst(int $pid = 0, array $auth = []): array
{ {
@ -107,9 +109,9 @@ class AdminRole extends BaseModel
/** /**
* 返回选择项 * 返回选择项
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function returnOptions(): array public static function returnOptions(): array
{ {

View File

@ -3,6 +3,10 @@
namespace app\common\model; namespace app\common\model;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* Class Advert * Class Advert
* @package app\common\model * @package app\common\model
@ -15,9 +19,9 @@ class Advert extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -4,9 +4,6 @@
namespace app\common\model; namespace app\common\model;
use app\common\model\BaseModel;
use app\common\model\SystemConfig;
/** /**
* Class attachment * Class attachment
* @package app\admin\model\widget * @package app\admin\model\widget

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * Class AttachmentCategory
@ -18,9 +20,9 @@ class AttachmentCategory extends BaseModel
* @param int $pid * @param int $pid
* @param bool $lower * @param bool $lower
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getCategoryLst(string $type = "image", int $pid = 0, bool $lower = false) 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 int $pid
* @param string $title * @param string $title
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function buildNodes(string $type = "images", int $pid = 0, string $title = "") public static function buildNodes(string $type = "images", int $pid = 0, string $title = "")
{ {
@ -90,9 +92,9 @@ class AttachmentCategory extends BaseModel
/** /**
* 返回选择项 * 返回选择项
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function returnOptions(): array public static function returnOptions(): array
{ {

View File

@ -11,25 +11,10 @@ class BaseModel extends Model
{ {
use ModelTrait; use ModelTrait;
private static $errorMsg;
private static $transaction = 0;
private static $DbInstance = [];
const DEFAULT_ERROR_MSG = '操作失败,请稍候再试!'; const DEFAULT_ERROR_MSG = '操作失败,请稍候再试!';
private static $errorMsg;
/** private static $transaction = 0;
* 设置错误信息 private static $DbInstance = [];
* @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;
}
/** /**
* 获取错误信息 * 获取错误信息
@ -49,22 +34,6 @@ class BaseModel extends Model
Db::startTrans(); Db::startTrans();
} }
/**
* 提交事务
*/
public static function commitTrans()
{
Db::commit();
}
/**
* 关闭事务
*/
public static function rollbackTrans()
{
Db::rollback();
}
/** /**
* 根据结果提交滚回事务 * 根据结果提交滚回事务
* @param $res * @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; namespace app\common\model;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* Class Comment * Class Comment
* @package app\common\model * @package app\common\model
@ -15,9 +19,9 @@ class Comment extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -3,6 +3,10 @@
namespace app\common\model; namespace app\common\model;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* Class Document * Class Document
* @package app\admin\model\system * @package app\admin\model\system
@ -15,9 +19,9 @@ class Document extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * Class DocumentArticle
@ -18,9 +20,9 @@ class DocumentArticle extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -3,7 +3,9 @@
namespace app\common\model; 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 * Class DocumentCategory
@ -17,9 +19,9 @@ class DocumentCategory extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-11-08 0:25 * @date 2021-11-08 0:25
*/ */
@ -37,9 +39,9 @@ class DocumentCategory extends BaseModel
* @param int $type * @param int $type
* @param array $ids * @param array $ids
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function selectByType(int $type = 0, array $ids = []) public static function selectByType(int $type = 0, array $ids = [])
{ {

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * Class DocumentCategoryContent
@ -18,9 +20,9 @@ class DocumentCategoryContent extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * Class DocumentProduct
@ -18,9 +20,9 @@ class DocumentProduct extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * Class FriendLink
@ -18,9 +20,9 @@ class FriendLink extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * Class InvitationCode
@ -18,9 +20,9 @@ class InvitationCode extends BaseModel
* 邀请码列表 * 邀请码列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -3,6 +3,10 @@
namespace app\common\model; namespace app\common\model;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* Class Document * Class Document
* @package app\admin\model\system * @package app\admin\model\system
@ -15,9 +19,9 @@ class MessageForm extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -4,6 +4,7 @@
namespace app\common\model; namespace app\common\model;
use think\db\Raw;
use think\Model; use think\Model;
trait ModelTrait trait ModelTrait
@ -33,7 +34,8 @@ trait ModelTrait
} }
} }
public static function all($function){ public static function all($function)
{
$query = self::newQuery(); $query = self::newQuery();
$function($query); $function($query);
return $query->select(); return $query->select();
@ -153,9 +155,10 @@ trait ModelTrait
* @param string $like 模糊查找 关键字 * @param string $like 模糊查找 关键字
* @return array * @return array
*/ */
public static function setWherePage($model=null,$where=[],$field=[],$fieldOr=[],$fun=null,$like='LIKE'){ 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(); if (!is_array($where) || !is_array($field)) return false;
if ($model === null) $model = new self();
//处理等于行查询 //处理等于行查询
foreach ($field as $key => $item) { foreach ($field as $key => $item) {
if (($count = strpos($item, '.')) === false) { if (($count = strpos($item, '.')) === false) {
@ -194,59 +197,68 @@ trait ModelTrait
* @param string $str * @param string $str
* @return string * @return string
*/ */
private static function get_field($id,$str='|'){ private static function get_field($id, $str = '|')
if(is_array($id)){ {
$sql=""; if (is_array($id)) {
$i=0; $sql = "";
foreach($id as $val){ $i = 0;
foreach ($id as $val) {
$i++; $i++;
if($i<count($id)){ if ($i < count($id)) {
$sql.=$val.$str; $sql .= $val . $str;
}else{ } else {
$sql.=$val; $sql .= $val;
} }
} }
return $sql; return $sql;
}else{ } else {
return $id; return $id;
} }
} }
/** /**
* 条件切割 * 条件切割
* @param string $order * @param string $order
* @param string $file * @param string $file
* @return string * @return string
*/ */
public static function setOrder($order,$file='-'){ public static function setOrder($order, $file = '-')
if(empty($order)) return ''; {
return str_replace($file,' ',$order); if (empty($order)) return '';
return str_replace($file, ' ', $order);
} }
/** /**
* 获取时间段之间的model * 获取时间段之间的model
* @param int|string $time * @param int|string $time
* @param string $ceil * @param string $ceil
* @return array * @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 ($model == null) $model = new self;
if(!isset($where[$data])) return $model; if (!isset($where[$data])) return $model;
switch ($where[$data]){ switch ($where[$data]) {
case 'today':case 'week':case 'month':case 'year':case 'yesterday': case 'today':
$model=$model->whereTime($prefix,$where[$data]); case 'week':
break; case 'month':
case 'year':
case 'yesterday':
$model = $model->whereTime($prefix, $where[$data]);
break;
case 'quarter': case 'quarter':
list($startTime,$endTime)=self::getMonth(); list($startTime, $endTime) = self::getMonth();
$model = $model->where($prefix, '>', strtotime($startTime)); $model = $model->where($prefix, '>', strtotime($startTime));
$model = $model->where($prefix, '<', strtotime($endTime)); $model = $model->where($prefix, '<', strtotime($endTime));
break; break;
case 'lately7': case 'lately7':
$model = $model->where($prefix,'between',[strtotime("-7 day"),time()]); $model = $model->where($prefix, 'between', [strtotime("-7 day"), time()]);
break; break;
case 'lately30': case 'lately30':
$model = $model->where($prefix,'between',[strtotime("-30 day"),time()]); $model = $model->where($prefix, 'between', [strtotime("-30 day"), time()]);
break; break;
default: default:
if(strstr($where[$data],$field)!==false){ if (strstr($where[$data], $field) !== false) {
list($startTime, $endTime) = explode($field, $where[$data]); list($startTime, $endTime) = explode($field, $where[$data]);
$model = $model->where($prefix, '>', strtotime($startTime)); $model = $model->where($prefix, '>', strtotime($startTime));
$model = $model->where($prefix, '<', strtotime($endTime)); $model = $model->where($prefix, '<', strtotime($endTime));
@ -255,14 +267,17 @@ trait ModelTrait
} }
return $model; return $model;
} }
/** /**
* 获取去除html去除空格去除软回车,软换行,转换过后的字符串 * 获取去除html去除空格去除软回车,软换行,转换过后的字符串
* @param string $str * @param string $str
* @return string * @return string
*/ */
public static function HtmlToMbStr($str){ public static function HtmlToMbStr($str)
return trim(strip_tags(str_replace(["\n","\t","\r"," ","&nbsp;"],'',htmlspecialchars_decode($str)))); {
return trim(strip_tags(str_replace(["\n", "\t", "\r", " ", "&nbsp;"], '', htmlspecialchars_decode($str))));
} }
/** /**
* 截取中文指定字节 * 截取中文指定字节
* @param string $str * @param string $str
@ -271,27 +286,31 @@ trait ModelTrait
* @param string $file * @param string $file
* @return string * @return string
*/ */
public static function getSubstrUTf8($str,$utf8len=100,$chaet='UTF-8',$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; if (mb_strlen($str, $chaet) > $utf8len) {
$str = mb_substr($str, 0, $utf8len, $chaet) . $file;
} }
return $str; return $str;
} }
/** /**
* 获取本季度 time * 获取本季度 time
* @param int|string $time * @param int|string $time
* @param string $ceil * @param string $ceil
* @return array * @return array
*/ */
public static function getMonth($time='',$ceil=0){ public static function getMonth($time = '', $ceil = 0)
if($ceil!=0) {
$season = ceil(date('n') /3)-$ceil; if ($ceil != 0)
$season = ceil(date('n') / 3) - $ceil;
else else
$season = ceil(date('n') /3); $season = ceil(date('n') / 3);
$firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y'))); $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'))); $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
return array($firstday,$lastday); return array($firstday, $lastday);
} }
/** /**
* 高精度 加法 * 高精度 加法
* @param int|string $uid id * @param int|string $uid id
@ -301,15 +320,15 @@ trait ModelTrait
* @param int $acc 精度 * @param int $acc 精度
* @return bool * @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(); $model = new self();
if($keyField === null) $keyField = $model->getPk(); if ($keyField === null) $keyField = $model->getPk();
$result = self::where($keyField,$key)->find(); $result = self::where($keyField, $key)->find();
if(!$result) return false; if (!$result) return false;
$new = bcadd($result[$incField],$inc,$acc); $new = bcadd($result[$incField], $inc, $acc);
return false !== $model->where($keyField,$key)->update([$incField=>$new]); return false !== $model->where($keyField, $key)->update([$incField => $new]);
} }
@ -323,16 +342,16 @@ trait ModelTrait
* @param int $acc 精度 * @param int $acc 精度
* @return bool * @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(); $model = new self();
if($keyField === null) $keyField = $model->getPk(); if ($keyField === null) $keyField = $model->getPk();
$result = self::where($keyField,$key)->find(); $result = self::where($keyField, $key)->find();
if(!$result) return false; if (!$result) return false;
if(!$minus && $result[$decField] < $dec) return false; if (!$minus && $result[$decField] < $dec) return false;
$new = bcsub($result[$decField],$dec,$acc); $new = bcsub($result[$decField], $dec, $acc);
return false !== $model->where($keyField,$key)->update([$decField=>$new]); 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 * @return int
*/ */
public static function counts($model): int public static function counts($model): int

View File

@ -4,7 +4,9 @@
namespace app\common\model; 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 * @param int $tab_id
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function lst($where): array public static function lst($where): array
{ {
@ -36,9 +38,9 @@ class SystemConfig extends BaseModel
* 获取字段值 * 获取字段值
* @param string $formName * @param string $formName
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getValueByFormName(string $formName): string public static function getValueByFormName(string $formName): string
{ {
@ -63,9 +65,9 @@ class SystemConfig extends BaseModel
* 获取字段值 * 获取字段值
* @param string $formNames * @param string $formNames
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getValuesByFormNames(array $formNames): array public static function getValuesByFormNames(array $formNames): array
{ {
@ -80,9 +82,9 @@ class SystemConfig extends BaseModel
* 获取参数 * 获取参数
* @param int $tab_id * @param int $tab_id
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function getLstByTabId(int $tab_id = 0): array public static function getLstByTabId(int $tab_id = 0): array
{ {

View File

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

View File

@ -3,6 +3,12 @@
namespace app\common\model; 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 * Class Tag
* @package app\common\model * @package app\common\model
@ -15,9 +21,9 @@ class Tag extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */
@ -41,8 +47,8 @@ class Tag extends BaseModel
* @param $tags * @param $tags
* @param $document_id * @param $document_id
* @param $user_id * @param $user_id
* @return \think\Collection * @return Collection
* @throws \Exception * @throws Exception
* @author 李玉坤 * @author 李玉坤
* @date 2021-11-08 0:53 * @date 2021-11-08 0:53
*/ */
@ -69,9 +75,9 @@ class Tag extends BaseModel
* 列表 * 列表
* @param $where * @param $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-02-15 23:24 * @date 2021-02-15 23:24
*/ */

View File

@ -3,7 +3,9 @@
namespace app\common\model; 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; use think\facade\Session;
/** /**
@ -15,7 +17,7 @@ use think\facade\Session;
*/ */
class User extends BaseModel 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"]; "ip", "status", "remark", "is_admin", "create_time", "update_time"];
/** /**
@ -23,9 +25,9 @@ class User extends BaseModel
* @param $name * @param $name
* @param $pwd * @param $pwd
* @return bool * @return bool
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function login(string $name, string $pwd): bool public static function login(string $name, string $pwd): bool
{ {
@ -60,15 +62,15 @@ class User extends BaseModel
public static function addAdminUser($data) public static function addAdminUser($data)
{ {
$insertData = []; $insertData = [];
foreach (self::$adminColumn as $key){ foreach (self::$adminColumn as $key) {
if (isset($data[$key])) { if (isset($data[$key])) {
$insertData[$key] = $data[$key]; $insertData[$key] = $data[$key];
} }
} }
if (!empty($insertData)){ if (!empty($insertData)) {
//标识后台用户 //标识后台用户
$insertData['is_admin'] = 1; $insertData['is_admin'] = 1;
return self::insert($insertData,true); return self::insert($insertData, true);
} }
return false; return false;
} }
@ -81,16 +83,16 @@ class User extends BaseModel
* @author 李玉坤 * @author 李玉坤
* @date 2022-01-03 3:48 * @date 2022-01-03 3:48
*/ */
public static function updateAdminUser($id ,$data) public static function updateAdminUser($id, $data)
{ {
$updateData = []; $updateData = [];
foreach (self::$adminColumn as $key){ foreach (self::$adminColumn as $key) {
if (isset($data[$key])) { if (isset($data[$key])) {
$updateData[$key] = $data[$key]; $updateData[$key] = $data[$key];
} }
} }
if (!empty($updateData)){ if (!empty($updateData)) {
return self::update($updateData,['id'=>$id]); return self::update($updateData, ['id' => $id]);
} }
return false; return false;
} }
@ -119,9 +121,9 @@ class User extends BaseModel
* 列表 * 列表
* @param array $where * @param array $where
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function systemPage(array $where): array public static function systemPage(array $where): array
{ {

View File

@ -93,7 +93,7 @@ class Ape extends TagLib
} }
$parse = '<?php '; $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 .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '"}'; $parse .= '{volist name="__LIST__" id="' . $void . '"}';
$parse .= $content; $parse .= $content;

View File

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

View File

@ -1,13 +1,19 @@
<?php <?php
use think\facade\Db;
use think\Exception;
use app\common\constant\Data; 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\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 int $row
* @param string $where * @param string $where
* @param string $orderby * @param string $orderby
* @return DocumentCategory[]|array|bool|\think\Collection * @return DocumentCategory[]|array|bool|Collection
* @throws Exception * @throws Exception
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-11-12 21:48 * @date 2021-11-12 21:48
*/ */
@ -309,14 +315,14 @@ function tpl_get_prenext($get, $cid = false, $none)
* @param $pageSize int 每页显示的数据数目 * @param $pageSize int 每页显示的数据数目
* @param $cid int 栏目分类id * @param $cid int 栏目分类id
* @param $type string 读取数据的方式son:'获取栏目下文章以及所有子孙分类文章',self:'获取栏目下文章',search:'获取关键字搜索的文章',where:'根据自定义条件获取文章where语句' * @param $type string 读取数据的方式son:'获取栏目下文章以及所有子孙分类文章',self:'获取栏目下文章',search:'获取关键字搜索的文章',where:'根据自定义条件获取文章where语句'
* @param string $table 文章内容扩展表名默认article * @param string $table 文章内容扩展表名默认article
* @param bool $where 自定义条件 * @param bool $where 自定义条件
* @param int $display * @param int $display
* @return array * @return array
* @throws Exception * @throws Exception
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
function tpl_get_list($orderBy, $pageSize, $cid, $type, $table = 'article', $where = false, $display = 1) 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': case 'tag':
//读取指定tag的文章 //读取指定tag的文章
$tag = substr(input('t'), 0, strpos(input('t'), '.')); //搜索关键词 $tag = substr(input('t'), 0, strpos(input('t'), '.')); //搜索关键词
$tagModel = new \app\common\model\Tag(); $tagModel = new Tag();
$tagList = $tagModel->where('name', $tag)->select()->toArray(); $tagList = $tagModel->where('name', $tag)->select()->toArray();
$documentListModel = $documentListModel->where('a.id', 'in', array_column($tagList, 'document_id')); $documentListModel = $documentListModel->where('a.id', 'in', array_column($tagList, 'document_id'));
break; break;
@ -563,10 +569,10 @@ function tpl_get_friend_link($type, $row)
* 广告 * 广告
* @param $type * @param $type
* @param $row * @param $row
* @return array|mixed|object|\think\App|\think\Collection|Db[] * @return array|mixed|object|App|Collection|Db[]
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-07-26 23:24 * @date 2021-07-26 23:24
*/ */
@ -658,16 +664,17 @@ function tpl_get_position($dc, $positionList = array())
return tpl_get_position($parentDc, $positionList); return tpl_get_position($parentDc, $positionList);
} }
function get_comment_children($parentIds){ function get_comment_children($parentIds)
$list = $commentModel = Comment::where('status', 1)->where('pid','in', $parentIds)->select()->toArray(); {
if (empty($list)){ $list = $commentModel = Comment::where('status', 1)->where('pid', 'in', $parentIds)->select()->toArray();
if (empty($list)) {
return $list; return $list;
} }
foreach ($list as &$item){ foreach ($list as &$item) {
$item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();; $item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();
} }
unset($item); 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 int $pageSize
* @param string $orderBy * @param string $orderBy
* @return array * @return array
* @throws \think\db\exception\DbException * @throws DbException
* @author 李玉坤 * @author 李玉坤
* @date 2021-12-05 23:54 * @date 2021-12-05 23:54
*/ */
@ -706,7 +713,7 @@ function tpl_get_comment_list($id, $type, $pageSize, $orderBy)
} }
$lists = []; $lists = [];
foreach ($commentModel as $key => $item) { 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; $lists[$key] = $item;
} }
return [ return [
@ -745,10 +752,10 @@ function get_comment_count($documentId, $type = 'top')
* @param $documentId * @param $documentId
* @param $row * @param $row
* @param string $table * @param string $table
* @return Document[]|array|\think\Collection * @return Document[]|array|Collection
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-11-28 1:02 * @date 2021-11-28 1:02
*/ */

View File

@ -3,14 +3,18 @@
namespace app\index\controller; namespace app\index\controller;
use app\admin\extend\Util as Util; use app\admin\extend\Util as Util;
use app\common\model\Document; use app\common\constant\Data;
use app\common\model\DocumentCategory;
use app\common\model\DocumentCategoryContent;
use app\common\model\Comment as commentModel; 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\common\model\Tag as TagModel;
use app\Request; 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 think\facade\Log;
use app\common\constant\Data;
/** /**
* 应用入口 * 应用入口
@ -22,10 +26,10 @@ class Article extends Base
/** /**
* 列表页 * 列表页
* @return string * @return string
* @throws \think\Exception * @throws Exception
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-10-29 0:17 * @date 2021-10-29 0:17
*/ */
@ -101,10 +105,10 @@ class Article extends Base
/** /**
* 详情页 * 详情页
* @return string * @return string
* @throws \think\Exception * @throws Exception
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-10-29 0:17 * @date 2021-10-29 0:17
*/ */
@ -140,7 +144,7 @@ class Article extends Base
$article['position'] = tpl_get_position($dc); $article['position'] = tpl_get_position($dc);
//更新浏览次数 //更新浏览次数
$documentModel->where('id', $article['id'])->inc('view')->update(); $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)) { if (!is_file($templateFile)) {
$this->error('模板文件不存在!'); $this->error('模板文件不存在!');
} }
@ -188,10 +192,10 @@ class Article extends Base
if ($data['email'] == "") $this->error("邮箱不能为空"); if ($data['email'] == "") $this->error("邮箱不能为空");
if ($data['url'] == "") $this->error("url不能为空"); if ($data['url'] == "") $this->error("url不能为空");
if ($data['content'] == "") $this->error("内容能为空"); 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); $res = commentModel::create($data);
if ($res) { if ($res) {
$this->success('提交成功',url('detail',['id'=>$data['document_id']])); $this->success('提交成功', url('detail', ['id' => $data['document_id']]));
} else { } else {
$this->error('提交失败,请联系站长查看', null); $this->error('提交失败,请联系站长查看', null);
} }
@ -200,9 +204,9 @@ class Article extends Base
/** /**
* 文章标签页面 * 文章标签页面
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-10-29 0:19 * @date 2021-10-29 0:19
*/ */
@ -258,9 +262,9 @@ class Article extends Base
/** /**
* 搜索页面 * 搜索页面
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-10-29 0:18 * @date 2021-10-29 0:18
*/ */

View File

@ -3,11 +3,14 @@
namespace app\index\controller; namespace app\index\controller;
use app\admin\extend\Util as Util; 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\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 * @param Request $request
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-10-17 1:03 * @date 2021-10-17 1:03
*/ */
@ -83,9 +86,9 @@ class Index extends Base
* 留言 * 留言
* @param Request $request * @param Request $request
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @author 李玉坤 * @author 李玉坤
* @date 2021-10-17 1:03 * @date 2021-10-17 1:03
*/ */

View File

@ -6,15 +6,20 @@
namespace app\index\controller; namespace app\index\controller;
use app\common\model\User as userModel;
use app\admin\extend\Util; 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 class Login extends Base
{ {
/** /**
* 登录 * 登录
* @return string * @return string
* @throws \Exception * @throws Exception
*/ */
public function login() public function login()
{ {
@ -25,9 +30,9 @@ class Login extends Base
/** /**
* 验证登录 * 验证登录
* @return mixed * @return mixed
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function verify() public function verify()
{ {
@ -43,7 +48,7 @@ class Login extends Base
/** /**
* 注册 * 注册
* @return string * @return string
* @throws \Exception * @throws Exception
*/ */
public function register() public function register()
{ {
@ -53,7 +58,7 @@ class Login extends Base
/** /**
* 忘记密码 * 忘记密码
* @return string * @return string
* @throws \Exception * @throws Exception
*/ */
public function forget() public function forget()
{ {
@ -63,7 +68,7 @@ class Login extends Base
/** /**
* 退出登陆 * 退出登陆
* @return mixed * @return mixed
* @throws \Exception * @throws Exception
*/ */
public function logout() public function logout()
{ {
@ -78,7 +83,7 @@ class Login extends Base
/** /**
* 验证码 * 验证码
* @return \think\Response * @return Response
*/ */
public function captcha() public function captcha()
{ {