first commit

This commit is contained in:
Mr.Qin
2022-08-19 19:48:37 +08:00
commit afdd648b65
3275 changed files with 631084 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\common\model\system;
use think\Model;
use app\common\library\ParseData;
/**
* @mixin \think\Model
*/
class Admin extends \think\Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 关联管理组
*
* @return \think\model\relation\HasOne
*/
public function group(): \think\model\relation\HasOne
{
return $this->hasOne(AdminGroup::class, 'id', 'group_id');
}
/**
* 根据用户名/密码 进行登录判断
* @param $user
* @param $pwd
* @return Admin|array|mixed|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function checkLogin($user, $pwd)
{
$where[] = ['pwd', '=', encryptPwd(trim($pwd))];
if (filter_var($user, FILTER_VALIDATE_EMAIL)) {
$where[] = ['email', '=', htmlspecialchars(trim($user))];
} else {
$where[] = ['name', '=', htmlspecialchars(trim($user))];
}
return Admin::where($where)->find();
}
/**
* 根据用户名/验证码 进行数据查找
* @param $user
* @param $code
* @return Admin|array|mixed|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function checkForget($user, $code)
{
// 校验格式
if (filter_var($user, FILTER_VALIDATE_EMAIL)) {
$where[] = ['email', '=', $user];
} else {
$where[] = ['mobile', '=', $user];
}
$where[] = ['valicode', '=', $code];
return Admin::where($where)->find();
}
/**
* 设置创建IP
*/
public function setCreateIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取创建IP
*/
public function getCreateIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 设置登录IP
*/
public function setLoginIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取登录IP
*/
public function getLoginIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
}

View File

@@ -0,0 +1,17 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
/**
* @mixin \think\Model
*/
class AdminAccess extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
}

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace app\common\model\system;
use think\Model;
/**
* @mixin \think\Model
*/
class AdminGroup extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 获取无限极分类
* @access public static
* @param string $tips 名称格式
* @param int $pid 栏目父ID
* @param array $array 引用数组
* @param int $blank 替换字符
* @param int $level 栏目等级
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getListGroup(string $tips = '', int $pid = 0, array &$array = [], int $blank = 0, int $level = 0): array
{
// 获取所有分类
$result = self::where('pid', $pid)->select()->toArray();
foreach ($result as $key => $value) {
if (!empty($tips)) {
$cateName = $tips . $value['title'];
$value['title'] = str_repeat('', $blank) . $cateName;
}
$value['_level'] = $level;
$array[] = $value;
unset($result[$key]);
self::getListGroup($tips, $value['id'], $array, $blank + 1, $level + 1);
}
return $array;
}
}

View File

