Joinin.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\admin\controller\guild;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 公会加入申请管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Joinin extends Backend
  11. {
  12. /**
  13. * Joinin模型对象
  14. * @var \app\admin\model\guild\Joinin
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\guild\Joinin;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. }
  23. public function import()
  24. {
  25. parent::import();
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //当前是否为关联查询
  38. $this->relationSearch = true;
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if ($this->request->isAjax()) {
  42. //如果发送的来源是Selectpage,则转发到Selectpage
  43. if ($this->request->request('keyField')) {
  44. return $this->selectpage();
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $list = $this->model
  48. ->with(['guild','user'])
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('guild')->visible(['name']);
  54. $row->getRelation('user')->visible(['username']);
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. /**
  62. * 审核
  63. */
  64. public function audit(){
  65. $id = input('id');
  66. $info = Db::name('guild_joinin')
  67. ->where('id',$id)
  68. ->find();
  69. if ($this->request->isPost()) {
  70. $status = input('status',0);
  71. Db::startTrans();
  72. if($status == 1){
  73. //判断重复
  74. $memberfind = \app\common\model\GuildMember::where(["user_id"=>$info['user_id']])->find();
  75. if($memberfind) {
  76. Db::rollback();
  77. //包括成员,副会,会长角色
  78. $this->error("该用户已有公会!");
  79. }
  80. //清理其他公会未审核的数据
  81. $joinWhere['user_id'] = $info['user_id'];
  82. $joinWhere['guild_id'] = ['neq',$info['guild_id']];
  83. $joinWhere['status'] = 0;
  84. $joinData = Db::name('guild_joinin')->where($joinWhere)->delete();
  85. $data = [];
  86. $data["guild_id"] = $info['guild_id'];
  87. $data["user_id"] = $info['user_id'];
  88. $data["role"] = 0;
  89. $data["createtime"] = time();
  90. $res3 = \app\common\model\GuildMember::insert($data);
  91. $res4 = \app\common\model\Guild::where(["id"=>$info['guild_id']])->setInc("member");
  92. //系统消息
  93. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'公会审核','入会审核已经通过');
  94. }elseif($status == -1){
  95. //系统消息
  96. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'公会审核','入会审核已经被拒绝');
  97. }
  98. $data = [
  99. 'status' => $status,
  100. 'updatetime' => time(),
  101. ];
  102. $rs = Db::name('guild_joinin')->where('id',$id)->update($data);
  103. Db::commit();
  104. $this->success('审核完成');
  105. }
  106. $this->assign('row',$info);
  107. return $this->view->fetch();
  108. }
  109. }