1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?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 good extends Command
- {
- protected function configure()
- { $this->setName('good')
- ->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];
- $data=[];
- $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");
- $uid= Db::connect("mysql_sys")->name("account_item")->where(["itemid"=>$daprtid])->column("account_id","itemid");
- foreach ($depart as $itmeid=>$depart_name){
- $ist=Db::name("depart_everyday")->where(["depart_id"=>$itmeid,'companyNo'=>$companyNo,"day_time"=>$date])->findOrEmpty();
- $uidArr =$uid[$itmeid]??[];
- $sale=$this->GetData($uidArr,$itmeid,$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,$departid=0,$companyNo){
- $day_total =Db::name("sale")->where([["apply_id","in",$uid],["is_del","=",0],['supplierNo',"=",$companyNo]])->whereDay("addtime","today")
- ->sum('total_price');
- $day_thtotal=Db::name("th_data")->alias("a")
- ->leftJoin("sale b","a.orderCode=b.orderCode")
- ->where([["a.apply_id","in",$uid],["a.is_del","=",0],['b.supplierNo',"=",$companyNo]])
- ->whereDay("a.addtime","today")->sum('a.th_fee');
- if($departid==56){
- $wlb= $this->wlb();
- $day_total+=$wlb;
- }
- return ["sale_total"=>$day_total,"th_total"=>$day_thtotal];
- }
- //网络部数据统计
- public function wlb(){
- $Db=Db::connect("mysql_cxinv");
- $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")
- ->whereDay("a.addtime","today")->where("b.companyNo","GS2203161855277894")->sum('totalPrice');
- return $day_total;
- }
- }
|