stat.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 stat extends Command
  10. {
  11. protected function configure()
  12. { $this->setName('stat')
  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. $companyNo='GS2203161855277894' ;
  23. $date=date("Y-m-d");
  24. $depart= Db::connect("mysql_sys")->name("company_item")->where(["id"=>$daprtid])->column("name","id");
  25. $company= Db::connect("mysql_sys")->name("business")->where(["companyNo"=>$companyNo])->column
  26. ("company","companyNo");
  27. foreach ($depart as $itmeid=>$depart_name){
  28. $ist=Db::name("depart_everyday")->where(["depart_id"=>$itmeid,'companyNo'=>$companyNo,"day_time"=>$date])
  29. ->findOrEmpty();
  30. $uidArr =getUidByDepartId($itmeid);
  31. $sale=$this->GetData($uidArr,$companyNo,$date);
  32. $zy=$this->GetData($uidArr,$companyNo,$date,1);
  33. $channel=$this->GetData($uidArr,$companyNo,$date,2);
  34. if($ist){
  35. $ist['sale_total']=$sale['sale_total']??0;
  36. $ist['th_total']=$sale['th_total']??0;
  37. $ist['zy_sale_total']=$zy['sale_total']-$zy['th_total'];
  38. $ist['channel_sale_total']=$channel['sale_total']-$channel['th_total'];
  39. }else{
  40. $ist=[
  41. "depart_id"=>$itmeid,
  42. "depart_name"=>$depart_name,
  43. "day_time"=>date("Y-m-d"),
  44. "sale_total"=>$sale['sale_total']??0,
  45. "th_total"=>$sale['th_total']??0,
  46. "zy_sale_total"=>$zy['sale_total']-$zy['th_total'],
  47. "channel_sale_total"=>$channel['sale_total']-$channel['th_total'],
  48. "companyNo"=>$companyNo,
  49. "companyName"=>$company[$companyNo],
  50. ];
  51. }
  52. Db::name("depart_everyday")->save($ist);
  53. }
  54. $date=date('Y-m-d H:i:s');
  55. $output->writeln("[{$date}] 更新数据成功");
  56. }
  57. //各部门统计数据
  58. /**
  59. * @param $uid
  60. * @param $companyNo
  61. * @param $date
  62. * @return array
  63. */
  64. public function GetData($uid,$companyNo,$date,$type=0):array{
  65. $where=[];
  66. if($type==1) $where[]=["cxCode","=",''];
  67. if($type==2) $where[]=["cxCode","<>",''];
  68. $day_total =Db::name("qrd_info")->where([["ownerid","in",$uid],["is_del","=",0],['companyNo',"=",$companyNo]])
  69. ->whereDay("createdTime",$date)
  70. ->where($where)
  71. ->sum(Db::raw('totalPrice+th_fee'));
  72. $day_thtotal=Db::name("th_source")->alias("a")
  73. ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo or a.th_qrdNo=b.cxCode")
  74. ->where([["b.ownerid","in",$uid],['b.companyNo',"=",$companyNo]])
  75. ->where($where)
  76. ->whereDay("a.createtime",$date)->sum(Db::raw('a.th_num*b.goodPrice'));
  77. return ["sale_total"=>$day_total,"th_total"=>$day_thtotal];
  78. }
  79. }