@@ -0,0 +1,195 @@
<?php
declare (strict_types=1);
namespace app\common\model\system;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class AdminRules extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 获取无限极分类
* @access public static
* @param string $tips 名称格式
* @param int $pid 栏目父ID
* @param array $array 引用数组
* @param int $blank 替换字符
* @param int $level 栏目等级
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getListRule(string $tips = '', int $pid = 0, array &$array = [], int $blank = 0, int $level = 0): array
{
$result = self::where('pid', $pid)->select()->toArray();
foreach ($result as $key => $value) {
if (!empty($tips)) {
$catename = $tips . $value['title'];
$value['title'] = str_repeat('', $blank) . $catename;
}
$value['_level'] = $level;
$array[] = $value;
unset($result[$key]);
self::getListRule($tips, $value['id'], $array, $blank + 1, $level + 1);
}
return $array;
}
/**
* 返回栏目树形结构
*
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getListTree()
{
$array = self::field('*,title as name')->order('sort asc')->select()->toArray();
foreach ($array as $key => $value) {
$array[$key]['name'] = __($value['name']);
$array[$key]['title'] = __($value['title']);
}
if (is_array($array) && !empty($array)) {
return list_to_tree($array);
}
}
/**
* 递归创建菜单
* @param array $list 菜单列表
* @param string $note
* @param mixed $parent 父类的name或pid
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function createMenu(array $list = [], string $note = '', $parent = 0)
{
$fields = array_flip(['title', 'router', 'alias', 'type', 'icon', 'note', 'status']);
foreach ($list as $key => $item) {
$data = array_intersect_key($item, $fields);
$data['pid'] = $parent;
$children = isset($item['children']) && $item['children'];
$data['type'] = $children ? 0 : $item['type'] ?? 1;
$data['note'] = $note;
$data['auth'] = $item['auth'] ?? 1;
$data['isSystem'] = $item['isSystem'] ?? 0;
$data['sort'] = $item['sort'] ?? self::count() + 1;
$data['alias'] = substr(str_replace('/', ':', $data['router']), 1);
$result = self::withTrashed()->where(['note' => $data['note'], 'pid' => $data['pid'], 'router' => $data['router']])->find();
if (empty($result)) {
$result = self::create($data);
} else {
$result->where('id', $result->id)->update($data);
}
if ($children) {
self::createMenu($item['children'], $note, $result['id']);
}
}
}
/**
* 启用菜单
* @param string $name
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function enabled(string $name)
{
$list = self::getNoteByMenus($name);
foreach ($list as $item) {
$item->restore();
}
}
/**
* 禁用菜单
* @param string $name
* @param bool $force
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function disabled(string $name, bool $force = false)
{
$list = self::getNoteByMenus($name);
foreach ($list as $item) {
self::destroy($item['id'], $force);
}
}
/**
* 导出指定名称的菜单规则
* @param string $name
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function export(string $name): array
{
$list = self::field('id,pid,title,router,icon,auth,type')->where('note', $name)->select()->toArray();
return self::parseMenuChildren(list_to_tree($list));
}
/**
* 解析菜单/子菜单
* @param array $list
* @return array
*/
protected static function parseMenuChildren(array $list): array
{
foreach ($list as $key => $value) {
unset($list[$key]['id']);
unset($list[$key]['pid']);
if (isset($value['children'])) {
$list[$key]['children'] = self::parseMenuChildren($value['children']);
}
}
return $list;
}
/**
* 根据名称获取规则IDS
* @param string $name
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getNoteByMenus(string $name)
{
return self::withTrashed()->where('note', $name)->select();
}
/**
* 字段修改器
*
* @param [type] $value
* @return void
*/
public function setSortAttr($value)
{
if (is_empty($value)) {
return self::max('id') + 1;
}
return $value;
}
}

View File

@@ -0,0 +1,32 @@
<?php
declare (strict_types=1);
namespace app\common\model\system;
use think\Model;
/**
* @mixin \think\Model
*/
class Attachment extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 获取文件大小
* @access public
* @param $filesize
* @return string
*/
public function getFilesizeAttr($filesize): string
{
if (!empty($filesize)) {
return format_bytes($filesize);
}
return $filesize;
}
}

View File

@@ -0,0 +1,16 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
/**
* @mixin \think\Model
*/
class Company extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
}

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\common\model\system;
use think\Model;
/**
* @mixin \think\Model
*/
class Config extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 获取系统配置
*
* @param string $name
* @param bool $group
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function all(string $name = '', bool $group = false): array
{
$config = [];
$where = $group ? ['group' => $name] : [];
$list = self::where($where)->select()->toArray();
foreach ($list as $option) {
if (!is_empty($option['type']) && 'array' == trim($option['type'])) {
$config[$option['name']] = json_decode($option['value'], true);
} else {
$config[$option['name']] = $option['value'];
}
}
return $config;
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use think\facade\Db;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class Department extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 树形分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getListTree(): array
{
$array = self::select()->toArray();
if (is_array($array) && !empty($array)) {
return list_to_tree($array);
}
return [];
}
// 字段修改器
public function setSortAttr($value)
{
if (is_empty($value)) {
return self::max('id') + 1;
}
return $value;
}
}

View File

@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class Dictionary extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
// 字段修改器
public function setSortAttr($value)
{
if (is_empty($value)) {
return self::max('id') + 1;
}
return $value;
}
/**
* 获取字典信息
* @param string $value
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getValueList(string $value = ''): array
{
$list = [];
$data = self::where([
'pid' => 0,
'value' => $value
])->find();
if (!empty($data)) {
$list = self::where('pid', $data['id'])->select();
}
return $list;
}
/**
* 返回最小id
* @return int
*/
public static function minId(): int
{
return (int)self::where('pid', '0')->min('id');
}
}

View File

