123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- class HouseLock extends Auth
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->table='house_lock';
- $this->model= new \app\common\model\HouseLock();
- }
- 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;
- $status = input('status','','trim');
- if($status != ''){
- $map[] = ['status','=',$status];
- }
- $b = input('start','','trim');
- $e = input('end','','trim');
- if($b){
- $b = date('Y-m-d 00:00:00',strtotime($b));
- $map[] = ['create_time','>=',$b];
- }
- if($e){
- $e = date('Y-m-d 23:59:59',strtotime($e));
- $map[] = ['create_time','<=',$e];
- }
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['user_id','=',$this->userId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
- $lists[$k]['deal_real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
- $lists[$k]['cur_user_id'] = $this->userId;
- }
- //数据返回
- $totalCount = db($this->table)->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();
- }
- }
- public function add()
- {
- $start = input('start');
- $end = input('end');
- if(!$start){
- // 获取开始时间,为空的没有数据
- $start = $this->model->getStartTime($this->userId);
- $end = date('Y-m-d H:i:s');
- }
- $data = $this->model->getDataInfo($start,$end,$this->userId,$this->orgId);
- $error = '';
- if(!$data){
- $error = $this->model->getError();
- }
- $this->assign('data',$data);
- $this->assign('error',$error);
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- public function addSave(){
- $start = input('start');
- $end = input('end');
- $remark = input('remark');
- $userId = $this->userId;
- $orgId = $this->orgId;
- $ret = $this->model->addSave($start,$end,$remark,$userId,$orgId);
- if(!$ret){
- $error = $this->model->getError();
- $this->error($error);
- }else{
- $this->success('操作成功');
- }
- }
- public function cancel($id){
- $ret = $this->model->deal($id,3,$this->userId);
- if(!$ret){
- $this->error($this->model->getError());
- }else{
- $this->success('操作是吧');
- }
- }
- public function detail($id)
- {
- $data = $this->model->getDataById($id);
- if(!$data){
- $this->error('记录不存在',url('HouseLock/index'));
- }
- $this->assign('data',$data);
- return $this->fetch();
- }
- public function edit($id)
- {
- $data = $this->model->getDataById($id);
- if(!$data){
- $this->error('记录不存在',url('HouseLock/index'));
- }
- $this->assign('data',$data);
- return $this->fetch();
- }
- public function apply(){
- 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;
- $status = input('status','','trim');
- if($status != ''){
- $map[] = ['status','=',$status];
- }
- $b = input('start','','trim');
- $e = input('end','','trim');
- if($b){
- $b = date('Y-m-d 00:00:00',strtotime($b));
- $map[] = ['create_time','>=',$b];
- }
- if($e){
- $e = date('Y-m-d 23:59:59',strtotime($e));
- $map[] = ['create_time','<=',$e];
- }
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
- $lists[$k]['deal_real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
- }
- //数据返回
- $totalCount = db($this->table)->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();
- }
- }
- public function detail2($id)
- {
- $data = $this->model->getDataById($id);
- if(!$data){
- $this->error('记录不存在',url('HouseLock/apply'));
- }
- $this->assign('data',$data);
- return $this->fetch();
- }
- public function agree($id){
- $ret = $this->model->deal($id,1,$this->userId);
- if(!$ret){
- $this->error($this->model->getError());
- }else{
- $this->success('操作成功');
- }
- }
- public function disagree($id){
- $ret = $this->model->deal($id,2,$this->userId);
- if(!$ret){
- $this->error($this->model->getError());
- }else{
- $this->success('操作成功');
- }
- }
- public function detail2print($id){
- $data = $this->model->getDataById($id);
- if(!$data){
- $this->error('记录不存在',url('HouseLock/apply'));
- }
- $data['count_logs'] = count($data['logs']);
- $this->assign('data',$data);
- return $this->fetch();
- }
- }
|