MatchCert.php 2.0 KB
<?php

namespace app\school\controller\match;

use think\Db;
use app\common\controller\ManystoreBase;
use app\school\model\match\MatchCert as MatchCertModel;
/**
 * 证书管理
 */
class MatchCert extends ManystoreBase
{
    protected $model = null;
    protected $noNeedRight = ['*'];
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new MatchCertModel();
    }
    /**
     * 证书管理首页
     * @return \think\response\Json|void
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $count = $this->model->where($where)->count();
            $list = $this->model
                ->where($where)
                ->order('createtime', 'desc')
                ->limit($offset, $limit)
                ->select();
            $list = collection($list)->toArray();
            $result = array("total" => $count, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }


    /**
     * 添加证书
     */
    public function add()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                if($this->shopIdAutoCondition && SCHOOL_ID){
                    $params['school_id'] = SCHOOL_ID;
                }
                Db::startTrans();
                try {
                    $result = $this->model->save($params);
                    Db::commit();
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error('添加失败');
                }
                $this->success();
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        return $this->view->fetch();
    }

}