fix(zy): 修复活动报名时间和状态逻辑

- 修复了活动报名时间判断逻辑,增加了对报名结束时间的判断
- 修改了活动报名状态的判断条件,提高了代码的可读性和准确性
- 优化了订单自动操作和支付后的处理流程,确保活动报名状态正确更新
- 新增了用户权限验证功能,确保只有管理员或裁判可以修改用户状态
This commit is contained in:
2025-05-31 21:22:44 +08:00
parent 2a1cec7909
commit 35725ffd2d
5 changed files with 76 additions and 28 deletions

View File

@@ -198,13 +198,15 @@ class Activity extends Base
if (empty($game)) { if (empty($game)) {
$this->error('活动不存在'); $this->error('活动不存在');
} }
if ($game['join_start_time'] > date('Y-m-d H:i:s')) { $currentTime = date('Y-m-d H:i:s');
$this->error('活动报名时间未开始'); if ($game['join_start_time'] > $currentTime || $game['join_end_time'] < $currentTime) {
$this->error('不在报名时间');
} }
if (empty($params['users']) || !is_array($params['users']) || empty($params['goods_list']) || !is_array($params['goods_list'])) { if (empty($params['users']) || !is_array($params['users']) || empty($params['goods_list']) || !is_array($params['goods_list'])) {
$this->error('请核对报名人员'); $this->error('请核对报名人员');
} }
if (GameJoin::get(['game_id' => $game['id'], 'act_id' => $game['act_id'], 'user_id' => $this->auth->id])) { $join = GameJoin::where(['game_id' => $game['id'], 'user_id' => $this->auth->id])->where('status', '>', -1)->find();
if (!empty($join)) {
$this->error('您已报名此活动'); $this->error('您已报名此活动');
} }
$order = GameJoin::where('game_id', $game['id'])->count(); $order = GameJoin::where('game_id', $game['id'])->count();
@@ -241,8 +243,8 @@ class Activity extends Base
'act_id' => $game['act_id'], 'act_id' => $game['act_id'],
'game_id' => $game['id'], 'game_id' => $game['id'],
'user_id' => $this->auth->id, 'user_id' => $this->auth->id,
'orer_id' => $order['id'], 'order_id' => $order['id'],
'status' => 0,//待支付 'status' => 0, //待支付
'users' => json_encode($params['users'] ?? []) 'users' => json_encode($params['users'] ?? [])
]); ]);
foreach ($participant as &$p) { foreach ($participant as &$p) {
@@ -256,6 +258,6 @@ class Activity extends Base
$this->error($e->getMessage(), $e); $this->error($e->getMessage(), $e);
} }
$this->success('Success'); $this->success('Success', $order);
} }
} }

View File

