Kirin пре 4 недеља
родитељ
комит
b85c2d91bb
2 измењених фајлова са 27 додато и 0 уклоњено
  1. 12 0
      app/command/CheckAchievement.php
  2. 15 0
      app/dao/user/level/UserLevelDao.php

+ 12 - 0
app/command/CheckAchievement.php

@@ -15,6 +15,7 @@ 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;
@@ -44,6 +45,8 @@ class CheckAchievement extends Command
         $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']);
@@ -51,6 +54,15 @@ class CheckAchievement extends Command
                 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]);
+
+                    $now_level = $levelService->getUerLevelInfoByUid($v['uid']);
+                    User::where('uid', $v['uid'])->update(['level' => $now_level['level_id'] ?? 0]);
+
+                    $output->info($this->log($v['uid'] . '降级完成'));
+                    return;
                 }
             }
         });

+ 15 - 0
app/dao/user/level/UserLevelDao.php

@@ -32,6 +32,21 @@ class UserLevelDao extends BaseDao
         return UserLevel::class;
     }
 
+
+    /**
+     * 搜索
+     * @param array $where
+     * @return \crmeb\basic\BaseModel|mixed
+     */
+    public function search(array $where = [])
+    {
+        if ($where) {
+            return $this->withSearchSelect(array_keys($where), $where);
+        } else {
+            return $this->getModel();
+        }
+    }
+
     /**
      * 根据uid 获取用户会员等级详细信息
      * @param int $uid