reportTips.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Cache;use think\facade\Db;
  10. class reportTips extends Command
  11. {
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('reporttips')
  16. ->setDescription('the reporttips command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. // 指令输出
  21. $sttime = Cache::get("repotTips");
  22. if($sttime==1) return '';
  23. Cache::set("repotTips",1,1800);
  24. $supplier = ["QS2203150147015222","QS2206011447553544","QS2203150147013805"];
  25. $this->GetData($supplier);
  26. $date=date('Y-m-d H:i:s');
  27. $output->writeln("[{$date}] 更新数据成功");
  28. }
  29. private function GetData($code){
  30. $month_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereMonth("createdTime","this month")
  31. ->group("companyNo")->column('sum(totalPrice+th_fee) as monthTotal','companyNo');
  32. $month_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereMonth("createtime","this month")
  33. ->group("th_companyNo")->column('sum(th_qrd_fee) as month_thTotal','th_companyNo');
  34. $week_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereWeek("createdTime","this week")
  35. ->group("companyNo")->column('sum(totalPrice+th_fee) as weekTotal','companyNo');
  36. $week_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereWeek("createtime","this week")
  37. ->group("th_companyNo")->column('sum(th_qrd_fee) as week_thTotal','th_companyNo');
  38. $day_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereDay("createdTime","today")->group("companyNo")
  39. ->column('sum(totalPrice+th_fee) as dayTotal','companyNo');
  40. $day_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereDay("createtime","today")
  41. ->group("th_companyNo")->column('sum(th_qrd_fee) as day_thTotal','th_companyNo');
  42. $tips = Db::name("depart_tips")->where('year=YEAR(NOW()) and month=month(NOW())')->column("department,total_tips","departcode");
  43. $data=[];
  44. $temp=["p"=>"总计","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,
  45. "tips"=>0,"rate"=>0,"thrate"=>0];
  46. foreach ($tips as $key=>$value){
  47. $t=[];
  48. $t['p']=$value['department'];
  49. $t['thtotal']=sprintf( "%.2f",(($month_total[$key]??0) - ($month_thtotal[$key]??0)));
  50. $t['mtotal']=sprintf( "%.2f",$month_total[$key]??0 );
  51. $t['mthfee']=sprintf( "%.2f",$month_thtotal[$key]??0);
  52. $t['wtotal']=sprintf( "%.2f",$week_total[$key]??0);
  53. $t['wthfee']= sprintf( "%.2f",$week_thtotal[$key]??0);
  54. $t['dtotal']=sprintf( "%.2f",$day_total[$key]??0);
  55. $t['thfee']= sprintf( "%.2f",$day_thtotal[$key]??0);
  56. $t['tips']= sprintf( "%.2f",$value['total_tips']??0);
  57. $t["rate"]=$value['total_tips']??number_format( $t['mtotal']/$value['total_tips']*100,2);
  58. $t["thrate"]=$value['total_tips']??number_format( $t['thtotal']/$value['total_tips']*100,2);
  59. $data[]=$t;
  60. }
  61. $temp['thtotal'] = sprintf( "%.2f",array_sum(array_column($data,'thtotal')));
  62. $temp['mtotal'] = sprintf( "%.2f",array_sum(array_column($data,'mtotal')));
  63. $temp['mthfee'] = sprintf( "%.2f",array_sum(array_column($data,'mthfee')));
  64. $temp['wtotal'] = sprintf( "%.2f",array_sum(array_column($data,'wtotal')));
  65. $temp['wthfee'] = sprintf( "%.2f",array_sum(array_column($data,'wthfee')));
  66. $temp['dtotal'] = sprintf( "%.2f",array_sum(array_column($data,'dtotal')));
  67. $temp['thfee'] = sprintf( "%.2f",array_sum(array_column($data,'thfee')));
  68. $temp['tips'] = sprintf( "%.2f",array_sum(array_column($data,'tips')));
  69. $temp["rate"]=$temp['tips']??number_format( $temp['mtotal']/$temp['tips']*100,2);
  70. $temp["thrate"]=$temp['tips']??number_format( $temp['thtotal']/$temp['tips']*100,2);
  71. $sort = array_column($data,"thrate");
  72. array_multisort($sort,SORT_DESC,$data);
  73. array_unshift($data,$temp);
  74. Cache::set("statContent",$data);
  75. }
  76. }