Gonghui.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $list = $this->model
  40. ->where($where)
  41. ->order($sort, $order)
  42. ->paginate($limit);
  43. $rows = collection($list->items())->toArray();
  44. foreach($rows as $key => $info){
  45. $info['usernum'] = Db::name('user')->where('gh_id',$info['id'])->count('id');
  46. $rows[$key] = $info;
  47. }
  48. $result = array("total" => $list->total(), "rows" => $rows);
  49. return json($result);
  50. }
  51. return $this->view->fetch();
  52. }
  53. }