good.php 4.7 KB

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