wugg 1 year ago
parent
commit
27d0101ffb
3 changed files with 114 additions and 4 deletions
  1. 109 0
      app/command/companyStats.php
  2. 4 4
      app/command/stat.php
  3. 1 0
      config/console.php

+ 109 - 0
app/command/companyStats.php

@@ -0,0 +1,109 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Db;
+
+class companyStats extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('companystats')
+            ->setDescription('the companystats command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+      $supplier = ["GS2302231124114965","GS2302231125079621","GS2302231323386950"];
+      try{
+	      foreach ($supplier as $sp){
+		      $this->checkData($sp);
+	      }
+      }catch (\Exception $e){
+      	echo $e->getMessage();
+      }
+
+    }
+
+    public function checkData($supplierNo){
+    	$sup =Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$supplierNo])->field("code,name,relation_code")->findOrEmpty();
+    	if(empty($sup)) return;
+    	$date=date("Y-m-d");
+    	$d=Db::name("depart_company")->where(["companyNo"=>$supplierNo,"day_time"=>$date])->column("*","type");
+    	$temp=[];
+		$total =Db::name("qrd_info")
+		->where(["companyNo"=>$supplierNo,"is_del"=>0,"cxCode"=>""])
+		->whereDay("createdTime","today")
+		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
+		$day_thtotal=Db::name("th_source")->alias("a")
+		 ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo")
+		 ->where([['a.th_companyNo',"=",$supplierNo],["b.is_del","=",0]])
+		 ->whereDay("a.createtime","today")->field('sum(a.th_qrd_fee) as th_total')->findOrEmpty();;
+		if(isset($d[1]))Db::name("depart_company")->where($d[1])->save(["sale_total"=>$total['total']??0,
+			"th_total"=>$day_thtotal['th_total']??0]);
+		else $temp[]=[
+			"companyNo"=>$supplierNo,
+			"companyName"=>$sup['name']??"",
+			"type"=>1,
+			"day_time"=>$date,
+			"sale_total"=>$total['total']??0,
+			"th_total"=>$day_thtotal['th_total']??0,
+			"addtime"=>date("Y-m-d H:i:s")
+			];
+		$total_cx =Db::name("qrd_info")
+		->where(["companyNo"=>$supplierNo,"is_del"=>0])
+		->where("cxCode","<>","")
+		->whereDay("createdTime","today")
+		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
+		$day_thtotal_cx=Db::name("th_source")->alias("a")
+		 ->leftJoin("qrd_info b","a.th_qrdNo=b.cxCode")
+		 ->where([['a.th_companyNo',"=",$supplierNo],["b.is_del","=",0]])
+		 ->whereDay("a.createtime","today")
+	    ->field("sum(a.th_num*b.goodPrice) as th_total")->findOrEmpty();
+		if(isset($d[2]))Db::name("depart_company")->where($d[2])->save(["sale_total"=>$total_cx['total']??0,
+		"th_total"=>$day_thtotal_cx['th_total']??0]);
+		else $temp[]=[
+			"companyNo"=>$supplierNo,
+			"companyName"=>$sup['name']??"",
+			"type"=>2,
+			"day_time"=>$date,
+			"sale_total"=>$total_cx['total']??0,
+			"th_total"=>$day_thtotal_cx['th_total']??0,
+			"addtime"=>date("Y-m-d H:i:s")
+			];
+		$cgd=$this->cgdData($sup['relation_code']);
+		if(isset($d[3]))Db::name("depart_company")->where($d[3])->save(["sale_total"=>$cgd['cgd_total'],
+		"th_total"=>$cgd['cgd_thtotal']]);
+		else $temp[]=[
+			"companyNo"=>$supplierNo,
+			"companyName"=>$sup['name']??"",
+			"type"=>3,
+			"day_time"=>$date,
+			"sale_total"=>$cgd['cgd_total'],
+			"th_total"=>$cgd['cgd_thtotal'],
+			"addtime"=>date("Y-m-d H:i:s")
+			];
+		if(!empty($temp))Db::name("depart_company")->insertAll($temp);
+
+    }
+    public function cgdData($sup){
+
+		$total =Db::name("cgd_info")
+		->where(["supplierNo"=>$sup,"is_del"=>0,"cxCode"=>""])
+		->whereDay("createdTime","today")
+		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
+		$day_thtotal=Db::name("th_source")->alias("a")
+		 ->leftJoin("cgd_info b","(a.th_cgdNo=b.sequenceNo and a.is_th=1) or (a.th_qrdNo=b.cxCode)")
+		 ->where([['b.supplierNo',"=",$sup],["b.is_del","=",0]])
+		 ->whereDay("a.createtime","today")
+	    ->field("sum(a.th_num*b.goodPrice) as th_total")->findOrEmpty();
+		return ["cgd_total"=>$total['total']??0,"cgd_thtotal"=>$day_thtotal['th_total']??0];
+    }
+}

+ 4 - 4
app/command/stat.php

@@ -54,11 +54,11 @@ class stat extends Command
 	//各部门统计数据
 	public  function GetData($uid,$companyNo){
 
-		$Db=Db::connect("mysql_cxinv");
-		$day_total =$Db->name("qrd_info")->where([["ownerid","in",$uid],["is_del","=",0],['companyNo',"=",$companyNo]])
+
+		$day_total =Db::name("qrd_info")->where([["ownerid","in",$uid],["is_del","=",0],['companyNo',"=",$companyNo]])
 		                         ->whereDay("createdTime","today")
-		              ->sum('totalPrice');
-		$day_thtotal=$Db->name("th_source")->alias("a")
+		              ->sum('totalPrice+th_fee');
+		$day_thtotal=Db::name("th_source")->alias("a")
 		               ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo or a.th_qrdNo=b.cxCode")
 		               ->where([["b.ownerid","in",$uid],['a.th_companyNo',"=",$companyNo]])
 		               ->whereDay("a.createtime","today")->sum('a.th_qrd_fee');

+ 1 - 0
config/console.php

@@ -13,6 +13,7 @@ return [
 
         'Good'=>app\command\good::class,//处理中间表的采销数据
         'stats'=>app\command\stat::class,//处理中间表的采销数据
+        'companystats'=>app\command\companyStats::class,//处理中间表的采销数据
         'reporttips'=>app\command\reportTips::class,//处理中间表的采销数据
 
         'Report'=>app\command\Report::class,//处理中间表的采销数据