Skip to content

Commit

Permalink
feat(admin/order): add search for out order id
Browse files Browse the repository at this point in the history
  • Loading branch information
Anankke committed Nov 13, 2024
1 parent 6286bb1 commit d607e08
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
$group->post('/product/ajax', App\Controllers\Admin\ProductController::class . ':ajax');
// 订单
$group->get('/order', App\Controllers\Admin\OrderController::class . ':index');
$group->post('/order/search', App\Controllers\Admin\OrderController::class . ':search');
$group->get('/order/{id:[0-9]+}/view', App\Controllers\Admin\OrderController::class . ':detail');
$group->post('/order/{id:[0-9]+}/cancel', App\Controllers\Admin\OrderController::class . ':cancel');
$group->delete('/order/{id:[0-9]+}', App\Controllers\Admin\OrderController::class . ':delete');
Expand Down
4 changes: 3 additions & 1 deletion resources/views/tabler/admin/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
</div>
</div>
<!-- js -->
<script src="//{$config['jsdelivr_url']}/npm/@tabler/core@latest/dist/js/tabler.min.js"></script>
<script>
let successDialog = new bootstrap.Modal(document.getElementById('success-dialog'));
let failDialog = new bootstrap.Modal(document.getElementById('fail-dialog'));
Expand All @@ -122,6 +123,8 @@
return;
}
let res = JSON.parse(evt.detail.xhr.response);
if (res.ret === 1) {
document.getElementById("success-message").innerHTML = res.msg;
successDialog.show();
Expand All @@ -135,7 +138,6 @@
location.reload();
});
</script>
<script src="//{$config['jsdelivr_url']}/npm/@tabler/core@latest/dist/js/tabler.min.js"></script>
<script>console.table([['数据库查询', '执行时间'], ['{count($queryLog)}', '{$optTime} ms']])</script>

</body>
Expand Down
41 changes: 41 additions & 0 deletions resources/views/tabler/admin/order/index.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
{include file='admin/header.tpl'}

<div class="page-wrapper">
<div class="modal modal-blur fade" id="search-gateway" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">查找订单</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">网关订单号</label>
<div class="col">
<input id="gateway_order_id" type="text" class="form-control"
placeholder="">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn me-auto" data-bs-dismiss="modal">取消</button>
<button id="create-button"
type="button"
class="btn btn-primary"
hx-post="/admin/order/search"
hx-swap="none"
hx-vals='js:{
gateway_order_id: document.getElementById("gateway_order_id").value
}'>查找
</button>
</div>
</div>
</div>
</div>

<div class="container-xl">
<div class="page-header d-print-none text-white">
<div class="row align-items-center">
Expand All @@ -12,6 +44,15 @@
<span class="home-subtitle">管理客户订单</span>
</div>
</div>
<div class="col-auto">
<div class="btn-list">
<a href="#" class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#search-gateway">
<i class="icon ti ti-search"></i>
查找
</a>
</div>
</div>
</div>
</div>
</div>
Expand Down
21 changes: 21 additions & 0 deletions src/Controllers/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controllers\BaseController;
use App\Models\Invoice;
use App\Models\Order;
use App\Models\Paylist;
use App\Utils\Tools;
use Exception;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -46,6 +47,26 @@ public function index(ServerRequest $request, Response $response, array $args):
);
}

public function search(ServerRequest $request, Response $response, array $args): ResponseInterface

Check failure on line 50 in src/Controllers/Admin/OrderController.php

View workflow job for this annotation

GitHub Actions / lint

* [Superfluous whitespace] Whitespace found at end of line
{
$out_order_id = $request->getParam('gateway_order_id');
$paylist = (new Paylist())->where('tradeno', $out_order_id)->first();
$invoice = (new Invoice())->where('id', $paylist?->invoice_id)->first();
$order = (new Order())->where('id', $invoice?->order_id)->first();

if ($order == null) {

Check failure on line 57 in src/Controllers/Admin/OrderController.php

View workflow job for this annotation

GitHub Actions / lint

* [Disallow equal operators] Operator == is disallowed, use === instead.
return $response->withJson([
'ret' => 0,
'msg' => '未找到订单',
]);
}

return $response->withHeader('HX-Redirect', '/admin/order/' . $order->id . '/view')->withJson([
'ret' => 1,
'msg' => '找到了订单',
]);
}

/**
* @throws Exception
*/
Expand Down

0 comments on commit d607e08

Please sign in to comment.