积分与余额账务系统硬切重构
This commit is contained in:
1 parent
ca12226b39
commit
5cae5b5c93
159 files changed
+7275
-4718
No files matched your search
@@ -15,6 +15,7 @@
|
||||
var DEFAULT_MAX_ELAPSED = 120000;
|
||||
var MAX_DELAY = 15000;
|
||||
var createFlights = Object.create(null);
|
||||
var operationKeys = Object.create(null);
|
||||
var polls = Object.create(null);
|
||||
var lastScope = "";
|
||||
var scopeGeneration = 0;
|
||||
@@ -47,6 +48,7 @@
|
||||
if (flight && typeof flight.cancel === "function") flight.cancel();
|
||||
});
|
||||
createFlights = Object.create(null);
|
||||
operationKeys = Object.create(null);
|
||||
Object.keys(polls).forEach(function (pollKey) {
|
||||
var active = polls[pollKey];
|
||||
if (active && active.handle && typeof active.handle.abort === "function") active.handle.abort();
|
||||
@@ -115,6 +117,7 @@
|
||||
|
||||
var key = userScope() + ":" + String(packageId) + ":" + method;
|
||||
if (createFlights[key]) return createFlights[key].promise;
|
||||
if (!operationKeys[key]) operationKeys[key] = window.AksrtRequest.createIdempotencyKey();
|
||||
|
||||
var requestController = !options.signal && window.AbortController
|
||||
? new window.AbortController()
|
||||
@@ -122,6 +125,7 @@
|
||||
var flight = {
|
||||
promise: request("/pay/vip", {
|
||||
method: "POST",
|
||||
headers: { "Idempotency-Key": operationKeys[key] },
|
||||
body: JSON.stringify({
|
||||
package_id: packageId,
|
||||
payment_method: method,
|
||||
@@ -143,22 +147,31 @@
|
||||
}, function () {
|
||||
if (createFlights[key] === flight) delete createFlights[key];
|
||||
});
|
||||
flight.promise.then(function (response) {
|
||||
if (response.ok) delete operationKeys[key];
|
||||
});
|
||||
return flight.promise;
|
||||
}
|
||||
|
||||
function exchange(options) {
|
||||
options = options || {};
|
||||
userScope();
|
||||
var scope = userScope();
|
||||
var packageId = parseInt(options.packageId || options.package_id || 0, 10);
|
||||
if (!packageId) {
|
||||
return Promise.resolve({ ok: false, status: 400, json: { message: "兑换套餐无效" } });
|
||||
}
|
||||
var key = scope + ":points-exchange:" + String(packageId);
|
||||
if (!operationKeys[key]) operationKeys[key] = window.AksrtRequest.createIdempotencyKey();
|
||||
return request("/pay/vip/points-exchange", {
|
||||
method: "POST",
|
||||
headers: { "Idempotency-Key": operationKeys[key] },
|
||||
body: JSON.stringify({ package_id: packageId }),
|
||||
signal: options.signal,
|
||||
}).then(function (response) {
|
||||
if (response.ok) invalidate(options.tags || ["vip", "orders"]);
|
||||
if (response.ok) {
|
||||
delete operationKeys[key];
|
||||
invalidate(options.tags || ["vip", "orders"]);
|
||||
}
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user