返回 小型企业站产品...... 登陆

小型企业站产品缩略图模块

1 2019-06-16 10:06:17 385

<?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'=>'删除失败']);

}

}

}


























 ?>

EVTI)`N8B]8MTOV{Y2AKD4Y.png

最新手记推荐

• 用composer安装thinkphp框架的步骤 • 省市区接口说明 • 用thinkphp,后台新增栏目 • 管理员添加编辑删除 • 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消 回复 发送
  • PHP中文网