@@ -237,6 +237,8 @@ class Game extends Base
} }
if (isset($params['status'])) { if (isset($params['status'])) {
$query->where('status', $params['status']); $query->where('status', $params['status']);
} else {
$query->where('status', 1);
} }
if (isset($params['gender'])) { if (isset($params['gender'])) {
$query->where('gender', $params['gender']); $query->where('gender', $params['gender']);
@@ -248,6 +250,31 @@ class Game extends Base
$this->success('Success', $query->select()); $this->success('Success', $query->select());
} }
// 用户
public function setUser()
{
$params = $this->request->param();
$user = Participant::get($params['id'] ?? NULL);
if (empty($user)) {
$this->error('用户不存在');
}
$game = $this->model->get($user['game_id']);
$referee = explode(',', $game['referee']); //裁判
$menber = Menber::where(['club_id' => $game['club_id'], 'user_id' => $this->auth->id])->where('role', '>', 1)->find();
if (empty($menber) && !in_array($this->auth->id, $referee)) {
$this->error('您没有权限');
}
$update['status'] = intval($params['status']);
if ($update['status'] > 1 || $update['status'] < -1) {
$this->error('status错误');
}
if (!empty($params['mark'])) {
$update['mark'] = $params['mark'];
}
$user->save($update);
$this->success('修改成功');
}
// 获取比赛匹配列表 // 获取比赛匹配列表
public function macthList() public function macthList()
{ {

View File

@@ -2,16 +2,18 @@
namespace addons\shopro\job; namespace addons\shopro\job;
use think\queue\Job;
use think\Log;
use think\Db; use think\Db;
use think\Log;
use think\queue\Job;
use think\Collection; use think\Collection;
use think\exception\HttpResponseException; use app\admin\model\zy\game\GameJoin;
use addons\shopro\exception\ShoproException;
use app\admin\model\shopro\order\Order; use app\admin\model\shopro\order\Order;
use app\admin\model\shopro\order\OrderItem;
use addons\shopro\service\order\OrderOper;
use app\admin\model\shopro\order\Action; use app\admin\model\shopro\order\Action;
use app\admin\model\zy\game\Participant;
use addons\shopro\service\order\OrderOper;
use think\exception\HttpResponseException;
use app\admin\model\shopro\order\OrderItem;
use addons\shopro\exception\ShoproException;
/** /**
* 订单自动操作 * 订单自动操作
@@ -22,7 +24,8 @@ class OrderAutoOper extends BaseJob
/** /**
* 订单自动关闭 * 订单自动关闭
*/ */
public function autoClose(Job $job, $data){ public function autoClose(Job $job, $data)
{
if (check_env('yansongda', false)) { if (check_env('yansongda', false)) {
set_addon_config('epay', ['version' => 'v3'], false); set_addon_config('epay', ['version' => 'v3'], false);
\think\Hook::listen('epay_config_init'); \think\Hook::listen('epay_config_init');
@@ -38,7 +41,12 @@ class OrderAutoOper extends BaseJob
Db::transaction(function () use ($order, $data) { Db::transaction(function () use ($order, $data) {
$orderOper = new OrderOper(); $orderOper = new OrderOper();
$order = $orderOper->close($order, null, 'system'); $order = $orderOper->close($order, null, 'system');
// zy体育报名处理(未支付,自动退坑)
$join = GameJoin::where('order_id', $data['order']['id'])->find();
if (!empty($join)) {
$join->save([' status' => -1]);
Participant::where('game_join_id', $join['id'])->update(['status' => -1]);
}
return $order; return $order;
}); });
} }
@@ -67,7 +75,8 @@ class OrderAutoOper extends BaseJob
/** /**
* 订单自动确认收货 * 订单自动确认收货
*/ */
public function autoConfirm(Job $job, $data) { public function autoConfirm(Job $job, $data)
{
try { try {
$order = $data['order']; $order = $data['order'];
$items = $data['items']; $items = $data['items'];
@@ -107,7 +116,8 @@ class OrderAutoOper extends BaseJob
public function autoComment(Job $job, $data) { public function autoComment(Job $job, $data)
{
try { try {
$order = $data['order']; $order = $data['order'];
$item = $data['item']; $item = $data['item'];

View File

@@ -2,15 +2,18 @@
namespace addons\shopro\job; namespace addons\shopro\job;
use think\queue\Job;
use think\Db; use think\Db;
use think\exception\HttpResponseException; use think\queue\Job;
use app\admin\model\shopro\order\Order;
use addons\shopro\service\StockSale; use addons\shopro\service\StockSale;
use addons\shopro\controller\zy\Game;
use app\admin\model\shopro\user\User; use app\admin\model\shopro\user\User;
use app\admin\model\shopro\order\Invoice as OrderInvoice; use app\admin\model\zy\game\GameJoin;
use app\admin\model\shopro\order\Order;
use app\admin\model\zy\game\Participant;
use addons\shopro\service\order\OrderOper; use addons\shopro\service\order\OrderOper;
use think\exception\HttpResponseException;
use addons\shopro\facade\Activity as ActivityFacade; use addons\shopro\facade\Activity as ActivityFacade;
use app\admin\model\shopro\order\Invoice as OrderInvoice;
/** /**
* 订单自动操作 * 订单自动操作
@@ -56,6 +59,9 @@ class OrderPaid extends BaseJob
// 触发订单支付完成事件 // 触发订单支付完成事件
$data = ['order' => $order, 'user' => $user]; $data = ['order' => $order, 'user' => $user];
\think\Hook::listen('order_paid_after', $data); \think\Hook::listen('order_paid_after', $data);
// zy体育报名处理
GameJoin::where('order_id', $order->id)->update(['status' => 1]);
}); });
} }
@@ -96,6 +102,9 @@ class OrderPaid extends BaseJob
// 触发订单选择线下支付(货到付款)完成事件 // 触发订单选择线下支付(货到付款)完成事件
$data = ['order' => $order, 'user' => $user]; $data = ['order' => $order, 'user' => $user];
\think\Hook::listen('order_offline_after', $data); \think\Hook::listen('order_offline_after', $data);
// zy体育报名处理
GameJoin::where('order_id', $order->id)->update(['status' => 1]);
}); });
} }

View File

@@ -24,7 +24,7 @@ class Tree
* @param \Closure $resultCb 用来处理每一次查询的结果 比如要取出树中的所有 name * @param \Closure $resultCb 用来处理每一次查询的结果 比如要取出树中的所有 name
* @return Collection * @return Collection
*/ */
public function getTree($items = 0, \Closure $resultCb = null) public function getTree($items = 0, ?\Closure $resultCb = null)
{ {
if (!is_array($items) && !$items instanceof Collection) { if (!is_array($items) && !$items instanceof Collection) {
$items = $this->getQuery()->where('parent_id', $items)->select(); $items = $this->getQuery()->where('parent_id', $items)->select();
@@ -48,7 +48,7 @@ class Tree
* @param \Closure $resultCb 用来处理每一次查询的结果 比如要取出树中的所有 name * @param \Closure $resultCb 用来处理每一次查询的结果 比如要取出树中的所有 name
* @return Collection * @return Collection
*/ */
public function getChildren($id, \Closure $resultCb = null) public function getChildren($id, ?\Closure $resultCb = null)
{ {
$self = $this->getQuery()->where('id', $id)->select(); $self = $this->getQuery()->where('id', $id)->select();
if(!$self) { if(!$self) {