12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- class AssetAllot extends Auth
- {
- public function index()
- {
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'id', 'trim'); //排序列
- $sort = input('sort', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $sn = input('sn', '', 'trim');
- if ($sn != '') {
- $map[] = ['ai.sn', 'like', '%' . $sn . '%'];
- }
- $stime = input('start', '');
- if ($stime != '') {
- $map[] = ['aa.create_time', '>=', date('Y-m-d H:i:s', strtotime($stime))];
- }
- $etime = input('end', '');
- if ($etime != '') {
- $map[] = ['aa.create_time', '<=', date('Y-m-d H:i:s', strtotime($etime))];
- }
- $map[] = ['aa.org_id', '=', cur_org_id()];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = Db::name('asset_allot')
- ->alias('aa')
- ->field('aa.*,ai.sn,ai.title')
- ->join('asset_items ai', 'ai.id = aa.items_id')
- ->where($map)
- ->limit($start, $length)
- ->order('id desc')
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['userName'] = Db::name('user')->where('id', $v['user_id'])->value('real_name');
- $lists[$k]['allotUserName'] = Db::name('user')->where('id', $v['allot_user_id'])->value('real_name');
- $lists[$k]['allotDepName'] = Db::name('dep')->where('id', $v['allot_dep_id'])->value('title');
- }
- //数据返回
- $totalCount = Db::name('asset_allot')
- ->alias('aa')
- ->field('aa.*,ai.sn')
- ->join('asset_items ai', 'ai.id = aa.items_id')
- ->where($map)
- ->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- } else {
- return $this->fetch();
- }
- }
- }
|