1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- class AttendanceMachineCmd 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('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $sn = input('sn', '', 'trim');
- if ($sn) {
- $map[] = ['am.sn', '=',$sn];
- }
- $map[] = ['am.org_id', '=', $this->orgId];
- $map[] = ['am.del', '=', 0];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db('attendance_machine_cmd')
- ->alias('amc')
- ->join('attendance_machine am','am.id = amc.machine_id')
- ->field('amc.*,am.sn,am.org_id')
- ->where($map)
- ->limit($start, $length)
- ->order('amc.id desc')
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['org_name'] = db('org')->where('id', $v['org_id'])->value('name');
- }
- //数据返回
- $totalCount = db('attendance_machine_cmd')
- ->alias('amc')
- ->join('attendance_machine am','am.id = amc.machine_id') ->where($map)
- ->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- } else {
- $orgList = db('org')->where('del', 0)->where('enable', 1)->where('type', 2)->select();
- $this->assign('orgList', $orgList);
- return $this->fetch();
- }
- }
- }
|