Blame view

application/admin/controller/qingdong/general/Form.php 2.67 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  <?php

  

  namespace app\admin\controller\qingdong\general;

  

  use addons\qingdong\model\FormField;

  use app\admin\controller\qingdong\Base;

  use addons\qingdong\model\Field;

  use think\Db;

  use think\Exception;

  

  /**

   * 字段管理

   */

  class Form extends Base {

  	protected $relationSearch = true;

  	/**

  	 * @var \addons\qingdong\model\Form

  	 */

  	protected $model       = null;

  

  

  	public function _initialize() {

  		parent::_initialize();

  		$this->model =new \addons\qingdong\model\Form;

  	}

  

  

  	/**

  	 * 查看

  	 */

  	public function index() {

  		//设置过滤方法

  		$this->request->filter(['strip_tags', 'trim']);

  		if ($this->request->isAjax()) {

  

  			$forms = $this->model->where([])->select();

  			$forms = collection($forms)->toArray();

  			if (empty($forms)) {

  				$insertALl = $this->model->field('name,type,data')->select();

  				$insertALl = collection($insertALl)->toArray();

  				foreach ($insertALl as $k => $item) {

  					$item['createtime'] = time();

  					$item['updatetime'] = time();

  					$insertALl[$k]      = $item;

  				}

  				$this->model->insertAll($insertALl);

  				$forms = $this->model->select();

  				$forms = collection($forms)->toArray();

  			}

  

  

  			$result = array("total" => count($forms), "rows" => $forms);

  

  			return json($result);

  		}

  

  		return $this->view->fetch();

  	}

  

  

      /**

       * 修改字段

       */

  	public function edit($ids = null) {

          if ($this->request->isPost()) {

              $id = input('id');

              $data = input('data');

              if (empty($id) || empty($data)) {

                  $this->error('参数错误');

              }

              $row = $this->model->where(['id' => $id])->find();

              if (empty($row)) {

                  $this->error('表单不存在');

              }

              Db::startTrans();

              try {

                  $result=$this->model->updateForm($id, $data);

                  if($result === false){

                      throw new Exception('修改表单失败');

                  }

                  Db::commit();

              } catch (Exception $e) {

                  Db::rollback();

                  $this->error($e->getMessage());

              }

              $this->success('设置成功');

          }

  		$basefile = request()->baseFile();

  

  		$this->assign("basefile", $basefile);

  		$this->assign("token", $this->request->token());

  

  		$this->view->engine->layout(false);

  

  		return $this->view->fetch();

  	}

  

      /**

       * 获取模板详情

       */

  	public function getinfo() {

  		$id = input('id');

  		if (empty($id)) {

  			$this->error('参数不存在');

  		}

  		$find = $this->model->where(['id' => $id])->find();

  

  		$this->success('请求成功', '', $find);

  	}

  }