abstract:<?php namespace app\admin\controller; use app\admin\controller\Commn; use think\facade\Request; use think\facade\Session; use app\admin\model\Newsl; use app\admin\model\Product; use app\admin
<?php
namespace app\admin\controller;
use app\admin\controller\Commn;
use think\facade\Request;
use think\facade\Session;
use app\admin\model\Newsl;
use app\admin\model\Product;
use app\admin\model\ProductPic;
/**
*
*/
class ProductlPic extends Commn
{
//缩略图展示
public function index()
{
//查询产品返回add页面
$res = ProductPic::order('propic_id','desc')->paginate(4);
$page = $res->render();
$this->assign('page',$page);
$this->assign('res',$res);
return $this->fetch();
}
public function add()
{
//查询产品返回add页面
$res = Product::all();
$this->assign('res',$res);
return $this->fetch();
}
public function add_do()
{
$data = Request::param();
$data['create_time'] = time();
$data['username'] = Session::get('username');
if ($res = ProductPic::insert($data)) {
return json(['code'=>0,'msg'=>'添加成功']);
}else{
return json(['code'=>1,'msg'=>'添加失败']);
}
}
//缩略图上传方法
public function upload()
{
//获取文件上传信息
$file = Request::file('file');
//验证点后缀移动到指定文件夹
if ($info = $file->validate(['ext'=>'jpg,png,jpng,gif'])->move('upload')) {
//拼接图片路径
$filename = '/upload/'.$info->getSaveName();
//返回json信息
return json(['code'=>1,'msg'=>'上传成功','data'=>$filename]);
}else{
echo $file->getError();
}
}
//删除缩略图方法
public function del()
{
$data = Request::param();
$propic_id = $data['propic_id'];
if ($res = ProductPic::where('propic_id',$propic_id)->delete()) {
return json(['code'=>0,'msg'=>'删除成功']);
}else{
return json(['code'=>1,'msg'=>'删除失败']);
}
}
}
?>
Correcting teacher:查无此人Correction time:2019-06-17 09:31:51
Teacher's summary:完成的不错。一天做了很多作业,对后台管理应该很熟悉了。继续加油。