123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\command;
- use think\console\Command;
- use think\console\input\Argument;
- use think\console\Input;
- use think\console\Output;
- use app\model\Talkskill;
- use app\model\UserSignLog;
- use app\model\Employee;
- use app\model\EmployeeMedal;
- use app\model\Medal as MedalModel;
- use app\model\CustomerClue;
- use app\model\TalkskillComment;
- use app\model\TrainDoneLog;
- use app\model\CustomerVisitLog;
- //勋章管理
- class Medal extends Command
- {
- protected function configure()
- {
- $this->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');
- }
- }
|