init
This commit is contained in:
15
code/app/model/AdminNodeModel.php
Normal file
15
code/app/model/AdminNodeModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminNodeModel extends BaseModel
|
||||
{
|
||||
protected $name = 'admin_node';
|
||||
protected $pk = 'an_id';
|
||||
}
|
||||
47
code/app/model/AdminRoleModel.php
Normal file
47
code/app/model/AdminRoleModel.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminRoleModel extends BaseModel
|
||||
{
|
||||
protected $name = 'admin_role';
|
||||
protected $pk = 'ar_id';
|
||||
|
||||
public function getRoleNodeByCache($intArId)
|
||||
{
|
||||
$strCacheKey = 'Admin:Role:Node:'.$intArId;
|
||||
|
||||
$arrRoleNode = Cache::get($strCacheKey);
|
||||
|
||||
if($arrRoleNode === NULL)
|
||||
{
|
||||
$AdminRoleNodeModel = new AdminRoleNodeModel();
|
||||
|
||||
$AdminRoleNodeModel = $AdminRoleNodeModel->alias('arn')
|
||||
->field('an.an_url')
|
||||
->leftjoin('admin_node an','an.an_id=arn.an_id');
|
||||
|
||||
if($intArId>0)
|
||||
{
|
||||
$AdminRoleNodeModel = $AdminRoleNodeModel->where('arn.ar_id',$intArId);
|
||||
}
|
||||
|
||||
$arrRoleNode = $AdminRoleNodeModel
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$arrRoleNode = array_column($arrRoleNode, 'an_url');
|
||||
|
||||
// Cache::set($strCacheKey,$arrRoleNode);
|
||||
}
|
||||
|
||||
return $arrRoleNode;
|
||||
}
|
||||
}
|
||||
15
code/app/model/AdminRoleNodeModel.php
Normal file
15
code/app/model/AdminRoleNodeModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminRoleNodeModel extends BaseModel
|
||||
{
|
||||
protected $name = 'admin_role_node';
|
||||
protected $pk = 'arn_id';
|
||||
}
|
||||
92
code/app/model/AdminUserModel.php
Normal file
92
code/app/model/AdminUserModel.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
use think\helper\Str;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminUserModel extends BaseModel
|
||||
{
|
||||
protected $name = 'admin_user';
|
||||
|
||||
protected $pk = 'au_id';
|
||||
|
||||
protected $token = "";
|
||||
|
||||
// protected $hidden = ['au_pwd'];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $strToken
|
||||
* @return AdminUserModel|NULL
|
||||
*/
|
||||
static public function getUserByToken($strToken = "")
|
||||
{
|
||||
if ($strToken == "") {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$strKey = "AdminToken:" . $strToken;
|
||||
|
||||
$intAuId = Cache::get($strKey);
|
||||
|
||||
if (empty($intAuId)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$AdminUserModel = self::getAdminUserModelByCache($intAuId);
|
||||
|
||||
$AdminUserModel->token = $strToken;
|
||||
|
||||
$AdminUserModel->refreshToken();
|
||||
|
||||
return $AdminUserModel;
|
||||
}
|
||||
|
||||
public function checkRole()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function createToken()
|
||||
{
|
||||
$this->token = Str::random(32);
|
||||
|
||||
$this->refreshToken();
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
public function refreshToken()
|
||||
{
|
||||
Cache::set("AdminToken:" . $this->token, $this->au_id, 3600);
|
||||
}
|
||||
|
||||
static public function getAdminUserModelByCache($intAuId, $boolForceUpdate = false)
|
||||
{
|
||||
$strKey = "AdminUser:Id:" . $intAuId;
|
||||
|
||||
$AdminUserModel = Cache::get($strKey);
|
||||
|
||||
if (empty($AdminUserModel) || $boolForceUpdate == true) {
|
||||
$AdminUserModel = self::where('au_id', $intAuId)->find();
|
||||
|
||||
if (empty($AdminUserModel)) {
|
||||
throw new \Exception("用户不存在", 9999);
|
||||
}
|
||||
$AdminUserModel->au_pwd = "";
|
||||
|
||||
Cache::set($strKey, $AdminUserModel);
|
||||
}
|
||||
|
||||
return $AdminUserModel;
|
||||
}
|
||||
}
|
||||
33
code/app/model/AutoSwitchViewModel.php
Normal file
33
code/app/model/AutoSwitchViewModel.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Request;
|
||||
|
||||
class AutoSwitchViewModel
|
||||
{
|
||||
static public function getViewConfig(): array
|
||||
{
|
||||
$Request = request();
|
||||
|
||||
$strDomain = $Request->rootDomain();
|
||||
|
||||
$DomainModel = DomainModel::getDomainByCache($strDomain);
|
||||
|
||||
$TemplatesModel = TemplatesModel::getValByCode($DomainModel->t_id);
|
||||
|
||||
$Request->DomainModel = $DomainModel;
|
||||
|
||||
$Request->TemplatesModel = $TemplatesModel;
|
||||
|
||||
return [
|
||||
'type' => 'Think',
|
||||
'auto_rule' => 3,
|
||||
'view_dir_name' => 'view',
|
||||
'view_suffix' => 'html',
|
||||
'view_path' => root_path($TemplatesModel->t_path),
|
||||
];
|
||||
}
|
||||
}
|
||||
21
code/app/model/BaseModel.php
Normal file
21
code/app/model/BaseModel.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class BaseModel extends Model
|
||||
{
|
||||
public function fill($arrData)
|
||||
{
|
||||
foreach ($arrData as $strKey => $strVal) {
|
||||
$this->$strKey = $strVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
code/app/model/CaiJiPeiZhiModel.php
Normal file
39
code/app/model/CaiJiPeiZhiModel.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class CaiJiPeiZhiModel extends BaseModel
|
||||
{
|
||||
protected $name = 'cai_ji_pei_zhi';
|
||||
protected $pk = 'cjpz_id';
|
||||
|
||||
static $arrCaiJiPeiZhi = [];
|
||||
|
||||
static public function getValByCode($strCode)
|
||||
{
|
||||
if (self::$arrCaiJiPeiZhi == []) {
|
||||
self::$arrCaiJiPeiZhi = Cache::get('CaiJiPeiZhi');
|
||||
|
||||
if (empty(self::$arrCaiJiPeiZhi)) {
|
||||
self::flushCache();
|
||||
self::$arrCaiJiPeiZhi = Cache::get('CaiJiPeiZhi');
|
||||
}
|
||||
}
|
||||
|
||||
return self::$arrCaiJiPeiZhi[$strCode] ?? NULL;
|
||||
}
|
||||
|
||||
static public function flushCache()
|
||||
{
|
||||
$arrCaiJiPeiZhi = self::column('cjpz_val', 'cjpz_code');
|
||||
Cache::tag('CaiJiPeiZhi')->set('CaiJiPeiZhi', $arrCaiJiPeiZhi);
|
||||
}
|
||||
}
|
||||
30
code/app/model/DomainModel.php
Normal file
30
code/app/model/DomainModel.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class DomainModel extends BaseModel
|
||||
{
|
||||
protected $name = 'domain';
|
||||
protected $pk = 'd_id';
|
||||
|
||||
|
||||
static public function getDomainByCache($strDomain)
|
||||
{
|
||||
$strKey = "D:" . $strDomain;
|
||||
return DomainModel::where('d_domain', $strDomain)->cache($strKey, 24 * 3600)->find();
|
||||
}
|
||||
|
||||
static public function flushDomainCache($strDomain)
|
||||
{
|
||||
$strKey = "D:" . $strDomain;
|
||||
return Cache::delete($strKey);
|
||||
}
|
||||
}
|
||||
133
code/app/model/FenLeiModel.php
Normal file
133
code/app/model/FenLeiModel.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class FenLeiModel extends BaseModel
|
||||
{
|
||||
protected $name = 'fen_lei';
|
||||
protected $pk = 'fl_id';
|
||||
|
||||
static $arrFenLei = [];
|
||||
|
||||
static public function addFenlei($intFlId, $intFlPId = 0, $strFlMingzi)
|
||||
{
|
||||
try {
|
||||
|
||||
if (empty($strFlMingzi)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$FenLeiModel = self::where('fl_pid',$intFlPId)->where('fl_mingzi',$strFlMingzi)->find();
|
||||
|
||||
if ($FenLeiModel) {
|
||||
return $FenLeiModel;
|
||||
}
|
||||
|
||||
$FenLeiModel = new self;
|
||||
// $FenLeiModel->fl_id = $intFlId;
|
||||
$FenLeiModel->fl_leixing = 0;
|
||||
$FenLeiModel->fl_pid = $intFlPId;
|
||||
$FenLeiModel->fl_mingzi = $strFlMingzi;
|
||||
$FenLeiModel->save();
|
||||
return $FenLeiModel;
|
||||
} catch (\Throwable $T) {
|
||||
}
|
||||
|
||||
if ($T->getCode() == 10501) {
|
||||
return self::addFenlei($intFlId, $intFlPId, $strFlMingzi);
|
||||
}
|
||||
throw $T;
|
||||
}
|
||||
|
||||
static public function getAllFenLei()
|
||||
{
|
||||
if (self::$arrFenLei == []) {
|
||||
self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI');
|
||||
|
||||
if (empty(self::$arrFenLei)) {
|
||||
self::flushCache();
|
||||
self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return self::$arrFenLei;
|
||||
}
|
||||
|
||||
|
||||
static public function getFenLeiByFlId($intFlId)
|
||||
{
|
||||
if (self::$arrFenLei == []) {
|
||||
self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI');
|
||||
|
||||
if (empty(self::$arrFenLei)) {
|
||||
self::flushCache();
|
||||
self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return self::$arrFenLei[$intFlId] ?? "";
|
||||
}
|
||||
|
||||
static public function getFenLeiMingZiByFlId($intFlId, $intZiFlId)
|
||||
{
|
||||
if (empty(self::$arrFenLei)) {
|
||||
self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI');
|
||||
|
||||
if (empty(self::$arrFenLei)) {
|
||||
self::flushCache();
|
||||
self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI');
|
||||
}
|
||||
}
|
||||
|
||||
if ($intZiFlId == 0) {
|
||||
return self::$arrFenLei[$intFlId]['fl_mingzi'] ?? '';
|
||||
} else {
|
||||
$arrFenLeiChild = self::$arrFenLei[$intFlId]['child'] ?? [];
|
||||
foreach ($arrFenLeiChild as $item) {
|
||||
if ($item['fl_id'] == $intZiFlId) {
|
||||
return $item['fl_mingzi'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
static public function flushCache()
|
||||
{
|
||||
// $arrFenLei = self::select()->toArray();
|
||||
$arrFenLei = self::order('fl_sort', 'desc')->select()->toArray();
|
||||
|
||||
$arrFenLei = static::buildTree($arrFenLei);
|
||||
|
||||
Cache::tag('SHI_PIN_FEN_LEI')->set('SHI_PIN_FEN_LEI', $arrFenLei);
|
||||
}
|
||||
|
||||
static public function buildTree(array $elements, $parentId = 0)
|
||||
{
|
||||
$branch = [];
|
||||
|
||||
foreach ($elements as $element) {
|
||||
if ($element['fl_pid'] == $parentId) {
|
||||
$children = static::buildTree($elements, $element['fl_id']);
|
||||
if ($children) {
|
||||
$element['child'] = $children;
|
||||
}
|
||||
$branch[$element['fl_id']] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
return $branch;
|
||||
}
|
||||
}
|
||||
17
code/app/model/PlanTaskModel.php
Normal file
17
code/app/model/PlanTaskModel.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class PlanTaskModel extends BaseModel
|
||||
{
|
||||
protected $name = 'plan_task';
|
||||
protected $pk = 'pt_id';
|
||||
}
|
||||
39
code/app/model/SystemConfigModel.php
Normal file
39
code/app/model/SystemConfigModel.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class SystemConfigModel extends BaseModel
|
||||
{
|
||||
protected $name = 'system_config';
|
||||
protected $pk = 'sc_id';
|
||||
|
||||
static $arrSystemConfig = [];
|
||||
|
||||
static public function getValByCode($strCode)
|
||||
{
|
||||
if (self::$arrSystemConfig == []) {
|
||||
self::$arrSystemConfig = Cache::get('Config');
|
||||
|
||||
if (empty(self::$arrSystemConfig)) {
|
||||
self::flushCache();
|
||||
self::$arrSystemConfig = Cache::get('Config');
|
||||
}
|
||||
}
|
||||
|
||||
return self::$arrSystemConfig[$strCode] ?? NULL;
|
||||
}
|
||||
|
||||
static public function flushCache()
|
||||
{
|
||||
$arrSystemConfig = self::column('sc_val', 'sc_code');
|
||||
Cache::tag('Config')->set('Config', $arrSystemConfig);
|
||||
}
|
||||
}
|
||||
42
code/app/model/TemplatesModel.php
Normal file
42
code/app/model/TemplatesModel.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class TemplatesModel extends BaseModel
|
||||
{
|
||||
protected $name = 'templates';
|
||||
protected $pk = 't_id';
|
||||
|
||||
static $arrTemplates = [];
|
||||
|
||||
static public function getValByCode($intTId)
|
||||
{
|
||||
if (self::$arrTemplates == []) {
|
||||
self::$arrTemplates = Cache::get('Templates');
|
||||
|
||||
if (empty(self::$arrTemplates)) {
|
||||
self::flushCache();
|
||||
self::$arrTemplates = Cache::get('Templates');
|
||||
}
|
||||
}
|
||||
|
||||
return self::$arrTemplates[$intTId] ?? NULL;
|
||||
}
|
||||
|
||||
static public function flushCache()
|
||||
{
|
||||
$TemplatesModelAll = self::select();
|
||||
|
||||
$TemplatesCol = $TemplatesModelAll->column(null, 't_id');
|
||||
|
||||
Cache::tag('Templates')->set('Templates', $TemplatesCol);
|
||||
}
|
||||
}
|
||||
40
code/app/model/ZiYuanDuanDianModel.php
Normal file
40
code/app/model/ZiYuanDuanDianModel.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class ZiYuanDuanDianModel extends BaseModel
|
||||
{
|
||||
protected $name = 'zi_yuan_duan_dian';
|
||||
protected $pk = 'zydd_id';
|
||||
|
||||
static $arrZiYuanDuanDian = [];
|
||||
|
||||
static public function getDomainByCode($strCode)
|
||||
{
|
||||
if (self::$arrZiYuanDuanDian == []) {
|
||||
self::$arrZiYuanDuanDian = Cache::get('Zydd');
|
||||
|
||||
if (empty(self::$arrZiYuanDuanDian)) {
|
||||
self::flushCache();
|
||||
self::$arrZiYuanDuanDian = Cache::get('Zydd');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return self::$arrZiYuanDuanDian[$strCode] ?? "";
|
||||
}
|
||||
|
||||
static public function flushCache()
|
||||
{
|
||||
$arrZiYuanDuanDian = self::column('zydd_domain', 'zydd_code');
|
||||
Cache::tag('Zydd')->set('Zydd', $arrZiYuanDuanDian);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user