AttendanceMachineCmd.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class AttendanceMachineCmd extends Auth
  5. {
  6. public function index()
  7. {
  8. if (request()->isAjax()) {
  9. //分页参数
  10. $length = input('rows', 10, 'intval'); //每页条数
  11. $page = input('page', 1, 'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx', 'id', 'trim'); //排序列
  15. $sort = input('sord', 'desc', 'trim'); //排序方式
  16. $order = $sortRow . ' ' . $sort;
  17. $sn = input('sn', '', 'trim');
  18. if ($sn) {
  19. $map[] = ['am.sn', '=',$sn];
  20. }
  21. $map[] = ['am.org_id', '=', $this->orgId];
  22. $map[] = ['am.del', '=', 0];
  23. $map = empty($map) ? true : $map;
  24. //数据查询
  25. $lists = db('attendance_machine_cmd')
  26. ->alias('amc')
  27. ->join('attendance_machine am','am.id = amc.machine_id')
  28. ->field('amc.*,am.sn,am.org_id')
  29. ->where($map)
  30. ->limit($start, $length)
  31. ->order('amc.id desc')
  32. ->select();
  33. foreach ($lists as $k => $v) {
  34. $lists[$k]['org_name'] = db('org')->where('id', $v['org_id'])->value('name');
  35. }
  36. //数据返回
  37. $totalCount = db('attendance_machine_cmd')
  38. ->alias('amc')
  39. ->join('attendance_machine am','am.id = amc.machine_id') ->where($map)
  40. ->count();
  41. $totalPage = ceil($totalCount / $length);
  42. $result['page'] = $page;
  43. $result['total'] = $totalPage;
  44. $result['records'] = $totalCount;
  45. $result['rows'] = $lists;
  46. return json($result);
  47. } else {
  48. $orgList = db('org')->where('del', 0)->where('enable', 1)->where('type', 2)->select();
  49. $this->assign('orgList', $orgList);
  50. return $this->fetch();
  51. }
  52. }
  53. }