|
<?php
namespace app\controller;
use think\App;
use think\facade\View;
use app\model\GoodsCategory as CategoryModel;
use app\model\Department as DepartmentModel;
class GoodsCategory extends Base
{
protected $model;
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new CategoryModel();
}
public function index()
{
$list = $this->model->select();
return View::fetch('',['list'=>$list]);
}
public function info($id)
{
$data = $this->model->find($id);
if ($this->request->isAjax()) {
return json(['code'=>2, 'data'=>$data]);
}
}
public function save()
{
if ($this->request->isPost()) {
$param = $this->request->param();
try {
if ($param['id']) {
$goodsCategory = $this->model->find(intval($param['id']));
} else {
$goodsCategory = new CategoryModel();
$goodsCategory->create_time = time();
}
$goodsCategory->name = $param['name'];
$goodsCategory->save();
} catch (\Exception $e) {
return json(['code'=>0, 'msg'=>$e->getMessage()]);
}
return json(['code'=>2]);
}
}
public function delete($id)
{
if ($this->request->isPost()) {
if ($this->model->destroy($id)) {
return json(['code'=>2]);
} else {
return json(['code'=>0]);
}
}
}
}
|