|
@@ -0,0 +1,78 @@
|
|
|
+<?php
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\command;
|
|
|
+
|
|
|
+use think\console\Command;
|
|
|
+use think\console\Input;
|
|
|
+use think\console\Output;
|
|
|
+use think\facade\Cache;
|
|
|
+use think\facade\Db;
|
|
|
+
|
|
|
+class stat extends Command
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ { $this->setName('stat')
|
|
|
+ ->setDescription('the good command');
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(Input $input, Output $output)
|
|
|
+ {
|
|
|
+ // 指令输出
|
|
|
+ $sttime = Cache::get("departTips");
|
|
|
+ if($sttime==1) return '';
|
|
|
+ Cache::set("departTips",1,1800);
|
|
|
+ $daprtid = [52,53,56,57];
|
|
|
+ $companyNo='GS2203161855277894' ;
|
|
|
+ $date=date("Y-m-d");
|
|
|
+ $depart= Db::connect("mysql_sys")->name("company_item")->where(["id"=>$daprtid])->column("name","id");
|
|
|
+ $company= Db::connect("mysql_sys")->name("company_info")->where(["companyNo"=>$companyNo])->column("company_name","companyNo");
|
|
|
+ foreach ($depart as $itmeid=>$depart_name){
|
|
|
+ $ist=Db::name("depart_everyday")->where(["depart_id"=>$itmeid,'companyNo'=>$companyNo,"day_time"=>$date])->findOrEmpty();
|
|
|
+ $uidArr =$this->getuid($itmeid);
|
|
|
+ $sale=$this->GetData($uidArr,$companyNo);
|
|
|
+ if($ist){
|
|
|
+ $ist['sale_total']=$sale['sale_total']??0;
|
|
|
+ $ist['th_total']=$sale['th_total']??0;
|
|
|
+ }else{
|
|
|
+ $ist=[
|
|
|
+ "depart_id"=>$itmeid,
|
|
|
+ "depart_name"=>$depart_name,
|
|
|
+ "day_time"=>date("Y-m-d"),
|
|
|
+ "sale_total"=>$sale['sale_total']??0,
|
|
|
+ "th_total"=>$sale['th_total']??0,
|
|
|
+ "companyNo"=>$companyNo,
|
|
|
+ "companyName"=>$company[$companyNo],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::name("depart_everyday")->save($ist);
|
|
|
+ }
|
|
|
+ $date=date('Y-m-d H:i:s');
|
|
|
+ $output->writeln("[{$date}] 更新数据成功");
|
|
|
+ }
|
|
|
+ //各部门统计数据
|
|
|
+ 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]])
|
|
|
+ ->whereDay("createdTime","today")
|
|
|
+ ->sum('totalPrice');
|
|
|
+ $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');
|
|
|
+ return ["sale_total"=>$day_total,"th_total"=>$day_thtotal];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function getuid($depart_id){
|
|
|
+ $uidArr=Cache::get("Depart_Uid_Arr_$depart_id");
|
|
|
+ if($uidArr==false){
|
|
|
+ $uidArr = Db::connect("mysql_sys")->name("account_item")->where(["itemid"=>$depart_id])->column("account_id");
|
|
|
+ Cache::set("Depart_Uid_Arr_$depart_id",$uidArr);
|
|
|
+ }
|
|
|
+ return $uidArr;
|
|
|
+ }
|
|
|
+}
|