setName('medal') ->addArgument('type', Argument::OPTIONAL, "type") ->addArgument('employee_id', Argument::OPTIONAL, "employee_id") ->addArgument('root_id', Argument::OPTIONAL, "root_id") ->setDescription('medal'); } protected function execute(Input $input, Output $output) { //勋章类型 $type = $input->getArgument('type'); $employee_id = (int)$input->getArgument('employee_id'); $root_id = (int)$input->getArgument('root_id'); $w[] = ['id','=',$employee_id]; $info = Employee::where($w)->field('id,uid,root_id')->find(); $root_id = $root_id ?: $info->root_id; //勋章体系 $w0[] = ['type','=',$type]; $w0[] = ['employee_id','=',$employee_id]; $w0[] = ['root_id','=',$root_id]; $employee_medal = EmployeeMedal::where($w0)->column('medal_id'); $w1[] = ['type','=',$type]; $w1[] = ['id','not in',$employee_medal];//排除已经获取到的勋章 $medal = MedalModel::where($w1)->order('condition asc')->select(); //签到勋章 $save = []; if ($type=='sign' && !$medal->isEmpty()) { //累计签到次数 $w2[] = ['user_id','=',$info->uid]; $w2[] = ['root_id','=',$root_id]; $count = UserSignLog::where($w2)->count(); }elseif ($type=='talkskill' && !$medal->isEmpty()) { //共享话术 //累计共享话术 $w2[] = ['employee_id','=',$info->id]; $w2[] = ['type','=','share']; $w2[] = ['approve','=',1]; $w2[] = ['root_id','=',$root_id]; $count = Talkskill::where($w2)->count(); }elseif ($type=='clue' && !$medal->isEmpty()) { //分享获客 $w2[] = ['employee_id','=',$info->id]; $w2[] = ['state','<>',2]; $count = CustomerClue::where($w2)->count(); }elseif ($type=='comment' && !$medal->isEmpty()) { //答疑解惑 $w2[] = ['root_id','=',$root_id]; $w2[] = ['uid','=',$info->uid]; $w2[] = ['approve','=',1]; $count = TalkskillComment::where($w2)->count(); }elseif ($type=='class' && !$medal->isEmpty()) { //课程学习 $w2[] = ['from','in',[0,1]]; $w2[] = ['root_id','=',$root_id]; $w2[] = ['done_percent','=',100]; $w2[] = ['employee_id','=',$info->id]; $count = TrainDoneLog::where($w2)->count(); }elseif($type=='visit_log' && !$medal->isEmpty()){ //客户跟踪 $w2[] = ['employee_id','=',$info->id]; $w2[] = ['state','not in',[11, '无效']]; $count = CustomerVisitLog::where($w2)->count(); } foreach ($medal as $k => $v) { if ($count >= $v->condition) { $save[] = [ 'employee_id' => $employee_id, 'medal_id' => $v->id, 'main' => 0, 'root_id' => $root_id, 'type' => $type ]; } } if(!empty($save)) (new EmployeeMedal())->saveAll($save); $output->writeln('ok'); } }