积分与余额账务系统硬切重构
This commit is contained in:
1 parent
ca12226b39
commit
5cae5b5c93
159 files changed
+7275
-4718
No files matched your search
+33
-16
@@ -8,9 +8,10 @@
|
||||
|
||||
var instances = new WeakMap();
|
||||
|
||||
function request(path, body, method) {
|
||||
function request(path, body, method, operationKey) {
|
||||
var options = { method: method || "POST" };
|
||||
if (body !== undefined) options.body = JSON.stringify(body || {});
|
||||
if (operationKey) options.headers = { "Idempotency-Key": operationKey };
|
||||
return window.AksrtRequest.request(path, options);
|
||||
}
|
||||
|
||||
@@ -30,12 +31,15 @@
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function formatMoney(order) {
|
||||
var amount = Number(order && order.amount || 0);
|
||||
return order && order.is_points
|
||||
? escapeHtml(order.currency_symbol || "积分") + " " + Math.round(amount)
|
||||
: "¥" + amount.toFixed(2);
|
||||
}
|
||||
function formatMoney(order) {
|
||||
var raw = String(order && order.amount != null ? order.amount : "0");
|
||||
if (order && order.is_points) {
|
||||
return escapeHtml(order.currency_symbol || "积分") + " " + (/^\d+$/.test(raw) ? raw : "0");
|
||||
}
|
||||
var match = /^(0|[1-9]\d*)(?:\.(\d{1,2}))?$/.exec(raw);
|
||||
var amount = match ? match[1] + "." + (match[2] || "").padEnd(2, "0") : "0.00";
|
||||
return "¥" + amount;
|
||||
}
|
||||
|
||||
function orderTag(orderNumber) {
|
||||
return "order:" + String(orderNumber || "").toLowerCase();
|
||||
@@ -100,9 +104,12 @@
|
||||
}
|
||||
|
||||
function detailOptions(state, orderNumber, refresh) {
|
||||
var actionKey = refresh ? "refresh:" + orderNumber : "";
|
||||
if (actionKey && !state.operationKeys[actionKey]) state.operationKeys[actionKey] = window.AksrtRequest.createIdempotencyKey();
|
||||
return {
|
||||
url: orderPath(orderNumber, refresh ? "/refresh" : ""),
|
||||
method: refresh ? "POST" : "GET",
|
||||
headers: actionKey ? { "Idempotency-Key": state.operationKeys[actionKey] } : {},
|
||||
kind: "orders",
|
||||
title: "订单详情",
|
||||
responseType: "json",
|
||||
@@ -123,7 +130,10 @@
|
||||
renderDetail(state, data, session);
|
||||
},
|
||||
onData: function (data) {
|
||||
if (refresh) invalidateOrder(orderNumber, data);
|
||||
if (refresh) {
|
||||
delete state.operationKeys[actionKey];
|
||||
invalidateOrder(orderNumber, data);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -244,12 +254,15 @@
|
||||
});
|
||||
}
|
||||
|
||||
function startPayment(state, button) {
|
||||
function startPayment(state, button) {
|
||||
var number = button.getAttribute("data-aksrt-order-pay") || "";
|
||||
var method = button.getAttribute("data-aksrt-order-method") || "";
|
||||
if (!number || button.disabled) return;
|
||||
button.disabled = true;
|
||||
request(orderPath(number, "/pay"), method ? { payment_method: method } : {}, "POST").then(function (result) {
|
||||
if (!number || button.disabled) return;
|
||||
var actionKey = "pay:" + number;
|
||||
if (!state.operationKeys[actionKey]) state.operationKeys[actionKey] = window.AksrtRequest.createIdempotencyKey();
|
||||
button.disabled = true;
|
||||
request(orderPath(number, "/pay"), method ? { payment_method: method } : {}, "POST", state.operationKeys[actionKey]).then(function (result) {
|
||||
delete state.operationKeys[actionKey];
|
||||
var data = result.data || {};
|
||||
invalidateOrder(number, data.order);
|
||||
if (data.redirect && data.payment_url) {
|
||||
@@ -273,8 +286,11 @@
|
||||
button.textContent = "确认关闭";
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
request(orderPath(number, "/cancel"), {}, "POST").then(function (result) {
|
||||
button.disabled = true;
|
||||
var actionKey = "cancel:" + number;
|
||||
if (!state.operationKeys[actionKey]) state.operationKeys[actionKey] = window.AksrtRequest.createIdempotencyKey();
|
||||
request(orderPath(number, "/cancel"), {}, "POST", state.operationKeys[actionKey]).then(function (result) {
|
||||
delete state.operationKeys[actionKey];
|
||||
var data = result.data || {};
|
||||
invalidateOrder(number, data.order);
|
||||
notyf("订单已关闭", "success");
|
||||
@@ -294,13 +310,14 @@
|
||||
|
||||
function initRoot(root) {
|
||||
if (instances.has(root)) return;
|
||||
var state = {
|
||||
var state = {
|
||||
root: root,
|
||||
detailOrderNumber: "",
|
||||
detailSession: null,
|
||||
detailReplacement: false,
|
||||
detailReplacementSession: null,
|
||||
countdownTimer: null,
|
||||
countdownTimer: null,
|
||||
operationKeys: {},
|
||||
};
|
||||
|
||||
state.onRootClick = function (event) {
|
||||
|
||||
Reference in new issue
Block a user