setName('reporttips') ->setDescription('the reporttips command'); } protected function execute(Input $input, Output $output) { // 指令输出 $sttime = Cache::get("repotTips"); if($sttime==1) return ''; Cache::set("repotTips",1,1800); $supplier = ["QS2203150147015222","QS2206011447553544","QS2203150147013805"]; $this->GetData($supplier); $date=date('Y-m-d H:i:s'); $output->writeln("[{$date}] 更新数据成功"); } private function GetData($code){ $month_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereMonth("createdTime","this month") ->group("companyNo")->column('sum(totalPrice+th_fee) as monthTotal','companyNo'); $month_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereMonth("createtime","this month") ->group("th_companyNo")->column('sum(th_qrd_fee) as month_thTotal','th_companyNo'); $week_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereWeek("createdTime","this week") ->group("companyNo")->column('sum(totalPrice+th_fee) as weekTotal','companyNo'); $week_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereWeek("createtime","this week") ->group("th_companyNo")->column('sum(th_qrd_fee) as week_thTotal','th_companyNo'); $day_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereDay("createdTime","today")->group("companyNo") ->column('sum(totalPrice+th_fee) as dayTotal','companyNo'); $day_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereDay("createtime","today") ->group("th_companyNo")->column('sum(th_qrd_fee) as day_thTotal','th_companyNo'); $tips = Db::name("depart_tips")->where('year=YEAR(NOW()) and month=month(NOW())')->column("department,total_tips","departcode"); $data=[]; $temp=["p"=>"总计","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0, "tips"=>0,"rate"=>0,"thrate"=>0]; foreach ($tips as $key=>$value){ $t=[]; $t['p']=$value['department']; $t['thtotal']=sprintf( "%.2f",(($month_total[$key]??0) - ($month_thtotal[$key]??0))); $t['mtotal']=sprintf( "%.2f",$month_total[$key]??0 ); $t['mthfee']=sprintf( "%.2f",$month_thtotal[$key]??0); $t['wtotal']=sprintf( "%.2f",$week_total[$key]??0); $t['wthfee']= sprintf( "%.2f",$week_thtotal[$key]??0); $t['dtotal']=sprintf( "%.2f",$day_total[$key]??0); $t['thfee']= sprintf( "%.2f",$day_thtotal[$key]??0); $t['tips']= sprintf( "%.2f",$value['total_tips']??0); $t["rate"]=$value['total_tips']??number_format( $t['mtotal']/$value['total_tips']*100,2); $t["thrate"]=$value['total_tips']??number_format( $t['thtotal']/$value['total_tips']*100,2); $data[]=$t; } $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"]=$temp['tips']??number_format( $temp['mtotal']/$temp['tips']*100,2); $temp["thrate"]=$temp['tips']??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("statContent",$data); } }