feat(zy): 添加消息通知功能并优化活动相关逻辑

- 在 Circle 控制器中添加点赞、评论和审核通知
- 在 Game 控制器中添加退坑、取消活动和发送消息功能
- 优化 Activity 控制器中的订单关联逻辑
- 更新语言包,添加新的活动状态翻译
This commit is contained in:
2025-05-26 11:03:39 +08:00
parent d48daea477
commit b7023e7ab3
7 changed files with 247 additions and 9 deletions

View File

@@ -5,12 +5,15 @@ namespace addons\shopro\controller\zy;
use think\Db;
use think\Exception;
use app\admin\model\zy\Club;
use app\admin\model\zy\Menber;
use app\admin\model\zy\Stadium;
use think\exception\PDOException;
use app\admin\model\zy\link\Message;
use app\admin\model\zy\game\GameJoin;
use app\admin\model\zy\game\GameMatch;
use think\exception\ValidateException;
use app\admin\model\zy\game\Participant;
use addons\shopro\service\order\OrderRefund;
class Game extends Base
@@ -76,6 +79,125 @@ class Game extends Base
$this->success('Success', $model);
}
// 退坑
public function quit()
{
$model = $this->model->get($this->request->param('id'));
if (empty($model)) {
$this->error(__('No rows were found'));
}
if ($model['status'] > 1) {
$this->error('活动已开始或结束,不能退出');
}
if ($model['status'] == -1) {
$this->error('活动已取消');
}
$join = GameJoin::where('user_id', $this->auth->id)->find();
if (empty($join) || $join['status'] == -1) {
$this->error('未报名或已取消');
}
if (date('Y-m-d H:i:s') >= $model['quit_time']) {
$this->error('已超过免费退出时间');
}
Db::startTrans();
try {
$join->save(['status' => -1]);
if ($join['status'] == 1) {
$order = $this->model->paid()->where('id', $join->order_id)->lock(true)->find();
if (!$order) {
$this->error('订单不存在或不可退款');
}
$orderRefund = new OrderRefund($order);
$orderRefund->fullRefund(NULL, [
'refund_type' => 'back',
'remark' => '用户自行退出活动'
]);
}
(new Message())->save([
'type' => 1,
'name' => '系统消息',
'avatar' => '',
'from_id' => 0,
'target_id' => $join->user_id,
'content' => json_encode([
'topic' => '退出',
'content' => '已退出 ' . $model['name'] . ' 活动',
'game_id' => $model->id
])
]);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('Success');
}
// 取消活动
public function cancle()
{
$model = $this->model->get($this->request->param('id'));
if (empty($model)) {
$this->error(__('No rows were found'));
}
$member = Menber::get(['club_id' => $model->club_id, 'user_id' => $this->auth->id]);
if (empty($member) || $member->role < 2) {
$this->error('无权取消活动');
}
if ($model['pid'] != 0) {
$this->error('不能取消子活动');
}
if ($model['status'] > 1) {
$this->error('活动已开始或结束,不能取消');
}
if ($model['status'] == -1) {
$this->error('活动已取消');
}
Db::startTrans();
try {
$model->save(['status' => -1]);
(new \app\admin\model\zy\game\Game)->where('pid', $model->id)->update(['status' => -1]);
//取消成功,进入退款流程并通知用户
$join = GameJoin::where('game_id', $model['id'])->select();
$msgs = [];
foreach ($join as $j) {
$j->save(['status' => -1]);
if ($j['status'] == 1) {
$order = $this->model->paid()->where('id', $j->order_id)->lock(true)->find();
if (!$order) {
$this->error('订单不存在或不可退款');
}
$orderRefund = new OrderRefund($order);
$orderRefund->fullRefund(NULL, [
'refund_type' => 'back',
'remark' => '活动取消,全额退款'
]);
}
$msgs[] = [
'type' => 1,
'name' => '系统消息',
'avatar' => '',
'from_id' => 0,
'target_id' => $j->user_id,
'content' => json_encode([
'topic' => '评论',
'content' => $model['name'] . ' 活动已取消',
'game_id' => $model->id
])
];
}
(new Message())->insertAll($msgs);;
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('Success');
}
public function getMacth()
{
@@ -138,4 +260,31 @@ class Game extends Base
// print_r($res);
$this->success('Success', $res);
}
public function describe()
{
$params = $this->request->param();
Db::startTrans();
try {
$game = $this->model->get($params['id'] ?? NULL);
if (empty($game)) {
$this->error('比赛不存在');
}
$gameClass = 'format\\Game' . $game['team_type'] . $game['rule_type'];
if (!class_exists($gameClass)) {
throw new Exception("赛制文件不存在,请联系管理人员: {$gameClass}");
}
$format = new $gameClass;
if (!$format instanceof \format\GameInterface) {
throw new Exception("赛制配置错误,请联系管理人员: {$gameClass}");
}
$describe = $format->describe();
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage(), $e);
}
$this->success('Success', $describe);
}
}