Guild.php 4.4 KB

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