<?php
|
|
namespace app\job\event;
|
|
use think\facade\Cache;
|
use app\job\model\plus\vip\User as VipUserModel;
|
|
/**
|
* VIP用户事件管理
|
*/
|
class VipUser
|
{
|
// 模型
|
private $model;
|
|
/**
|
* 执行函数
|
*/
|
public function handle()
|
{
|
try {
|
$this->model = new VipUserModel();
|
$cacheKey = "task_space_VipUser";
|
if (!Cache::has($cacheKey)) {
|
// 处理用户升级逻辑
|
$this->processUserUpgrades();
|
|
// 处理用户降级逻辑
|
$this->processUserDowngrades();
|
|
Cache::set($cacheKey, time(), 60);
|
}
|
} catch (\Throwable $e) {
|
echo 'ERROR VipUser: ' . $e->getMessage() . PHP_EOL;
|
log_write('VipUser TASK : ' . '__ ' . $e->getMessage(), 'task');
|
}
|
return true;
|
}
|
|
/**
|
* 处理用户升级
|
*/
|
private function processUserUpgrades()
|
{
|
// 获取需要升级的用户列表
|
$list = $this->model->getUpgradeList();
|
if ($list->isEmpty()) return false;
|
|
// 处理逻辑...
|
$processedIds = [];
|
foreach ($list as $item) {
|
// 具体处理逻辑
|
$processedIds[] = $item['user_id'];
|
}
|
|
// 标记已处理
|
if (!empty($processedIds)) {
|
$this->model->processGradeChange($processedIds, true);
|
}
|
|
// 记录日志
|
$this->dologs('processUserUpgrades', ['Count' => count($processedIds)]);
|
return true;
|
}
|
|
/**
|
* 处理用户降级
|
*/
|
private function processUserDowngrades()
|
{
|
// 获取需要降级的用户列表
|
$list = $this->model->getDowngradeList();
|
if ($list->isEmpty()) return false;
|
|
// 处理逻辑...
|
$processedIds = [];
|
foreach ($list as $item) {
|
// 具体处理逻辑
|
$processedIds[] = $item['user_id'];
|
}
|
|
// 标记已处理
|
if (!empty($processedIds)) {
|
$this->model->processGradeChange($processedIds, false);
|
}
|
|
// 记录日志
|
$this->dologs('processUserDowngrades', ['Count' => count($processedIds)]);
|
return true;
|
}
|
|
/**
|
* 记录日志
|
*/
|
private function dologs($method, $params = [])
|
{
|
$value = 'behavior VipUser --' . $method;
|
foreach ($params as $key => $val) {
|
$value .= ' --' . $key . ' ' . (is_array($val) ? json_encode($val) : $val);
|
}
|
return log_write($value, 'task');
|
}
|
}
|