setName('good') ->setDescription('the good command'); } protected function execute(Input $input, Output $output) { // 指令输出 $sttime = Cache::get("departTips"); if($sttime==1) return ''; Cache::set("departTips",1,1800); $daprtid = [52,53,56,57]; $temp=["p"=>"总计","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,"tips"=>0,"rate"=>0,"thrate"=>0]; $data=[]; foreach ($daprtid as $itmeid){ $uidArr =Db::name("depart_user")->where(['itemid'=>$itmeid,"status"=>1,"is_del"=>0])->column("uid"); $data[]=$this->GetData($uidArr,$itmeid); } $temp['thtotal'] = sprintf( "%.2f",array_sum(array_column($data,'thtotal'))); $temp['mtotal'] = sprintf( "%.2f",array_sum(array_column($data,'mtotal'))); $temp['mthfee'] = sprintf( "%.2f",array_sum(array_column($data,'mthfee'))); $temp['wtotal'] = sprintf( "%.2f",array_sum(array_column($data,'wtotal'))); $temp['wthfee'] = sprintf( "%.2f",array_sum(array_column($data,'wthfee'))); $temp['dtotal'] = sprintf( "%.2f",array_sum(array_column($data,'dtotal'))); $temp['thfee'] = sprintf( "%.2f",array_sum(array_column($data,'thfee'))); $temp['tips'] = sprintf( "%.2f",array_sum(array_column($data,'tips'))); $temp["rate"]=number_format( $temp['mtotal']/$temp['tips']*100,2); $temp["thrate"]=number_format( $temp['thtotal']/$temp['tips']*100,2); $sort = array_column($data,"thrate"); array_multisort($sort,SORT_DESC,$data); array_unshift($data,$temp); Cache::set("departContent",$data); $date=date('Y-m-d H:i:s'); $output->writeln("[{$date}] 更新数据成功"); } //各部门统计数据 public function GetData($uid,$departid=0){ $temp=["p"=>"","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,"tips"=>0,"rate"=>0,"thrate"=>0]; $tips = Db::name("depart_tips")->where(['year'=>date("Y") ,"month"=>date("m"),"depart_id"=>$departid]) ->field("depart_item,total_tips")->findOrEmpty(); $temp['p']= $tips['depart_item']??""; $temp['tips']= sprintf( "%.2f",$tips['total_tips']??0); $month_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0]])->whereMonth("addtime","this month") ->sum('total_price'); $month_thtotal=Db::name("th_data")->where([["apply_id","in",$uid],["is_del","=",0]])->whereMonth("addtime","this month") ->sum('th_fee'); $week_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0]])->whereWeek("addtime","this week") ->sum('total_price'); $week_thtotal=Db::name("th_data")->where([["apply_id","in",$uid],["is_del","=",0]])->whereWeek("addtime","this week") ->sum('th_fee'); $day_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0]])->whereDay("addtime","today") ->sum('total_price'); $day_thtotal=Db::name("th_data")->where([["apply_id","in",$uid],["is_del","=",0]])->whereDay("addtime","today")->sum('th_fee'); if($departid==56){ $wlb= $this->wlb(); $month_total+=$wlb['month_total']; $week_total+=$wlb['week_total']; $day_total+=$wlb['day_total']; } $temp['thtotal']=sprintf( "%.2f",(($month_total??0) - ($month_thtotal??0))); $temp['mtotal']=sprintf( "%.2f",$month_total??0 ); $temp['mthfee']=sprintf( "%.2f",$month_thtotal??0); $temp['wtotal']=sprintf( "%.2f",$week_total??0); $temp['wthfee']= sprintf( "%.2f",$week_thtotal??0); $temp['dtotal']=sprintf( "%.2f",$day_total??0); $temp['thfee']= sprintf( "%.2f",$day_thtotal??0); $temp["rate"]=number_format( $temp['mtotal']/$tips['total_tips']*100,2); $temp["thrate"]=number_format( $temp['thtotal']/$tips['total_tips']*100,2); return $temp; } //网络部数据统计 public function wlb(){ $Db=Db::connect("mysql_cxinv"); $month_total =$Db->name("inter_order")->alias("a")->leftjoin("qrd_info b","a.orderCode=b.sequenceNo and b.qrdSource = 10 and b.is_del = 0") ->whereMonth("a.addtime","this month")->where("b.companyNo","GS2203161855277894")->sum('totalPrice'); $week_total =$Db->name("inter_order")->alias("a")->leftjoin("qrd_info b","a.orderCode=b.sequenceNo and b.qrdSource = 10 and b.is_del = 0") ->whereWeek("a.addtime","this week")->where("b.companyNo","GS2203161855277894")->sum('totalPrice'); $day_total =$Db->name("inter_order")->alias("a")->leftjoin("qrd_info b","a.orderCode=b.sequenceNo and b.qrdSource = 10 and b.is_del = 0") ->whereDay("a.addtime","today")->where("b.companyNo","GS2203161855277894")->sum('totalPrice'); return ["month_total"=>$month_total,"week_total"=>$week_total,"day_total"=>$day_total] ; } }