12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\command;
- use app\model\user\User;
- use app\services\user\AwardIntegralServices;
- use app\services\user\level\UserLevelServices;
- use Swoole\Process;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- /**
- * 重置密码
- * Class ResetAdminPwd
- * @package app\command
- */
- class CheckAchievement extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('checkAchievement')
- ->setDescription('Check User Achievement');
- }
- /**
- * @param Input $input
- * @param Output $output
- * @return int|void|null
- */
- protected function execute(Input $input, Output $output)
- {
- $process = new Process(function () use ($output) {
- /** @var AwardIntegralServices $service */
- $service = app()->make(AwardIntegralServices::class);
- /** @var UserLevelServices $levelService */
- $levelService = app()->make(UserLevelServices::class);
- $users = User::where('level', '>', 0)->select();
- foreach ($users as $v) {
- $achievement = $service->getAchievement($v['uid']);
- $month_achievement = $service->getLastMonthAchievement($v['uid']);
- if ($month_achievement < $achievement / 10) {
- $output->info($this->log($v['uid'] . '总业绩:' . $achievement . '月业绩:' . $month_achievement));
- $output->info($this->log($v['uid'] . '月业绩未达标,执行降级'));
- $userLevel = $levelService->getUerLevelInfoByUid($v['uid']);
- $levelService->search()->where('uid', $v['uid'])->where('level_id', $userLevel['level_id'])->update(['status' => 0, 'is_del' => 1]);
- $output->info($this->log($v['uid'] . '原等级' . $userLevel['level_id']));
- $now_level = $levelService->getUerLevelInfoByUid($v['uid']);
- User::where('uid', $v['uid'])->update(['level' => $now_level['level_id'] ?? 0]);
- $output->info($this->log($v['uid'] . '降级为' . ($now_level['level_id'] ?? 0)));
- $output->info($this->log($v['uid'] . '降级完成'));
- // return;
- }
- }
- });
- $process->start();
- Process::wait(true);
- $output->info('处理完毕');
- }
- protected function log($str)
- {
- return date('Y-m-d H:i:s') . ' ' . $str . PHP_EOL;
- }
- }
|