CN-122022792-A - Order payment method and related equipment
Abstract
The disclosure provides an order payment method and related equipment, the method comprises the steps of responding to an order creation request from a user side for a target order, creating a corresponding order table in a database, setting a payment state of the order table as to be paid, creating a delay message related to the target order in a delay queue, responding to detection of an order payment operation for the target order, updating the state of the target order as to be paid, creating a first time container with a first priority, responding to detection of time reaching a preset moment before expiration of the delay message, creating a second time container with a second priority, responding to receiving payment success information of the target order, and updating the payment state of the order table based on the first time container, the second time container and a distributed lock.
Inventors
- DONG YUZHU
- WANG PENG
- WANG HONGLI
Assignees
- 北京华益精点生物技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260106
Claims (10)
- 1. An order payment method, comprising: Responding to an order creation request from a user side aiming at a target order, creating a corresponding order table in a database, setting the payment state of the order table as to be paid, and creating a delay message about the target order in a delay queue; In response to detecting an order payment operation for the target order, updating the state of the target order into payment, and creating a first time container with a first priority, wherein the first time container is used for updating the payment state of the order table into paid in a first effective time period, and the first effective time period is determined based on the payment time corresponding to the order payment operation and a first preset duration; Establishing a second time container with a second priority in response to detecting that the time reaches a preset time before the expiration of the delay message, wherein the second time container is used for updating the payment state of the order form to be cancelled in a second effective time period; in response to receiving payment success information for the target order, the payment status of the order form is updated based on the first time container, the second time container, and a distributed lock.
- 2. The method of claim 1, wherein the first priority decreases with increasing time and the second priority increases with increasing time; Updating the payment status of the order form based on the first time container, the second time container, and a distributed lock, comprising: Determining, in response to the first valid period of time and the second valid period of time overlapping, whether the first time container or the second time container is used to update the payment status based on the magnitudes of the first priority and the second priority; updating the payment status based on the first time container or the second time container, and the distributed lock; Wherein determining, based on the magnitudes of the first priority and the second priority, the first time container or the second time container for updating the payment status comprises: Determining, in response to the first priority being greater than the second priority, that the first time container is to be used to update the payment status; determining, in response to the first priority being less than the second priority, that the second time container is to be used to update the payment status; determining, in response to the first priority being equal to the second priority, that the first time container or the second time container is used to update the payment status based on a first effective duration corresponding to the first time container and a second effective duration corresponding to the second time container; wherein determining, based on the first validity duration corresponding to the first time container and the second validity duration corresponding to the second time container, that the first time container or the second time container is used for updating the payment status includes: determining that the first time container is used to update the payment status in response to the first time period being greater than or equal to the second time period; And in response to the first effective duration being less than the second effective duration, determining that the second time container is used to update the payment status.
- 3. The method of claim 2, wherein updating the payment status based on the first time container and the distributed lock comprises: Acquiring a first distributed lock of the target order; in response to successfully acquiring the first distributed lock of the target order, acquiring the current payment state and a first version number of the order form; in response to the current payment state being in payment, comparing the first version number with a current version number of the order table based on an update operation of the first time container to the current payment state; updating the current payment status of the order table to paid and updating the first version number in response to the first version number being consistent with the current version number, and releasing the first distributed lock; And in response to the first version number not being consistent with the current version number, retrying to update the current payment state of the order form to paid or ending.
- 4. A method according to claim 3, further comprising: transmitting refund information to the payer in response to the current payment status being cancelled; in response to the first distributed lock not successfully acquiring the target order, retrying to acquire the first distributed lock or sending an exception message to indicate that the target order is an exception order.
- 5. The method of claim 2, wherein updating the payment status of the order table based on the first time container, the second time container, and a distributed lock further comprises: In response to detecting that only the first time container is present, updating the payment status based on the first time container and the distributed lock; in response to detecting that only the second time container is present, the payment status is updated based on the second time container and the distributed lock.
- 6. The method of claim 5, wherein updating the payment status based on the second time container and the distributed lock comprises: Acquiring a second distributed lock of the target order; In response to successfully acquiring the second distributed lock of the target order, acquiring the current payment status and a second version number of the order form; executing order cancellation operation in response to the current payment state being in payment, and comparing the second version number with the current version number of the order table based on updating operation of the second time container on the current payment state; Updating the current payment status of the order table to cancelled and to update the current version number, and releasing the second distributed lock, in response to the second version number being consistent with the current version number; And in response to the second version number not being consistent with the current version number, retrying to update the current payment state of the order form to cancelled or ended.
- 7. The method of claim 6, further comprising: Retrying to acquire the second distributed lock or sending an exception message to indicate that the target order is an exception order in response to the second distributed lock not successfully acquiring the target order; in response to the current payment status being paid, an order cancellation operation is refused to be performed and the second distributed lock is released.
- 8. An order payment device, comprising: The order creation module is used for responding to an order creation request from a user side aiming at a target order, creating a corresponding order table in a database, setting the payment state of the order table as to-be-paid, and creating a delay message about the target order in a delay queue; The system comprises a first container module, a first time container, a second container module, a third container module, a fourth container module and a third container module, wherein the first container module is used for responding to the detection of the order payment operation for the target order, updating the state of the target order into payment, and creating a first time container with a first priority, and the first time container is used for updating the payment state of the order table into paid in a first effective time period; The second container module is used for responding to the detection that the time reaches the preset time before the expiration of the delay message, and creating a second time container with a second priority, wherein the second time container is used for updating the payment state of the order form to be cancelled within a second effective time period; And a state updating module for updating the payment state of the order form based on the first time container, the second time container and a distributed lock in response to receiving payment success information of the target order.
- 9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of any one of claims 1 to 7 when the program is executed.
- 10. A non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the method of any one of claims 1 to 7.
Description
Order payment method and related equipment Technical Field The disclosure relates to the field of order payment, and in particular relates to an order payment method and related equipment. Background In order processing systems of e-commerce platforms, order status is typically updated in dependence upon timed tasks and payment callbacks. The timed task is used to automatically cancel an unpaid order after a timeout, while the payment callback updates the order status to "paid" after the user completes the payment. However, this solution has significant drawbacks when faced with concurrent operations. When the user completes the payment at exactly the critical moment when the order is about to be cancelled, the payment callback and timing task may trigger at the same time or nearly the same time, resulting in a race condition. In this case, the system may not accurately determine the final status of the order, so that the user may pay successfully but the order is wrongly cancelled, the system accounts are inconsistent, and inventory management is chaotic. Not only the user experience is affected and customer complaints are increased, but also the manual processing cost is greatly increased, and the operation efficiency of the platform is seriously affected. Disclosure of Invention Accordingly, an object of the present disclosure is to provide an order payment method and related devices. In a first aspect of the present disclosure, there is provided an order payment method, including: Responding to an order creation request from a user side aiming at a target order, creating a corresponding order table in a database, setting the payment state of the order table as to be paid, and creating a delay message about the target order in a delay queue; In response to detecting an order payment operation for the target order, updating the state of the target order into payment, and creating a first time container with a first priority, wherein the first time container is used for updating the payment state of the order table into paid in a first effective time period, and the first effective time period is determined based on the payment time corresponding to the order payment operation and a first preset duration; Establishing a second time container with a second priority in response to detecting that the time reaches a preset time before the expiration of the delay message, wherein the second time container is used for updating the payment state of the order form to be cancelled in a second effective time period; in response to receiving payment success information for the target order, the payment status of the order form is updated based on the first time container, the second time container, and a distributed lock. In a second aspect of the present disclosure, an order payment device is provided, comprising: The order creation module is used for responding to an order creation request from a user side aiming at a target order, creating a corresponding order table in a database, setting the payment state of the order table as to-be-paid, and creating a delay message about the target order in a delay queue; The system comprises a first container module, a first time container, a second container module, a third container module, a fourth container module and a third container module, wherein the first container module is used for responding to the detection of the order payment operation for the target order, updating the state of the target order into payment, and creating a first time container with a first priority, and the first time container is used for updating the payment state of the order table into paid in a first effective time period; The second container module is used for responding to the detection that the time reaches the preset time before the expiration of the delay message, and creating a second time container with a second priority, wherein the second time container is used for updating the payment state of the order form to be cancelled within a second effective time period; And a state updating module for updating the payment state of the order form based on the first time container, the second time container and a distributed lock in response to receiving payment success information of the target order. In a third aspect of the present disclosure, there is provided an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method according to the first aspect when executing the program. In a fourth aspect of the present disclosure, there is provided a non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the method of the first aspect. In a fifth aspect of the present disclosure, there is provided a computer program product comprising computer program instructions which, when executed on a computer, cause the computer to perform