Guild.php 5.3 KB

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