Head.php 3.6 KB

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