更新
This commit is contained in:
41
app/model/Action.php
Normal file
41
app/model/Action.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Action {
|
||||
|
||||
protected function getStatusTextAttr($value, $data) {
|
||||
$status = array(-1 => '删除', 0 => '禁用', 1 => '正常', 2 => '待审核');
|
||||
return $status[$data['status']];
|
||||
}
|
||||
|
||||
public $fieldlist = array(
|
||||
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden'),
|
||||
array('name' => 'name', 'title' => '行为标识', 'type' => 'text', 'help' => '输入行为标识 英文字母'),
|
||||
array('name' => 'title', 'title' => '行为名称', 'type' => 'text', 'help' => '输入行为名称'),
|
||||
array('name' => 'type', 'title' => '行为类型', 'type' => 'select', 'help' => '选择行为类型', 'option' => ''),
|
||||
array('name' => 'remark', 'title' => '行为描述', 'type' => 'textarea', 'help' => '输入行为描述'),
|
||||
array('name' => 'rule', 'title' => '行为规则', 'type' => 'textarea', 'help' => '输入行为规则,不写则只记录日志'),
|
||||
array('name' => 'log', 'title' => '日志规则', 'type' => 'textarea', 'help' => '记录日志备注时按此规则来生成,支持[变量|函数]。目前变量有:user,time,model,record,data'),
|
||||
);
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
foreach ($this->fieldlist as $key => $value) {
|
||||
if ($value['name'] == 'type') {
|
||||
$value['option'] = get_action_type(null, true);
|
||||
}
|
||||
$this->fieldlist[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
app/model/ActionLog.php
Normal file
21
app/model/ActionLog.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class ActionLog {
|
||||
|
||||
protected function getModelIdAttr($value, $data) {
|
||||
$value = get_document_field($data['model'], "name", "id");
|
||||
return $value ? $value : 0;
|
||||
}
|
||||
}
|
||||
36
app/model/Ad.php
Normal file
36
app/model/Ad.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Ad {
|
||||
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time');
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'cover_id' => 'integer',
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden', 'help' => '', 'option' => ''),
|
||||
array('name' => 'place_id', 'title' => 'PLACE_ID', 'type' => 'hidden', 'help' => '', 'option' => ''),
|
||||
array('name' => 'title', 'title' => '广告名称', 'type' => 'text', 'help' => '', 'option' => ''),
|
||||
array('name' => 'cover_id', 'title' => '广告图片', 'type' => 'image', 'help' => '', 'option' => ''),
|
||||
array('name' => 'url', 'title' => '广告链接', 'type' => 'text', 'help' => '', 'option' => ''),
|
||||
array('name' => 'photolist', 'title' => '辅助图片', 'type' => 'images', 'help' => '', 'option' => ''),
|
||||
array('name' => 'listurl', 'title' => '辅助链接', 'type' => 'textarea', 'help' => '对应辅助图片的排序,一行一个', 'option' => ''),
|
||||
array('name' => 'background', 'title' => '广告背景颜色', 'type' => 'text', 'help' => '', 'option' => ''),
|
||||
array('name' => 'content', 'title' => '广告描述', 'type' => 'textarea', 'help' => '', 'option' => ''),
|
||||
array('name' => 'status', 'title' => '状态', 'type' => 'select', 'help' => '', 'option' => array('1' => '开启', '0' => '禁用')),
|
||||
);
|
||||
}
|
||||
54
app/model/AdPlace.php
Normal file
54
app/model/AdPlace.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class AdPlace {
|
||||
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time');
|
||||
protected $type = array(
|
||||
'start_time' => 'integer',
|
||||
'end_time' => 'integer',
|
||||
);
|
||||
|
||||
public $show_type = array(
|
||||
'1' => '幻灯片',
|
||||
'2' => '对联',
|
||||
'3' => '图片列表',
|
||||
'4' => '图文列表',
|
||||
'5' => '文字列表',
|
||||
'6' => '代码广告',
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden', 'help' => '', 'option' => ''),
|
||||
array('name' => 'title', 'title' => '广告位名称', 'type' => 'text', 'help' => '', 'option' => ''),
|
||||
array('name' => 'name', 'title' => '广告位标识', 'type' => 'text', 'help' => '调用使用{:ad("广告位标识",参数)}', 'option' => ''),
|
||||
array('name' => 'show_type', 'title' => '类型', 'type' => 'select', 'help' => '', 'option' => ''),
|
||||
array('name' => 'show_num', 'title' => '显示条数', 'type' => 'num', 'help' => '', 'option' => ''),
|
||||
array('name' => 'start_time', 'title' => '开始时间', 'type' => 'datetime', 'help' => '', 'option' => ''),
|
||||
array('name' => 'end_time', 'title' => '结束时间', 'type' => 'datetime', 'help' => '', 'option' => ''),
|
||||
array('name' => 'template', 'title' => '广告模版', 'type' => 'text', 'help' => '', 'option' => ''),
|
||||
array('name' => 'status', 'title' => '状态', 'type' => 'select', 'help' => '', 'option' => array('1' => '开启', '0' => '禁用')),
|
||||
);
|
||||
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
foreach ($this->keyList as $key => $value) {
|
||||
if ($value['name'] == 'show_type') {
|
||||
$value['option'] = $this->show_type;
|
||||
}
|
||||
$this->keyList[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/model/Attribute.php
Normal file
105
app/model/Attribute.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Attribute {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected static function init() {
|
||||
self::afterInsert(function ($data) {
|
||||
if ($data['model_id']) {
|
||||
$name = db('Model')->where('id', $data['model_id'])->value('name');
|
||||
$db = new \com\Datatable();
|
||||
$attr = $data->toArray();
|
||||
$model_attr = array(
|
||||
'model_id' => $data['model_id'],
|
||||
'attr_id' => $data->id,
|
||||
'group_id' => 0,
|
||||
'is_add_table' => 1,
|
||||
'is_show' => $data['is_show'],
|
||||
'is_must' => $data['is_must'],
|
||||
'sort' => 0,
|
||||
);
|
||||
$attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
|
||||
return $db->columField(strtolower($name), $attr)->query();
|
||||
}
|
||||
});
|
||||
self::beforeUpdate(function ($data) {
|
||||
$attr = $data->toArray();
|
||||
$attr['action'] = 'CHANGE';
|
||||
$attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
|
||||
if ($attr['id']) {
|
||||
$name = db('Model')->where('id', $attr['model_id'])->value('name');
|
||||
$db = new \com\Datatable();
|
||||
return $db->columField(strtolower($name), $attr)->query();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function getTypeTextAttr($value, $data) {
|
||||
$type = config('config_type_list');
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
|
||||
public function getFieldlist($map, $index = 'id') {
|
||||
$list = array();
|
||||
$row = db('Attribute')->field('*,remark as help,type,extra as "option",model_id')->where($map)->order('group_id asc, sort asc')->select();
|
||||
foreach ($row as $key => $value) {
|
||||
if (in_array($value['type'], array('checkbox', 'radio', 'select', 'bool'))) {
|
||||
$value['option'] = parse_field_attr($value['extra']);
|
||||
} elseif ($value['type'] == 'bind') {
|
||||
$extra = parse_field_bind($value['extra'], '', $value['model_id']);
|
||||
$option = array();
|
||||
foreach ($extra as $k => $v) {
|
||||
$option[$v['id']] = $v['title_show'];
|
||||
}
|
||||
$value['option'] = $option;
|
||||
}
|
||||
$list[$value['id']] = $value;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function del($id, $model_id) {
|
||||
$map['id'] = $id;
|
||||
$info = $this->find($id);
|
||||
$tablename = db('Model')->where(array('id' => $model_id))->value('name');
|
||||
|
||||
//先删除字段表内的数据
|
||||
$result = $this->where($map)->delete();
|
||||
if ($result) {
|
||||
$tablename = strtolower($tablename);
|
||||
//删除模型表中字段
|
||||
$db = new \com\Datatable();
|
||||
if (!$db->CheckField($tablename, $info['name'])) {
|
||||
return true;
|
||||
}
|
||||
$result = $db->delField($tablename, $info['name'])->query();
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
app/model/AuthGroupAccess.php
Normal file
19
app/model/AuthGroupAccess.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthGroupAccess extends Model{
|
||||
|
||||
}
|
||||
55
app/model/AuthRule.php
Normal file
55
app/model/AuthRule.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthRule extends Model{
|
||||
|
||||
const rule_url = 1;
|
||||
const rule_mian = 2;
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'module','title'=>'所属模块','type'=>'hidden'),
|
||||
array('name'=>'title','title'=>'节点名称','type'=>'text','help'=>''),
|
||||
array('name'=>'name','title'=>'节点标识','type'=>'text','help'=>''),
|
||||
array('name'=>'group','title'=>'功能组','type'=>'text','help'=>'功能分组'),
|
||||
array('name'=>'status','title'=>'状态','type'=>'select','option'=>array('1'=>'启用','0'=>'禁用'),'help'=>''),
|
||||
array('name'=>'condition','title'=>'条件','type'=>'text','help'=>'')
|
||||
);
|
||||
|
||||
public function uprule($data, $type){
|
||||
foreach ($data as $value) {
|
||||
$data = array(
|
||||
'module' => $type,
|
||||
'type' => 2,
|
||||
'name' => $value['url'],
|
||||
'title' => $value['title'],
|
||||
'group' => $value['group'],
|
||||
'status' => 1,
|
||||
);
|
||||
$id = $this->where(array('name' => $data['name']))->value('id');
|
||||
if ($id) {
|
||||
$data['id'] = $id;
|
||||
$this->save($data, array('id' => $id));
|
||||
} else {
|
||||
self::create($data);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
43
app/model/Category.php
Normal file
43
app/model/Category.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Category {
|
||||
|
||||
protected $name = "Category";
|
||||
protected $auto = array('update_time', 'status' => 1);
|
||||
|
||||
protected $type = array(
|
||||
'icon' => 'integer',
|
||||
);
|
||||
|
||||
public function change() {
|
||||
$data = input('post.');
|
||||
if ($data['id']) {
|
||||
$result = $this->save($data, array('id' => $data['id']));
|
||||
} else {
|
||||
unset($data['id']);
|
||||
$result = $this->save($data);
|
||||
}
|
||||
if (false !== $result) {
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function info($id, $field = true) {
|
||||
return $this->db()->where(array('id' => $id))->field($field)->find();
|
||||
}
|
||||
}
|
||||
23
app/model/Channel.php
Normal file
23
app/model/Channel.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Channel {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected $auto = array('update_time', 'status' => 1);
|
||||
protected $insert = array('create_time');
|
||||
}
|
||||
19
app/model/Client.php
Normal file
19
app/model/Client.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* Client模型
|
||||
*/
|
||||
class Client {
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time');
|
||||
|
||||
}
|
||||
82
app/model/Config.php
Normal file
82
app/model/Config.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
class Config extends Model {
|
||||
|
||||
public function getValuesAttr($value, $data) {
|
||||
return self::parse($data['type'], $data['value']);
|
||||
}
|
||||
|
||||
public static function getConfigList($request) {
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = self::where($map)->field('type,name,value')->select();
|
||||
|
||||
$config = array();
|
||||
if ($data) {
|
||||
foreach ($data->toArray() as $value) {
|
||||
$config[$value['name']] = self::parse($value['type'], $value['value']);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function getConfig($request) {
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = self::where($map)->select()->append(['values']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getConfigTree($request) {
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = self::where($map)->select();
|
||||
|
||||
$group = Cache::get('config')['config_group_list'];
|
||||
$config = [];
|
||||
foreach ($data->toArray() as $value) {
|
||||
if (isset($group[$value['group']])) {
|
||||
$config[$group[$value['group']]][] = $value;
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置类型解析配置
|
||||
* @param integer $type 配置类型
|
||||
* @param string $value 配置值
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
private static function parse($type, $value) {
|
||||
$data = [];
|
||||
switch ($type) {
|
||||
case 'textarea': //解析数组
|
||||
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
|
||||
if (strpos($value, ':')) {
|
||||
foreach ($array as $val) {
|
||||
$list = explode(':', $val);
|
||||
if (isset($list[2])) {
|
||||
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1], 'other' => $list[2]];
|
||||
} else {
|
||||
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($array as $key => $val) {
|
||||
$data[] = ['key' => $key, 'value' => $val, 'label' => $val];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
21
app/model/Content.php
Normal file
21
app/model/Content.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class ContentModel {
|
||||
|
||||
protected $type = array(
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
);
|
||||
}
|
||||
16
app/model/Department.php
Normal file
16
app/model/Department.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Department extends Model {
|
||||
|
||||
protected $name = "member_department";
|
||||
}
|
||||
43
app/model/Dictionary.php
Normal file
43
app/model/Dictionary.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\facade\Db;
|
||||
|
||||
class Dictionary extends Model {
|
||||
|
||||
protected $type = [
|
||||
'pid' => 'integer',
|
||||
'code' => 'integer'
|
||||
];
|
||||
|
||||
public function getTitleAttr($value, $data){
|
||||
return $data['name'];
|
||||
}
|
||||
|
||||
public function getDictionList($request){
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
$order = "id asc";
|
||||
|
||||
if (isset($param['title']) && $param['title'] != '') {
|
||||
$map[] = ['title', 'LIKE', '%'.$param['title'].'%'];
|
||||
}
|
||||
if (isset($param['status']) && $param['status'] != '') {
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (isset($param['type']) && $param['type'] != '') {
|
||||
$map[] = ['model', '=', $param['type']];
|
||||
}
|
||||
|
||||
return self::where($map)->field('id, name, pid, code, model')->order($order)->select();
|
||||
}
|
||||
|
||||
}
|
||||
18
app/model/DiyForm.php
Normal file
18
app/model/DiyForm.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 自定义表单模型
|
||||
*/
|
||||
class DiyFormModel {
|
||||
|
||||
protected $attrDb = 'FormAttr';
|
||||
}
|
||||
93
app/model/Form.php
Normal file
93
app/model/Form.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 表单
|
||||
*/
|
||||
class Form {
|
||||
|
||||
protected $auto = ['update_time'];
|
||||
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid' => "id:ID\r\ntitle:标题\r\ncreate_time:添加时间|time_format\r\nupdate_time:更新时间|time_format"];
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
);
|
||||
|
||||
public $addField = array(
|
||||
array('name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''),
|
||||
array('name' => 'title', 'title' => '标题', 'type' => 'text', 'help' => ''),
|
||||
);
|
||||
|
||||
public $editField = array(
|
||||
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden', 'help' => ''),
|
||||
array('name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''),
|
||||
array('name' => 'title', 'title' => '标题', 'type' => 'text', 'help' => ''),
|
||||
array('name' => 'list_grid', 'title' => '列表定义', 'type' => 'textarea', 'help' => ''),
|
||||
);
|
||||
|
||||
protected static function init() {
|
||||
self::beforeInsert(function ($event) {
|
||||
$data = $event->toArray();
|
||||
$tablename = 'form_' . strtolower($data['name']);
|
||||
//实例化一个数据库操作类
|
||||
$db = new \com\Datatable();
|
||||
//检查表是否存在并创建
|
||||
if (!$db->CheckTable($tablename)) {
|
||||
//创建新表
|
||||
return $db->initTable($tablename, $data['title'], 'id')->query();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
self::afterInsert(function ($event) {
|
||||
$data = $event->toArray();
|
||||
|
||||
$fields = include (APP_PATH . 'admin/fields.php');
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $key => $value) {
|
||||
if (in_array($key, array('uid', 'status', 'view', 'create_time', 'update_time'))) {
|
||||
$fields[$key]['form_id'] = $data['id'];
|
||||
} else {
|
||||
unset($fields[$key]);
|
||||
}
|
||||
}
|
||||
model('FormAttr')->saveAll($fields);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// self::beforeUpdate(function($event){
|
||||
// $data = $event->toArray();
|
||||
// if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
// $attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
|
||||
// if (!empty($attribute_sort)) {
|
||||
// foreach ($attribute_sort as $key => $value) {
|
||||
// db('FormAttr')->where('id', 'IN', $value)->setField('group_id', $key);
|
||||
// foreach ($value as $k => $v) {
|
||||
// db('FormAttr')->where('id', $v)->setField('sort', $k);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
}
|
||||
|
||||
public function getStatusTextAttr($value, $data) {
|
||||
$status = array(
|
||||
0 => '禁用',
|
||||
1 => '启用',
|
||||
);
|
||||
return $status[$data['status']];
|
||||
}
|
||||
|
||||
}
|
||||
105
app/model/FormAttr.php
Normal file
105
app/model/FormAttr.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class FormAttr {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected static function init() {
|
||||
self::afterInsert(function ($data) {
|
||||
if ($data['form_id']) {
|
||||
$name = db('Form')->where('id', $data['form_id'])->value('name');
|
||||
$db = new \com\Datatable();
|
||||
$attr = $data->toArray();
|
||||
$model_attr = array(
|
||||
'form_id' => $data['form_id'],
|
||||
'attr_id' => $data->id,
|
||||
'group_id' => 0,
|
||||
'is_add_table' => 1,
|
||||
'is_show' => $data['is_show'],
|
||||
'is_must' => $data['is_must'],
|
||||
'sort' => 0,
|
||||
);
|
||||
$attr['after'] = db('FormAttr')->where('name', '<>', $data['name'])->where('form_id', $data['form_id'])->order('id desc')->value('name');
|
||||
return $db->columField('form_' . strtolower($name), $attr)->query();
|
||||
}
|
||||
});
|
||||
self::beforeUpdate(function ($data) {
|
||||
$attr = $data->toArray();
|
||||
$attr['action'] = 'CHANGE';
|
||||
$attr['oldname'] = db('FormAttr')->where('id', $attr['id'])->value('name');
|
||||
if ($attr['id']) {
|
||||
$name = db('Form')->where('id', $attr['form_id'])->value('name');
|
||||
$db = new \com\Datatable();
|
||||
return $db->columField('form_' . strtolower($name), $attr)->query();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function getTypeTextAttr($value, $data) {
|
||||
$type = config('config_type_list');
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
|
||||
public function getFieldlist($map, $index = 'id') {
|
||||
$list = array();
|
||||
$row = $this->field('*,remark as help,type,extra as "option"')->where($map)->order('group_id asc, sort asc')->select();
|
||||
foreach ($row as $key => $value) {
|
||||
if (in_array($value['type'], array('checkbox', 'radio', 'select', 'bool'))) {
|
||||
$value['option'] = parse_field_attr($value['extra']);
|
||||
} elseif ($value['type'] == 'bind') {
|
||||
$extra = parse_field_bind($value['extra']);
|
||||
$option = array();
|
||||
foreach ($extra as $k => $v) {
|
||||
$option[$v['id']] = $v['title_show'];
|
||||
}
|
||||
$value['option'] = $option;
|
||||
}
|
||||
$list[$value['id']] = $value;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function del($id, $model_id) {
|
||||
$map['id'] = $id;
|
||||
$info = $this->find($id);
|
||||
$tablename = db('Form')->where(array('id' => $model_id))->value('name');
|
||||
|
||||
//先删除字段表内的数据
|
||||
$result = $this->where($map)->delete();
|
||||
if ($result) {
|
||||
$tablename = strtolower($tablename);
|
||||
//删除模型表中字段
|
||||
$db = new \com\Datatable();
|
||||
if (!$db->CheckField($tablename, $info['name'])) {
|
||||
return true;
|
||||
}
|
||||
$result = $db->delField($tablename, $info['name'])->query();
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
app/model/Link.php
Normal file
40
app/model/Link.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 友情链接类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Link extends \app\common\model\Base {
|
||||
|
||||
public $keyList = array(
|
||||
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden'),
|
||||
array('name' => 'title', 'title' => '友链标题', 'type' => 'text', 'help' => ''),
|
||||
array('name' => 'url', 'title' => 'URL链接', 'type' => 'text', 'help' => ''),
|
||||
array('name' => 'ftype', 'title' => '友链类别', 'type' => 'select', 'option' => array(
|
||||
'1' => '常用链接',
|
||||
'2' => '网站导读',
|
||||
'3' => '对公服务',
|
||||
'4' => '校内服务',
|
||||
), 'help' => ''),
|
||||
array('name' => 'cover_id', 'title' => '网站LOGO', 'type' => 'image', 'help' => ''),
|
||||
array('name' => 'status', 'title' => '状态', 'type' => 'select', 'option' => array('1' => '启用', '0' => '禁用'), 'help' => ''),
|
||||
array('name' => 'sort', 'title' => '链接排序', 'type' => 'text', 'help' => ''),
|
||||
array('name' => 'descrip', 'title' => '描述', 'type' => 'textarea', 'help' => ''),
|
||||
);
|
||||
|
||||
protected $auto = array('update_time');
|
||||
|
||||
protected $type = array(
|
||||
'cover_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
);
|
||||
}
|
||||
192
app/model/Member.php
Normal file
192
app/model/Member.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model;
|
||||
|
||||
use sent\jwt\facade\JWTAuth;
|
||||
use think\Model;
|
||||
use xin\helper\Server;
|
||||
|
||||
class Member extends Model {
|
||||
|
||||
protected $pk = 'uid';
|
||||
|
||||
protected $createTime = 'reg_time';
|
||||
protected $updateTime = 'last_login_time';
|
||||
|
||||
protected $insert = ['reg_ip'];
|
||||
|
||||
protected $status = [
|
||||
1 => '正常',
|
||||
0 => '禁用',
|
||||
];
|
||||
|
||||
public $loginVisible = ['uid', 'username', 'nickname', 'access_token', 'department']; //用户登录成功返回的字段
|
||||
|
||||
protected function getStatusTextAttr($value, $data) {
|
||||
return isset($this->status[$data['status']]) ? $this->status[$data['status']] : '未知';
|
||||
}
|
||||
|
||||
protected function getAvatarAttr($value, $data) {
|
||||
return avatar($data['uid']);
|
||||
}
|
||||
|
||||
protected function setPasswordAttr($value, $data) {
|
||||
return md5($value . $data['salt']);
|
||||
}
|
||||
|
||||
protected function setRegIpAttr($value) {
|
||||
return Server::getRemoteIp();
|
||||
}
|
||||
|
||||
protected function getAccessTokenAttr($value, $data) {
|
||||
$token = ['data' => ['uid' => $data['uid'], 'username' => $data['username'], 'password' => $data['password'], 'department' => $data['department']]];
|
||||
return JWTAuth::builder($token); //参数为用户认证的信息,请自行添加
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
public function login($request) {
|
||||
$username = $request->param('username', '');
|
||||
$password = $request->param('password', '');
|
||||
$type = $request->param('type', 1);
|
||||
$map = array();
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$map['username'] = $username;
|
||||
break;
|
||||
case 2:
|
||||
$map['email'] = $username;
|
||||
break;
|
||||
case 3:
|
||||
$map['mobile'] = $username;
|
||||
break;
|
||||
default:
|
||||
$this->error = "参数错误";
|
||||
return false; //参数错误
|
||||
}
|
||||
if (!$username) {
|
||||
$this->error = "用户名不能为空";
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->where($map)->find();
|
||||
if (isset($user['uid']) && $user['uid'] && $user['status']) {
|
||||
/* 验证用户密码 */
|
||||
if (md5($password . $user['salt']) === $user['password']) {
|
||||
/* 更新登录信息 */
|
||||
$this->record($user);
|
||||
return $user->append(array('access_token', 'avatar'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
|
||||
} else {
|
||||
$this->error = "密码错误";
|
||||
return false; //密码错误
|
||||
}
|
||||
} else {
|
||||
$this->error = "用户不存在或被禁用";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title: 注册
|
||||
*/
|
||||
public function register($request) {
|
||||
$data = [];
|
||||
$data['username'] = $request->param('username', '');
|
||||
$data['password'] = $request->param('password', '');
|
||||
$data['repassword'] = $request->param('repassword', '');
|
||||
$data['email'] = $request->param('email', '');
|
||||
$data['mobile'] = $request->param('mobile', '');
|
||||
$data['salt'] = rand_string(6);
|
||||
|
||||
$result = self::create($data);
|
||||
if (false !== $result) {
|
||||
$user = $this->where('uid', $result->uid)->find();
|
||||
} else {
|
||||
$this->error = "注册失败!";
|
||||
return false;
|
||||
}
|
||||
/* 更新登录信息 */
|
||||
$this->record($user);
|
||||
return $user->append(array('access_token', 'avatar'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
|
||||
}
|
||||
|
||||
/**
|
||||
* @title: 获取用户列表
|
||||
*/
|
||||
public function getUserList($request) {
|
||||
$map = array();
|
||||
$param = $request->param();
|
||||
|
||||
$order = "status desc, uid desc";
|
||||
|
||||
$map[] = ['status', '>=', 0];
|
||||
|
||||
if (isset($param['status']) && $param['status'] != '') {
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
}
|
||||
|
||||
if (isset($param['department']) && $param['department'] != '') {
|
||||
$map[] = ['department', '=', $param['department']];
|
||||
}
|
||||
|
||||
if (isset($param['email']) && $param['email'] != '') {
|
||||
$map[] = ['email', '=', $param['email']];
|
||||
}
|
||||
if (isset($param['name']) && $param['name'] != '') {
|
||||
$map[] = ['username|nickname', 'LIKE', '%' . $param['name'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($param['task_id']) && $param['task_id']) {
|
||||
$map[] = ['uid', 'IN', function ($query) use ($param) {
|
||||
$query->name('task_user')->where('task_id', $param['task_id'])->field('user_id');
|
||||
}];
|
||||
}
|
||||
|
||||
$list = self::with(['depart', 'role'])->field('uid,username,nickname,status,email,mobile,department,reg_time')->where($map)->order($order)->paginate($request->pageConfig);
|
||||
return $list->append(['avatar', 'status_text'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @title: 获取用户列表
|
||||
*/
|
||||
public function getUserDetail($request) {
|
||||
$uid = $request->param('uid', $request->user['uid']);
|
||||
if (!$uid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$info = $this->where('uid', $uid)->find();
|
||||
return $info->append(['avatar', 'status_text'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录信息更新
|
||||
* @param [type] $user [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function record($user) {
|
||||
/* 更新登录信息 */
|
||||
$data = array(
|
||||
'uid' => $user['uid'],
|
||||
'login' => array('inc', '1'),
|
||||
'last_login_time' => time(),
|
||||
'last_login_ip' => get_client_ip(1),
|
||||
);
|
||||
self::where(array('uid' => $user['uid']))->update($data);
|
||||
}
|
||||
|
||||
public function depart() {
|
||||
return $this->hasOne('Department', 'id', 'department');
|
||||
}
|
||||
|
||||
public function role() {
|
||||
return $this->hasOne('RoleAccess', 'uid', 'uid');
|
||||
}
|
||||
}
|
||||
49
app/model/MemberLog.php
Normal file
49
app/model/MemberLog.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use xin\helper\Server;
|
||||
|
||||
/**
|
||||
* @title: 用户日志模型
|
||||
*/
|
||||
class MemberLog extends Model {
|
||||
|
||||
protected $type = [
|
||||
'param' => 'json',
|
||||
'visite_time' => 'timestamp',
|
||||
];
|
||||
|
||||
public static function record($request) {
|
||||
$data = [
|
||||
'uid' => $request->user['uid'],
|
||||
'url' => $request->baseUrl(),
|
||||
'param' => $request->param(),
|
||||
'method' => $request->method(),
|
||||
'visite_time' => $request->time(),
|
||||
'client_ip' => Server::getRemoteIp(),
|
||||
'create_time' => time(),
|
||||
];
|
||||
self::create($data);
|
||||
}
|
||||
|
||||
public function getMemberLogList($request) {
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
$order = "id desc";
|
||||
|
||||
return self::with(['user'])->where($map)->order($order)->paginate($request->pageConfig);
|
||||
}
|
||||
|
||||
public function user() {
|
||||
return $this->hasOne('Member', 'uid', 'uid')->field('uid,nickname,username');
|
||||
}
|
||||
}
|
||||
36
app/model/Menu.php
Normal file
36
app/model/Menu.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 菜单模型类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Menu extends \app\common\model\Base {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public function getAuthNodes($type = 'admin') {
|
||||
$map['type'] = $type;
|
||||
$rows = $this->db()->field('id,pid,group,title,url')->where($map)->order('id asc')->select();
|
||||
foreach ($rows as $key => $value) {
|
||||
$data[$value['id']] = $value;
|
||||
}
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value['pid'] > 0) {
|
||||
$value['group'] = $data[$value['pid']]['title'] . '管理';
|
||||
$list[] = $value;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
120
app/model/Module.php
Normal file
120
app/model/Module.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Module {
|
||||
|
||||
protected $auto = ['update_time'];
|
||||
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid' => "id:ID\r\ntitle:标题\r\ncreate_time:添加时间|time_format\r\nupdate_time:更新时间|time_format"];
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
);
|
||||
|
||||
protected static function init() {
|
||||
self::beforeInsert(function ($event) {
|
||||
$data = $event->toArray();
|
||||
$tablename = strtolower($data['name']);
|
||||
//实例化一个数据库操作类
|
||||
$db = new \com\Datatable();
|
||||
//检查表是否存在并创建
|
||||
if (!$db->CheckTable($tablename)) {
|
||||
//创建新表
|
||||
return $db->initTable($tablename, $data['title'], 'id')->query();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
self::afterInsert(function ($event) {
|
||||
$data = $event->toArray();
|
||||
|
||||
$fields = include (APP_PATH . 'admin/fields.php');
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $key => $value) {
|
||||
if ($data['is_doc']) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
} else {
|
||||
if (in_array($key, array('uid', 'status', 'view', 'create_time', 'update_time'))) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
} else {
|
||||
unset($fields[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
model('Attribute')->saveAll($fields);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
self::beforeUpdate(function ($event) {
|
||||
$data = $event->toArray();
|
||||
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
|
||||
if (!empty($attribute_sort)) {
|
||||
foreach ($attribute_sort as $key => $value) {
|
||||
db('Attribute')->where('id', 'IN', $value)->setField('group_id', $key);
|
||||
foreach ($value as $k => $v) {
|
||||
db('Attribute')->where('id', $v)->setField('sort', $k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
protected function setAttributeSortAttr($value) {
|
||||
return $value ? json_encode($value) : '';
|
||||
}
|
||||
|
||||
public function setNameAttr($value) {
|
||||
return strtolower($value);
|
||||
}
|
||||
|
||||
public function getStatusTextAttr($value, $data) {
|
||||
$status = array(
|
||||
0 => '禁用',
|
||||
1 => '启用',
|
||||
);
|
||||
return $status[$data['status']];
|
||||
}
|
||||
|
||||
public function del() {
|
||||
$id = input('id', '', 'trim,intval');
|
||||
$tablename = $this->where('id', $id)->value('name');
|
||||
|
||||
//删除数据表
|
||||
$db = new \com\Datatable();
|
||||
if ($db->CheckTable($tablename)) {
|
||||
//检测表是否存在
|
||||
$result = $db->delTable($tablename)->query();
|
||||
if (!$result) {
|
||||
return false;
|
||||
$this->error = "数据表删除失败!";
|
||||
}
|
||||
}
|
||||
db('Attribute')->where('model_id', $id)->delete(); //删除字段信息
|
||||
$result = $this->where('id', $id)->delete();
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "模型删除失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function attribute() {
|
||||
return $this->hasMany('Attribute');
|
||||
}
|
||||
}
|
||||
85
app/model/Record.php
Normal file
85
app/model/Record.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Record extends \think\Model {
|
||||
|
||||
protected $type = [
|
||||
'new_data' => 'json',
|
||||
'old_data' => 'json',
|
||||
'order_num' => 'float'
|
||||
];
|
||||
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
$order = "id desc";
|
||||
$param = $request->param();
|
||||
|
||||
if (isset($param['name']) && $param['name'] != '') {
|
||||
$map[] = ['data_name', 'LIKE', '%' . $param['name'] . '%'];
|
||||
}
|
||||
if (isset($param['nickname']) && $param['nickname'] != '') {
|
||||
$searchUser = db('Member')->where('nickname', $param['nickname'])->field('uid,department')->find();
|
||||
if ($searchUser) {
|
||||
$map[] = ['uid', '=', $searchUser['uid']];
|
||||
}
|
||||
}
|
||||
if (isset($param['data']) && count($param['data']) == 2 && $param['data'][0] && $param['data'][1]) {
|
||||
$data = [strtotime($param['data'][0]), strtotime($param['data'][1])];
|
||||
$map[] = ['create_time', 'between time', $data];
|
||||
}
|
||||
//数据权限
|
||||
if ($request->user['role']['data_auth'] == 1) {
|
||||
// 部门数据...
|
||||
$user = Db::name('Member')->field('uid')
|
||||
->where('department', $request->user['department'])
|
||||
->buildSql();
|
||||
$map[] = ["uid", "EXP", "in " . $user];
|
||||
} elseif ($request->user['role']['data_auth'] == 2) {
|
||||
// 个人数据...
|
||||
$map[] = ['uid', '=', $request->user['uid']];
|
||||
}
|
||||
|
||||
$list = self::with(['member'])->where($map)
|
||||
->order($order)->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* title : 添加记录
|
||||
* param : old 旧数据,new 新数据 type 类型
|
||||
*/
|
||||
public function adds($old = array(), $new = array(), $type = 'customer') {
|
||||
$edit = array(); //修改过的字段
|
||||
foreach ($new as $key => $value) {
|
||||
if (isset($old[$key]) && $value != $old[$key]) {
|
||||
$edit[] = $key;
|
||||
}
|
||||
}
|
||||
if (!empty($edit)) {
|
||||
$data['data_id'] = $old['id'];
|
||||
$data['data_name'] = $old['name'];
|
||||
$data['type'] = $type;
|
||||
$data['uid'] = session('user_auth.uid');
|
||||
$data['old_data'] = json_encode($old);
|
||||
$data['new_data'] = json_encode($new);
|
||||
$data['fields'] = json_encode($edit);
|
||||
$data['create_time'] = time();
|
||||
return $this->insert($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function member() {
|
||||
return $this->hasOne('Member', 'uid', 'uid')->field('uid,username,nickname');
|
||||
}
|
||||
}
|
||||
37
app/model/Rewrite.php
Normal file
37
app/model/Rewrite.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 伪静态
|
||||
*/
|
||||
class Rewrite {
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
public $keyList = array(
|
||||
array('name' => 'id', 'title' => '标识', 'type' => 'hidden'),
|
||||
array('name' => 'rule', 'title' => '规则名称', 'type' => 'text', 'option' => '', 'help' => '规则名称,方便记忆'),
|
||||
array('name' => 'url', 'title' => '规则地址', 'type' => 'text', 'option' => '', 'help' => '规则地址'),
|
||||
);
|
||||
|
||||
/**
|
||||
* 数据修改
|
||||
* @return [bool] [是否成功]
|
||||
*/
|
||||
public function change() {
|
||||
$data = \think\Request::instance()->post();
|
||||
if (isset($data['id']) && $data['id']) {
|
||||
return $this->validate(true)->save($data, array('id' => $data['id']));
|
||||
} else {
|
||||
return $this->validate(true)->save($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
app/model/Role.php
Normal file
39
app/model/Role.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 角色模型
|
||||
*/
|
||||
class Role extends \think\Model {
|
||||
|
||||
protected $name = "auth_group";
|
||||
public $type = [
|
||||
'api_auth' => 'json',
|
||||
'component_auth' => 'json',
|
||||
];
|
||||
|
||||
public function getStatusTextAttr($value, $data) {
|
||||
$status = [1 => '开启', 0 => '禁用'];
|
||||
return isset($status[$data['status']]) ? $status[$data['status']] : '未知';
|
||||
}
|
||||
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
$list = self::where($map)->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getUserAuthInfo($request){
|
||||
$data = self::where('id', $request->user['role']['group_id'])->find();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
36
app/model/RoleAccess.php
Normal file
36
app/model/RoleAccess.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 角色模型
|
||||
*/
|
||||
class RoleAccess extends \think\Model {
|
||||
|
||||
protected $name = "auth_group_access";
|
||||
|
||||
public function getStatusTextAttr($value, $data) {
|
||||
$status = [1 => '开启', 0 => '禁用'];
|
||||
return isset($status[$data['status']]) ? $status[$data['status']] : '未知';
|
||||
}
|
||||
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
$list = self::where($map)->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getRoleByUid($uid) {
|
||||
return self::where('uid', $uid)->alias('ra')->field('ra.group_id, r.data_auth,r.api_auth')
|
||||
->join('auth_group r', 'r.id = ra.group_id')
|
||||
->find();
|
||||
}
|
||||
}
|
||||
127
app/model/SeoRule.php
Normal file
127
app/model/SeoRule.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class SeoRule {
|
||||
|
||||
public $keyList = array(
|
||||
array('name' => 'id', 'title' => '标识', 'type' => 'hidden'),
|
||||
array('name' => 'title', 'title' => '规则名称', 'type' => 'text', 'option' => '', 'help' => '规则名称,方便记忆'),
|
||||
array('name' => 'app', 'title' => '模块名', 'type' => 'select', 'option' => array('*' => '-所有模块-', 'index' => '前台模块', 'user' => '用户中心'), 'help' => '不选表示所有模块'),
|
||||
array('name' => 'controller', 'title' => '控制器', 'type' => 'text', 'option' => '', 'help' => '不填表示所有控制器'),
|
||||
array('name' => 'action', 'title' => '方法', 'type' => 'text', 'option' => '', 'help' => '不填表示所有方法'),
|
||||
array('name' => 'seo_title', 'title' => 'SEO标题', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'),
|
||||
array('name' => 'seo_keywords', 'title' => 'SEO关键字', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'),
|
||||
array('name' => 'seo_description', 'title' => 'SEO描述', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'),
|
||||
array('name' => 'status', 'title' => '状态', 'type' => 'select', 'option' => array('0' => '禁用', '1' => '启用'), 'help' => ''),
|
||||
array('name' => 'sort', 'title' => '排序', 'type' => 'text', 'option' => '', 'help' => ''),
|
||||
);
|
||||
|
||||
protected function setAppAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function setControllerAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function setActionAttr($value) {
|
||||
return (isset($value) && $value) ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getAppAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getControllerAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getActionAttr($value) {
|
||||
return (isset($value) && $value) ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getRuleNameAttr($value, $data) {
|
||||
return $data['app'] . '/' . $data['controller'] . '/' . $data['action'];
|
||||
}
|
||||
|
||||
public function getMetaOfCurrentPage($seo) {
|
||||
$request = \think\Request::instance();
|
||||
foreach ($seo as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$seo_to_str[$key] = implode(',', $value);
|
||||
} else {
|
||||
$seo_to_str[$key] = $value;
|
||||
}
|
||||
}
|
||||
$result = $this->getMeta($request->module(), $request->controller(), $request->action(), $seo_to_str);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getMeta($module, $controller, $action, $seo) {
|
||||
//获取相关的规则
|
||||
$rules = $this->getRelatedRules($module, $controller, $action);
|
||||
|
||||
//按照排序计算最终结果
|
||||
$title = '';
|
||||
$keywords = '';
|
||||
$description = '';
|
||||
|
||||
$need_seo = 1;
|
||||
foreach ($rules as $e) {
|
||||
//如果存在完全匹配的seo配置,则不用程序设置的seo资料
|
||||
if ($e['app'] && $e['controller'] && $e['action']) {
|
||||
$need_seo = 0;
|
||||
}
|
||||
if (!$title && $e['seo_title']) {
|
||||
$title = $e['seo_title'];
|
||||
}
|
||||
if (!$keywords && $e['seo_keywords']) {
|
||||
$keywords = $e['seo_keywords'];
|
||||
}
|
||||
if (!$description && $e['seo_description']) {
|
||||
$description = $e['seo_description'];
|
||||
}
|
||||
}
|
||||
if ($need_seo) {
|
||||
//默认让全站的seo规则优先级小于$this->setTitle等方式设置的规则。
|
||||
if ($seo['title']) {
|
||||
$title = $seo['title'];
|
||||
}
|
||||
if ($seo['keywords']) {
|
||||
$keywords = $seo['keywords'];
|
||||
}
|
||||
if ($seo['description']) {
|
||||
$description = $seo['description'];
|
||||
}
|
||||
}
|
||||
//生成结果
|
||||
$result = array('title' => $title, 'keywords' => $keywords, 'description' => $description);
|
||||
|
||||
//返回结果
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getRelatedRules($module, $controller, $action) {
|
||||
//查询与当前页面相关的SEO规则
|
||||
$rules = $this->where('app', ['=', '*'], ['=', $module], 'or')
|
||||
->where('controller', ['=', '*'], ['=', $controller], 'or')
|
||||
->where('action', ['=', '*'], ['=', $action], 'or')
|
||||
->where('status', 1)
|
||||
->order('sort asc')
|
||||
->select();
|
||||
|
||||
//返回规则列表
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user