BhPhRecord.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class BhPhRecord extends Auth {
  5. public function index() {
  6. if (request()->isAjax()) {
  7. //分页参数
  8. $length = input('rows', 10, 'intval'); //每页条数
  9. $page = input('page', 1, 'intval'); //第几页
  10. $start = ($page - 1) * $length; //分页开始位置
  11. //排序
  12. $sortRow = input('sidx', 'sort', 'trim'); //排序列
  13. $sort = input('sord', 'asc', 'trim'); //排序方式
  14. $order = $sortRow . ' ' . $sort . ' ,id desc';
  15. $title = input('title', '', 'trim');
  16. if ($title) {
  17. $map[] = ['d.content', 'like', '%' . $title . '%'];
  18. }
  19. $map[] = ['dr.org_id', '=', $this->orgId];
  20. $map = empty($map) ? true : $map;
  21. //数据查询
  22. $lists = Db::name('ph_record')
  23. ->alias('dr')
  24. ->field('dr.*')
  25. ->where($map)
  26. ->limit($start, $length)
  27. ->order($order)
  28. ->select();
  29. foreach ($lists as $k => $v) {
  30. $lists[$k]['user_name'] = Db::name('user')
  31. ->where('id', $v['user_id'])->value('real_name');
  32. }
  33. //数据返回
  34. $totalCount = Db::name('ph_record')
  35. ->alias('dr')
  36. ->field('dr.*')
  37. ->where($map)
  38. ->count();
  39. $totalPage = ceil($totalCount / $length);
  40. $result['page'] = $page;
  41. $result['total'] = $totalPage;
  42. $result['records'] = $totalCount;
  43. $result['rows'] = $lists;
  44. return json($result);
  45. }
  46. else {
  47. $this->assign('meta_title', '陪护检查记录列表');
  48. return $this->fetch();
  49. }
  50. }
  51. public function details($id) {
  52. if (!$id) {
  53. $this->error('参数错误');
  54. }
  55. $ret = Db::name('ph_record')->where('id', $id)->find();
  56. $ret['images'] = !empty($ret['images'])?explode(',',$ret['images']):[];
  57. $ret['check_json'] = json_decode($ret['check_json'], true);
  58. $ret['user_name'] = Db::name('user')->where('id', $ret['user_id'])
  59. ->value('real_name');
  60. $this->assign('info', $ret);
  61. $this->assign('meta_title', '陪护检查记录详情');
  62. return $this->fetch();
  63. }
  64. }