HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/cs.wgegeghx.com/application/formguide/controller/Field.php
<?php





// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )





// | 表单字段后台管理

namespace app\formguide\controller;

use app\common\controller\Adminbase;
use app\formguide\model\ModelField as ModelField;
use think\Db;

class Field extends AdminBase
{
    public $fields, $banfie;
    protected $modelClass = null;
    //初始化
    protected function initialize()
    {
        parent::initialize();
        //允许使用的字段列表
        $this->banfie     = array("text", "checkbox", "textarea", "radio", "select", "image", "number", "Ueditor", "color", "file");
        $this->modelClass = new ModelField;
    }

    //首页
    public function index()
    {
        $fieldid = $this->request->param('id/d', 0);
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $order                      = $this->request->param("order/s", "DESC");
            $sort                       = $this->request->param("sort", 'id');
            $count                      = $this->modelClass->where($where)->where(['modelid' => $fieldid])->count();
            $data                       = $this->modelClass->where($where)->where(['modelid' => $fieldid])->page($page, $limit)->order($sort, $order)->select();
            return json(["code" => 0, 'count' => $count, "data" => $data]);
        } else {
            $this->assign("id", $fieldid);
            return $this->fetch();
        }
    }

    //添加
    public function add()
    {
        if ($this->request->isPost()) {
            //增加字段
            $data   = $this->request->post();
            $result = $this->validate($data, 'ModelField');
            if (true !== $result) {
                return $this->error($result);
            }
            try {
                $res = $this->modelClass->addField($data);
            } catch (\Exception $e) {
                $this->error($e->getMessage());
            }
            $this->success('新增成功');
        } else {
            $fieldid   = $this->request->param('id/d', 0);
            $fieldType = Db::name('field_type')->where('name', 'in', $this->banfie)->order('listorder')->column('name,title,default_define,ifoption,ifstring');
            $modelInfo = Db::name('model')->where('id', $fieldid)->find();
            $this->assign(
                [
                    'modelType' => $modelInfo['type'],
                    "modelid"   => $fieldid,
                    'fieldType' => $fieldType,
                ]
            );
            return $this->fetch();
        }

    }

    //编辑
    public function edit()
    {
        $fieldid = $this->request->param('id/d', 0);
        if ($this->request->isPost()) {
            $data   = $this->request->post();
            $result = $this->validate($data, 'ModelField');
            if (true !== $result) {
                return $this->error($result);
            }
            try {
                $this->modelClass->editField($data, $fieldid);
            } catch (\Exception $e) {
                $this->error($e->getMessage());
            }
            $this->success("更新成功!");
        } else {
            //字段信息
            $fieldData = ModelField::get($fieldid);
            //字段扩展配置
            $fieldData['setting'] = unserialize($fieldData['setting']);
            if (empty($fieldData)) {
                $this->error('该字段信息不存在!');
            }
            //模型信息
            $modedata = Db::name('model')->where('id', $fieldData->getAttr('modelid'))->find();
            if (empty($modedata)) {
                $this->error('该模型不存在!');
            }
            $fieldType = Db::name('field_type')->where('name', 'in', $this->banfie)->order('listorder')->column('name,title,default_define,ifoption,ifstring');
            $this->assign([
                'data'      => $fieldData,
                'fieldid'   => $fieldid,
                'fieldType' => $fieldType,
            ]);
            return $this->fetch();
        }
    }

    //删除
    public function del()
    {
        $fieldid = $this->request->param('id/d', 0);
        if (empty($fieldid)) {
            $this->error('字段ID不能为空!');
        }
        try {
            $this->modelClass->deleteField($fieldid);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success("字段删除成功!");
    }
}