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; /** * *
<?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;
/**
*
*/
class Productl extends Commn
{
//产品展示
public function index()
{
//查询产品
$data = Product::order('product_id','desc')->paginate(4);
//分页page
$page = $data->render();
$this->assign('page',$page);
$this->assign('data',$data);
return $this->fetch();
}
//图片上传页面
public function uplode()
{
//获取图片信息
$file = Request::file('img');
if ($info = $file->validate(['ext'=>'jpg,png,jpeg,gif'])->move('upload')){
//返回上次成功信息
return json(['errno'=>0,'data'=>["/upload/" .$info->getSaveName()]]);
}else{
echo $info->getError();
}
}
public function add()
{
// //查询产品分类
// $res = Product::all();
// $this->assign('res',$res);
return $this->fetch();
}
public function add_do()
{
$data = Request::param();
$data['username'] = Session::get('username');
$product_name = $data['product_name'];
if ($res = Product::where('product_name',$product_name)->find()) {
return json(['code'=>1,'msg'=>'产品名重复,添加产品失败']);
}
$data['create_time'] = time();
if ($product = Product::insert($data)) {
return json(['code'=>2,'msg'=>'添加产品成功']);
}else{
return json(['code'=>3,'msg'=>'添加产品失败']);
}
}
public function upl()
{
$data = Request::param();
$product_id = $data['product_id'];
$res = Product::where('product_id',$product_id)->find();
$this->assign('res',$res);
return $this->fetch();
}
public function upl_do()
{
$data = Request::param();
$product_id = $data['product_id'];
$data['create_time'] = time();
//查询这条用户数据
$res = Product::where('product_id',$product_id)->find();
// //判断如果传过来的产品名称重复,是根据产品id查询出来的产品一致
if ($res['product_name'] == $data['product_name']) {
if ($Productl = Product::where('product_id',$product_id)->update($data)) {
return json(['code'=>1,'msg'=>'修改产品成功']);
}else{
return json(['code'=>2,'msg'=>'修改产品失败']);
}
}else{
if ($info = Product::where('product_id',$product_id)->all()) {
return json(['code'=>3,'msg'=>'修改产品名已经存在,修改产品失败']);
}
}
}
public function del()
{
//接值
$data = Request::param();
//产品id
$product_id = $data['id'];
//删除操作
if ($Productl = Product::where('product_id',$product_id)->delete()) {
return json(['code'=>1,'msg'=>'删除产品成功']);
}else{
return json(['code'=>2,'msg'=>'删除产品失败']);
}
}
}
?>
Correcting teacher:查无此人Correction time:2019-06-17 09:31:47
Teacher's summary:完成的不错。一天做了很多作业,对后台管理应该很熟悉了。继续加油。