CheckAchievement.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\command;
  12. use app\model\user\User;
  13. use app\services\user\AwardIntegralServices;
  14. use app\services\user\level\UserLevelServices;
  15. use Swoole\Process;
  16. use think\console\Command;
  17. use think\console\Input;
  18. use think\console\Output;
  19. /**
  20. * 重置密码
  21. * Class ResetAdminPwd
  22. * @package app\command
  23. */
  24. class CheckAchievement extends Command
  25. {
  26. protected function configure()
  27. {
  28. // 指令配置
  29. $this->setName('checkAchievement')
  30. ->setDescription('Check User Achievement');
  31. }
  32. /**
  33. * @param Input $input
  34. * @param Output $output
  35. * @return int|void|null
  36. */
  37. protected function execute(Input $input, Output $output)
  38. {
  39. $process = new Process(function () use ($output) {
  40. /** @var AwardIntegralServices $service */
  41. $service = app()->make(AwardIntegralServices::class);
  42. /** @var UserLevelServices $levelService */
  43. $levelService = app()->make(UserLevelServices::class);
  44. $users = User::where('level', '>', 0)->select();
  45. foreach ($users as $v) {
  46. $achievement = $service->getAchievement($v['uid']);
  47. $month_achievement = $service->getLastMonthAchievement($v['uid']);
  48. if ($month_achievement < $achievement / 10) {
  49. $output->info($this->log($v['uid'] . '总业绩:' . $achievement . '月业绩:' . $month_achievement));
  50. $output->info($this->log($v['uid'] . '月业绩未达标,执行降级'));
  51. $userLevel = $levelService->getUerLevelInfoByUid($v['uid']);
  52. $levelService->search()->where('uid', $v['uid'])->where('level_id', $userLevel['level_id'])->update(['status' => 0, 'is_del' => 1]);
  53. $output->info($this->log($v['uid'] . '原等级' . $userLevel['level_id']));
  54. $now_level = $levelService->getUerLevelInfoByUid($v['uid']);
  55. User::where('uid', $v['uid'])->update(['level' => $now_level['level_id'] ?? 0]);
  56. $output->info($this->log($v['uid'] . '降级为' . ($now_level['level_id'] ?? 0)));
  57. $output->info($this->log($v['uid'] . '降级完成'));
  58. // return;
  59. }
  60. }
  61. });
  62. $process->start();
  63. Process::wait(true);
  64. $output->info('处理完毕');
  65. }
  66. protected function log($str)
  67. {
  68. return date('Y-m-d H:i:s') . ' ' . $str . PHP_EOL;
  69. }
  70. }