Head.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\library\Auth;
  5. use app\common\model\Apply;
  6. use app\common\model\SystemMessages;
  7. use app\common\model\User as UserModel;
  8. use fast\Date;
  9. /**
  10. * 会员管理
  11. *
  12. * @icon fa fa-user
  13. */
  14. class Head extends Backend
  15. {
  16. protected $relationSearch = true;
  17. protected $searchFields = 'id,username,nickname';
  18. /**
  19. * @var \app\admin\model\User
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = model('User');
  26. }
  27. /**
  28. * 查看
  29. */
  30. public function index()
  31. {
  32. //设置过滤方法
  33. $this->request->filter(['strip_tags', 'trim']);
  34. if ($this->request->isAjax()) {
  35. //如果发送的来源是Selectpage,则转发到Selectpage
  36. if ($this->request->request('keyField')) {
  37. return $this->selectpage();
  38. }
  39. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  40. $list = $this->model
  41. ->with('group')
  42. ->where($where)
  43. ->order($sort, $order)
  44. ->paginate($limit);
  45. foreach ($list as $k => $v) {
  46. $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
  47. $v->hidden(['password', 'salt']);
  48. }
  49. $result = array("total" => $list->total(), "rows" => $list->items());
  50. return json($result);
  51. }
  52. return $this->view->fetch();
  53. }
  54. /**
  55. * 审核
  56. */
  57. public function audit($ids = '',$audit = ''){
  58. if (!$this->request->isPost()) {
  59. $this->error(__("Invalid parameters"));
  60. }
  61. $ids = $ids ? $ids : $this->request->post("ids");
  62. $row = $this->model->get($ids);
  63. if (!$row) {
  64. // print_r($ids);
  65. // exit();
  66. $this->error(__('No Results were found'));
  67. }
  68. if($audit == 1){
  69. $row->image_audit = $audit;
  70. $row->save($row->image_audit);
  71. SystemMessages::messages('headimg_yes',$ids);
  72. $time = Date('Y-m-d H:i:s');
  73. $row->save(['avatar_time'=>$time,'avatar'=>$row->avatar_new]);
  74. //奖励邀请者狗粮
  75. if($row->id_authentication && $row->inviter_id){
  76. $gain_grain = config('site.gain_grain')['邀请用户注册'];
  77. UserModel::money($gain_grain,$row->inviter_id,'邀请用户奖励');
  78. }
  79. }elseif($audit == 2) {
  80. $row->image_audit = $audit;
  81. $reason = '拒绝原因:'.$this->request->post('avatar_reason');
  82. $row->save($row->image_audit);
  83. SystemMessages::messages('headimg_no',$ids,$reason);
  84. }
  85. //发送微信模板消息
  86. Apply::wxAuditMessage($row->id,1,$audit);
  87. $this->success();
  88. }
  89. /**
  90. * 添加
  91. */
  92. public function add()
  93. {
  94. if ($this->request->isPost()) {
  95. $this->token();
  96. }
  97. return parent::add();
  98. }
  99. /**
  100. * 编辑
  101. */
  102. public function edit($ids = null)
  103. {
  104. if ($this->request->isPost()) {
  105. $this->token();
  106. }
  107. $row = $this->model->get($ids);
  108. $this->modelValidate = true;
  109. if (!$row) {
  110. $this->error(__('No Results were found'));
  111. }
  112. $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
  113. return parent::edit($ids);
  114. }
  115. /**
  116. * 删除
  117. */
  118. public function del($ids = "")
  119. {
  120. if (!$this->request->isPost()) {
  121. $this->error(__("Invalid parameters"));
  122. }
  123. $ids = $ids ? $ids : $this->request->post("ids");
  124. $row = $this->model->get($ids);
  125. $this->modelValidate = true;
  126. if (!$row) {
  127. $this->error(__('No Results were found'));
  128. }
  129. Auth::instance()->delete($row['id']);
  130. $this->success();
  131. }
  132. }