|
@@ -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];
|
|
|
+ }
|
|
|
+}
|