修复后台模块

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']];
}

View File

@@ -9,6 +9,15 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use app\model\Model;
$model = Model::where('status', '>', 0)->field(['id', 'name'])->select()->toArray();
foreach ($model as $value) {
Route::rule('/admin/' . $value['name'] . '/:function', 'admin.content/:function')->append(['name'=>$value['name']]);
Route::rule('/front/' . $value['name'] . '/:function', 'front.content/:function')->append(['name'=>$value['name']]);
Route::rule('/user/' . $value['name'] . '/:function', 'user.content/:function')->append(['name'=>$value['name']]);
}
Route::rule('/', 'Front.Index/index');
Route::rule('search', 'Front.Content/search');
@@ -48,4 +57,4 @@ Route::group('api', function () {
'Access-Control-Allow-Headers' => 'authorization, token, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
]);
Route::miss('Index/miss');
Route::miss('front.Index/miss');

View File

@@ -6,8 +6,8 @@
<h2>{$meta_title}</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{:url('admin/content/add?model_id='.$model_id)}">新 增</a>
<button class="btn btn-danger ajax-post confirm" url="{:url('admin/content/del?model_id='.$model_id)}" target-form="ids">删 除</button>
<a class="btn btn-primary" href="{:url('/admin/'.$model_name.'/add')}">新 增</a>
<button class="btn btn-danger ajax-post confirm" url="{:url('/admin/'.$model_name.'/del')}" target-form="ids">删 除</button>
</div>
</header>
<div class="main-box-body clearfix">
@@ -38,7 +38,7 @@
<thead>
<tr>
<th width="30"><input class="checkbox check-all" type="checkbox"></th>
{volist name="grid['grids']" id="item"}
{volist name="grid" id="item"}
<th>{$item['title']}</th>
{/volist}
<th>操作</th>
@@ -47,7 +47,7 @@
<tbody>
{if condition="empty($list)"}
{php}
$cow = count($grid['grids'])+2;
$cow = count($grid)+2;
{/php}
<tr>
<td colspan="{$cow}" align="center">暂无数据!</td>
@@ -56,30 +56,30 @@
{volist name="list" id="item"}
<tr>
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></td>
{volist name="grid['grids']" id="vo"}
{volist name="grid" id="vo"}
{if isset($vo['format'])}
<td>{$item[$vo['field'][0]]|$vo['format']}</td>
<td>{$item[$vo['field']]|$vo['format']}</td>
{else/}
<td>{$item[$vo['field'][0]]}</td>
<td>{$item[$vo['field']]}</td>
{/if}
{/volist}
<td>
{if isset($item['is_top'])}
{if $item['is_top']}
<a href="{:url('admin/content/settop?model_id='.$model_id,array('id'=>$item['id'],'is_top'=>'0'))}" class="ajax-get">取消置顶</a>
<a href="{:url('/admin/'.$model_name.'/settop', ['id'=>$item['id'],'is_top'=>'0'])}" class="ajax-get">取消置顶</a>
{else/}
<a href="{:url('admin/content/settop?model_id='.$model_id,array('id'=>$item['id'],'is_top'=>'1'))}" class="ajax-get">置顶</a>
<a href="{:url('/admin/'.$model_name.'/settop', ['id'=>$item['id'],'is_top'=>'1'])}" class="ajax-get">置顶</a>
{/if}
{/if}
{if isset($item['status'])}
{if $item['status']}
<a href="{:url('admin/content/status?model_id='.$model_id,array('id'=>$item['id'],'status'=>'0'))}" class="ajax-get">取消审核</a>
<a href="{:url('/admin/'.$model_name.'/status', ['id'=>$item['id'],'status'=>'0'])}" class="ajax-get">取消审核</a>
{else/}
<a href="{:url('admin/content/status?model_id='.$model_id,array('id'=>$item['id'],'status'=>'1'))}" class="ajax-get">审核</a>
<a href="{:url('/admin/'.$model_name.'/status', ['id'=>$item['id'],'status'=>'1'])}" class="ajax-get">审核</a>
{/if}
{/if}
<a href="{:url('admin/content/edit?model_id='.$model_id,array('id'=>$item['id']))}" >编辑</a>
<a href="{:url('admin/content/del?model_id='.$model_id,array('id'=>$item['id']))}" class="ajax-get confirm">删除</a>
<a href="{:url('/admin/'.$model_name.'/edit', ['id'=>$item['id']])}" >编辑</a>
<a href="{:url('/admin/'.$model_name.'/del', ['id'=>$item['id']])}" class="ajax-get confirm">删除</a>
</td>
</tr>
{/volist}