abstract:
namespace app\admin\controller;
use think\Controller;
use app\admin\model\User;
use app\admin\model\Sort;
use think\facade\Session;
use think\facade\Request;
use app\admin\controller\Commn;
class Sortl extends Commn
{
public function index()
{
$res = Sort::order('sort_id','desc')->paginate(4);
$page = $res->render();
$this->assign('res',$res);
$this->assign('page',$page);
return $this->fetch();
}
public function index_do()
{
$data = Request::param();
$data['username'] = Session::get('username');
$data['sort_create_time'] = time();
$sort_name = $data['sort_name'];
if ($res = Sort::where('sort_name',$sort_name)->find()) {
return json(['code'=>1,'msg'=>'不可以添加重复分类']);
}
if ($sort = Sort::insert($data)) {
return json(['code'=>2,'msg'=>'添加分类成功']);
}else{
return json(['code'=>3,'msg'=>'添加分类失败']);
}
}
public function upl()
{
$data = Request::param();
$sort_id = $data['id'];
$res = Sort::where('sort_id',$sort_id)->find();
$this->assign('res',$res);
return $this->fetch();
}
public function upl_do()
{
$data = Request::param();
//验证唯一
$sort_id = $data['sort_id'];
//查询
// $res = Sort::where('sort_id',$sort_id)->find();
// if ($res['sort_name'] == $data['sort_name']) {
// if ($res = Sort::where('sort_id',$sort_id)->update($data)) {
// return json(['code'=>1,'msg'=>'修改分类成功']);
// }else{
// return json(['code'=>2,'msg'=>'修改操作错误,请重新修改']);
// }
// }
if ($Sort = Sort::where('sort_id',$sort_id)->update($data)) {
return json(['code'=>1,'msg'=>'修改分类成功']);
}else{
return json(['code'=>2,'msg'=>'修改操作错误,请重新修改']);
}
}
public function del()
{
$data = Request::param();
$sort_id = $data['id'];
if ($res = Sort::where('sort_id',$sort_id)->delete()) {
return json(['code'=>1,'msg'=>'删除分类成功']);
}else{
return json(['code'=>2,'msg'=>'删除分类失败']);
}
}
}
Correcting teacher:查无此人Correction time:2019-06-17 09:31:55
Teacher's summary:完成的不错。一天做了很多作业,对后台管理应该很熟悉了。继续加油。