<?php
namespace app\store\controller\setting;
use app\store\controller\Controller;
use app\store\model\ReturnAddress as ReturnAddressModel;
class Address extends Controller
{
public function index()
{
$model = new ReturnAddressModel;
$list = $model->getList();
return $this->fetch('index', compact('list'));
}
public function add()
{
if (!$this->request->isAjax()) {
return $this->fetch('add');
}
$model = new ReturnAddressModel;
if ($model->add($this->postData('address'))) {
return $this->renderSuccess('添加成功', url('setting.address/index'));
}
return $this->renderError($model->getError() ?: '添加失败');
}
public function edit($address_id)
{
$model = ReturnAddressModel::detail($address_id);
if (!$this->request->isAjax()) {
return $this->fetch('edit', compact('model'));
}
if ($model->edit($this->postData('address'))) {
return $this->renderSuccess('更新成功', url('setting.address/index'));
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function delete($address_id)
{
$model = ReturnAddressModel::detail($address_id);
if (!$model->remove()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}