Guild.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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(['user','shoproarea'])
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->getRelation('user')->visible(['username']);
  55. $row->getRelation('shoproarea')->visible(['province_name','name']);
  56. }
  57. $result = array("total" => $list->total(), "rows" => $list->items());
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 编辑
  64. */
  65. public function edit($ids = null)
  66. {
  67. $row = $this->model->get($ids);
  68. if (!$row) {
  69. $this->error(__('No Results were found'));
  70. }
  71. $adminIds = $this->getDataLimitAdminIds();
  72. if (is_array($adminIds)) {
  73. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  74. $this->error(__('You have no permission'));
  75. }
  76. }
  77. if ($this->request->isPost()) {
  78. $params = $this->request->post("row/a");
  79. if (!$params) {
  80. $this->error(__('Parameter %s can not be empty', ''));
  81. }
  82. $params = $this->preExcludeFields($params);
  83. $result = false;
  84. try {
  85. //是否采用模型验证
  86. if ($this->modelValidate) {
  87. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  88. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  89. $row->validateFailException(true)->validate($validate);
  90. }
  91. if (isset($params['status'])) {
  92. if ($params['status'] == 1) {
  93. //房间也给打开
  94. $udpate = [
  95. 'status' => 1,
  96. ];
  97. Db::name('party')->where('id',$row['party_id'])->update($udpate);
  98. Message::addMessage($row['user_id'],'公会申请通知','您申请的公会'.$row['name'].'已审核通过');
  99. } elseif ($params['status'] == -1) {
  100. Message::addMessage($row['user_id'],'公会申请通知','您申请的公会'.$row['name'].'已被拒绝');
  101. }
  102. }
  103. $result = $row->allowField(true)->save($params);
  104. } catch (ValidateException|PDOException|Exception $e) {
  105. $this->error($e->getMessage());
  106. }
  107. if ($result == false) {
  108. $this->error(__('No rows were updated'));
  109. }
  110. $this->success();
  111. }
  112. $this->view->assign("row", $row);
  113. return $this->view->fetch();
  114. }
  115. }