Files
fast/addons/shopro/job/Test.php
xiadc 98eda4e5ff feat(zy): 添加俱乐部功能和用户消息功能
- 新增俱乐部相关接口和功能,包括创建俱乐部、申请加入俱乐部、邀请加入俱乐部等
- 添加用户消息功能,包括发送消息、查看消息等
- 优化了部分代码结构,提高了可维护性
- 更新了文档,添加了新的接口说明
2025-05-04 11:11:44 +08:00

121 lines
4.5 KiB
PHP

<?php
namespace addons\shopro\job;
use think\Db;
use think\Exception;
use think\queue\Job;
use think\exception\PDOException;
use think\exception\ValidateException;
class Test extends BaseJob
{
/**
* 普通优先级队列测试
*/
public function shopro(Job $job, $data)
{
// 创建目录
$this->mkdir();
// 写入日志文件
$filename = RUNTIME_PATH . 'storage/queue/shopro.log';
file_put_contents($filename, date('Y-m-d H:i:s'));
$job->delete();
}
/**
* 高优先级队列测试
*/
public function shoproHigh(Job $job, $data)
{
// 创建目录
$this->mkdir();
// 写入日志文件
$filename = RUNTIME_PATH . 'storage/queue/shopro-high.log';
file_put_contents($filename, date('Y-m-d H:i:s'));
$job->delete();
}
/**
* 创建目录
*/
private function mkdir()
{
$dir = RUNTIME_PATH . 'storage/queue/';
if (!is_dir($dir)) {
@mkdir($dir, 0755, true);
}
}
/**
* 周期性活动创建比赛
*/
public function zy(Job $job, $data)
{
Db::startTrans();
try {
$_actModel = new \app\admin\model\zy\game\Activity();
$_gameModel = new \app\admin\model\zy\game\Game();
$week = date('w'); //当前星期
$current = time(); //当前时间
$activity = (clone $_actModel)::where('type', 1)->where('pid', 0)->select(); //周期性主活动
foreach ($activity as $act) {
$act = $act->toArray();
$publicTime = json_decode($act['public_time'] ?? '[]', true);
$publicBefore = intval($publicTime['before'] ?? 0); //提前几天
$PublicWeek = $act['week'] - $publicBefore; //设定应该发布的星期
if ($PublicWeek != $week && ($PublicWeek + 7) != $week) {
print_r('星期不对');
continue; // 星期不对
}
$public_time = strtotime($publicTime['time']); //设定的时间
if ($current < $public_time) {
print_r('时间未到');
continue; //时间未到
}
$act['public_time'] = date('Y-m-d H:i:s', $public_time - $publicBefore * 86400); //设定的时间
$act['date'] = date('Y-m-d', $public_time - $publicBefore * 86400); //设定的日期
$games = (clone $_gameModel)::where('act_id', $act['id'])
->where('public_time', $act['public_time'])
->where('date', $act['date'])->select();
if (!empty($games)) {
print_r('已存在');
continue; // 已存在
}
$joinStartTime = json_decode($act['join_start_time'] ?? '[]', true);
$act['join_start_time'] = date('Y-m-d H:i:s', strtotime($joinStartTime['time']) - intval($joinStartTime['before']) * 86400);
$joinEndTime = json_decode($act['join_end_time'] ?? '[]', true);
$act['join_end_time'] = date('Y-m-d H:i:s', strtotime($joinEndTime['time']) - intval($joinEndTime['before']) * 86400);
$quitTime = json_decode($act['quit_time'] ?? '[]', true);
$act['quit_time'] = date('Y-m-d H:i:s', strtotime($quitTime['time']) - intval($quitTime['before']) * 86400);
$act['act_id'] = $act['id'];
unset($act['id']);
$res = (clone $_gameModel)->allowField(true)->save($act);
$subs = (clone $_actModel)::where('pid', $act['act_id'])->select();
foreach ($subs as $sub) { //存在子活动
$sub = $sub->toArray();
$sub['public_time'] = $act['public_time'];
$sub['join_start_time'] = $act['join_start_time'];
$sub['join_end_time'] = $act['join_end_time'];
$sub['quit_time'] = $act['quit_time'];
$sub['act_id'] = $act['act_id'];
$sub['date'] = $act['date'];
unset($sub['id']);
$res = (clone $_gameModel)->allowField(true)->save($sub);
}
}
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
format_log_error($e, 'zy.activity create game');
}
$job->release(600); //$delay为延迟时间
}
}