reportTips.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. $supplier = ["QS2203150147015222","QS2206011447553544","QS2203150147013805"];
  22. $this->GetData($supplier);
  23. $output->writeln('reporttips');
  24. }
  25. private function GetData($code){
  26. $month_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereMonth("createdTime","this month")
  27. ->group("companyNo")->column('sum(totalPrice+th_fee) as monthTotal','companyNo');
  28. $month_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereMonth("createtime","this month")
  29. ->group("th_companyNo")->column('sum(th_qrd_fee) as month_thTotal','th_companyNo');
  30. $week_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereWeek("createdTime","this week")
  31. ->group("companyNo")->column('sum(totalPrice+th_fee) as weekTotal','companyNo');
  32. $week_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereWeek("createtime","this week")
  33. ->group("th_companyNo")->column('sum(th_qrd_fee) as week_thTotal','th_companyNo');
  34. $day_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereDay("createdTime","today")->group("companyNo")
  35. ->column('sum(totalPrice+th_fee) as dayTotal','companyNo');
  36. $day_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereDay("createtime","today")
  37. ->group("th_companyNo")->column('sum(th_qrd_fee) as day_thTotal','th_companyNo');
  38. $tips = Db::name("depart_tips")->where('year=YEAR(NOW()) and month=month(NOW())')->column("department,total_tips","departcode");
  39. $data=[];
  40. $temp=["p"=>"总计","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,
  41. "tips"=>0,"rate"=>0,"thrate"=>0];
  42. foreach ($tips as $key=>$value){
  43. $t=[];
  44. $t['p']=$value['department'];
  45. $t['thtotal']=$month_total[$key]??0 - $month_thtotal[$key]??0;
  46. $t['mtotal']=$month_total[$key]??0 ;
  47. $t['mthfee']=$month_thtotal[$key]??0;
  48. $t['wtotal']=$week_total[$key]??0;
  49. $t['wthfee']= $week_thtotal[$key]??0;
  50. $t['dtotal']=$day_total[$key]??0;
  51. $t['thfee']= $day_thtotal[$key]??0;
  52. $t['tips']= $value['total_tips']??0;
  53. $t["rate"]=number_format( $t['mtotal']/$value['total_tips']*100,2);
  54. $t["thrate"]=number_format( $t['thtotal']/$value['total_tips']*100,2);
  55. $data[]=$t;
  56. }
  57. $temp['thtotal'] = array_sum(array_column($data,'thtotal'));
  58. $temp['mtotal'] = array_sum(array_column($data,'mtotal'));
  59. $temp['mthfee'] = array_sum(array_column($data,'mthfee'));
  60. $temp['wtotal'] = array_sum(array_column($data,'wtotal'));
  61. $temp['wthfee'] = array_sum(array_column($data,'wthfee'));
  62. $temp['dtotal'] = array_sum(array_column($data,'dtotal'));
  63. $temp['thfee'] = array_sum(array_column($data,'thfee'));
  64. $temp['tips'] = array_sum(array_column($data,'tips'));
  65. $temp["rate"]=number_format( $temp['mtotal']/$temp['tips']*100,2);
  66. $temp["thrate"]=number_format( $temp['thtotal']/$temp['tips']*100,2);
  67. $sort = array_column($data,"thrate");
  68. array_multisort($sort,SORT_DESC,$data);
  69. array_unshift($data,$temp);
  70. Cache::store("redis")->set("statContent",$data);
  71. }
  72. }