time()){ return $cache_token['access_token']; } $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $res = json_decode(file_get_contents($url),true); $token = $res['access_token']; $res['expires_in'] = time()+ $res['expires_in'] - 100; cache('wx_1_token',$res); return $token; } //获取链接 function get_urlcheme(){ $id = input('id'); $token = $this->gettoken(); $url1 = 'https://api.weixin.qq.com/wxa/generatescheme?access_token='.$token; $ch = curl_init(); $data1 = array("path"=>"/pages/eval/eval", "query"=>"id=".$id,"env_version"=>"release"); $data = json_encode(array("expire_type"=>1,"expire_interval"=>5,"jump_wxa"=>$data1)); curl_setopt($ch, CURLOPT_URL, $url1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $p = (json_decode($output,true)); if(empty($p['openlink'])){ echo '生成链接失败:'.(!empty($p['errmsg'])?$p['errmsg']:''); exit; } header("Location: {$p['openlink']}"); } //员工的基本的信息 public function staff_user(){ $get = $this->request->get();//获取到员工的ID $inof=Db::name('staff')->where('id',$get['staff_id'])->find(); $inof['staff_img']=UrlServer::getFileUrl($inof['image']); if($inof){ $inof['ordermonth']= Db::name('order_exe') ->where('staff_id', $get['staff_id']) ->whereTime('autotime', 'month') ->where('staff_status',3) ->count(); //拥挤当月完成订单 $inof['year']=Db::name('order_exe') ->where('staff_id', $get['staff_id']) ->whereTime('autotime', 'year') ->where('staff_status',3) ->count(); //拥挤本年完成订单 $inof['addtime']=Db::name('order_exe')->where('staff_id', $get['staff_id'])->whereTime('autotime', 'month')->where('staff_status',3)->count(); //拥挤本年完成订单 $inof['notfinish']=Db::name('order_exe')->where('staff_id', $inof['id'])->whereTime('autotime', 'month')->where('staff_status',3)->where('addtime',1)->sum('add')/60; //上午加时 $inof['finish']=Db::name('order_exe')->where('staff_id', $inof['id'])->whereTime('autotime', 'month')->where('staff_status',3)->where('addtime',2)->sum('add')/60; $inof['amount']=Db::name('order_exe')->where('staff_id', $inof['id'])->whereTime('autotime', 'month')->where('staff_status',3)->sum('account'); return $this->_success('获取数据成功',$inof); } } //首页的数据统计 public function index(){ $get = $this->request->get();//获取到员工的ID // 计算明天的日期 $tomorrow = date('Y-m-d', strtotime('+1 day')); $start = strtotime($tomorrow); //开始时间 $end = strtotime($tomorrow.' 23:59:59'); //结束时间 $tomorrows = date('Y-m-d', strtotime('+2 day')); $starts = strtotime($tomorrows); //开始时间 $ends = strtotime($tomorrows.' 23:59:59'); //结束时间 $tomorrows= date('Y-m-d', strtotime('+2 day')); $userinfo=Db::name('staff')->where('id',$get['uid'])->find(); $userinfo['dataorder']=Db::name('order_exe')->whereTime('autotime', 'today')->where('staff_id',$get['uid'])->count(); //统计今天的订单 $userinfo['tomorrow']=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',$get['uid'])->count(); //统计今天的订单 $userinfo['tomorrows']=Db::name('order_exe')->where('autotime','>=',$starts)->where('autotime','<=',$ends)->where('staff_id',$get['uid'])->count(); //统计今天的订单 return $this->_success('获取数据成功',$userinfo); } //获取等待接单 public function order_list(){ $get = $this->request->get();//获取到员工的ID $lists=StaffLogic::order_list($get); $this->_success('获取数据成功', $lists); } //获取等待接单 public function order_start(){ $get = $this->request->get();//获取到员工的ID $order = new Orderexe(); $lists = $order->where('staff_id',$get['staff_id']) ->where('staff_status',$get['staff_status']) ->order('autotime desc') ->select(); foreach ($lists as $list){ $custom=Db::name('order')->where('order_sn',$list['order_sn'])->find(); $list['address']= $custom['address']; $list['lat']= $custom['lat']; $list['lng']= $custom['lng']; $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); $list['goods_name']= $goods['name']; if(intval(($list['autotime']-time())/86400)>1){ $list['jldate']=intval(($list['autotime']-time())/86400); }else{ $list['jldate']='-'; } $adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find(); if($adder){ $admin=Db::name('admin')->where('id',$adder['admin_id'])->find(); if($admin){ $list['admin_name']=$admin['name']; $list['admin_phone']=$admin['phone']; }else{ $list['admin_name']='-'; $list['admin_phone']='-'; } } if($list['addtime']==1){ $list['sw']='上午'; $list['sw_time']='8:00-12:00'; }else{ $list['sw']='下午'; $list['sw_time']='14:00-18:00'; } //查询其他用户 $more_where = [ ['staff_id','<>',$get['staff_id']], ['order_sn','=',$list['order_sn']], ['autotime','=',$list['autotime']] ]; $more_users = $order->where($more_where) ->order('autotime desc') ->column('staff_id'); if(!empty($more_users)){ $list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select(); } $list['autotime']=date("Y-m-d",$list['autotime']); } $this->_success('获取数据成功', $lists); } //已经开始的服务的订单 public function order_progress(){ $get = $this->request->get();//获取到员工的ID $order = new Orderexe(); $lists = $order->where('staff_id',$get['staff_id']) ->where('staff_status',$get['staff_status']) ->order('autotime desc') ->select(); foreach ($lists as $list){ $custom=Db::name('order')->where('order_sn',$list['order_sn'])->find(); $list['address']= $custom['address']; $list['lat']= $custom['lat']; $list['lng']= $custom['lng']; $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); $list['goods_name']= $goods['name']; if(intval(($list['autotime']-time())/86400)>1){ $list['jldate']=intval(($list['autotime']-time())/86400); }else{ $list['jldate']='-'; } $adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find(); if($adder){ $admin=Db::name('admin')->where('id',$adder['admin_id'])->find(); if($admin){ $list['admin_name']=$admin['name']; $list['admin_phone']=$admin['phone']; }else{ $list['admin_name']='-'; $list['admin_phone']='-'; } } if($list['addtime']==1){ $list['sw']='上午'; $list['sw_time']='8:00-12:00'; }else{ $list['sw']='下午'; $list['sw_time']='14:00-18:00'; } //查询其他用户 $more_where = [ ['staff_id','<>',$get['staff_id']], ['order_sn','=',$list['order_sn']], ['autotime','=',$list['autotime']] ]; $more_users = $order->where($more_where) ->order('autotime desc') ->column('staff_id'); if(!empty($more_users)){ $list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select(); } $list['autotime']=date("Y-m-d",$list['autotime']); } $this->_success('获取数据成功', $lists); } //异常订单列表 public function abnormal(){ $get = $this->request->get();//获取到员工的ID $order = new Orderexe(); $lists = $order->where('staff_id',$get['staff_id']) ->where('abnormal',$get['staff_status']) ->order('autotime desc') ->select(); foreach ($lists as $list){ $custom=Db::name('order')->where('order_sn',$list['order_sn'])->find(); $list['address']= $custom['address']; $list['lat']= $custom['lat']; $list['lng']= $custom['lng']; $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); $list['goods_name']= $goods['name']; if(intval(($list['autotime']-time())/86400)>1){ $list['jldate']=intval(($list['autotime']-time())/86400); }else{ $list['jldate']='-'; } $adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find(); if($adder){ $admin=Db::name('admin')->where('id',$adder['admin_id'])->find(); if($admin){ $list['admin_name']=$admin['name']; $list['admin_phone']=$admin['phone']; }else{ $list['admin_name']='-'; $list['admin_phone']='-'; } } if($list['addtime']==1){ $list['sw']='上午'; $list['sw_time']='8:00-12:00'; }else{ $list['sw']='下午'; $list['sw_time']='14:00-18:00'; } //查询其他用户 $more_where = [ ['staff_id','<>',$get['staff_id']], ['order_sn','=',$list['order_sn']], ['autotime','=',$list['autotime']] ]; $more_users = $order->where($more_where) ->order('autotime desc') ->column('staff_id'); if(!empty($more_users)){ $list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select(); } $list['autotime']=date("Y-m-d",$list['autotime']); } $this->_success('获取数据成功', $lists); } //获取当月的订单 public function complete(){ $get = $this->request->get();//获取到员工的ID $order = new Orderexe(); $lists = $order->where('staff_id',$get['staff_id']) ->where('staff_status',3) ->whereTime('autotime','month') ->order('autotime desc') ->select(); foreach ($lists as $list){ $custom=Db::name('order')->where('order_sn',$list['order_sn'])->find(); $list['address']= $custom['address']; $list['lat']= $custom['lat']; $list['lng']= $custom['lng']; $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); $list['goods_name']= $goods['name']; if(intval(($list['autotime']-time())/86400)>1){ $list['jldate']=intval(($list['autotime']-time())/86400); }else{ $list['jldate']='-'; } $adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find(); if($adder){ $admin=Db::name('admin')->where('id',$adder['admin_id'])->find(); if($admin){ $list['admin_name']=$admin['name']; $list['admin_phone']=$admin['phone']; }else{ $list['admin_name']='-'; $list['admin_phone']='-'; } } if($list['addtime']==1){ $list['sw']='上午'; $list['sw_time']='8:00-12:00'; }else{ $list['sw']='下午'; $list['sw_time']='14:00-18:00'; } //查询其他用户 $more_where = [ ['staff_id','<>',$get['staff_id']], ['order_sn','=',$list['order_sn']], ['autotime','=',$list['autotime']] ]; $more_users = $order->where($more_where) ->order('autotime desc') ->column('staff_id'); if(!empty($more_users)){ $list['users'] = Db::name('staff')->field('mobile,name,addr')->whereIn('id',$more_users)->select(); } $list['autotime']=date("Y-m-d",$list['autotime']); } $this->_success('获取数据成功', $lists); } //保洁师开始接单 public function staff_taking(){ $get = $this->request->get();//获取子订单的iD $taking=Db::name('order_exe')->where('id',$get['orderid'])->update(['staff_status'=>1]); $this->_success('获取数据成功',$taking); } //保洁师开始开始服务 public function start_tim(){ $get = $this->request->get();//获取子订单的iD $orderlist=Db::name('order_exe')->where('id',$get['orderid'])->find(); //获取订单的基本信息 if($orderlist['addtime']==1){ //派单上午订单 $selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间 $timeStamp = strtotime($selectime . ' 07:30:00'); if($timeStampwhere('id',$get['orderid'])->update(['staff_status'=>2,'start_time'=>time(),'status'=>0]); $this->_success('获取数据成功'); }else{ $this->_error('开始失败'); } }else{ $selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间 $timeStamp = strtotime($selectime . ' 13:30:00'); if($timeStampwhere('id',$get['orderid'])->update(['staff_status'=>2,'start_time'=>time(),'status'=>0]); $this->_success('获取数据成功'); }else{ $this->_error('开始失败'); } } } //保洁师确定订单服务已经完成 public function complete_time(){ $get = $this->request->get();//获取子订单的iD $orderlist=Db::name('order_exe')->where('id',$get['orderid'])->find(); //获取订单的基本信息 if($orderlist['addtime']==1){ //派单上午订单 $selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间 $timeStamp = strtotime($selectime . ' 11:30:00'); if($timeStampwhere('id',$get['orderid'])->update(['staff_status'=>3,'timeout'=>time(),'status'=>1]); $this->_success('获取数据成功',$start); }else{ $this->_error('开始失败'); } }else{ $selectime=date("Y-m-d",$orderlist['autotime']); //获取上午的时间 $timeStamp = strtotime($selectime . ' 17:30:00'); if($timeStampwhere('id',$get['orderid'])->update(['staff_status'=>3,'start_time'=>time()]); $this->_success('获取数据成功'); }else{ $this->_error('开始失败'); } } } //员工排期订单的查询 public function timeorder(){ $get = $this->request->get();//获取子订单的iD $order = new Orderexe(); $start = strtotime($get['ordertime']); //开始时间 $end = strtotime($get['ordertime'].'23:59:59'); //结束时间 $lists = $order->where('staff_id',$get['uid']) ->where('autotime','>=',$start)->where('autotime','<=',$end) ->order('autotime asc') ->select(); foreach ($lists as $list){ $custom=Db::name('order')->where('order_sn',$list['order_sn'])->find(); $list['address']= $custom['address']; $list['lat']= $custom['lat']; $list['lng']= $custom['lng']; $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); $list['goods_name']= $goods['name']; if(intval(($list['autotime']-time())/86400)>1){ $list['jldate']=intval(($list['autotime']-time())/86400); }else{ $list['jldate']='-'; } $list['autotime']=date("Y-m-d",$list['autotime']); $adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find(); if($adder){ $admin=Db::name('admin')->where('id',$adder['admin_id'])->find(); if($admin){ $list['admin_name']=$admin['name']; $list['admin_phone']=$admin['phone']; }else{ $list['admin_name']='-'; $list['admin_phone']='-'; } } if($list['addtime']==1){ $list['sw']='上午'; $list['sw_time']='8:00-12:00'; }else{ $list['sw']='下午'; $list['sw_time']='14:00-18:00'; } } $this->_success('获取数据成功', $lists); } //获取报销的类型 public function sement(){ $get = $this->request->get();//获取子订单的iD $lists=Db::name('finance_type')->select(); //获取报销的类型 $this->_success('获取数据成功', $lists); } //增加保洁记录 public function addsement(){ $get = $this->request->get();//获取子订单的iD $orderinfo=Db::name('order_exe')->where('id',$get['orderid'])->find(); $sement=Db::name('finance')->where('order_id',$get['orderid'])->find(); //查询报销订单重复 $data=[ 'order_id'=>$get['orderid'], 'staff_id'=>$orderinfo['staff_id'], 'user_id'=>$orderinfo['staff_id'], 'status'=>1, 'pay'=>$get['money'], 'brand_id'=>$get['type'], 'remarks'=>$get['reak'], 'create_time'=>time() ]; if($sement){ $this->_error('报销单据已经重复'); }else{ $inser=Db::name('finance')->data($data)->insert(); if($inser){ $this->_success('增加报销单成功'); } } } //根据订单获取报销的列表 public function listsement(){ $get = $this->request->get(); $where = []; $where[] = ['order_id', '=', $get['order_id']]; if (isset($get['status']) && !empty($get['status'])) { $where[] = ['status', '=', $get['status']]; } $lists = Db::name('finance')->where($where)->select(); // 批量查询优化(避免N+1查询) $orderIds = array_column($lists, 'order_id'); $brandIds = array_column($lists, 'brand_id'); // 批量获取订单信息 $orderExes = []; if (!empty($orderIds)) { $orderExes = Db::name('order_exe') ->where('id', 'in', $orderIds) ->column('*', 'id'); } // 批量获取品牌信息 $financeTypes = []; if (!empty($brandIds)) { $financeTypes = Db::name('finance_type') ->where('id', 'in', $brandIds) ->column('*', 'id'); } foreach ($lists as &$list){ // 安全获取订单信息 $order_exe = $orderExes[$list['order_id']] ?? []; $list['order_sn'] = $order_exe['order_sn'] ?? ''; // 修复逻辑错误:= 改为 == if (isset($order_exe['addtime']) && $order_exe['addtime'] == 1) { $list['sw'] = "8:00-12:00"; } else { $list['sw'] = "14:00-16:00"; } // 安全获取品牌信息 $type = $financeTypes[$list['brand_id']] ?? []; $list['type_name'] = $type['name'] ?? ''; } $this->_success('获取报销单数据', $lists); } //根据订单获取报销的列表 public function numberement(){ $get = $this->request->get();//获取子订单的iD $lists=Db::name('finance')->where('order_id',$get['order_id'])->find(); $this->_success('获取报销单数据',$lists); } //员工修改报销的单据 public function editsement(){ $get = $this->request->get();//获取子订单的iD $data=[ 'order_id'=>$get['orderid'], 'status'=>1, 'pay'=>$get['money'], 'brand_id'=>$get['type'], 'remarks'=>$get['reak'], 'create_time'=>time() ]; $lists=Db::name('finance')->where('order_id',$get['orderid'])->data($data)->update(); $this->_success('修改报销单据成功',$lists); } //员工订单加时间 public function addtime(){ $get = $this->request->get();//获取子订单的iD $info=Db::name('order_timeadd')->where('orderid',$get['orderid'])->find(); if($info){ $this->_error('订单已经加时'); }else{ $data=[ 'orderid'=>$get['orderid'], 'status'=>1, 'minute'=>$get['minute'], 'remarks'=>$get['reak'], 'staff_id'=>$get['staff_id'], 'user_id'=>$get['staff_id'], // 'pay_type'=>$get['type'], 'pay'=>$get['pay'], 'create_time'=>time() ]; $inser=Db::name('order_timeadd')->data($data)->insert(); if($inser){ $this->_success('增加服务加时成功'); } } } //根据订单显示加时的详细详细 public function addtimeinfo(){ $get = $this->request->get();//获取子订单的iD $result = StaffLogic::infoaddtim($get); $this->_success('获取报销单数据',$result); } //更具订单显示详情 public function addtimenumber(){ $get = $this->request->get();//获取子订单的iD $inof=Db::name('order_timeadd')->where('orderid',$get['orderid'])->find(); $this->_success('获取报销单数据',$inof); } //员工端口修改加时间 public function editaddtime(){ $get = $this->request->get();//获取子订单的iD $update=Db::name('order_timeadd')->where('orderid',$get['orderid'])->where('status',1)->update(['minute'=>$get['minute'],'remarks'=>$get['reak'],'pay'=>$get['pay']]); if($update){ $this->_success('修改成功',$update); }else{ $this->_error('审核已经通过无法修改'); } } //根据订单ID 获取订单的基本信息 public function orderinfo(){ $get = $this->request->get();//获取到员工的ID // dump($get); // if (is_array($get['order_id'])) { // $data = $get['order_id']; // }else { // $data = json_decode($get['order_id'], true); // } $orders=Db::name('order_timeadd')->where('orderid',$get['order_id'])->find(); //查询加时表格 $lists = Db::name('order_exe')->where('id',$get['order_id'])->find(); //查询子订单信息 if($lists){ $lists['autotime']=date("Y-m-d",$lists['autotime']); if($lists['addtime']==1){ $lists['sw']='上午'; }else{ $lists['sw']='下午'; } $goods= Db::name('order')->where('order_sn',$lists['order_sn'])->find(); //查询子订单信息 if($goods){ $lists['adder']= $goods['address']; $lists['lat']= $goods['lat']; $lists['lng']= $goods['lng']; }else{ $lists['adder']= '-'; } $goods=Db::name('goods')->where('id',$goods['goods_id'])->find(); $lists['goods_name']= $goods['name']; $admin=Db::name('admin')->where('id',$lists['admin'])->find(); if($admin){ $lists['admin_name']=$admin['name']; $lists['admin_phone']=$admin['phone']; }else{ $lists['admin_name']='-'; $lists['admin_phone']='-'; } if($orders){ $lists['add']=$orders['minute']; }else{ $lists['add']=0; } } $this->_success('获取数据成功', $lists); } //查询所有的订单接口 public function orderlist(){ $get = $this->request->get();//获取到员工的ID $order = new Orderexe(); $where=[]; if($get['type']==1){ $date='year'; }else{ $date='month'; } if($get['type']==3){ $where[]=['add', '>', 0]; $date='month'; } if($get['type']==4){ $where[]=['account', '>', 0]; $date='month'; } $lists = $order->where('staff_id',$get['staff_id'])->where($where) ->where('staff_status',3) ->whereTime('autotime',$date) ->order('autotime asc') ->select(); foreach ($lists as $list){ $custom=Db::name('order')->where('order_sn',$list['order_sn'])->find(); $list['address']= $custom['address']; $list['lat']= $custom['lat']; $list['lng']= $custom['lng']; $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); $list['goods_name']= $goods['name']; if(intval(($list['autotime']-time())/86400)>1){ $list['jldate']=intval(($list['autotime']-time())/86400); }else{ $list['jldate']='-'; } $list['autotime']=date("Y-m-d",$list['autotime']); $adder=Db::name('user_address')->where('telephone',$custom['mobile'])->find(); if($adder){ $admin=Db::name('admin')->where('id',$adder['admin_id'])->find(); if($admin){ $list['admin_name']=$admin['name']; $list['admin_phone']=$admin['phone']; }else{ $list['admin_name']='-'; $list['admin_phone']='-'; } } if($list['addtime']==1){ $list['sw']='上午'; $list['sw_time']='8:00-12:00'; }else{ $list['sw']='下午'; $list['sw_time']='14:00-18:00'; } } $this->_success('获取数据成功', $lists); } public function staff_qjia(){ $get = $this->request->get();//获取提交的基本信息 $order=Db::name('order_exe')->where('autotime','>=',$get['start_time'])->where('autotime','<=',$get['end_time'])->where('staff_id',$get['staff_id'])->select(); //统计今天的订单 if($order){ $this->_error('无法请假有订单',$order); }else{ $lent=Db::name('leave')->where('user_id',$get['staff_id'])->where('time','>=',$get['start_time'])->where('time','<=',$get['end_time'])->select(); if($lent){ $this->_error('请假数据重复',$lent); }else{ $this->_success('',StaffLogic::leaveadd($get)); } } } public function count(){ $order = new Orderexe(); $get = $this->request->get();//获取提交的基本信息 $today = date('Y-m-d'); // 计算明天的日期 $tomorrow = date('Y-m-d', strtotime($today . ' +1 day')); $tomorrows = date('Y-m-d', strtotime($today . ' +2 day')); $data['toder'] = $order->where('staff_id',$get['staff_id']) ->where('staff_status',0) ->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"]) ->order('autotime desc') ->count(); $data['ardfs'] = $order->where('staff_id',$get['staff_id']) ->whereTime('autotime', 'between', ["$today 00:00:00", "$tomorrow 23:59:59"]) ->where('staff_status',1) ->order('autotime desc') ->count(); $data['fwz'] = $order->where('staff_id',$get['staff_id']) ->where('staff_status',2) ->order('autotime desc') ->count(); $data['fwywc'] = $order->where('staff_id',$get['staff_id']) ->where('staff_status',3) ->whereTime('autotime','month') ->count(); $data['ycorder'] = $order->where('staff_id',$get['staff_id']) ->where('abnormal',1) ->whereTime('autotime','month') ->count(); $this->_success('获取数据成功',$data); } }