TypeController.php 1.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: yhbr
 * Date: 2018/8/29
 * Time: 9:36
 */

namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class TypeController extends AdminBaseController {

    public function index() {
        $res=Db::name('type')->order('listorder')->paginate(20);
        return $this->fetch('index', [
            'type'  =>  $res,
            'page'  =>  $res->render()
        ]);
    }

    public function add() {
        $request=request();
        if($request->isPost()) {
            $post=$request->param();
            if(!empty($post['type_icon'])) {
                $post['type_icon'] = cmf_get_image_url($post['type_icon']);
            }
            if(Db::name('type')->insert($post)) {
                $this->success('添加成功');
            }else {
                $this->error('添加失败');
            }
        }else {
            return $this->fetch();
        }
    }

    public function edit() {
        $request=request();
        if($request->isPost()) {
            $post=$request->param();
            if(!empty($post['type_icon'])) {
                $post['type_icon'] = cmf_get_image_url($post['type_icon']);
            }
            if(Db::name('type')->update($post)) {
                $this->success('编辑成功');
            }else {
                $this->error('您未作出任何修改');
            }
        }else {
            return $this->fetch('edit', [
                'info'  =>  Db::name('type')->where(['id'=>$request->param('id')])->find()
            ]);
        }
    }

    public function del() {

    }

    public function listOrder() {
        $request=request();
        if($request->isAjax()) {
            Db::name('type')->update($request->param());
        }
    }

}