Intention.php 3.8 KB

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