作者 王智

文档修改

... ... @@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 商城轮播图
... ... @@ -35,6 +36,92 @@ class ShopBanner extends Backend
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['goods'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->getRelation('goods')->visible(['title']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
$Info = Db::name('season_banner')->where('id', $ids)->find();
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->assignconfig('type', $Info['type']);
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'ID',
'Image' => '轮播图',
'Weigh' => '权重',
'Id' => 'ID',
'Image' => '轮播图',
'Web' => '跳转地址',
'Page' => '小程序Page',
'Type' => '跳转类型',
'Type 1' => '商品单品',
'Type 2' => 'WEB链接',
'Type 3' => '小程序内部跳转',
'Goods_id' => '单品',
'Weigh' => '权重',
'Createtime' => '创建时间',
'Updatetime' => '更改时间'
'Updatetime' => '更改时间',
'Goods.title' => '商品名称'
];
... ...
... ... @@ -25,9 +25,9 @@ class ShopBanner extends Model
// 追加属性
protected $append = [
'type_text'
];
protected static function init()
{
... ... @@ -37,6 +37,28 @@ class ShopBanner extends Model
});
}
public function getTypeList()
{
return ['1' => __('Type 1'), '2' => __('Type 2'),'3' => __('Type 3')];
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
$list = $this->getTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function goods()
{
return $this->belongsTo('Goods', 'Goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
... ...
... ... @@ -14,11 +14,41 @@
<ul class="row list-inline faupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group" id="jump_page" style="display: none;">
<label class="control-label col-xs-12 col-sm-2">{:__('Page')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-page" class="form-control" name="row[page]" type="text">
</div>
</div>
<div class="form-group" id="jump_web" style="display: none;">
<label class="control-label col-xs-12 col-sm-2">{:__('Web')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-web" class="form-control" name="row[web]" type="text">
</div>
</div>
<div class="form-group" id="Goods">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-Goods_id" data-rule="" data-source="Goods/index" data-field="title" class="form-control selectpage" name="row[Goods_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
<!--<input id="c-weigh" class="form-control" name="row[weigh]" type="number">-->
<!--</div>-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
<!--<input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number">-->
<!--</div>-->
<!--</div>-->
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
... ...
... ... @@ -14,11 +14,42 @@
<ul class="row list-inline faupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group" id="jump_page">
<label class="control-label col-xs-12 col-sm-2">{:__('Page')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-page" class="form-control" name="row[page]" type="text" value="{$row.page|htmlentities}">
</div>
</div>
<div class="form-group" id="jump_web">
<label class="control-label col-xs-12 col-sm-2">{:__('Web')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-web" class="form-control" name="row[web]" type="text" value="{$row.web|htmlentities}">
</div>
</div>
<div class="form-group" id="Goods">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-Goods_id" data-rule="" data-source="Goods/index" data-field="title" class="form-control selectpage" name="row[Goods_id]" type="text" value="{$row.Goods_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.type"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
<!--<input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">-->
<!--</div>-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
<!--<input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">-->
<!--</div>-->
<!--</div>-->
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
... ...
... ... @@ -27,9 +27,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
// {field: 'web', title: __('Web'), operate: 'LIKE'},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
// {field: 'Goods_id', title: __('Goods_id')},
// {field: 'weigh', title: __('Weigh'), operate: false},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
// {field: 'goods.title', title: __('Goods.title'), operate: 'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
... ... @@ -39,9 +43,68 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
Table.api.bindevent(table);
},
add: function () {
var Type = document.getElementById("c-type");
var JumpWeb = document.getElementById("jump_web");
var JumpPage = document.getElementById("jump_page");
var Goods = document.getElementById("Goods");
Type.onchange = function () {
if (Type.value == 1) {
JumpPage.style.display = 'none';
Goods.style.display = 'block';
JumpWeb.style.display = 'none';
}
if(Type.value == 2){
Goods.style.display = 'none';
JumpWeb.style.display = 'block';
JumpPage.style.display = 'none';
}
if(Type.value == 3){
Goods.style.display = 'none';
JumpWeb.style.display = 'none';
JumpPage.style.display = 'block';
}
};
Controller.api.bindevent();
},
edit: function () {
var Type = Config.type;
var JumpWeb = document.getElementById("jump_web");
var JumpPage = document.getElementById("jump_page");
var Goods = document.getElementById("Goods");
if (Type == 1) {
JumpPage.style.display = 'none';
Goods.style.display = 'block';
JumpWeb.style.display = 'none';
}
if(Type == 2){
Goods.style.display = 'none';
JumpWeb.style.display = 'block';
JumpPage.style.display = 'none';
}
if(Type == 3){
Goods.style.display = 'none';
JumpWeb.style.display = 'none';
JumpPage.style.display = 'block';
}
var Type2 = document.getElementById("c-type");
Type2.onchange = function () {
if (Type2.value == 1) {
JumpPage.style.display = 'none';
Goods.style.display = 'block';
JumpWeb.style.display = 'none';
}
if(Type2.value == 2){
Goods.style.display = 'none';
JumpWeb.style.display = 'block';
JumpPage.style.display = 'none';
}
if(Type2.value == 3){
Goods.style.display = 'none';
JumpWeb.style.display = 'none';
JumpPage.style.display = 'block';
}
};
Controller.api.bindevent();
},
api: {
... ...