1
0

Medal.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\command;
  3. use think\console\Command;
  4. use think\console\input\Argument;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use app\model\Talkskill;
  8. use app\model\UserSignLog;
  9. use app\model\Employee;
  10. use app\model\EmployeeMedal;
  11. use app\model\Medal as MedalModel;
  12. use app\model\CustomerClue;
  13. use app\model\TalkskillComment;
  14. use app\model\TrainDoneLog;
  15. use app\model\CustomerVisitLog;
  16. //勋章管理
  17. class Medal extends Command
  18. {
  19. protected function configure()
  20. {
  21. $this->setName('medal')
  22. ->addArgument('type', Argument::OPTIONAL, "type")
  23. ->addArgument('employee_id', Argument::OPTIONAL, "employee_id")
  24. ->addArgument('root_id', Argument::OPTIONAL, "root_id")
  25. ->setDescription('medal');
  26. }
  27. protected function execute(Input $input, Output $output)
  28. {
  29. //勋章类型
  30. $type = $input->getArgument('type');
  31. $employee_id = (int)$input->getArgument('employee_id');
  32. $root_id = (int)$input->getArgument('root_id');
  33. $w[] = ['id','=',$employee_id];
  34. $info = Employee::where($w)->field('id,uid,root_id')->find();
  35. $root_id = $root_id ?: $info->root_id;
  36. //勋章体系
  37. $w0[] = ['type','=',$type];
  38. $w0[] = ['employee_id','=',$employee_id];
  39. $w0[] = ['root_id','=',$root_id];
  40. $employee_medal = EmployeeMedal::where($w0)->column('medal_id');
  41. $w1[] = ['type','=',$type];
  42. $w1[] = ['id','not in',$employee_medal];//排除已经获取到的勋章
  43. $medal = MedalModel::where($w1)->order('condition asc')->select();
  44. //签到勋章
  45. $save = [];
  46. if ($type=='sign' && !$medal->isEmpty()) {
  47. //累计签到次数
  48. $w2[] = ['user_id','=',$info->uid];
  49. $w2[] = ['root_id','=',$root_id];
  50. $count = UserSignLog::where($w2)->count();
  51. }elseif ($type=='talkskill' && !$medal->isEmpty()) {
  52. //共享话术
  53. //累计共享话术
  54. $w2[] = ['employee_id','=',$info->id];
  55. $w2[] = ['type','=','share'];
  56. $w2[] = ['approve','=',1];
  57. $w2[] = ['root_id','=',$root_id];
  58. $count = Talkskill::where($w2)->count();
  59. }elseif ($type=='clue' && !$medal->isEmpty()) {
  60. //分享获客
  61. $w2[] = ['employee_id','=',$info->id];
  62. $w2[] = ['state','<>',2];
  63. $count = CustomerClue::where($w2)->count();
  64. }elseif ($type=='comment' && !$medal->isEmpty()) {
  65. //答疑解惑
  66. $w2[] = ['root_id','=',$root_id];
  67. $w2[] = ['uid','=',$info->uid];
  68. $w2[] = ['approve','=',1];
  69. $count = TalkskillComment::where($w2)->count();
  70. }elseif ($type=='class' && !$medal->isEmpty()) {
  71. //课程学习
  72. $w2[] = ['from','in',[0,1]];
  73. $w2[] = ['root_id','=',$root_id];
  74. $w2[] = ['done_percent','=',100];
  75. $w2[] = ['employee_id','=',$info->id];
  76. $count = TrainDoneLog::where($w2)->count();
  77. }elseif($type=='visit_log' && !$medal->isEmpty()){
  78. //客户跟踪
  79. $w2[] = ['employee_id','=',$info->id];
  80. $w2[] = ['state','not in',[11, '无效']];
  81. $count = CustomerVisitLog::where($w2)->count();
  82. }
  83. foreach ($medal as $k => $v) {
  84. if ($count >= $v->condition) {
  85. $save[] = [
  86. 'employee_id' => $employee_id,
  87. 'medal_id' => $v->id,
  88. 'main' => 0,
  89. 'root_id' => $root_id,
  90. 'type' => $type
  91. ];
  92. }
  93. }
  94. if(!empty($save)) (new EmployeeMedal())->saveAll($save);
  95. $output->writeln('ok');
  96. }
  97. }