PhoneMonitor.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class PhoneMonitor extends Auth {
  6. public function __construct(App $app = null) {
  7. parent::__construct($app);
  8. $this->table = 'phone_monitor';
  9. $this->model = new \app\common\model\PhoneMonitor();
  10. }
  11. public function index() {
  12. if (request()->isAjax()) {
  13. //分页参数
  14. $length = input('rows', 10, 'intval'); //每页条数
  15. $page = input('page', 1, 'intval'); //第几页
  16. $start = ($page - 1) * $length; //分页开始位置
  17. //排序
  18. $sortRow = input('sidx', 'id', 'trim'); //排序列
  19. $sort = input('sord', 'desc', 'trim'); //排序方式
  20. $order = $sortRow . ' ' . $sort;
  21. $title = input('title', '', 'trim');
  22. if ($title) {
  23. $map[] = ['title', 'like', '%' . $title . '%'];
  24. }
  25. $enable = input('enable', '', 'trim');
  26. if ($enable != '') {
  27. $map[] = ['enable', '=', $enable];
  28. }
  29. $map[] = ['del', '=', 0];
  30. $map[] = ['org_id', '=', $this->orgId];
  31. $map = empty($map) ? true : $map;
  32. //数据查询
  33. $lists = db($this->table)->where($map)->limit($start, $length)->order($order)->select();
  34. foreach ($lists as $k => $v) {
  35. $lists[$k]['user_name'] = Db::name('user')
  36. ->where('id', $v['user_id'])
  37. ->value('real_name');
  38. $lists[$k]['dep_name'] = Db::name('user_dep')
  39. ->alias('a')
  40. ->join('dep b', 'a.dep_id=b.id')
  41. ->where('a.user_id', $v['user_id'])
  42. ->value('b.title');
  43. $lists[$k]['address_title'] = Db::name('address')
  44. ->where('id', $v['address_id'])
  45. ->value('title');
  46. }
  47. //数据返回
  48. $totalCount = db($this->table)->where($map)->count();
  49. $totalPage = ceil($totalCount / $length);
  50. $result['page'] = $page;
  51. $result['total'] = $totalPage;
  52. $result['records'] = $totalCount;
  53. $result['rows'] = $lists;
  54. return json($result);
  55. }
  56. else {
  57. return $this->fetch();
  58. }
  59. }
  60. /**
  61. * 新增/编辑
  62. */
  63. public function add($id = 0) {
  64. if (request()->isPost()) {
  65. $res = $this->model->updates();
  66. if ($res) {
  67. $this->success('操作成功', url('index'));
  68. }
  69. else {
  70. $this->error($this->model->getError());
  71. }
  72. }
  73. else {
  74. if ($id) {
  75. $info = db($this->table)->where('id', $id)->find();
  76. $this->assign('info', $info);
  77. }
  78. $user = model('user')->gerUserAll($this->orgId);
  79. $address = (new \app\common\model\Address())->getListByType(1);
  80. $this->assign('user', $user);
  81. $this->assign('address', $address);
  82. return $this->fetch();
  83. }
  84. }
  85. /**
  86. * 删除记录
  87. * @param int $id
  88. */
  89. public function del($id = 0) {
  90. if (!$id) {
  91. $this->error('参数错误');
  92. }
  93. $res = db($this->table)->where('id', $id)->setField('del', 1);
  94. if ($res) {
  95. $this->success('删除成功');
  96. }
  97. else {
  98. $this->error('删除失败');
  99. }
  100. }
  101. public function show() {
  102. if(request()->isAjax()){
  103. //分页参数
  104. $length = input('rows',10,'intval'); //每页条数
  105. $page = input('page',1,'intval'); //第几页
  106. $start = ($page - 1) * $length; //分页开始位置
  107. //排序
  108. $sortRow = input('sidx','id','trim'); //排序列
  109. $sort = input('sord','desc','trim'); //排序方式
  110. $order = $sortRow.' '.$sort;
  111. $content = input('title','','trim');
  112. if($content){
  113. $map[] = ['phone|order_id','like','%'.$content.'%'];
  114. }
  115. $map[] = ['del','=',0];
  116. $map[] = ['org_id','=',$this->orgId];
  117. $map= empty($map) ? true: $map;
  118. //数据查询
  119. $lists = db('phone_monitor_record')->where($map)
  120. ->limit($start,$length)->order($order)->select();
  121. foreach ($lists as $k=>$v){
  122. }
  123. //数据返回
  124. $totalCount = db('phone_monitor_record')->where($map)->count();
  125. $totalPage = ceil($totalCount/$length);
  126. $result['page'] = $page;
  127. $result['total'] = $totalPage;
  128. $result['records'] = $totalCount;
  129. $result['rows'] = $lists;
  130. return json($result);
  131. }else{
  132. return $this->fetch();
  133. }
  134. }
  135. }