作者 王智

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();
}
}
... ...
... ... @@ -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>
... ...