Intention.php 3.3 KB

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