@@ -0,0 +1,38 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class Jobs extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
/**
* 树形分类
*/
public static function getListTree()
{
$array = self::select()->toArray();
if (is_array($array) && !empty($array)) {
return list_to_tree($array);
}
}
// 字段修改器
public function setSortAttr($value)
{
if (is_empty($value)) {
return self::max('id') + 1;
}
return $value;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\common\model\system;
use think\Model;
/**
* login_log
* 登录日志
* @package app\admin\model\system
*/
class LoginLog extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $deleteTime = false;
}

View File

@@ -0,0 +1,20 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class Project extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
}

View File

@@ -0,0 +1,55 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use app\common\library\ParseData;
/**
* @mixin \think\Model
*/
class SystemLog extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
// 写入日志
public static function write($logs = null)
{
if (!empty($logs) && is_array($logs)) {
try {
self::create($logs);
}
catch (\Throwable $th) {
if (preg_match('/\'(.*?)\'/',$th->getMessage(),$matches)) {
$logs[$matches[1]] = '0'; // 字节太长
self::write($logs);
}
}
}
}
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public function setIPAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public function getIPAttr($ip)
{
return ParseData::getIPAttr($ip);
}
}

View File

@@ -0,0 +1,196 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use app\common\library\ParseData;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class User extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
// 定义第三方关联
public function third(): \think\model\relation\HasMany
{
return $this->hasMany(UserThird::class,'user_id');
}
/**
* 关联用户组
*
* @return \think\model\relation\HasOne
*/
public function group(): \think\model\relation\HasOne
{
return $this->hasOne(UserGroup::class,'id','group_id');
}
/**
* 注册会员前
* @param object $model
* @return void
*/
public static function onBeforeInsert(object $model)
{}
/**
* 更新会员前
* @param object $model
* @return void
*/
public static function onBeforeUpdate(object $model)
{}
/**
* 注册会员后
* @param object $model
* @return void
*/
public static function onAfterInsert(object $model)
{}
/**
* 更新会员数据
* @param object $model
* @return void
*/
public static function onAfterUpdate(object $model)
{}
/**
* 获取头像
* @param string $value
* @param array $data
* @return string
*/
public function getAvatarAttr(string $value, array $data): string
{
if ($value && strpos($value,'://')) {
return $value;
}
if (empty($value)) {
$value = '/static/images/user_default.jpg';
}
$prefix = cdn_Prefix();
if (!empty($prefix) && $value) {
if (!str_contains($value,'data:image')) {
return $prefix.$value;
}
}
return $value;
}
/**
* 设置头像
* @param string $value
* @param array $data
* @return string
*/
public function setAvatarAttr(string $value, array $data): string
{
return ParseData::setImageAttr($value, $data);
}
/**
* 登录时间
*/
public function getLoginTimeAttr($value)
{
if (!empty($value)) {
$value = date('Y-m-d H:i:s',$value);
}
return $value;
}
/**
* 设置创建IP
* @param $ip
* @return mixed
*/
public function setCreateIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取创建IP
* @param $ip
* @return mixed
*/
public function getCreateIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 设置登录IP
* @param $ip
* @return mixed
*/
public function setLoginIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取登录IP
*/
public function getLoginIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public function setIPAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public function getIPAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 减少会员积分
*
* @param integer $id
* @param integer $score
* @return void
*/
public static function reduceScore(int $id = 0, int $score = 0)
{
try {
if ($score) {
self::where('id', $id)->dec('score', $score)->update();
}
} catch (\Throwable $th) {
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\Model;
use think\facade\Db;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class UserGroup extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 关联用户组
*
* @return int|\think\model\relation\HasMany
*/
public function userTotal()
{
return $this->hasMany(User::class,'group_id','id');
}
/**
* 获取用户组
*
* @param integer $id
* @param boolean $mark
* @return void|array
* @throws DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function ToObtain(int $id = 0, bool $mark = true)
{
$groupList = system_cache('groupList');
if (empty($groupList)) {
$groupList = self::select()->toArray();
system_cache('groupList',$groupList,86400);
}
return $groupList;
}
}

View File

@@ -0,0 +1,17 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
/**
* @mixin \think\Model
*/
class UserThird extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updatetime = 'update_time';
}

View File

@@ -0,0 +1,42 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use app\common\library\ParseData;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class UserValidate extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public function setIPAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public function getIPAttr($ip)
{
return ParseData::getIPAttr($ip);
}
}