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

119 lines
3.9 KiB
PHP

<?php
namespace addons\shopro\controller\zy;
use think\Db;
use think\Cache;
use think\Exception;
use think\exception\PDOException;
use addons\shopro\library\RedisCache;
use think\exception\ValidateException;
use addons\shopro\service\order\OrderCreate;
class Activity extends Base
{
protected $noNeedLogin = ['test'];
public function __construct()
{
$this->model = new \app\admin\model\zy\game\Activity;
parent::__construct();
}
public function index()
{
$params = $this->request->param();
$model = $this->model;
if (isset($params['name'])) {
$model->where('name', 'like', '%' . $params['name'] . '%');
}
if (isset($params['club_id'])) {
$model->where('club_id', $params['club_id']);
}
if (isset($params['week'])) {
$model->where('week', $params['week']);
}
if (isset($params['pid'])) {
$model->where('pid', $params['pid']);
} else {
$model->where('pid', 0);
}
$res = $model->select();
foreach ($res as &$v) {
$v['public_time'] = json_decode($v['public_time'] ?? '[]', true);
$v['join_start_time'] = json_decode($v['join_start_time'] ?? '[]', true);
$v['join_end_time'] = json_decode($v['join_end_time'] ?? '[]', true);
$v['quit_time'] = json_decode($v['quit_time'] ?? '[]', true);
$v['cost'] = json_decode($v['cost'] ?? '[]', true);
$v['referee'] = explode(',', $v['referee']);
}
$this->success('Success', $res);
}
public function view()
{
$model = $this->model->get($this->request->param('id'));
if (empty($model)) {
$this->error(__('No rows were found'));
}
$model['public_time'] = json_decode($model['public_time'] ?? '[]', true);
$model['join_start_time'] = json_decode($model['join_start_time'] ?? '[]', true);
$model['join_end_time'] = json_decode($model['join_end_time'] ?? '[]', true);
$model['quit_time'] = json_decode($model['quit_time'] ?? '[]', true);
$model['cost'] = json_decode($model['cost'] ?? '[]', true);
$model['referee'] = explode(',', $model['referee']);
$this->success('Success', $model);
}
// 启动周期性活动创建比赛任务
public function test()
{
if (!\think\Cache::has('addons\shopro\job\Test@zy')) {
$res = \think\Queue::push('\addons\shopro\job\Test@zy', time(), 'shopro');
\think\Cache::set('addons\shopro\job\Test@zy', $res);
$this->success('Success', $res);
}
$this->success('Success', '任务已存在');
}
// 比赛报名
public function gameJoin()
{
Db::startTrans();
try {
$params = $this->request->param();
$game = \app\admin\model\zy\game\Game::where('id', $params['act_id'] ?? NULL)
->where('date', $params['date'] ?? NULL)->find();
if (empty($game)) {
$this->error(__('No rows were found'));
}
$this->svalidate($params, ".create");
$orderCreate = new OrderCreate($params);
$result = $orderCreate->calc('create');
$order = $orderCreate->create($result);
$join = new \app\admin\model\zy\game\GameJoin;
$join->allowField(true)->save([
'act_id' => $game['act_id'],
'game_id' => $game['id'],
'user_id' => $this->auth->id,
'orer_id' => $order['order_sn'],
'status' => 1,
'users' => json_encode($params['users'] ?? [])
]);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage(), $e);
}
$this->success('Success', $join);
}
}