mirror of https://gitee.com/karson/fastadmin.git
多站点CMS
parent
0dd970e7ff
commit
88a27290a6
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @desc: 文章模型
|
||||||
|
* @Author: Dr.Xing <ezfwork@foxmail.com>
|
||||||
|
* @Since: 2018/2/2 16:54
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class Archives extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
// 追加属性
|
||||||
|
protected $append = [
|
||||||
|
'views',
|
||||||
|
'updatetime_text',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function base(&$query){
|
||||||
|
if(\think\Session::has("user_site_id")) {
|
||||||
|
$query->where(['status'=>'normal', 'isDelete'=>0, 'site_id' =>\think\Session::get("user_site_id")]);
|
||||||
|
/*strict
|
||||||
|
$query->where('site_id', 'in', function($query){
|
||||||
|
$domain = request()->domain();
|
||||||
|
$query->table(config("database.prefix") . 'sites')->where('domain', $domain)->field('id');
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}else{
|
||||||
|
$query->where(['status'=>'normal', 'isDelete'=>0]);
|
||||||
|
}
|
||||||
|
//$query->field('site_id,authorid', true);
|
||||||
|
//$query->alias('a')->join('counter as c', 'c.item_id=a.id and c.item_type=`archive`');
|
||||||
|
//$query->alias('a')->join('counter c', 'c.item_id=a.id')->where('c.item_type','archive')->field('c.views, c.good, c.bad, c.comments');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getViewsAttr($value,$data)
|
||||||
|
{
|
||||||
|
if(!isset($data['id'])) return 0;
|
||||||
|
$result = Counter::get(['item_id'=>$data['id'], 'item_type'=>'archive']);
|
||||||
|
return $result?$result['views']:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatetimeTextAttr($value,$data)
|
||||||
|
{
|
||||||
|
if(!isset($data['updatetime'])) return '';
|
||||||
|
return datetime($data['updatetime'], 'Y-m-d');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @desc: 栏目模型
|
||||||
|
* @Author: Dr.Xing <ezfwork@foxmail.com>
|
||||||
|
* @Since: 2018/2/1 15:04
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class Channel extends Model
|
||||||
|
{
|
||||||
|
protected $name = 'channel';
|
||||||
|
|
||||||
|
protected function base(&$query){
|
||||||
|
if(\think\Session::has("user_site_id")) {
|
||||||
|
$query->where(['status' => 'normal', 'site_id' =>\think\Session::get("user_site_id")]);
|
||||||
|
}else{
|
||||||
|
$query->where(['status'=>'normal', 'site_id'=>0]);
|
||||||
|
}
|
||||||
|
$query->order('weigh DESC, id DESC');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成菜单
|
||||||
|
* @param string $active 激活项
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getNav($active='index')
|
||||||
|
{
|
||||||
|
$list = self::all();
|
||||||
|
$result = [];
|
||||||
|
foreach ($list as $key => &$v)
|
||||||
|
{
|
||||||
|
if($v['pid']==0 ) {
|
||||||
|
$sub = [];
|
||||||
|
foreach($list as $sk => $sv){
|
||||||
|
if($sv['pid'] == $v['id']) {
|
||||||
|
$sub[] = [
|
||||||
|
'text' => $sv['name'],
|
||||||
|
'url' => $sv['type']=='redirect' ? $sv['redirect'] :
|
||||||
|
($sv['diyname']!=''?
|
||||||
|
url('index/channel/index', ['name'=>$sv['diyname']]) :
|
||||||
|
url('index/channel/index', ['id'=>$sv['id']])
|
||||||
|
),
|
||||||
|
'active' => false,
|
||||||
|
'child' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = [
|
||||||
|
'text' => $v['name'],
|
||||||
|
'url' => $v['type']=='redirect' ? $v['redirect'] :
|
||||||
|
($v['diyname']!=''?
|
||||||
|
url('index/channel/index', ['name'=>$v['diyname']]) :
|
||||||
|
url('index/channel/index', ['id'=>$v['id']])
|
||||||
|
) ,
|
||||||
|
'active' => false,
|
||||||
|
'child' => count($sub),
|
||||||
|
'sub' => $sub
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @desc: 访问统计
|
||||||
|
* @Author: Dr.Xing <ezfwork@foxmail.com>
|
||||||
|
* @Since: 2017/12/14 12:09
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class Counter extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 增/减访问计数器
|
||||||
|
* @param int $item_id 被统计数据的ID
|
||||||
|
* @param string $item_type 被统计数据的类型
|
||||||
|
* @param int $added 计数器增长数(默认+1)
|
||||||
|
*/
|
||||||
|
public static function added($item_id, $item_type='', $added=1)
|
||||||
|
{
|
||||||
|
$count = self::get(['item_id'=>$item_id]);
|
||||||
|
if($count){
|
||||||
|
$count->views=$count->views+$added;
|
||||||
|
$count->save();
|
||||||
|
} else {
|
||||||
|
self::create(['item_id'=>$item_id, 'item_type'=>$item_type, 'views'=>$added]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//点赞+1
|
||||||
|
public static function good($item_id, $item_type='', $added=1)
|
||||||
|
{
|
||||||
|
$count = self::get(['item_id'=>$item_id]);
|
||||||
|
if($count){
|
||||||
|
$count->good=$count->good+$added;
|
||||||
|
$count->save();
|
||||||
|
} else {
|
||||||
|
self::create(['item_id'=>$item_id, 'item_type'=>$item_type, 'good'=>$added]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//点踩+1
|
||||||
|
public static function bad($item_id, $item_type='', $added=1)
|
||||||
|
{
|
||||||
|
$count = self::get(['item_id'=>$item_id]);
|
||||||
|
if($count){
|
||||||
|
$count->bad=$count->bad+$added;
|
||||||
|
$count->save();
|
||||||
|
} else {
|
||||||
|
self::create(['item_id'=>$item_id, 'item_type'=>$item_type, 'bad'=>$added]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @desc: Created by PhpStorm.
|
||||||
|
* @Author: Dr.Xing <ezfwork@foxmail.com>
|
||||||
|
* @Since: 2018/2/1 16:44
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class Page extends Model
|
||||||
|
{
|
||||||
|
protected $name = 'page';
|
||||||
|
|
||||||
|
protected function base(&$query){
|
||||||
|
if(\think\Session::has("user_site_id")) {
|
||||||
|
$query->where(['status' => 'normal', 'site_id' =>\think\Session::get("user_site_id")]);
|
||||||
|
}else{
|
||||||
|
$query->where('status', 'normal');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
use think\Session;
|
||||||
|
|
||||||
|
class Sites extends Model
|
||||||
|
{
|
||||||
|
// 表名
|
||||||
|
protected $name = 'sites';
|
||||||
|
|
||||||
|
protected $autoWriteTimestamp = 'int';
|
||||||
|
|
||||||
|
protected $createTime = 'createtime';
|
||||||
|
protected $updateTime = 'updatetime';
|
||||||
|
|
||||||
|
|
||||||
|
// 追加属性
|
||||||
|
protected $append = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function config()
|
||||||
|
{
|
||||||
|
return $this->hasOne('SitesConfig', 'site_id','id')->field('seo,custom');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新路由缓存
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function refreshRulesCache()
|
||||||
|
{
|
||||||
|
\think\Cache::rm('rules');
|
||||||
|
|
||||||
|
$list = self::all(['status'=>'normal']);
|
||||||
|
$rules = [];
|
||||||
|
|
||||||
|
foreach ($list as $k => $v) {
|
||||||
|
if (empty($v['domain']) && empty($v['url'])) continue;
|
||||||
|
if($v['domain']=='www') continue;
|
||||||
|
|
||||||
|
//只绑定一种语言,设置为默认语言
|
||||||
|
if(!strpos(',', $v['lang'])) {
|
||||||
|
$vars = '?user_site_id=' . $v['id'] . '&lang=' . $v['lang'];
|
||||||
|
|
||||||
|
if (!empty($v['domain'])) {
|
||||||
|
$rules[] = ['s' => $v['domain'], 'p' => $vars];
|
||||||
|
}
|
||||||
|
if (!empty($v['url'])) {
|
||||||
|
$rules[] = ['s' => $v['url'], 'p' => $vars];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$multilang = explode(',', $v['lang']);
|
||||||
|
foreach ($multilang as $key => $lang) {
|
||||||
|
if ($lang != 'zh-cn') {
|
||||||
|
$vars = '?user_site_id=' . $v['id'] . '&lang=' . $lang;
|
||||||
|
if (!empty($v['domain'])) {
|
||||||
|
$rules[] = ['s' => $lang . '.' . $v['domain'], 'p' => $vars];
|
||||||
|
}
|
||||||
|
if (!empty($v['url'])) {
|
||||||
|
$rules[] = ['s' => $lang . '.' . $v['url'], 'p' => $vars];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\think\Cache::set('rules', $rules, 86400);
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class SitesConfig extends Model
|
||||||
|
{
|
||||||
|
protected $name = 'SitesConfig';
|
||||||
|
|
||||||
|
public function sites()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('Sites', 'site_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue