input('id/d',0), 'user_id' => input('uid/d',0), 'status' => input('status/d',0), 'labor' => input('labor/f','','trim'), 'other' => input('other/f','','trim'), 'child' => input('child/f','','trim'), 'remark' => input('remark','','trim'), 'company_id' => input('companyId/d',0) ]; $result = validate('UserLabor')->check($data,[],''); if(true !== $result){ HelpHander::error(validate('UserLabor')->getError()); } $id = $data['id']; unset($data['id']); if($id > 0){ $data['update_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($data,['id'=>$id]); }else{ $data['create_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($data); } if(!$ret){ HelpHander::error('操作失败'); } return true; } public function info($id){ $info = $this->where('id',$id)->find(); if(!$info){ HelpHander::error('数据不存在'); } $data = $info->toArray(); $data['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name'); return $data; } public function lists($page,$size,$orgId,$name,$phone,$status){ if($name != ''){ $map[] = ['ui.name','like','%'.$name.'%']; } if($phone != ''){ $map[] = ['u.phone','like','%'.$phone.'%']; } if($status >= 0){ $map[] = ['ur.status','=',$status]; } $map = empty($map)?true:$map; $lists = Db::name('user_labor') ->alias('ur') ->join('user u','u.id = ur.user_id') ->join('user_info ui','ui.user_id = ur.user_id') ->where($map) ->field('ur.*,u.phone,ui.name,ui.gender') ->page($page,$size) ->order('id desc') ->select(); foreach ($lists as $k=>$v){ $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); } $total = Db::name('user_labor') ->alias('ur') ->join('user u','u.id = ur.user_id') ->join('user_info ui','ui.user_id = ur.user_id') ->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists:[] ]; return $data; } public function del($id){ $ret = $this->where('id',$id)->delete(); if(!$ret){ HelpHander::error('删除失败'); } return true; } public function changeStatus($id,$enable){ $ret = Db::name('user_labor')->where('id',$id)->setField('status',$enable); if(!$ret){ HelpHander::error('操作失败'); } return true; } public function laborUser($page,$size,$name,$phone,$orgId){ // $uids = Db::name('user_labor')->column('user_id'); $map[] = ['ui.is_working','in','1,2']; if($phone){ $map[] = ['u.phone','like','%'.$phone.'%']; } if($name){ $map[] = ['ui.name','like','%'.$name.'%']; } // if($uids){ // $map[] = ['u.id','not in',$uids]; // } $lists = Db::name('user') ->alias('u') ->join('user_info ui','ui.user_id = u.id') ->where($map) ->field('u.id,u.phone,ui.name,ui.join_time,ui.gender') ->page($page,$size) ->order('ui.id desc') ->select(); $total = Db::name('user') ->alias('u') ->join('user_info ui','ui.user_id = u.id') ->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists:[] ]; return $data; } }