setName('update_data_statistics') ->addArgument('root_id', Argument::OPTIONAL, "root_id") ->setDescription('update_data_statistics'); } protected function execute(Input $input, Output $output) { //店面id $root_id = $input->getArgument('root_id'); if ($root_id=='all') { $root_ids = Company::where('1=1')->column('root_id'); foreach ($root_ids as $v) { $this->update($v); } $res = 'ok'; }elseif($root_id){ $res = $this->update($root_id); $res = !$res ? '参数错误' : 'ok'; }else{ $res = '无效参数'; } $output->writeln($res); } private function update($root_id){ // $company = Company::where('root_id',$root_id)->findOrEmpty(); if($company->isEmpty()) return false; $where[] = ['root_id','=',$root_id]; $info = DataStatistics::where($where)->findOrEmpty(); if($info->isEmpty()) DataStatistics::insert(['root_id'=>$root_id]); $query = ['root_id','=',$root_id]; //员工数量 $data['emp_count'] = Employee::where([$query,['state','=','在职'],['uid','>',0]])->count(); //员工管理员数量 $data['emp_manage_count'] = Employee::where([$query,['state','=','在职'],['uid','>',0],['is_manager','=',1]])->count(); //部门数量 $data['org_count'] = Org::where([['path','like',$root_id.'-%']])->count(); //运营数量 $data['motion_count'] = Employee::where([$query,['state','=','在职'],['grant_id','>',0]])->count(); //店面开通日期 $data['root_date'] = strtotime($company->addtime); //案例数量 $data['case_count'] = MaterialCase::where([$query,['del','=',0]])->count(); //课程数量 $data['course_count'] = TrainClass::where([$query,['del','=',0]])->count(); //楼盘数量 $data['building_count'] = Building::where([$query,['del','=',0]])->count(); //话术数量 $talk1 = TalkskillChosen::where([$query])->count(); $talk2 = TalkskillSuccess::where([$query])->count(); $talk3 = Talkskill::where([$query,['approve','=',1]])->count(); $data['talkskill_count'] = $talk1 + $talk2 + $talk3; //Vr作品数量 $group = VrGroup::where([$query,['status','=',2]])->column('size'); $data['group_count'] = count($group); $data['use_count'] = $group ? array_sum($group) : 0; //设计师数量 $org_ids = Org::where([['path','like',$root_id.'-%'],['org_type','=',2]])->column('id'); $data['designer_count'] = Employee::where([$query,['state','=','在职'],['uid','>',0],['org_id','in',$org_ids]])->count(); //在施工地数量 $data['plant_count'] = Construction::where([$query,['status','=',1]])->count(); DataStatistics::where('root_id',$root_id)->update($data); return true; } }