120 行
3.2 KiB
PHP
120 行
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\model\ReportModel;
|
|
|
|
/**
|
|
* 订单报修管理
|
|
* Class Report
|
|
* @package app\admin\controller
|
|
*/
|
|
class Report extends Backend
|
|
{
|
|
|
|
/**
|
|
* 模型对象
|
|
* @var \app\common\model\ReportModel
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new ReportModel();
|
|
$this->error('报修功能已关闭');
|
|
}
|
|
|
|
/**
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
*/
|
|
|
|
/**
|
|
* 获取列表
|
|
* @return mixed|string|\think\response\Json
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function index()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('post.page/d', 1);
|
|
$rows = input('post.rows/d', 20);
|
|
$search = input('post.search/a');
|
|
|
|
$result = $this->model->getLists([
|
|
'search' => $search,
|
|
], $rows, $page);
|
|
|
|
foreach ($result['list'] as &$item) {
|
|
$item['images'] = !empty($item['images']) ? explode(',', $item['images']) : '';
|
|
}
|
|
|
|
return json($result);
|
|
}
|
|
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 添加/编辑
|
|
public function add()
|
|
{
|
|
$data = input('post.');
|
|
if (!empty($data)) {
|
|
// 添加
|
|
if (empty($data['id'])) {
|
|
unset($data['id']);
|
|
$data['create_time'] = time();
|
|
if ($this->model->add($data)) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '添加成功'
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 400,
|
|
'msg' => '添加失败'
|
|
]);
|
|
}
|
|
}
|
|
|
|
// 编辑
|
|
$data['update_time'] = time();
|
|
|
|
if ($this->model->edit($data)) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '编辑成功'
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 400,
|
|
'msg' => '编辑失败'
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 删除
|
|
public function dell()
|
|
{
|
|
$id = input('id');
|
|
if (!empty($id)) {
|
|
$ids = strpos($id, ',') !== false ? explode(',', $id) : [$id];
|
|
foreach ($ids as $v) {
|
|
if (!$this->model->getItem((int)$v)) {
|
|
return json(['code' => 401, 'msg' => '您要删除的报修订单不存在']);
|
|
}
|
|
}
|
|
|
|
foreach ($ids as $v) {
|
|
$this->model->del($v);
|
|
}
|
|
return json(['code' => 200, 'msg' => '删除成功']);
|
|
}
|
|
}
|
|
|
|
}
|