修复后台模块

This commit is contained in:
2020-03-30 22:40:52 +08:00
parent f31f3b99fa
commit de73484cca
10 changed files with 73 additions and 65 deletions

View File

@@ -42,6 +42,10 @@ function parse_field_bind(){
}
function time_format($value){
return date('Y-m-d H:i:s', $value);
}
/**
* 获取客户端IP地址
* @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字

View File

@@ -228,7 +228,7 @@ class Config extends Base {
* @return json
*/
public function setthemes($name, $id) {
$result = ConfigM::where('name', $name . '_themes')->setField('value', $id);
$result = ConfigM::update(['value' => $id], ['name' => $name."_themes"]);
if (false !== $result) {
Cache::pull('system_config_data');
return $this->success('设置成功!');

View File

@@ -9,14 +9,21 @@
namespace app\controller\admin;
use think\facade\Db;
use app\model\Model;
use app\model\Attribute;
/**
* @title 内容管理
*/
class Content extends Base {
public $modelInfo = [];
public function initialize() {
parent::initialize();
$this->getContentMenu();
$this->modelInfo = Model::where('name', $this->request->param('name'))->find()->append(['grid_list'])->toArray();
}
/**
@@ -28,27 +35,25 @@ class Content extends Base {
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
}
$grid_list = get_grid_list($this->modelInfo['list_grid']);
$order = "id desc";
$map = $this->buildMap();
$field = array_filter($grid_list['fields']);
$map = [];
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, array(
$list = Db::name($this->modelInfo['name'])->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, array(
'query' => $this->request->param(),
));
$data = array(
'grid' => $grid_list,
$this->data = array(
'grid' => $this->modelInfo['grid_list'],
'list' => $list,
'page' => $list->render(),
'model_name' => $this->modelInfo['name'],
'model_id' => $this->modelInfo['id']
);
if ($this->modelInfo['template_list']) {
$template = 'content/' . $this->modelInfo['template_list'];
$template = 'admin/content/' . $this->modelInfo['template_list'];
} else {
$template = 'content/index';
$template = 'admin/content/index';
}
$this->assign($data);
$this->setMeta($this->modelInfo['title'] . "列表");
return $this->fetch($template);
}
@@ -60,27 +65,25 @@ class Content extends Base {
if ($this->request->isPost()) {
$result = $this->model->save($this->request->param());
if ($result) {
//记录行为
action_log('add_content', 'content', $result, session('auth_user.uid'));
return $this->success("添加成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
} else {
return $this->error($this->model->getError(), url('admin/content/add', array('model_id' => $this->modelInfo['id'])));
}
} else {
$info = array(
$info = [
'model_name' => $this->modelInfo['name'],
'model_id' => $this->modelInfo['id'],
);
$data = array(
];
$this->data = [
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo),
);
];
if ($this->modelInfo['template_add']) {
$template = 'content/' . $this->modelInfo['template_add'];
} else {
$template = 'public/edit';
}
$this->assign($data);
$this->setMeta("添加" . $this->modelInfo['title']);
return $this->fetch($template);
}
}
@@ -190,7 +193,7 @@ class Content extends Base {
}
//获得数组的第一条数组
$rows = model('Attribute')->getFieldlist($map, 'id');
$rows = Attribute::getFieldlist($map, 'id');
if (!empty($rows)) {
foreach ($rows as $key => $value) {
$list[$value['group_id']][] = $value;

View File

@@ -9,6 +9,7 @@
namespace app\controller\admin;
use app\model\Model as ModelM;
use app\model\Attribute;
/**
* @title 模型管理
@@ -74,11 +75,11 @@ class Model extends Base {
return $this->error($this->model->getError());
}
} else {
$info = $this->model->where('id', $request->param('id'))->find();
$info = ModelM::find($request->param('id'));
$field_group = parse_config_attr($info['attribute_group']);
//获取字段列表
$rows = db('Attribute')->where('model_id', $request->param('id'))->where('is_show', 1)->order('group_id asc, sort asc')->select();
$rows = Attribute::where('model_id', $request->param('id'))->where('is_show', 1)->order('group_id asc, sort asc')->select();
if ($rows) {
// 梳理属性的可见性
foreach ($rows as $key => $field) {
@@ -90,13 +91,11 @@ class Model extends Base {
} else {
$fields = array();
}
$data = array(
$this->data = array(
'info' => $info,
'field_group' => $field_group,
'fields' => $fields,
);
$this->assign($data);
$this->setMeta('编辑模型');
return $this->fetch();
}
}

View File

@@ -18,7 +18,7 @@ class Index extends Base {
return $this->fetch();
}
public function ad(){
return $this->fetch('ad');
public function miss(){
return $this->fetch();
}
}

View File

@@ -1,20 +0,0 @@
<?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 Content extends Model {
protected $auto = ['update_time'];
protected $insert = ['create_time', 'status' => 1];
}

View File

@@ -81,11 +81,24 @@ class Model extends \think\Model{
return strtolower($value);
}
public function getGridListAttr($value, $data){
$list = [];
if ($data['list_grid'] !== '') {
$row = explode(PHP_EOL, $data['list_grid']);
foreach ($row as $r) {
list($field, $title) = explode(":", $r);
$list[$field] = ['field' => $field, 'title' => $title];
if (strrpos($title, "|")) {
$title = explode("|", $title);
$list[$field] = ['field' => $field, 'title' => $title[0], 'format' => $title[1]];
}
}
}
return $list;
}
public function getStatusTextAttr($value, $data) {
$status = array(
0 => '禁用',
1 => '启用',
);
$status = [0 => '禁用', 1 => '启用'];
return $status[$data['status']];
}