AssetAllot.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class AssetAllot 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('sort', 'desc', 'trim'); //排序方式
  16. $order = $sortRow . ' ' . $sort;
  17. $sn = input('sn', '', 'trim');
  18. if ($sn != '') {
  19. $map[] = ['ai.sn', 'like', '%' . $sn . '%'];
  20. }
  21. $stime = input('start', '');
  22. if ($stime != '') {
  23. $map[] = ['aa.create_time', '>=', date('Y-m-d H:i:s', strtotime($stime))];
  24. }
  25. $etime = input('end', '');
  26. if ($etime != '') {
  27. $map[] = ['aa.create_time', '<=', date('Y-m-d H:i:s', strtotime($etime))];
  28. }
  29. $map[] = ['aa.org_id', '=', cur_org_id()];
  30. $map = empty($map) ? true : $map;
  31. //数据查询
  32. $lists = Db::name('asset_allot')
  33. ->alias('aa')
  34. ->field('aa.*,ai.sn,ai.title')
  35. ->join('asset_items ai', 'ai.id = aa.items_id')
  36. ->where($map)
  37. ->limit($start, $length)
  38. ->order('id desc')
  39. ->select();
  40. foreach ($lists as $k => $v) {
  41. $lists[$k]['userName'] = Db::name('user')->where('id', $v['user_id'])->value('real_name');
  42. $lists[$k]['allotUserName'] = Db::name('user')->where('id', $v['allot_user_id'])->value('real_name');
  43. $lists[$k]['allotDepName'] = Db::name('dep')->where('id', $v['allot_dep_id'])->value('title');
  44. }
  45. //数据返回
  46. $totalCount = Db::name('asset_allot')
  47. ->alias('aa')
  48. ->field('aa.*,ai.sn')
  49. ->join('asset_items ai', 'ai.id = aa.items_id')
  50. ->where($map)
  51. ->count();
  52. $totalPage = ceil($totalCount / $length);
  53. $result['page'] = $page;
  54. $result['total'] = $totalPage;
  55. $result['records'] = $totalCount;
  56. $result['rows'] = $lists;
  57. return json($result);
  58. } else {
  59. return $this->fetch();
  60. }
  61. }
  62. }