Intention.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\AuthGroup;
  4. use app\admin\model\AuthGroupAccess;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\Session;
  8. /**
  9. *
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Intention extends Backend
  14. {
  15. //快速搜索的字段
  16. protected $searchFields = ['unit_name','contacts'];
  17. /**
  18. * 无需鉴权的方法,但需要登录
  19. * @var array
  20. */
  21. protected $noNeedRight = ['unittypelist'];
  22. /**
  23. * Intention模型对象
  24. * @var \app\admin\model\Intention
  25. */
  26. protected $model = null;
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. $this->model = model('Intention');
  31. }
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags']);
  39. if ($this->request->isAjax())
  40. {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField'))
  43. {
  44. return $this->selectpage();
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $total = $this->model
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->count();
  51. $list = $this->model
  52. ->where($where)
  53. ->order($sort, $order)
  54. ->limit($offset, $limit)
  55. ->select();
  56. $list = collection($list)->toArray();
  57. $result = array("total" => $total, "rows" => $list);
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 添加
  64. */
  65. public function add()
  66. {
  67. if ($this->request->isPost())
  68. {
  69. $params = $this->request->post("row/a");
  70. if ($params)
  71. {
  72. if ($this->dataLimit && $this->dataLimitFieldAutoFill)
  73. {
  74. $params[$this->dataLimitField] = $this->auth->id;
  75. }
  76. try
  77. {
  78. //是否采用模型验证
  79. if ($this->modelValidate)
  80. {
  81. $name = basename(str_replace('\\', '/', get_class($this->model)));
  82. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  83. $this->model->validate($validate);
  84. }
  85. $params['usr_id'] = Session::get('admin')['id']; //usr id
  86. $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname
  87. $params['created_at'] = date('Y-m-d H:i:s'); //创建时间
  88. $params['usr_depart'] = Session::get('admin')['usr_depart']; //获取所属组名
  89. $params['depart_id'] = Session::get('admin')['depart_id']; //获取所属组id
  90. \app\admin\model\Intention::addUnitType($params['unit_type']);
  91. $result = $this->model->allowField(true)->save($params);
  92. if ($result !== false)
  93. {
  94. $this->success();
  95. }
  96. else
  97. {
  98. $this->error($this->model->getError());
  99. }
  100. }
  101. catch (\think\exception\PDOException $e)
  102. {
  103. $this->error($e->getMessage());
  104. }
  105. }
  106. $this->error(__('Parameter %s can not be empty', ''));
  107. }
  108. return $this->view->fetch();
  109. }
  110. /**
  111. * 性质列表
  112. */
  113. public function unitTypeList()
  114. {
  115. $list = Db::table('unit_type')
  116. ->select();
  117. $searchlist = [];
  118. foreach ($list as $key => $value)
  119. {
  120. $searchlist[] = ['id'=>$value['name'], 'name' => $value['name']];
  121. }
  122. $data = ['rows' => $searchlist];
  123. return $data;
  124. }
  125. }