abstrait:<?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
{
//產(chǎn)品展示
public function index()
{
//查詢產(chǎn)品
$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()
{
// //查詢產(chǎn)品分類
// $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'=>'產(chǎn)品名重復(fù),添加產(chǎn)品失敗']);
}
$data['create_time'] = time();
if ($product = Product::insert($data)) {
return json(['code'=>2,'msg'=>'添加產(chǎn)品成功']);
}else{
return json(['code'=>3,'msg'=>'添加產(chǎn)品失敗']);
}
}
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();
//查詢這條用戶數(shù)據(jù)
$res = Product::where('product_id',$product_id)->find();
// //判斷如果傳過來的產(chǎn)品名稱重復(fù),是根據(jù)產(chǎn)品id查詢出來的產(chǎn)品一致
if ($res['product_name'] == $data['product_name']) {
if ($Productl = Product::where('product_id',$product_id)->update($data)) {
return json(['code'=>1,'msg'=>'修改產(chǎn)品成功']);
}else{
return json(['code'=>2,'msg'=>'修改產(chǎn)品失敗']);
}
}else{
if ($info = Product::where('product_id',$product_id)->all()) {
return json(['code'=>3,'msg'=>'修改產(chǎn)品名已經(jīng)存在,修改產(chǎn)品失敗']);
}
}
}
public function del()
{
//接值
$data = Request::param();
//產(chǎn)品id
$product_id = $data['id'];
//刪除操作
if ($Productl = Product::where('product_id',$product_id)->delete()) {
return json(['code'=>1,'msg'=>'刪除產(chǎn)品成功']);
}else{
return json(['code'=>2,'msg'=>'刪除產(chǎn)品失敗']);
}
}
}
?>
Professeur correcteur:查無此人Temps de correction:2019-06-17 09:31:47
Résumé du professeur:完成的不錯(cuò)。一天做了很多作業(yè),對(duì)后臺(tái)管理應(yīng)該很熟悉了。繼續(xù)加油。