mirror of
https://github.com/v2board/v2board.git
synced 2025-01-10 16:19:10 +08:00
update: order queue
This commit is contained in:
parent
c2577e37c4
commit
c80d93fa25
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Jobs\OrderHandleJob;
|
||||||
use App\Services\OrderService;
|
use App\Services\OrderService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
@ -45,20 +46,8 @@ class CheckOrder extends Command
|
|||||||
ini_set('memory_limit', -1);
|
ini_set('memory_limit', -1);
|
||||||
$orders = Order::whereIn('status', [0, 1])
|
$orders = Order::whereIn('status', [0, 1])
|
||||||
->get();
|
->get();
|
||||||
foreach ($orders as $item) {
|
foreach ($orders as $order) {
|
||||||
$orderService = new OrderService($item);
|
OrderHandleJob::dispatch($order->trade_no);
|
||||||
switch ($item->status) {
|
|
||||||
// cancel
|
|
||||||
case 0:
|
|
||||||
if ($item->created_at <= (time() - 1800)) {
|
|
||||||
$orderService->cancel();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
$orderService->open();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,16 +78,14 @@ class V2boardStatistics extends Command
|
|||||||
|
|
||||||
private function statServer()
|
private function statServer()
|
||||||
{
|
{
|
||||||
$endAt = strtotime(date('Y-m-d'));
|
$startAt = strtotime(date('Y-m-d'));
|
||||||
$startAt = strtotime('-1 day', $endAt);
|
|
||||||
$statistics = ServerLog::select([
|
$statistics = ServerLog::select([
|
||||||
'server_id',
|
'server_id',
|
||||||
'method as server_type',
|
'method as server_type',
|
||||||
DB::raw("sum(u) as u"),
|
DB::raw("sum(u) as u"),
|
||||||
DB::raw("sum(d) as d"),
|
DB::raw("sum(d) as d"),
|
||||||
])
|
])
|
||||||
->where('log_at', '>=', $startAt)
|
->where('log_at', $startAt)
|
||||||
->where('log_at', '<', $endAt)
|
|
||||||
->groupBy('server_id', 'method')
|
->groupBy('server_id', 'method')
|
||||||
->get()
|
->get()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
@ -169,9 +169,8 @@ class OrderController extends Controller
|
|||||||
}
|
}
|
||||||
// free process
|
// free process
|
||||||
if ($order->total_amount <= 0) {
|
if ($order->total_amount <= 0) {
|
||||||
$order->total_amount = 0;
|
$orderService = new OrderService($order);
|
||||||
$order->status = 1;
|
if (!$orderService->paid($order->trade_no)) abort(500, '');
|
||||||
$order->save();
|
|
||||||
return response([
|
return response([
|
||||||
'type' => -1,
|
'type' => -1,
|
||||||
'data' => true
|
'data' => true
|
||||||
|
52
app/Jobs/OrderHandleJob.php
Normal file
52
app/Jobs/OrderHandleJob.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Order;
|
||||||
|
use App\Services\OrderService;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class OrderHandleJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
protected $order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($tradeNo)
|
||||||
|
{
|
||||||
|
$this->onQueue('order_handle');
|
||||||
|
$this->order = Order::where('trade_no', $tradeNo)
|
||||||
|
->lockForUpdate()
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (!$this->order) return;
|
||||||
|
$orderService = new OrderService($this->order);
|
||||||
|
switch ($this->order->status) {
|
||||||
|
// cancel
|
||||||
|
case 0:
|
||||||
|
if ($this->order->created_at <= (time() - 1800)) {
|
||||||
|
$orderService->cancel();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
$orderService->open();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Jobs\OrderHandleJob;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
use App\Models\Plan;
|
use App\Models\Plan;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -220,7 +221,9 @@ class OrderService
|
|||||||
$order->status = 1;
|
$order->status = 1;
|
||||||
$order->paid_at = time();
|
$order->paid_at = time();
|
||||||
$order->callback_no = $callbackNo;
|
$order->callback_no = $callbackNo;
|
||||||
return $order->save();
|
if (!$order->save()) return false;
|
||||||
|
OrderHandleJob::dispatch($order->trade_no);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cancel():bool
|
public function cancel():bool
|
||||||
|
@ -165,24 +165,6 @@ return [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'environments' => [
|
'environments' => [
|
||||||
'production' => [
|
|
||||||
'V2board' => [
|
|
||||||
'connection' => 'redis',
|
|
||||||
'queue' => [
|
|
||||||
'traffic_fetch',
|
|
||||||
'server_log',
|
|
||||||
'send_email',
|
|
||||||
'send_telegram',
|
|
||||||
'stat_server'
|
|
||||||
],
|
|
||||||
'balance' => 'auto',
|
|
||||||
'minProcesses' => 1,
|
|
||||||
'maxProcesses' => 64,
|
|
||||||
'tries' => 1,
|
|
||||||
'nice' => 0,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
|
|
||||||
'local' => [
|
'local' => [
|
||||||
'V2board' => [
|
'V2board' => [
|
||||||
'connection' => 'redis',
|
'connection' => 'redis',
|
||||||
@ -191,7 +173,8 @@ return [
|
|||||||
'server_log',
|
'server_log',
|
||||||
'send_email',
|
'send_email',
|
||||||
'send_telegram',
|
'send_telegram',
|
||||||
'stat_server'
|
'stat_server',
|
||||||
|
'order_handle'
|
||||||
],
|
],
|
||||||
'balance' => 'auto',
|
'balance' => 'auto',
|
||||||
'minProcesses' => 1,
|
'minProcesses' => 1,
|
||||||
|
2
public/assets/admin/umi.js
vendored
2
public/assets/admin/umi.js
vendored
File diff suppressed because one or more lines are too long
2
public/theme/v2board/assets/umi.js
vendored
2
public/theme/v2board/assets/umi.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user