good.php 4.9 KB

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