国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

產(chǎn)品的添加,編輯,刪除操作

Original 2019-02-03 10:54:27 319
abstract:<?php/** * Created by PhpStorm. * User: Administrator * Date: 2019-01-31 * Time: 10:18 */namespace app\admin\controller;use app\admin\controller\Common;use think\facade\Request;use think\facade\Ses

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019-01-31
* Time: 10:18
*/

namespace app\admin\controller;

use app\admin\controller\Common;
use think\facade\Request;
use think\facade\Session;
use app\admin\model\ProductModel;

class Product extends Common
{
   public  function index()
   {
       $product = new ProductModel();

       $products = $product->order('id','desc')->paginate(5);

       $this->view->products =$products;

      return $this->fetch();
   }

   public function add()
   {
       return $this->view->fetch();
   }

   public function edit()
   {
     $id =Request::param('id');

     $product =ProductModel::get($id);

     $this->view->product = $product;

     return $this->fetch();



   }

   public function doadd()
   {
       $data =Request::param();

       $title =$data['title'];

       $info = ProductModel::where('title',$title)->find();

       if ($info)
       {
           return ['res'=>0,'msg'=>'產(chǎn)品名稱重復(fù)'];
       }

       $data['time']=time();
       $data['username']=Session::get('username');

       $produst = new ProductModel();

       $res =$produst->save($data);

       if ($res)
       {
           return ['res'=>1,'msg'=>'保存成功'];
       }
       else
       {
           return  ['res'=>0,'msg'=>'保存失敗'];
       }

   }

   public function upload()
   {
       $file= Request::file('img');

       $info = $file->validate(['ext'=>'jpg,jpeg,png,gif'])-> move('upload');

       if ($info)
       {
           return json(['errno'=>0,'data'=>['/upload/'.$info->getSaveName()]]);
       }
       else
       {
           return $file->getError();
       }
   } //上傳圖片

   public function doedit() //編輯商品
   {
       $data = Request::param();

       $product = new ProductModel();

       $data['time']= time();

       $data['username']= Session::get('username');

       $info = $product-> save([
         'title'=>$data['title'],
         'desc'=> $data['desc'],
          'content'=> $data['content'],
           'price1'=>$data['price1'],
          'price2'=> $data['price2'],
           'time'=> $data['time'],
            'username'=> $data['username'],],['id'=>$data['id']]   );

       if($info)
       {
           return ['res'=>1, 'msg'=>'更新成功'];
       }
       else
       {
           return ['res'=>0,'msg'=>'更新失敗'];

       }

   }


   public function del()
   {
       $id= Request::param('id');

       $product = new ProductModel();

       $res = $product->destroy($id);

       if ($res)
       {
           return ['res'=>1,'msg'=>' 刪除成功'];
       }
   }

}

Correcting teacher:天蓬老師Correction time:2019-02-03 15:06:10
Teacher's summary:下次不要這樣提交了, 一行注釋不寫, 讓人猜嗎

Release Notes

Popular Entries