refactor(zy): 修改消息通知的类型和功能

This commit is contained in:
2025-06-09 10:52:18 +08:00
parent c9a8b9d5e8
commit 70baaa2fd5
5 changed files with 127 additions and 109 deletions

View File

@@ -486,20 +486,20 @@ class User extends Common
'reason' => $params['reason'] ?? '', 'reason' => $params['reason'] ?? '',
'status' => 1 'status' => 1
]); ]);
(new Message())->allowField(true)->save([ // 消息通知 // (new Message())->allowField(true)->save([ // 消息通知
'type' => 2, // 'type' => 2,
'name' => $fromUser->nickname, // 'name' => $fromUser->nickname,
'avatar' => $fromUser->avatar, // 'avatar' => $fromUser->avatar,
'from_id' => $fromUser->id, // 'from_id' => $fromUser->id,
'user_id' => $user->id, // 'user_id' => $user->id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '申请联系信息', // 'topic' => '申请联系信息',
'申请人' => $fromUser->nickname, // '申请人' => $fromUser->nickname,
'申请时间' => date('Y-m-d H:i:s'), // '申请时间' => date('Y-m-d H:i:s'),
'reason' => $params['reason'] ?? '', // 'reason' => $params['reason'] ?? '',
'apply_id' => $apply->id // 'apply_id' => $apply->id
]) // ])
]); // ]);
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
Db::rollback(); Db::rollback();

View File

