Skip to content

Commit

Permalink
feat: better cron error handling & add more empty value detection
Browse files Browse the repository at this point in the history
Anankke/SSPanel-UIM#1879

I can't believe I have to spend time on this stupid "problem".
  • Loading branch information
AutisticShark committed Apr 3, 2023
1 parent 46c4d79 commit dd9ed54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
6 changes: 3 additions & 3 deletions resources/views/tabler/admin/product/create.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">用户分组</label>
<label class="form-label col-3 col-form-label required">用户分组</label>
<div class="col">
<input id="node_group" type="text" class="form-control" value="">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">速率限制 (Mbps)</label>
<label class="form-label col-3 col-form-label required">速率限制 (Mbps)</label>
<div class="col">
<input id="speed_limit" type="text" class="form-control"
value="">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">同时连接IP限制</label>
<label class="form-label col-3 col-form-label required">同时连接IP限制</label>
<div class="col">
<input id="ip_limit" type="text" class="form-control"
value="">
Expand Down
6 changes: 3 additions & 3 deletions src/Command/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public function boot(): void
// 如果用户账户中没有已激活的订单,且有等待激活的订单,则激活最早的等待激活订单
if ($activated_order === null && count($pending_activation_orders) > 0) {
$order = $pending_activation_orders[0];
$order->status = 'activated';
$order->update_time = time();
$order->save();
// 获取订单内容准备激活
$content = json_decode($order->product_content);
// 激活商品
Expand All @@ -85,6 +82,9 @@ public function boot(): void
$user->node_speedlimit = $content->speed_limit;
$user->node_iplimit = $content->ip_limit;
$user->save();
$order->status = 'activated';
$order->update_time = time();
$order->save();
echo "订单 #{$order->id} 已激活。\n";
continue;
}
Expand Down
22 changes: 4 additions & 18 deletions src/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public function add(ServerRequest $request, Response $response, array $args): Re

$product = new Product();

if ($name === '') {
if ($name === '' || $stock === '' || $node_group === '' || $speed_limit === '' || $ip_limit === '') {
return $response->withJson([
'ret' => 0,
'msg' => '商品名称不能为空',
'msg' => '请填写所有必要栏位',
]);
}

Expand All @@ -130,13 +130,6 @@ public function add(ServerRequest $request, Response $response, array $args): Re
]);
}

if ($stock === '') {
return $response->withJson([
'ret' => 0,
'msg' => '商品库存不能为空',
]);
}

if ($type === 'tabp') {
if ($time === '' || $time <= 0) {
return $response->withJson([
Expand Down Expand Up @@ -257,10 +250,10 @@ public function update(ServerRequest $request, Response $response, array $args):

$product = Product::find($product_id);

if ($name === '') {
if ($name === '' || $stock === '' || $node_group === '' || $speed_limit === '' || $ip_limit === '') {
return $response->withJson([
'ret' => 0,
'msg' => '商品名称不能为空',
'msg' => '请填写所有必要栏位',
]);
}

Expand All @@ -271,13 +264,6 @@ public function update(ServerRequest $request, Response $response, array $args):
]);
}

if ($stock === '') {
return $response->withJson([
'ret' => 0,
'msg' => '商品库存不能为空',
]);
}

if ($type === 'tabp') {
if ($time === '' || $time <= 0) {
return $response->withJson([
Expand Down

0 comments on commit dd9ed54

Please sign in to comment.