作者 王智

daima

... ... @@ -2,7 +2,6 @@
namespace app\admin\controller;
use think\Db;
use app\common\controller\Backend;
/**
... ... @@ -44,20 +43,22 @@ class Renwu extends Backend
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['user', 'vip'])
->with(['user','vip'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['user', 'vip'])
->with(['user','vip'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
... ... @@ -65,7 +66,7 @@ class Renwu extends Backend
foreach ($list as $row) {
$row->getRelation('user')->visible(['nickname', 'mobile', 'address', 'address_con', 'car_num', 'color', 'car_type', 'vip']);
$row->getRelation('user')->visible(['nickname','mobile','address','address_con','car_num','color','car_type','vip']);
$row->getRelation('vip')->visible(['title']);
}
$list = collection($list)->toArray();
... ... @@ -75,59 +76,4 @@ class Renwu extends Backend
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
// dump($row);
// die;
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->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
... ... @@ -8,13 +8,13 @@ use think\Model;
class Renwu extends Model
{
// 表名
protected $name = 'renwu';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
... ... @@ -31,9 +31,9 @@ class Renwu extends Model
'startime_text',
'endtime_text'
];
public function getTypeList()
{
return ['1' => __('Type 1'), '0' => __('Type 0'), '2' => __('Type 2')];
... ...
... ... @@ -21,10 +21,10 @@
<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>
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
... ... @@ -39,10 +39,10 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Xi_type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-xi_type" class="form-control selectpicker" name="row[xi_type]">
{foreach name="xiTypeList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
... ... @@ -71,10 +71,10 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Zhao_type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-zhao_type" class="form-control selectpicker" name="row[zhao_type]">
{foreach name="zhaoTypeList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
... ...
... ... @@ -27,8 +27,7 @@
<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>
<option value="{$key}" {in name="key" value="$row.type" }selected{/in}>{$vo}</option>
{/foreach}
</select>
... ... @@ -48,8 +47,7 @@
<select id="c-xi_type" class="form-control selectpicker" name="row[xi_type]">
{foreach name="xiTypeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.xi_type" }selected{
/in}>{$vo}</option>
<option value="{$key}" {in name="key" value="$row.xi_type" }selected{/in}>{$vo}</option>
{/foreach}
</select>
... ... @@ -89,8 +87,7 @@
<select id="c-zhao_type" class="form-control selectpicker" name="row[zhao_type]">
{foreach name="zhaoTypeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.zhao_type" }selected{
/in}>{$vo}</option>
<option value="{$key}" {in name="key" value="$row.zhao_type" }selected{/in}>{$vo}</option>
{/foreach}
</select>
... ...
<div class="panel panel-default panel-intro">
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="type">
... ... @@ -30,11 +30,11 @@
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('renwu/edit')}"
data-operate-del="{:$auth->check('renwu/del')}"
data-operate-edit="{:$auth->check('renwu/edit')}"
data-operate-del="{:$auth->check('renwu/del')}"
width="100%">
</table>
</div>
... ...