亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

產(chǎn)品模塊代碼

Original 2019-04-27 13:55:39 272
abstract:<?php /**  * Created by PhpStorm.  * User: Jason  * Date: 2019/4/26  * Time: 22:10  */ namespace app\admin\controller; u
<?php
/**
 * Created by PhpStorm.
 * User: Jason
 * Date: 2019/4/26
 * Time: 22:10
 */

namespace app\admin\controller;

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

// 產(chǎn)品控制器,繼承公共控制器,Common
class Product extends Common
{
    // 產(chǎn)品列表
    public function index()
    {
        // 獲取產(chǎn)品信息
        $product = ProductModel::order('id','desc')->paginate(8);

        // 模板賦值
        $this->assign('product',$product);

        // 渲染產(chǎn)品列表
        return $this->fetch();
    }

    // 添加產(chǎn)品頁面
    public function add()
    {
        // 渲染添加頁面
        return $this->fetch();
    }

    // 添加產(chǎn)品操作
    public function DoAdd()
    {
        // 接收表單上傳的數(shù)據(jù)
        $data = Request::param();
        // 獨立產(chǎn)品標(biāo)題
        $title = $data['title'];
        // 查詢標(biāo)題是否重復(fù)
        $pro = ProductModel::where('title',$title)->find();
        if($pro == true) {
            return ['code'=>0,'msg'=>'產(chǎn)品標(biāo)題重復(fù)!'];
        }

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

        $ins = ProductModel::create($data);
        if($ins == true) {
            return ['code'=>1,'msg'=>'產(chǎn)品添加成功'];
        }

        return ['code'=>0,'msg'=>'產(chǎn)品添加失敗'];
    }

    // 編輯頁面
    public function edit()
    {
        // 獲取產(chǎn)品ID
        $proid = Request::param('id');
        // 根據(jù)產(chǎn)品ID獲取數(shù)據(jù)
        $product = ProductModel::where('id',$proid)->find();
        // 模板賦值
        $this->assign('product',$product);
        // 渲染模板
        return $this->fetch();
    }

    // 編輯操作
    public function DoEdit()
    {
        // 獲取提交數(shù)據(jù)
        $data = Request::param();
        // 更新條件
        $pid = $data['pid'];
        // 更新操作
        $ins = ProductModel::where('id',$pid)->update([
            'title'=>$data['title'],
            'desc'=>$data['desc'],
            'content'=>$data['content'],
            'once'=>$data['once'],
            'over_night'=>$data['over_night'],
            'time'=>time(),
            'username'=>Session::get('username'),
        ]);

        if($ins) {
            // 返回更新成功
            return ['code'=>1,'msg'=>'產(chǎn)品信息編輯成功'];
        }
        // 返回更新失敗
        return ['code'=>0,'msg'=>'產(chǎn)品信息編輯失敗'];
    }

    // 圖片上傳
    public function upload()
    {
        // 獲取上傳圖片信息
        $file = Request::file('img');

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

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


    // 使用軟刪除
    public function DoDel()
    {
        // 獲取刪除條件
        $pid = Request::param('pid');
        // 刪除操作
        $del = ProductModel::destroy($pid);
        // 是否刪除成功
        if($del) {
            return ['code'=>1,'msg'=>'刪除成功'];
        }
        return ['code'=>0,'msg'=>'刪除失敗'];
    }
}


Correcting teacher:查無此人Correction time:2019-04-27 17:27:38
Teacher's summary:完成的不錯,cms后臺就是對數(shù)據(jù)庫數(shù)據(jù)進行操作。繼續(xù)加油

Release Notes

Popular Entries