good.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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;
  10. use think\facade\Db;
  11. class good extends Command
  12. {
  13. protected function configure()
  14. { $this->setName('good')
  15. ->setDescription('the good command');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. // 指令输出
  20. $sttime = Cache::get("departTips");
  21. if($sttime==1) return '';
  22. Cache::set("departTips",1,1800);
  23. $daprtid = [52,53,56,57];
  24. $temp=["p"=>"总计","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,"tips"=>0,"rate"=>0,"thrate"=>0];
  25. $data=[];
  26. foreach ($daprtid as $itmeid){
  27. $uidArr =Db::name("depart_user")->where(['itemid'=>$itmeid,"status"=>1,"is_del"=>0])->column("uid");
  28. $data[]=$this->GetData($uidArr,$itmeid);
  29. }
  30. $temp['thtotal'] = sprintf( "%.2f",array_sum(array_column($data,'thtotal')));
  31. $temp['mtotal'] = sprintf( "%.2f",array_sum(array_column($data,'mtotal')));
  32. $temp['mthfee'] = sprintf( "%.2f",array_sum(array_column($data,'mthfee')));
  33. $temp['wtotal'] = sprintf( "%.2f",array_sum(array_column($data,'wtotal')));
  34. $temp['wthfee'] = sprintf( "%.2f",array_sum(array_column($data,'wthfee')));
  35. $temp['dtotal'] = sprintf( "%.2f",array_sum(array_column($data,'dtotal')));
  36. $temp['thfee'] = sprintf( "%.2f",array_sum(array_column($data,'thfee')));
  37. $temp['tips'] = sprintf( "%.2f",array_sum(array_column($data,'tips')));
  38. $temp["rate"]=number_format( $temp['mtotal']/$temp['tips']*100,2);
  39. $temp["thrate"]=number_format( $temp['thtotal']/$temp['tips']*100,2);
  40. $sort = array_column($data,"thrate");
  41. array_multisort($sort,SORT_DESC,$data);
  42. array_unshift($data,$temp);
  43. Cache::set("departContent",$data);
  44. $date=date('Y-m-d H:i:s');
  45. $output->writeln("[{$date}] 更新数据成功");
  46. }
  47. //各部门统计数据
  48. public function GetData($uid,$departid=0){
  49. $temp=["p"=>"","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,"tips"=>0,"rate"=>0,"thrate"=>0];
  50. $tips = Db::name("depart_tips")->where(['year'=>date("Y") ,"month"=>date("m"),"depart_id"=>$departid])
  51. ->field("depart_item,total_tips")->findOrEmpty();
  52. $temp['p']= $tips['depart_item']??"";
  53. $temp['tips']= sprintf( "%.2f",$tips['total_tips']??0);
  54. $month_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0]])->whereMonth("addtime","this month")
  55. ->sum('total_price');
  56. $month_thtotal=Db::name("th_data")->where([["apply_id","in",$uid],["is_del","=",0]])->whereMonth("addtime","this month")
  57. ->sum('th_fee');
  58. $week_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0]])->whereWeek("addtime","this week")
  59. ->sum('total_price');
  60. $week_thtotal=Db::name("th_data")->where([["apply_id","in",$uid],["is_del","=",0]])->whereWeek("addtime","this week")
  61. ->sum('th_fee');
  62. $day_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0]])->whereDay("addtime","today")
  63. ->sum('total_price');
  64. $day_thtotal=Db::name("th_data")->where([["apply_id","in",$uid],["is_del","=",0]])->whereDay("addtime","today")->sum('th_fee');
  65. if($departid==56){
  66. $wlb= $this->wlb();
  67. $month_total+=$wlb['month_total'];
  68. $week_total+=$wlb['week_total'];
  69. $day_total+=$wlb['day_total'];
  70. }
  71. $temp['thtotal']=sprintf( "%.2f",(($month_total??0) - ($month_thtotal??0)));
  72. $temp['mtotal']=sprintf( "%.2f",$month_total??0 );
  73. $temp['mthfee']=sprintf( "%.2f",$month_thtotal??0);
  74. $temp['wtotal']=sprintf( "%.2f",$week_total??0);
  75. $temp['wthfee']= sprintf( "%.2f",$week_thtotal??0);
  76. $temp['dtotal']=sprintf( "%.2f",$day_total??0);
  77. $temp['thfee']= sprintf( "%.2f",$day_thtotal??0);
  78. $temp["rate"]=number_format( $temp['mtotal']/$tips['total_tips']*100,2);
  79. $temp["thrate"]=number_format( $temp['thtotal']/$tips['total_tips']*100,2);
  80. return $temp;
  81. }
  82. //网络部数据统计
  83. public function wlb(){
  84. $Db=Db::connect("mysql_cxinv");
  85. $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")
  86. ->whereMonth("a.addtime","this month")->where("b.companyNo","GS2203161855277894")->sum('totalPrice');
  87. $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")
  88. ->whereWeek("a.addtime","this week")->where("b.companyNo","GS2203161855277894")->sum('totalPrice');
  89. $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")
  90. ->whereDay("a.addtime","today")->where("b.companyNo","GS2203161855277894")->sum('totalPrice');
  91. return ["month_total"=>$month_total,"week_total"=>$week_total,"day_total"=>$day_total] ;
  92. }
  93. }