<?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');
|
}
|
|
}
|