quanwei
2025-11-28 3ea53e61cc23fdb3ddf8b38a199ca60a6da8c407
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
 
namespace app\job\event;
 
use think\facade\Cache;
use app\job\model\plus\bonus\User as BonusUserModel;
use app\common\library\helper;
 
/**
 * 超级分红事件管理
 */
class BonusUser
{
    // 模型
    private $model;
 
    // 应用id
    private $appId;
 
    /**
     * 执行函数
     */
    public function handle($app_id)
    {
        try {
            $this->appId = $app_id;
            $this->model = new BonusUserModel();
            // 设置队长排位过期状态
            $this->setExpired();
            // 解冻业绩
            $this->backFreezeMoneySecond();
        } catch (\Throwable $e) {
            echo 'ERROR BonusUser: ' . $e->getMessage() . PHP_EOL;
            log_write('BonusUser TASK : ' . '__ ' . $e->getMessage(), 'task');
        }
        return true;
    }
 
    /**
     * 设置队长过期状态
     */
    private function setExpired()
    {
        $cacheKey = "task_space_BonusUser__{$this->appId}";
        if (Cache::has($cacheKey)) return true;
        // 获取已过期的队长ID集
        $userIds = $this->model->getExpiredUserIds($this->appId);
        // 记录日志
        $this->dologs('setExpired', [
            'userIds' => json_encode($userIds),
        ]);
        // 更新已过期状态
        $this->model->setIsExpire($userIds);
        Cache::set($cacheKey, time(), 3600);
        return true;
    }
 
    /**
     * 获取可解冻业绩的队长列表
     */
    private function backFreezeMoneySecond()
    {
        $cacheKey = "task_space_BonusUser_back__{$this->appId}";
        if (Cache::has($cacheKey)) return true;
        // 获得可解冻的队长
        $userList = $this->model->getBackUserList($this->appId);
        $userIds = helper::getArrayColumn($userList, 'user_id');
        // 记录日志
        $this->dologs('setBackFreezeMoneySecond', [
            'userIds' => json_encode($userIds),
        ]);
        // 解冻
        $this->model->setBackFreezeMoneySecond($userList);
        Cache::set($cacheKey, time(), 3600 * 6);
        return true;
    }
 
    /**
     * 记录日志
     */
    private function dologs($method, $params = [])
    {
        $value = 'BonusUser --' . $method;
        foreach ($params as $key => $val)
            $value .= ' --' . $key . ' ' . $val;
        return log_write($value, 'task');
    }
 
}