Guild.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\controller\guild;
  3. use app\admin\model\Message;
  4. use app\common\controller\Backend;
  5. /**
  6. * 工会管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Guild extends Backend
  11. {
  12. protected $searchFields = 'g_id,user.u_id,user.nickname,name';
  13. /**
  14. * Guild模型对象
  15. * @var \app\admin\model\guild\Guild
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\guild\Guild;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. //当前是否为关联查询
  39. $this->relationSearch = true;
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if ($this->request->isAjax()) {
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. $list = $this->model
  49. ->with(['party','user','auth'])
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->getRelation('party')->visible(['party_name']);
  55. $row->getRelation('user')->visible(['u_id','nickname']);
  56. $row->getRelation('auth')->visible(['realname']);
  57. }
  58. $result = array("total" => $list->total(), "rows" => $list->items());
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 编辑
  65. */
  66. public function edit($ids = null)
  67. {
  68. $row = $this->model->get($ids);
  69. if (!$row) {
  70. $this->error(__('No Results were found'));
  71. }
  72. $adminIds = $this->getDataLimitAdminIds();
  73. if (is_array($adminIds)) {
  74. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  75. $this->error(__('You have no permission'));
  76. }
  77. }
  78. if ($this->request->isPost()) {
  79. $params = $this->request->post("row/a");
  80. if (!$params) {
  81. $this->error(__('Parameter %s can not be empty', ''));
  82. }
  83. $params = $this->preExcludeFields($params);
  84. $result = false;
  85. try {
  86. //是否采用模型验证
  87. if ($this->modelValidate) {
  88. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  89. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  90. $row->validateFailException(true)->validate($validate);
  91. }
  92. if (isset($params['status'])) {
  93. if ($params['status'] == 1) {
  94. Message::addMessage($row['user_id'],'家族申请通知','您申请的家族'.$row['name'].'已审核通过');
  95. } elseif ($params['status'] == -1) {
  96. Message::addMessage($row['user_id'],'家族申请通知','您申请的家族'.$row['name'].'已被拒绝');
  97. }
  98. }
  99. $result = $row->allowField(true)->save($params);
  100. } catch (ValidateException|PDOException|Exception $e) {
  101. $this->error($e->getMessage());
  102. }
  103. if ($result == false) {
  104. $this->error(__('No rows were updated'));
  105. }
  106. $this->success();
  107. }
  108. $this->view->assign("row", $row);
  109. return $this->view->fetch();
  110. }
  111. }