Browse Source

会员升级

Kirin 4 weeks ago
parent
commit
04597785a3
2 changed files with 71 additions and 0 deletions
  1. 64 0
      app/command/CheckAchievement.php
  2. 7 0
      app/services/user/AwardIntegralServices.php

+ 64 - 0
app/command/CheckAchievement.php

@@ -0,0 +1,64 @@
+<?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 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);
+            $users = User::where('level', '>', 0)->select();
+            foreach ($users as $v) {
+                $achievement = $service->getAchievement($v['uid']);
+                $month_achievement = $service->getLastMonthAchievement($v['uid']);
+                $output->info($this->log($v['uid'] . '总业绩:' . $achievement . '月业绩:' . $month_achievement));
+            }
+        });
+        $process->start();
+        Process::wait(true);
+        $output->info('处理完毕');
+    }
+
+    protected function log($str)
+    {
+        return date('Y-m-d H:i:s') . ' ' . $str . PHP_EOL;
+    }
+
+}

+ 7 - 0
app/services/user/AwardIntegralServices.php

@@ -134,6 +134,13 @@ class AwardIntegralServices extends BaseServices
         return $this->dao->sum($where, 'order_price', true) + $service->getAchievement($uid, 1);
     }
 
+    public function getLastMonthAchievement($uid)
+    {
+        $where = ['uid' => array_merge([$uid], get_group_user($uid))];
+        $where['time'] = 'last month';
+        return $this->dao->sum($where, 'order_price', true);
+    }
+
 
     /**
      * 加积分