www_fpvone_cn/application/admin/controller/cms/Diyform.php

118 lines
3.0 KiB
PHP
Raw Normal View History

2024-12-20 12:29:51 +08:00
<?php
namespace app\admin\controller\cms;
use app\common\controller\Backend;
/**
* 自定义表单表
*
* @icon fa fa-list
*/
class Diyform extends Backend
{
/**
* Model模型对象
*/
protected $model = null;
protected $searchFields = 'id,name,title,table';
protected $noNeedRight = ['check_element_available'];
public function _initialize()
{
parent::_initialize();
$config = get_addon_config('cms');
if ($config['diyformdatalimit'] != 'all') {
$this->dataLimit = $config['diyformdatalimit'];
}
$this->assignconfig('spiderRecord', intval($config['spiderrecord']?? 0));
$this->model = new \app\admin\model\cms\Diyform;
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where($where)
->order($sort, $order)
->paginate($limit);
\app\admin\model\cms\SpiderLog::render($list, 'diyform');
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function add()
{
if ($this->request->isAjax()){
$params = $this->request->post('row/a');
if ($params['notice'] == 1 && empty($params['notice_mobile'])){
$this->error("通知人手机号不能为空!");
}
parent::add();
}
return $this->view->fetch();
}
public function edit($ids = null)
{
if ($this->request->isAjax()){
$params = $this->request->post('row/a');
if ($params['notice'] == 1 && empty($params['notice_mobile'])){
$this->error("通知人手机号不能为空!");
}
}
parent::edit($ids);
return $this->view->fetch();
}
/**
* 检测元素是否可用
* @internal
*/
public function check_element_available()
{
$id = $this->request->request('id');
$name = $this->request->request('name');
$value = $this->request->request('value');
$name = substr($name, 4, -1);
if (!$name) {
$this->error(__('Parameter %s can not be empty', 'name'));
}
if ($id) {
$this->model->where('id', '<>', $id);
}
$exist = $this->model->where($name, $value)->find();
if ($exist) {
$this->error(__('The data already exist'));
} else {
$this->success();
}
}
}