Gonghui.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. *
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Gonghui extends Backend
  11. {
  12. /**
  13. * Gonghui模型对象
  14. * @var \app\admin\model\Gonghui
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Gonghui;
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 查看
  28. */
  29. public function index()
  30. {
  31. //设置过滤方法
  32. $this->request->filter(['strip_tags', 'trim']);
  33. if ($this->request->isAjax()) {
  34. //如果发送的来源是Selectpage,则转发到Selectpage
  35. if ($this->request->request('keyField')) {
  36. return $this->selectpage();
  37. }
  38. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  39. //公会分权限
  40. $gh_map = [];
  41. $gh_ids = db('admin')->where('id',$this->auth->id)->value('gh_ids');
  42. if(empty($gh_ids)){
  43. $gh_map = ['id' => '-1'];
  44. }else{
  45. $gh_map = ['id' => ['IN',$gh_ids]];
  46. }
  47. if($gh_ids == '*'){
  48. $gh_map = [];
  49. }
  50. $list = $this->model
  51. ->where($where)
  52. ->where($gh_map)
  53. ->order($sort, $order)
  54. //->select(false);dump($list);exit;
  55. ->paginate($limit);
  56. $rows = collection($list->items())->toArray();
  57. foreach($rows as $key => $info){
  58. $info['usernum'] = Db::name('user')->where('gh_id',$info['id'])->count('id');
  59. $rows[$key] = $info;
  60. }
  61. $result = array("total" => $list->total(), "rows" => $rows);
  62. return json($result);
  63. }
  64. return $this->view->fetch();
  65. }
  66. }