good.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. $data=[];
  23. $companyNo='GS2203161855277894' ;
  24. $date=date("Y-m-d");
  25. $depart= Db::connect("mysql_sys")->name("company_item")->where(["id"=>$daprtid])->column("name","id");
  26. $company= Db::connect("mysql_sys")->name("company_info")->where(["companyNo"=>$companyNo])->column("company_name","companyNo");
  27. $uid= Db::connect("mysql_sys")->name("account_item")->where(["itemid"=>$daprtid])->column("account_id","itemid");
  28. foreach ($depart as $itmeid=>$depart_name){
  29. $ist=Db::name("depart_everyday")->where(["depart_id"=>$itmeid,'companyNo'=>$companyNo,"day_time"=>$date])->findOrEmpty();
  30. $uidArr =$uid[$itmeid]??[];
  31. $sale=$this->GetData($uidArr,$itmeid,$companyNo);
  32. if($ist){
  33. $ist['sale_total']=$sale['sale_total']??0;
  34. $ist['th_total']=$sale['th_total']??0;
  35. }else{
  36. $ist=[
  37. "depart_id"=>$itmeid,
  38. "depart_name"=>$depart_name,
  39. "day_time"=>date("Y-m-d"),
  40. "sale_total"=>$sale['sale_total']??0,
  41. "th_total"=>$sale['th_total']??0,
  42. "companyNo"=>$companyNo,
  43. "companyName"=>$company[$companyNo],
  44. ];
  45. }
  46. Db::name("depart_everyday")->save($ist);
  47. }
  48. $date=date('Y-m-d H:i:s');
  49. $output->writeln("[{$date}] 更新数据成功");
  50. }
  51. //各部门统计数据
  52. public function GetData($uid,$departid=0,$companyNo){
  53. $day_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0],['supplierNo',"=",$companyNo]])->whereDay("addtime","today")
  54. ->sum('total_price');
  55. $day_thtotal=Db::name("th_data")->alias("a")
  56. ->leftJoin("sale b","a.orderCode=b.orderCode")
  57. ->where([["a.apply_id","in",$uid],["a.is_del","=",0],['b.supplierNo',"=",$companyNo]])
  58. ->whereDay("a.addtime","today")->sum('a.th_fee');
  59. if($departid==56){
  60. $wlb= $this->wlb();
  61. $day_total+=$wlb;
  62. }
  63. return ["sale_total"=>$day_total,"th_total"=>$day_thtotal];
  64. }
  65. //网络部数据统计
  66. public function wlb(){
  67. $Db=Db::connect("mysql_cxinv");
  68. $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")
  69. ->whereDay("a.addtime","today")->where("b.companyNo","GS2203161855277894")->sum('totalPrice');
  70. return $day_total;
  71. }
  72. }