@@ -9,6 +9,7 @@ use app\admin\model\zy\Stadium;
use app\admin\model\zy\game\Game; use app\admin\model\zy\game\Game;
use think\exception\PDOException; use think\exception\PDOException;
use app\admin\model\shopro\Category; use app\admin\model\shopro\Category;
use app\admin\model\zy\link\Message;
use app\admin\model\zy\game\GameJoin; use app\admin\model\zy\game\GameJoin;
use think\exception\ValidateException; use think\exception\ValidateException;
use app\admin\model\shopro\goods\Goods; use app\admin\model\shopro\goods\Goods;
@@ -211,7 +212,8 @@ class Activity extends Base
} }
$order = GameJoin::where('game_id', $game['id'])->count(); $order = GameJoin::where('game_id', $game['id'])->count();
$gender = ['man' => 0, 'woman' => 0]; $gender = ['man' => 0, 'woman' => 0];
$participant = []; $user = auth_user();
$participant = $msgs = [];
foreach ($params['users'] as $u) { foreach ($params['users'] as $u) {
$order++; $order++;
$participant[] = [ $participant[] = [
@@ -229,6 +231,19 @@ class Activity extends Base
} else { } else {
$gender['man'] += 1; $gender['man'] += 1;
} }
$msgs[] = [
'type' => 1,
'name' => '系统消息',
'avatar' => '',
'from_id' => 0,
'user_id' => $u['user_id'],
'content' => json_encode([
'msgType' => 1,
'content' => $user['nickname'] . ' 帮你报名了组球',
'game_id' => $game['id'],
'act_id' => $game['act_id'],
])
];
} }
foreach ($gender as $k => $v) { foreach ($gender as $k => $v) {
if ($params['goods_list'][$k]['goods_num'] != $v) { if ($params['goods_list'][$k]['goods_num'] != $v) {
@@ -254,6 +269,7 @@ class Activity extends Base
$p['game_join_id'] = $join->id; $p['game_join_id'] = $join->id;
} }
(new Participant)->insertAll($participant); (new Participant)->insertAll($participant);
(new Message())->insertAll($msgs);
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {

View File

@@ -134,18 +134,18 @@ class Circle extends Base
'avatar' => $user['avatar'], 'avatar' => $user['avatar'],
'gender' => $user['gender'], 'gender' => $user['gender'],
]); ]);
(new Message())->allowField(true)->save([ // 消息通知 // (new Message())->allowField(true)->save([ // 消息通知
'type' => 1, // 'type' => 1,
'name' => '互动消息', // 'name' => '互动消息',
'avatar' => '', // 'avatar' => '',
'from_id' => 0, // 'from_id' => 0,
'user_id' => $circle->user_id, // 'user_id' => $circle->user_id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '点赞', // 'topic' => '点赞',
'content' => $user['nickname'] . '点赞了你的帖子', // 'content' => $user['nickname'] . '点赞了你的帖子',
'circle_id' => $circle->id // 'circle_id' => $circle->id
]) // ])
]); // ]);
} else { // 取消点赞 } else { // 取消点赞
$like->delete(); $like->delete();
} }
@@ -186,18 +186,18 @@ class Circle extends Base
'gender' => $user['gender'], 'gender' => $user['gender'],
'content' => $params['content'], 'content' => $params['content'],
]); ]);
(new Message())->allowField(true)->save([ // 消息通知 // (new Message())->allowField(true)->save([ // 消息通知
'type' => 1, // 'type' => 1,
'name' => '互动消息', // 'name' => '互动消息',
'avatar' => '', // 'avatar' => '',
'from_id' => 0, // 'from_id' => 0,
'target_id' => $circle->user_id, // 'target_id' => $circle->user_id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '评论', // 'topic' => '评论',
'content' => $user['nickname'] . '评论了你的帖子', // 'content' => $user['nickname'] . '评论了你的帖子',
'circle_id' => $circle->id // 'circle_id' => $circle->id
]) // ])
]); // ]);
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
Db::rollback(); Db::rollback();
@@ -231,18 +231,18 @@ class Circle extends Base
throw new Exception($model->id . ' 此记录不在待审核状态'); throw new Exception($model->id . ' 此记录不在待审核状态');
} }
$model->save(['status' => $params['status']]); $model->save(['status' => $params['status']]);
(new Message())->allowField(true)->save([ // 消息通知 // (new Message())->allowField(true)->save([ // 消息通知
'type' => 3, // 'type' => 3,
'name' => '通知消息', // 'name' => '通知消息',
'avatar' => '', // 'avatar' => '',
'from_id' => 1, // 'from_id' => 1,
'user_id' => $model->user_id, // 'user_id' => $model->user_id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '影圈审核', // 'topic' => '影圈审核',
'result' => ($params['status'] == 1) ? '通过' : '不通过', // 'result' => ($params['status'] == 1) ? '通过' : '不通过',
'circle_id' => $model->id // 'circle_id' => $model->id
]) // ])
]); // ]);
} }
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {

View File

@@ -223,20 +223,20 @@ class Club extends Base
'reason' => $params['reason'], 'reason' => $params['reason'],
'status' => 1 'status' => 1
]); ]);
(new Message())->allowField(true)->save([ // 消息通知 // (new Message())->allowField(true)->save([ // 消息通知
'type' => 3, // 'type' => 3,
'name' => $club->name, // 'name' => $club->name,
'avatar' => $club->logo, // 'avatar' => $club->logo,
'from_id' => $club->id, // 'from_id' => $club->id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '俱乐部加入申请', // 'topic' => '俱乐部加入申请',
'俱乐部名称' => $club->name, // '俱乐部名称' => $club->name,
'申请人' => $this->user->nickname, // '申请人' => $this->user->nickname,
'申请时间' => date('Y-m-d H:i:s'), // '申请时间' => date('Y-m-d H:i:s'),
'reason' => $params['reason'] ?? '', // 'reason' => $params['reason'] ?? '',
'apply_id' => $apply->id // 'apply_id' => $apply->id
]) // ])
]); // ]);
} }
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
@@ -296,20 +296,20 @@ class Club extends Base
'reason' => $params['reason'], 'reason' => $params['reason'],
'status' => 1 'status' => 1
]); ]);
(new Message())->allowField(true)->save([ // 消息通知 // (new Message())->allowField(true)->save([ // 消息通知
'type' => 3, // 'type' => 3,
'name' => $club->name, // 'name' => $club->name,
'avatar' => $club->logo, // 'avatar' => $club->logo,
'from_id' => $club->id, // 'from_id' => $club->id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '俱乐部加入申请', // 'topic' => '俱乐部加入申请',
'俱乐部名称' => $club->name, // '俱乐部名称' => $club->name,
'申请人' => $user->nickname, // '申请人' => $user->nickname,
'申请时间' => date('Y-m-d H:i:s'), // '申请时间' => date('Y-m-d H:i:s'),
'reason' => $params['reason'] ?? '', // 'reason' => $params['reason'] ?? '',
'apply_id' => $apply->id, // 'apply_id' => $apply->id,
]) // ])
]); // ]);
} }
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {

View File

@@ -9,6 +9,7 @@ use app\admin\model\zy\Menber;
use app\admin\model\zy\Stadium; use app\admin\model\zy\Stadium;
use think\exception\PDOException; use think\exception\PDOException;
use app\admin\model\zy\link\Message; use app\admin\model\zy\link\Message;
use app\admin\model\zy\game\Activity;
use app\admin\model\zy\game\GameJoin; use app\admin\model\zy\game\GameJoin;
use app\admin\model\zy\game\GameMatch; use app\admin\model\zy\game\GameMatch;
use think\exception\ValidateException; use think\exception\ValidateException;
@@ -30,9 +31,10 @@ class Game extends Base
$params = $this->request->param(); $params = $this->request->param();
$query = $this->model->alias('g') $query = $this->model->alias('g')
->join([Participant::$tableName => 'p'], 'p.game_id=g.id', 'LEFT') ->join([Participant::$tableName => 'p'], 'p.game_id=g.id', 'LEFT')
->join([Activity::$tableName => 'a'], 'a.id=g.act_id', 'LEFT')
->join([Stadium::$tableName => 's'], 's.id = g.gym_id', 'LEFT') ->join([Stadium::$tableName => 's'], 's.id = g.gym_id', 'LEFT')
->join([Club::$tableName => 'c'], 'c.id = g.club_id', 'LEFT') ->join([Club::$tableName => 'c'], 'c.id = g.club_id', 'LEFT')
->field('g.*, s.name as gym_name, c.name as club_name,JSON_ARRAYAGG(p.avatar) as avatar,count(p.id) as join_num'); ->field('g.*,a.type,s.name as gym_name,c.name as club_name,JSON_ARRAYAGG(p.avatar) as avatar,count(p.id) as join_num');
if (isset($params['name'])) { if (isset($params['name'])) {
$query->where('g.name', 'like', '%' . $params['name'] . '%'); $query->where('g.name', 'like', '%' . $params['name'] . '%');
} }
@@ -43,14 +45,14 @@ class Game extends Base
$query->where('g.week', $params['week']); $query->where('g.week', $params['week']);
} }
if (isset($params['pid'])) { if (isset($params['pid'])) {
$query->where('pid', $params['pid']); $query->where('g.pid', $params['pid']);
} else { } else {
$query->where('pid', 0); $query->where('g.pid', 0);
} }
if (isset($params['public_time'])) { if (isset($params['public_time'])) {
$query->where('public_time', $params['public_time']); $query->where('g.public_time', $params['public_time']);
} else { } else {
$query->where('public_time', '<=', date('Y-m-d H:i:s')); $query->where('g.public_time', '<=', date('Y-m-d H:i:s'));
} }
if (isset($params['page'])) { if (isset($params['page'])) {
$pageSize = intval($params['pageSize'] ?? 10); $pageSize = intval($params['pageSize'] ?? 10);
@@ -113,18 +115,18 @@ class Game extends Base
'remark' => '用户自行退出活动' 'remark' => '用户自行退出活动'
]); ]);
} }
(new Message())->save([ // (new Message())->save([
'type' => 1, // 'type' => 1,
'name' => '系统消息', // 'name' => '系统消息',
'avatar' => '', // 'avatar' => '',
'from_id' => 0, // 'from_id' => 0,
'user_id' => $join->user_id, // 'user_id' => $join->user_id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '退出', // 'topic' => '退出',
'content' => '已退出 ' . $model['name'] . ' 活动', // 'content' => '已退出 ' . $model['name'] . ' 活动',
'game_id' => $model->id // 'game_id' => $model->id
]) // ])
]); // ]);
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
@@ -175,21 +177,21 @@ class Game extends Base
'remark' => '活动取消,全额退款' 'remark' => '活动取消,全额退款'
]); ]);
} }
$msgs[] = [ // $msgs[] = [
'type' => 1, // 'type' => 1,
'name' => '系统消息', // 'name' => '系统消息',
'avatar' => '', // 'avatar' => '',
'from_id' => 0, // 'from_id' => 0,
'user_id' => $j->user_id, // 'user_id' => $j->user_id,
'content' => json_encode([ // 'content' => json_encode([
'topic' => '评论', // 'topic' => '评论',
'content' => $model['name'] . ' 活动已取消', // 'content' => $model['name'] . ' 活动已取消',
'game_id' => $model->id // 'game_id' => $model->id
]) // ])
]; // ];
} }
(new Message())->insertAll($msgs);; // (new Message())->insertAll($msgs);;
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
Db::rollback(); Db::rollback();