1、修复几处bug;
2、完善内容管理中的细节功能
This commit is contained in:
@@ -150,9 +150,8 @@ class User extends Base {
|
||||
* @author colin <colin@tensent.cn>
|
||||
*/
|
||||
private function getUserinfo($uid = null, $pass = null, $errormsg = null) {
|
||||
$uid = $uid ? $uid : input('id');
|
||||
//如果无UID则修改当前用户
|
||||
$uid = $uid ? $uid : session('user_auth.uid');
|
||||
$uid = $uid ? $uid : $this->request->param('uid', session('userInfo.uid'));
|
||||
$map['uid'] = $uid;
|
||||
if ($pass != null) {
|
||||
unset($map);
|
||||
|
||||
@@ -14,6 +14,16 @@ use \app\controller\Base as BaseC;
|
||||
|
||||
class Base extends BaseC {
|
||||
|
||||
protected function initialize() {
|
||||
$url = str_replace(".", "/", strtolower($this->request->controller())) . '/' . $this->request->action();
|
||||
if (!is_login() and !in_array($url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
$this->redirect('/admin/index/login');
|
||||
}
|
||||
|
||||
if (!in_array($url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
}
|
||||
}
|
||||
|
||||
protected function fetch($template = '') {
|
||||
$config = Cache::get('system_config_data');
|
||||
$this->tpl_config['view_depr'] = '_';
|
||||
@@ -29,6 +39,15 @@ class Base extends BaseC {
|
||||
if ($template == '') {
|
||||
$template = str_replace(".", "@", strtolower($this->request->controller())) . "/" . $this->request->action();
|
||||
}
|
||||
$template_path = str_replace("public", "", $this->tpl_config['view_dir_name']);
|
||||
$this->tpl_config['tpl_replace_string'] = [
|
||||
'__static__' => '/static',
|
||||
'__img__' => $template_path . 'static/images',
|
||||
'__css__' => $template_path . 'static/css',
|
||||
'__js__' => $template_path . 'static/js',
|
||||
'__plugins__' => '/static/plugins',
|
||||
'__public__' => $template_path . 'static',
|
||||
];
|
||||
|
||||
View::config($this->tpl_config);
|
||||
View::assign($this->data);
|
||||
|
||||
@@ -16,14 +16,16 @@ use think\Validate;
|
||||
class Category extends Validate{
|
||||
protected $rule = [
|
||||
'title' => 'require',
|
||||
'model_id' => 'require'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'title.require' => '栏目名称必须',
|
||||
'model_id.require' => '绑定模型必须',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'adminadd' => ['title'],
|
||||
'adminedit' => ['title'],
|
||||
'adminadd' => ['title', 'model_id'],
|
||||
'adminedit' => ['title', 'model_id'],
|
||||
];
|
||||
}
|
||||
+22
-5
@@ -22,26 +22,32 @@ class Attribute extends \think\Model {
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
/**
|
||||
* @title 新增后事件
|
||||
*/
|
||||
protected static function onAfterInsert($data){
|
||||
$data = $data->toArray();
|
||||
if ($data['model_id']) {
|
||||
$db = new \com\Datatable();
|
||||
$name = Models::where('id', $data['model_id'])->value('name');
|
||||
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
|
||||
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id desc')->value('name');
|
||||
return $db->columField(strtolower($name), $data)->query();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新后事件
|
||||
*/
|
||||
protected static function onAfterUpdate($data){
|
||||
$data = $data->toArray();
|
||||
if ($data['model_id']) {
|
||||
if (isset($data['model_id']) && isset($data['name'])) {
|
||||
$tablename = Models::where('id', $data['model_id'])->value('name');
|
||||
|
||||
//删除模型表中字段
|
||||
$db = new \com\Datatable();
|
||||
if ($db->CheckField($tablename, $data['name'])) {
|
||||
$data['action'] = 'CHANGE';
|
||||
}
|
||||
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id asc')->value('name');
|
||||
$result = $db->columField(strtolower($tablename), $data)->query();
|
||||
return $result;
|
||||
}else{
|
||||
@@ -49,6 +55,9 @@ class Attribute extends \think\Model {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除后事件
|
||||
*/
|
||||
protected static function onAfterDelete($data){
|
||||
$data = $data->toArray();
|
||||
if ($data['model_id']) {
|
||||
@@ -94,9 +103,14 @@ class Attribute extends \think\Model {
|
||||
}elseif($data['type'] == 'bool'){
|
||||
$list = [['key'=>0,'label'=>'禁用'],['key'=>1,'label'=>'启用']];
|
||||
}elseif($data['type'] == 'bind'){
|
||||
$map = [];
|
||||
$db = new \com\Datatable();
|
||||
if (strrpos($data['extra'], ":")) {
|
||||
$extra = explode(":", $data['extra']);
|
||||
$row = Db::name($extra[0])->select()->toArray();
|
||||
if ($db->CheckField($extra[0], 'model_id')) {
|
||||
$map[] = ['model_id', '=', $data['model_id']];
|
||||
}
|
||||
$row = Db::name($extra[0])->where($map)->select()->toArray();
|
||||
if ($extra[1] == 'tree') {
|
||||
$row = (new Tree())->toFormatTree($row);
|
||||
foreach ($row as $val) {
|
||||
@@ -108,7 +122,10 @@ class Attribute extends \think\Model {
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$row = Db::name($data['extra'])->select()->toArray();
|
||||
if ($db->CheckField($data['extra'], 'model_id')) {
|
||||
$map[] = ['model_id', '=', $data['model_id']];
|
||||
}
|
||||
$row = Db::name($data['extra'])->select($map)->toArray();
|
||||
foreach ($row as $val) {
|
||||
$list[] = ['key'=>$val['id'], 'label'=>$val['title']];
|
||||
}
|
||||
|
||||
+4
-16
@@ -21,6 +21,10 @@ class Category extends \think\Model{
|
||||
'icon' => 'integer',
|
||||
);
|
||||
|
||||
protected static function onAfterUpdate($model){
|
||||
$data = $model->toArray();
|
||||
}
|
||||
|
||||
public static function getCategoryTree($map = []){
|
||||
$list = self::where($map)->select();
|
||||
|
||||
@@ -31,22 +35,6 @@ class Category extends \think\Model{
|
||||
return $list;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
+11
-2
@@ -69,19 +69,28 @@ class Model extends \think\Model{
|
||||
}
|
||||
|
||||
protected static function onAfterUpdate($data){
|
||||
$data = $data->toArray();
|
||||
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
|
||||
$attr = [];
|
||||
if (!empty($attribute_sort)) {
|
||||
foreach ($attribute_sort as $key => $value) {
|
||||
$attr[$key] = Attribute::where('id', 'IN', $value)->column('*', 'id');
|
||||
foreach ($value as $k => $v) {
|
||||
$attr[] = ['id' => $v, 'group_id' => $key, 'sort' => $k];
|
||||
$attr[$key][$v]['group'] = $key;
|
||||
$attr[$key][$v]['sort'] = $k;
|
||||
}
|
||||
}
|
||||
}
|
||||
$save = [];
|
||||
foreach($attr as $value){
|
||||
if(!empty($value)){
|
||||
$save = array_merge($save, $value);
|
||||
}
|
||||
}
|
||||
if (!empty($attr)) {
|
||||
(new Attribute())->saveAll($attr);
|
||||
(new Attribute())->saveAll($save);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user