A method, device, electronic device and medium for processing commodity inventory data
By receiving order request data in the e-commerce system, locking and deduction operations for inventory volume, and using cache database for high concurrency processing, the problems of system congestion and inventory deduction failure are solved, and the stability and data of the system are achieved Accuracy improves high concurrent data processing capabilities.
Patent Information
- Application Number
- CN202111529469.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-13
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2041-12-13
AI Technical Summary
In the case of high concurrency, existing e-commerce systems are prone to system congestion and failure in inventory deduction, and cannot effectively deal with the situation where a large number of users purchase goods at the same time, resulting in insufficient database deduction connections and the system cannot bear the purchase requests of massive users. .
By receiving the client's order request data, obtaining the product inventory, and performing locking and deduction operations based on the inventory, generating target orders, performing abnormal detection, ensuring the accuracy and consistency of the inventory data, and using a cache database to perform high Concurrent read and write, reducing the pressure on servers and databases.
It effectively avoids the problems of system congestion and failure of inventory deduction under high concurrency conditions, ensures the stability of the system and the accuracy of inventory data, improves the high concurrent data processing capabilities of the e-commerce system, and ensures the normal progress of shopping.
Smart Images

Figure CN114202284B_ABST
Abstract
Description
[0001] In the field of technology
[0002] The present invention relates to the field of artificial intelligence technology, and in particular to a commodity inventory data processing method, device, electronic equipment and medium. Background Art
[0003] In recent years, with the improvement of national consumption level, the convenience of logistics and the rapid development of Internet technology, the development of e-commerce at home and abroad has also been driven. More and more people choose to trade goods through e-commerce platforms, which makes the volume of online transactions larger and larger, which undoubtedly brings new challenges to the system framework of e-commerce platforms.
[0004] At present, most e-commerce systems use distributed storage, transaction regression and synchronous data to achieve high database concurrency data to support national data throughput for a period of time. The databases of most e-commerce systems adopt the method of separating read and write databases, and the data used by merchants' inventories are all infinite. However, the actual merchant inventory is limited. For example, the commemorative coins launched by a bank need to be sold through an e-commerce platform, but the inventory of commemorative coins is limited and will change dramatically or be 0 in a short period of time. When using the previous e-commerce system, when you shop based on the inventory data obtained in this second, the inventory submitted in the next second has changed, so that the shopping cannot be completed normally. Therefore, the existing e-commerce platform database uses an infinite inventory method that cannot meet the shopping needs in some specific scenarios. In addition, most e-commerce systems use relational data commodity libraries to store data to ensure transactional operations. Every time a user purchases a product, the system initiates an inventory deduction request to the relational database. However, this method cannot meet high concurrency situations, and in severe cases, system congestion and deduction failures may occur. If a large number of users purchase promotional products at the same time, and the database has a single deduction entry, it will inevitably cause system congestion, which is mainly reflected in the insufficient number of database deduction connections and the system cannot support a large number of users purchasing products at the same time. Summary of the invention
[0005] The present invention provides a commodity inventory data processing method, device, electronic device and medium to solve the problems of system congestion and inventory deduction failure in high concurrency situations in the prior art.
[0006] The commodity inventory data processing method provided by the present invention comprises:
[0007] Receive order request data from a user to purchase from a client, the order request data including an identifier of the commodity to be purchased and a purchase quantity of the commodity to be purchased, and obtain the inventory quantity of the commodity to be purchased stored in a cache database according to the identifier of the commodity to be purchased;
[0008] If the purchase quantity of the commodity to be purchased is greater than the inventory quantity of the commodity to be purchased, obtaining the commodity category of the commodity to be purchased, and matching a replacement commodity according to the commodity category of the commodity to be purchased;
[0009] Obtaining a matching degree between the commodity to be purchased and the substitute commodity, determining a target commodity according to the matching degree, and generating a target order, wherein the target order includes a target commodity identifier and a target commodity purchase quantity;
[0010] Acquire the target commodity inventory stored in the cache database according to the target commodity identifier, lock the target commodity inventory, and acquire the payment status of the target order within a preset time period;
[0011] If the payment status is paid, the target product inventory is deducted according to the purchase amount of the target product, the target product inventory is unlocked, the new inventory change data is obtained, and the new inventory change data is detected for abnormalities. If the detection result is normal, the deducted target product inventory is returned to the client.
[0012] Optionally, the locking process for the target commodity inventory includes:
[0013] Acquire the storage address of the target inventory quantity according to the target commodity identifier, and lock the storage address;
[0014] If the storage address can be inserted into the cache database, the locking is successful;
[0015] If the storage address cannot be inserted into the cache database, locking fails;
[0016] If locking fails, the locking data is obtained, and locking exception processing is performed according to the locking data.
[0017] Optionally, before generating the target order, the step further includes:
[0018] If the target product inventory is less than the preset inventory, the number of users waiting to purchase is obtained;
[0019] If the number of users to be purchased is greater than a preset user number threshold, the time when the order request is sent by the users to be purchased is obtained, and the target order is generated according to the time when the order request is sent.
[0020] Optionally, before receiving the order request data of the user to purchase from the client, the step further includes:
[0021] If the user to be purchased has completed login, obtaining the frequency of the order request data sent by the user to be purchased;
[0022] Compare the frequency with the frequency threshold to obtain a comparison result, and if the comparison result is abnormal, generate a verification code;
[0023] If the user to be purchased completes the verification code verification, the order request data of the user to be purchased from the client is received.
[0024] Optionally, the performing anomaly detection on the newly added updated inventory data includes:
[0025] Obtaining the purchase quantity of the goods in the paid order, and comparing the purchase quantity of the goods in the paid order with the newly added inventory change data;
[0026] If the purchase quantity of the goods in the paid order is the same as the newly added inventory change data, the detection result is normal;
[0027] If the purchase quantity of the goods in the paid order is different from the newly added inventory change data, the detection result is abnormal.
[0028] Optionally, obtaining the matching degree between the commodity to be purchased and the substitute commodity includes:
[0029] Acquire the commodity parameters of the commodity to be purchased and the commodity parameters of the substitute commodity, determine the similarity between the commodity to be purchased and the substitute commodity, and obtain a target similarity;
[0030] Acquire the data of the user to be purchased, and acquire the preference of the user to be purchased for the alternative commodity according to the data of the user to be purchased, wherein the data of the user to be purchased includes historical purchase data, historical click data and historical evaluation data;
[0031] The matching degree between the commodity to be purchased and the substitute commodity is determined according to the target similarity and the preference.
[0032] Optionally, obtaining the preference of the user to purchase for the substitute product according to the user to purchase data includes:
[0033] Setting target weights according to preset preference rules, the target weights include: purchase weight, click weight, and evaluation weight;
[0034] Determining the preference degree according to the to-be-purchased user data and the target weight;
[0035] The mathematical expression of the preference is:
[0036] X = A1*B1+A2*B2+A3*B3;
[0037] Among them, X is the preference of the user to be purchased for the alternative product, A1 is the historical purchase data, B1 is the purchase weight, A2 is the historical click data, B2 is the click weight, A3 is the historical evaluation data, and B3 is the evaluation weight.
[0038] The present invention also provides a commodity inventory data processing device, comprising:
[0039] The inventory acquisition module is used to receive order request data from a user to be purchased from a client, wherein the order request data includes an identifier of the commodity to be purchased and a purchase quantity of the commodity to be purchased, and acquire the inventory quantity of the commodity to be purchased stored in the cache database according to the identifier of the commodity to be purchased;
[0040] A commodity matching module, configured to obtain the commodity category of the commodity to be purchased if the purchase quantity of the commodity to be purchased is greater than the inventory quantity of the commodity to be purchased, and match a replacement commodity according to the commodity category of the commodity to be purchased;
[0041] An order generation module, used to obtain the matching degree between the commodity to be purchased and the substitute commodity, determine the target commodity according to the matching degree, and generate a target order, wherein the target order includes a target commodity identifier and a target commodity purchase quantity;
[0042] A payment status acquisition module, used to acquire the target commodity inventory stored in the cache database according to the target commodity identifier, lock the target commodity inventory, and acquire the payment status of the target order within a preset time period;
[0043] The inventory deduction module is used to deduct the target commodity inventory according to the target commodity purchase quantity if the payment status is paid, unlock the target commodity inventory, obtain new inventory change data, and perform abnormal detection on the new inventory change data. If the detection result is normal, the deducted target commodity inventory is returned to the client. The inventory acquisition module, the commodity matching module, the order generation module, the payment status acquisition module and the inventory deduction module are connected.
[0044] The present invention also provides a device including a memory, a processor, and a computer program stored in the memory and executable on the processor, so that the electronic device executes the commodity inventory data processing method.
[0045] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the commodity inventory data processing method is implemented.
[0046] As described above, the present invention provides a method, device, electronic device and medium for processing commodity inventory data, which have the following beneficial effects: by storing the commodity inventory in a cache database that supports high concurrent read and write speeds, the problems of system congestion and inventory deduction failure under high concurrency are avoided, thereby ensuring the stability of the system. By performing anomaly detection on the newly added inventory change data, when the detection result is normal, the deducted target commodity inventory is returned to the client, thereby avoiding the problem of overselling of commodities. By comparing the frequency of order requests sent by users to be purchased with the frequency threshold, generating a verification code when the comparison result is abnormal, and performing subsequent inventory data processing after the user completes the verification code verification, the user's access to the commodity inventory is reduced, thereby reducing the pressure on the server and database by shielding unnecessary information on the back end, thereby improving the high concurrent data processing capability of the e-commerce system. By locking the commodity inventory and unlocking it after the order payment is completed, the inconsistency between the commodity inventory displayed by the system and read by the user and the actual inventory of unpurchased commodities is avoided, and the consistency of commodity inventory information and order information, the accuracy of commodity inventory information and the accuracy of order status are ensured. In the process of processing commodity inventory, multiple threads are avoided from processing the inventory of commodities to be processed at the same time, thereby ensuring the normal progress of current shopping. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 is a flow chart of a method for processing commodity inventory data in an embodiment of the present invention;
[0049] Figure 2 is a flow chart of a method for obtaining a matching degree in an embodiment of the present invention;
[0050] Figure 3 is a flow chart of a method for obtaining preference in an embodiment of the present invention;
[0051] Figure 4 is a flow chart of a method for detecting abnormality of inventory data in an embodiment of the present invention;
[0052] Figure 5 is a module diagram of a commodity inventory data processing device in an embodiment of the present invention;
[0053] Figure 6Schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0054] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0055] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0056] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration. Specific embodiments
[0058] Figure 1 It is a flowchart of a method for processing commodity inventory data provided in one embodiment of the present invention.
[0059] like Figure 1 As shown, the above commodity inventory data processing method includes steps S110-S150:
[0060] S110, receiving order request data from a user to purchase, the order request data including an identifier of the commodity to be purchased and a purchase quantity of the commodity to be purchased, and acquiring the inventory quantity of the commodity to be purchased stored in a cache database according to the identifier of the commodity to be purchased;
[0061] S120, if the purchase quantity of the commodity to be purchased is greater than the inventory quantity of the commodity to be purchased, obtaining the commodity category of the commodity to be purchased, and matching a replacement commodity according to the commodity category of the commodity to be purchased;
[0062] S130, obtaining the matching degree between the commodity to be purchased and the substitute commodity, determining the target commodity according to the matching degree, and generating a target order, wherein the target order includes the target commodity identifier and the purchase quantity of the target commodity;
[0063] S140, obtaining the target commodity inventory stored in the cache database according to the target commodity identifier, locking the target commodity inventory, and obtaining the payment status of the target order within a preset time period;
[0064] S150, if the payment status is paid, the target commodity inventory is deducted according to the target commodity purchase quantity, the target commodity inventory is unlocked, the newly added inventory change data is obtained, and the newly added inventory change data is detected for abnormalities.
[0065] In step S110 of this embodiment, the commodity inventory data processing method is applied to an e-commerce system. When receiving the order request data of the user to be purchased, it is necessary to determine whether the account data of the user to be purchased meets the preset purchase rules. If the account data of the user to be purchased meets the preset purchase rules, the order request data of the user to be purchased is received. Before determining whether the account data of the user to be purchased meets the preset purchase rules, it is also necessary to determine whether the user to be purchased has completed account registration. If the user to be purchased is in an unregistered state, the user to be purchased does not meet the preset purchase rules, and the user to be purchased needs to complete account registration. If the user to be purchased is in a registered state, it is necessary to determine whether the user is in a logged-in state. If the user is not logged in, the user needs to complete the login; if the user is logged in, the user's historical purchase information is obtained; if the user's historical purchase information includes the current commodity, the user to be purchased does not meet the preset purchase rules, and the user to be purchased cannot purchase the current commodity; by eliminating the users to be purchased who do not meet the preset purchase rules, the user's access to the commodity inventory is reduced, thereby shielding unnecessary information at the back end to reduce the pressure on the server and database, thereby improving the high concurrent data processing capability of the e-commerce system.
[0066] In one embodiment, the preset purchase rule also includes setting a frequency threshold for sending order requests. Specifically, if the user to be purchased has completed login, the frequency of the order request data sent by the user to be purchased is obtained; the frequency of sending the order request data is compared with the frequency threshold to obtain the comparison result. If the comparison result is abnormal, a verification code is generated; if the user to be purchased completes the verification code verification, the account data of the user to be purchased meets the preset purchase rule; and only one order request from the multiple order requests of the user to be purchased is received. Some users want to increase the probability of successful purchase through a higher request frequency, so they use the same account to send dozens or even hundreds of requests at a time; however, this method greatly increases the load pressure of the server and also undermines the fairness of sales activities. By completing the verification code and receiving only one order request from the multiple order requests of the user to be purchased, the user's access to the commodity inventory, the pressure on the server and the database are reduced, thereby improving the high concurrent data processing capability of the e-commerce system.
[0067] In one embodiment, in order to obtain more user accounts, some hackers write hacker scripts such as automatic registration and accumulate a considerable number of "zombie accounts". In order to avoid this situation, the preset purchase rules also include setting a verification code according to the frequency of the IP sending requests of the user account to be purchased. When it is detected that the frequency of sending requests of the IP address corresponding to the user account to be purchased is higher than the preset IP frequency threshold within a specific time, it is marked as a suspicious IP segment and a verification code is generated. If the verification code entered by the user to be purchased is incorrect or the verification code is not entered within the preset time, the order request of the user to be purchased will not be accepted. By determining the frequency of sending requests to obtain abnormal user accounts and not accepting order requests from such user accounts, the pressure on the server and database is reduced, thereby improving the high concurrent data processing capability of the e-commerce system.
[0068] In one embodiment, in addition to detecting the frequency of requests sent by the IP of the account of the user to be purchased to obtain abnormal users, abnormal users can also be determined by analyzing the user's account data. The specific implementation method of analyzing abnormal users according to the account data of the user to be purchased is to obtain the account data of multiple users, and use a clustering algorithm to classify the account data of multiple users to obtain classification results; obtain the user category of the user to be purchased according to the account data of the user to be purchased and the classification results; if the user category of the user to be purchased is normal, the account data of the user to be purchased meets the preset purchase rules.
[0069] In one embodiment, when a clustering algorithm is used to classify account data, the account data includes but is not limited to behavioral data, and the behavioral data includes but is not limited to mouse click data, keyboard click data, mouse wheel data, account login data, account login data and IP address data. Clustering algorithms include but are not limited to K-means clustering algorithms. The account data of multiple users are classified using the K-means clustering algorithm to obtain classification results. The classification results include user categories, and the user categories include normal and abnormal. Specifically, according to K=2, the account data of multiple users are clustered using the K-means clustering algorithm to obtain clustering results. The clustering results include different clusters (normal and abnormal), and different clusters are marked to obtain corresponding user categories.
[0070] In one embodiment, the e-commerce system includes but is not limited to an order module and a rush purchase module. The order module can realize functions such as order generation, order review, order payment, order distribution, and order cancellation. After the order is generated, if the payment of the order is not completed within the preset time period, the order will be automatically canceled; the order review is mainly for the case of malicious orders or order brushing by users. In the rush purchase module, the rush purchase product page is static, specifically including: writing the product description, product transaction volume, product specification parameters and product user evaluation into the static page; when the user requests the rush purchase product service, the static resource is directly returned to the user without accessing the background. Since the client clock and the server clock may be inconsistent, resulting in the client clock being unreliable, the client timing is used to synchronize the time with the server; since the interface of the synchronized clock will not be designed into the background logic, the server only needs to send the time of the current node to the client, and the calculation of the current server time is mainly CPU operation, so the running speed is very fast. In addition, in order to prevent the front-end from infinitely looping access to the interface, the access frequency is set through the tokenID, and data is cached. Access requests within 5ms all return the same result, and the order grabbing operations with the same tokenID return the same data within the time interval.
[0071] In one embodiment, all information such as commodity inventory information and commodity order information are stored in the database of the same server corresponding to the e-commerce system. The commodity inventory information and other information except the commodity inventory information can be stored separately, wherein the commodity inventory information is stored in the cache database, and other information except the commodity inventory information is still stored in the database of the same server corresponding to the e-commerce system. The cache database supports the read and write speed under high concurrency, and can realize the distributed locking of the commodity inventory information to be processed under high concurrency according to the database structure in the cache database. The cache database can be a database structure that has used the Redis cluster as the cache database. Redis has significant high concurrency capabilities, and the theoretical peak value is that a single machine can support 100,000 reads and writes per second. Redis can also support distributed clusters with strong scalability, and grabbing orders is a typical scenario of more reads and less writes, which is suitable for operating memory rather than operating hard disks. The operation of Redis itself guarantees atomicity, so the thread safety of the operation that requests Redis to write can be guaranteed. By storing the inventory quantity in a cache database that supports read and write speeds under high concurrency, it is possible to cope with the large flow impact when grabbing orders, cut peaks and fill valleys, reduce server load pressure when selling goods, improve commodity sales efficiency, and reduce resource consumption.
[0072] In step S120 of the present embodiment, if the purchase quantity of the commodity to be purchased is greater than the inventory quantity of the commodity to be purchased, the user's purchase demand state is obtained, and the demand state includes willingness to purchase alternative commodities and unwillingness to purchase alternative commodities. If the user's purchase demand state is willingness to purchase alternative commodities, the commodity category of the commodity to be purchased is obtained, and the alternative commodity is matched according to the commodity category of the commodity to be purchased, wherein the commodity category of the alternative commodity is the same as that of the commodity to be purchased, and the purchase quantity of the alternative commodity is equal to the difference between the purchase quantity of the commodity to be purchased and the commodity inventory quantity.
[0073] In step S130 of this embodiment, the specific implementation method of obtaining the matching degree between the to-be-purchased product and the substitute product can be found in Figure 2 . Figure 2 It is a flowchart of a method for obtaining a matching degree in one embodiment of the present invention.
[0074] like Figure 2 As shown, the method for obtaining the matching degree may include the following steps S210-S230:
[0075] S210, obtaining product parameters of the product to be purchased and product parameters of the substitute product, determining the similarity between the product to be purchased and the substitute product, and obtaining a target similarity;
[0076] S220, obtaining the data of the user to be purchased, and obtaining the preference of the user to be purchased for the alternative goods according to the data of the user to be purchased;
[0077] S230, determining the matching degree between the commodity to be purchased and the substitute commodity according to the target similarity and preference.
[0078] In one embodiment, the commodity parameter of the commodity to be purchased is the first commodity parameter, and the commodity parameter of the commodity to be purchased is the second commodity parameter. The distance between the first commodity parameter and the second commodity parameter is obtained, and then the similarity between the commodity to be purchased and the substitute commodity is determined based on the obtained distance to obtain the target similarity. The specific implementation method of determining the matching degree between the commodity to be purchased and the substitute commodity based on the target similarity and preference includes: setting a similarity weight and a preference weight; determining a similarity parameter based on the similarity weight and the target similarity; determining a preference parameter based on the preference weight and the preference; and obtaining the matching degree between the commodity to be purchased and the substitute commodity based on the similarity parameter and the preference parameter. The mathematical expression of the matching degree is:
[0079] C = X*X1+Y*Y1;
[0080] Among them, C is the matching degree between the product to be purchased and the alternative product, X is the preference of the user to be purchased for the alternative product, X1 is the preference weight, Y is the target similarity, and Y1 is the similarity weight.
[0081] In one embodiment, the specific implementation method of obtaining the preference of the user to be purchased for the alternative goods according to the user data to be purchased can be found in Figure 3 . Figure 3 It is a flowchart of a method for obtaining preference in one embodiment of the present invention.
[0082] like Figure 3 As shown, the method for obtaining the preference may include the following steps S310-S320:
[0083] S310, setting a target weight according to a preset preference rule;
[0084] S320, determining the preference according to the user data to be purchased and the target weight.
[0085] In one embodiment, the user data to be purchased includes but is not limited to historical purchase data, historical click data and historical evaluation data, and the target ball weight includes but is not limited to purchase weight, click weight and evaluation weight. The specific implementation method of determining the preference degree according to the user data to be purchased and the target weight includes: determining the purchase parameter according to the historical purchase data and the purchase weight; determining the click parameter according to the historical click data and the click weight; determining the evaluation parameter according to the historical evaluation data and the evaluation weight; determining the preference degree according to the purchase parameter, the click parameter and the evaluation parameter. Among them, the mathematical expression of the preference degree is:
[0086] X = A1*B1+A2*B2+A3*B3;
[0087] Among them, X is the preference of the user to be purchased for the alternative product, A1 is the historical purchase data, B1 is the purchase weight, A2 is the historical click data, B2 is the click weight, A3 is the historical evaluation data, and B3 is the evaluation weight.
[0088] In one embodiment, after obtaining the matching degree between the commodity to be purchased and the alternative commodity, a target order is generated according to the order request, the target commodity and the purchase quantity of the target commodity; before generating the target order, it also includes: judging whether the target commodity meets the user's needs, if so, generating the target order according to the order request, the target commodity and the purchase quantity of the target commodity, if not, canceling the order.
[0089] In step S140 of this embodiment, under high concurrency, the quantity of goods available for sale is usually limited. Due to reasons such as data transmission congestion, when the commodity inventory information is processed using a database row-level lock, the deduction delay of the commodity inventory information is high, which may cause the quantity of goods available for sale to be less than or equal to the order quantity, thereby reducing its availability. After the commodity identifier is generated, it is necessary to determine the storage address of the commodity inventory and lock the storage address of the commodity inventory. According to the database structure of the cache database, the storage address of the commodity inventory can be locked in a distributed manner, thereby reducing the importance of a single object and improving the performance of the entire system. By performing distributed locking on the inventory data, the timeliness, accuracy and convenience of the processing of the commodity inventory data are guaranteed. Therefore, by adopting the method of locking and unlocking the commodity inventory information and deducting the inventory after the order payment is completed, the consistency of the commodity inventory information and the order information, the accuracy of the commodity inventory information, and the accuracy of the order status are guaranteed.
[0090] In one embodiment, the lock in the locking process is a distributed lock, which specifically includes a locking module, an unlocking module and an exception determination module; in order to ensure the smooth completion of the locking step, the target commodity inventory is locked, including: obtaining the storage address of the target inventory according to the target commodity identifier, and locking the storage address; if the storage address can be inserted into the cache database, the locking is successful; if the storage address cannot be inserted into the cache database, the locking fails; if the locking fails, the locking data is obtained, and the locking exception is handled according to the locking data.
[0091] In one embodiment, the specific implementation method of obtaining locking data and performing locking exception processing according to the locking data includes: if the storage address is in a deadlock state, performing deadlock exception processing on the locking data. In order to avoid deadlock, an expiration time is set for the locked storage address. Therefore, the expiration time can be obtained and the acquisition result can be converted into a value corresponding to the storage address. If it is detected that the value corresponding to the storage address matches the specified value, it is determined that the storage address is in a deadlock state. For example, this embodiment pre-sets a specified value, and the specified value indicates that the storage address is in a deadlock state. If the storage address is locked but the expiration time is not set, the expiration time of the storage address cannot be obtained, and the returned value is the same as the specified value, indicating that the reason for the locking failure is caused by deadlock. This embodiment pre-sets a specified value, which may be but not limited to -1.
[0092] In one embodiment, before generating the target order, the method further includes: if the target commodity inventory is less than the preset inventory, obtaining the number of users to be purchased; if the number of users to be purchased is greater than the preset user quantity threshold, obtaining the order request sending time of the users to be purchased, and generating the target order according to the order request sending time. The specific implementation method of generating the target order according to the order request sending time includes: sorting the users according to the order request sending time of the users to be purchased, and generating sequence data; if the sequence data of the users to be purchased is less than or equal to the preset user quantity threshold, generating the target order; if the sequence data of the users to be purchased is greater than the preset user quantity threshold, generating waiting information, and if other users to be purchased cancel the order, generating the target order of the users to be purchased whose sequence data is greater than the preset user quantity threshold. By using the preset inventory and the number of users to be purchased, when the target commodity inventory is less than the preset inventory, obtaining the number of users to be purchased, when the number of users to be purchased is greater than the preset user quantity threshold, obtaining the number of users to be purchased, when the number of users to be purchased is greater than the preset user quantity threshold, sorting the users to be purchased and generating sequence data, and if the sequence data of the users to be purchased is greater than the preset user quantity threshold, generating waiting information, thereby avoiding the problem of overselling.
[0093] In one embodiment, before obtaining the payment status of the target order within the preset time period, it also includes: obtaining the purchase data of the target order, wherein the purchase data of the target order includes but is not limited to: user points, store red envelopes, payment amount and order ID, and the user selects the payment method according to the purchase data of the target order, such as using points, red envelopes, user account balance or mixed payment methods to complete the payment. When the user uses points and red envelopes to pay, it is necessary to determine whether the points or red envelopes used meet the current order restrictions. If not, it is necessary to select a suitable payment method. In addition, it is also necessary to determine whether the user has paid successfully. If the user fails to pay, the order failure information is returned, and then it is determined whether the commodity inventory is 0. If not, the user needs to queue up to place an order. In order to avoid querying the database every time, the memory cache and single-threaded working mode of redis are used. There is no single-threaded concurrency security problem in the concurrent process, and the inventory of the commodity is stored in the cache; the order payment status and the generation of the target order can also be processed asynchronously. First, the order content is fed back to the user, and then the order service is called to place an order asynchronously, and the order success information is fed back to the user.
[0094] In step S150 of this embodiment, the user's purchase information can also be saved in the cache database, and then the order request is obtained according to the user data and the product information in the cache is checked. In order to prevent users from purchasing multiple times, the current product is limited to one user ID with only one order opportunity, and a redis optimistic lock is used to add a lock between checking the product inventory and whether the user data has placed an order, to determine whether the user has placed an order. If the user has placed an order, an order failure message is generated; if the user has not placed an order, the product inventory is obtained, and if the product inventory is 0, an order failure message is generated; if the inventory meets the user's order request, the payment status of the target order is obtained, and if the payment status is paid, the redis order working mode is used to perform inventory deduction operations. After the order is completed, RabbitMQ is used to asynchronously notify the order server to place the order.
[0095] In one embodiment, the specific implementation method of performing anomaly detection on newly added inventory change data can be found in Figure 4 . Figure 4 4 is a flow chart of a method for detecting abnormality in inventory data in one embodiment of the present invention.
[0096] like Figure 4 As shown, the method for detecting abnormality in inventory data may include the following steps S410-S430:
[0097] S410, obtaining the commodity purchase quantity of the paid order, and comparing the commodity purchase quantity of the paid order with the newly added inventory change data;
[0098] S420, if the purchase quantity of the goods in the paid order is the same as the newly added inventory change data, the detection result is normal;
[0099] S430, if the purchase quantity of the goods in the paid order is different from the newly added inventory change data, the detection result is abnormal;
[0100] If the test result is normal, the target product inventory after deduction will be returned to the client. By comparing the purchase quantity of the paid order with the new inventory change data, the abnormal detection of the new inventory change data is realized, thereby ensuring the correctness of the inventory deduction data. By returning the target product inventory after deduction when the test result is normal to the client, the correctness of the inventory is guaranteed and the problem of overselling of goods is avoided.
[0101] The embodiment of the present invention provides a method for processing commodity inventory data. The method avoids system congestion and inventory deduction failure under high concurrency by storing the commodity inventory in a cache database that supports high concurrent read and write speeds, thereby ensuring the stability of the system. By adopting a method of performing subsequent inventory data processing after the user account data meets the preset purchase rules, the user's access to the commodity inventory is reduced, and the pressure on the server and database is reduced by shielding unnecessary information at the back end, thereby improving the high concurrent data processing capability of the e-commerce system. By adopting a method of locking the commodity inventory and unlocking the commodity inventory after the order payment is completed, the situation that the commodity inventory displayed by the system and read by the user is inconsistent with the actual inventory of the unpurchased commodity is avoided, the consistency of the commodity inventory information and the order information, the accuracy of the commodity inventory information and the accuracy of the order status are ensured, and in the process of processing the commodity inventory, multiple threads are avoided from processing the commodity inventory to be processed at the same time, thereby ensuring the normal progress of the current shopping.
[0102] Based on the same inventive concept as the commodity inventory data processing method, this embodiment also provides a commodity inventory data processing device. The commodity inventory data processing device executes the commodity inventory data processing method described in any of the above embodiments. The specific functions and technical effects can be referred to the above embodiments, and will not be repeated here.
[0103] Figure 5 This is a module diagram of the commodity inventory data processing device provided by the present invention. Figure 5 As shown, the above-mentioned commodity inventory data processing device includes: 51 inventory acquisition module, 52 commodity matching module, 53 order generation module, 54 payment status acquisition module and 55 inventory deduction module.
[0104] The inventory acquisition module is used to receive order request data from a user to be purchased from a client, the order request data including the identifier of the commodity to be purchased and the purchase quantity of the commodity to be purchased, and to obtain the inventory quantity of the commodity to be purchased stored in the cache database according to the identifier of the commodity to be purchased;
[0105] A product matching module, for obtaining the product category of the product to be purchased if the purchase quantity of the product to be purchased is greater than the inventory quantity of the product to be purchased, and matching a replacement product according to the product category of the product to be purchased;
[0106] An order generation module is used to obtain the matching degree between the commodity to be purchased and the substitute commodity, determine the target commodity according to the matching degree, and generate a target order, which includes the target commodity identifier and the target commodity purchase quantity;
[0107] The payment status acquisition module is used to acquire the target commodity inventory stored in the cache database according to the target commodity identifier, lock the target commodity inventory, and acquire the payment status of the target order within a preset time period;
[0108] The inventory deduction module is used to deduct the target commodity inventory according to the target commodity purchase quantity if the payment status is paid, unlock the target commodity inventory, obtain the new inventory change data, and perform anomaly detection on the new inventory change data. If the detection result is normal, the deducted target commodity inventory is returned to the client, inventory acquisition module, commodity matching module, order generation module, payment status acquisition module and inventory deduction module.
[0109] In some exemplary embodiments, the inventory acquisition module further includes:
[0110] A frequency acquisition unit, used to acquire the frequency of the order request data sent by the user to purchase if the user to purchase has completed login;
[0111] A verification code generating unit, used to compare the frequency with the frequency threshold, obtain a comparison result, and generate a verification code if the comparison result is abnormal;
[0112] The judgment unit is used to receive the order request data of the user to be purchased from the client if the user to be purchased completes the verification code verification.
[0113] In some exemplary embodiments, the payment status acquisition module includes:
[0114] A locking unit, used to obtain a storage address of a target inventory quantity according to a target commodity identifier, and to lock the storage address;
[0115] A first locking judgment unit, used for locking successfully if the storage address can be inserted into the cache database;
[0116] A second locking judgment unit, used for locking failure if the storage address cannot be inserted into the cache database;
[0117] The exception handling unit is used to obtain locking data if locking fails, and perform locking exception handling according to the locking data.
[0118] In some exemplary embodiments, the payment status acquisition module further includes:
[0119] A user quantity acquisition unit, used to acquire the number of users to purchase if the target product inventory is less than the preset inventory;
[0120] The target order generation unit is used to obtain the order request sending time of the user to be purchased if the number of users to be purchased is greater than the preset user threshold, and generate a target order according to the order request sending time.
[0121] In some exemplary embodiments, the product matching module includes:
[0122] A target similarity determination unit, used to obtain product parameters of the product to be purchased and product parameters of the substitute product, determine the similarity between the product to be purchased and the substitute product, and obtain the target similarity;
[0123] A preference acquisition unit is used to acquire the data of the user to be purchased, and acquire the preference of the user to be purchased for the alternative goods according to the data of the user to be purchased, wherein the data of the user to be purchased includes historical purchase data, historical click data and historical evaluation data;
[0124] The matching degree obtaining unit is used to determine the matching degree between the commodity to be purchased and the substitute commodity according to the target similarity and preference.
[0125] In some exemplary embodiments, the preference acquisition unit includes:
[0126] The weight setting subunit is used to set the target weight according to the preset preference rules. The target weight includes: purchase weight, click weight and evaluation weight;
[0127] A preference acquisition subunit is used to determine the preference according to the user data to be purchased and the target weight;
[0128] The mathematical expression of preference is:
[0129] X = A1*B1+A2*B2+A3*B3;
[0130] Among them, X is the preference of the user to be purchased for the alternative product, A1 is the historical purchase data, B1 is the purchase weight, A2 is the historical click data, B2 is the click weight, A3 is the historical evaluation data, and B3 is the evaluation weight.
[0131] In some exemplary embodiments, the inventory deduction module includes:
[0132] The anomaly detection unit is used to obtain the commodity purchase quantity of the paid order and compare the commodity purchase quantity of the paid order with the newly added inventory change data; if the commodity purchase quantity of the paid order is the same as the newly added inventory change data, the detection result is normal; if the commodity purchase quantity of the paid order is different from the newly added inventory change data, the detection result is abnormal.
[0133] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0134] This embodiment further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, any one of the methods in this embodiment is implemented.
[0135] In one embodiment, see Figure 6 This embodiment also provides an electronic device 600, including a memory 601, a processor 602, and a computer program stored in the memory and executable on the processor. When the processor 602 executes the computer program, the steps of the method described in any of the above embodiments are implemented.
[0136] The computer-readable storage medium in this embodiment can be understood by ordinary technicians in this field: all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0137] The electronic device provided in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run the computer program so that the electronic device executes each step of the above method.
[0138] In this embodiment, the memory may include a random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0139] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0140] In the above embodiments, the description refers to "this embodiment", "an embodiment", "another embodiment", "in some exemplary embodiments" or "other embodiments" to indicate that the specific features, structures or characteristics described in conjunction with the embodiments are included in at least some embodiments, but not necessarily all embodiments. Multiple occurrences of "this embodiment", "an embodiment", "another embodiment" do not necessarily all refer to the same embodiment.
[0141] In the above-described embodiments, although the invention has been described in conjunction with specific embodiments of the invention, many substitutions, modifications, and variations of these embodiments will be apparent to those of ordinary skill in the art based on the foregoing description. For example, other storage structures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed. Embodiments of the invention are intended to encompass all such substitutions, modifications, and variations that fall within the broad scope of the appended claims.
[0142] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0143] The present invention can be used in many general or special computing system environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and the like.
[0144] The present invention may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0145] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present invention. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A method for processing commodity inventory data, characterized in that: The commodity inventory data processing method comprises: Receive order request data from a user to purchase from a client, the order request data including an identifier of the commodity to be purchased and a purchase quantity of the commodity to be purchased, and obtain the inventory quantity of the commodity to be purchased stored in a cache database according to the identifier of the commodity to be purchased; If the purchase quantity of the commodity to be purchased is greater than the inventory quantity of the commodity to be purchased, obtaining the commodity category of the commodity to be purchased, and matching a replacement commodity according to the commodity category of the commodity to be purchased; Obtaining a matching degree between the commodity to be purchased and the substitute commodity, determining a target commodity according to the matching degree, and generating a target order, wherein the target order includes a target commodity identifier and a target commodity purchase quantity; Wherein, obtaining the degree of matching between the commodity to be purchased and the substitute commodity includes: obtaining commodity parameters of the commodity to be purchased and commodity parameters of the substitute commodity, determining the degree of similarity between the commodity to be purchased and the substitute commodity, and obtaining target similarity; obtaining data of a user to be purchased, and obtaining the degree of preference of the user to be purchased for the substitute commodity according to the data of the user to be purchased, wherein the data of the user to be purchased includes historical purchase data, historical click data, and historical evaluation data; determining the degree of matching between the commodity to be purchased and the substitute commodity according to the target similarity and the preference; Obtaining the preference of the user to be purchased for the substitute product according to the user to be purchased data, including: setting a target weight according to a preset preference rule, wherein the target weight includes: purchase weight, click weight and evaluation weight; Determining the preference degree according to the to-be-purchased user data and the target weight; The mathematical expression of the preference is: X=A1*B1+A2*B2+A3*B3; Wherein, X is the preference of the user to be purchased for the alternative product, A1 is the historical purchase data, B1 is the purchase weight, A2 is the historical click data, B2 is the click weight, A3 is the historical evaluation data, and B3 is the evaluation weight; according to the target product identifier, the target product inventory stored in the cache database is obtained, the target product inventory is locked, and the payment status of the target order within the preset time period is obtained; If the payment status is paid, the target product inventory is deducted according to the purchase amount of the target product, the target product inventory is unlocked, the new inventory change data is obtained, and the new inventory change data is detected for abnormalities. If the detection result is normal, the deducted target product inventory is returned to the client.
2. The commodity inventory data processing method according to claim 1, characterized in that: The locking process for the target commodity inventory includes: Acquire the storage address of the target commodity inventory according to the target commodity identifier, and lock the storage address; If the storage address can be inserted into the cache database, the locking is successful; If the storage address cannot be inserted into the cache database, locking fails; If locking fails, the locking data is obtained, and locking exception processing is performed according to the locking data.
3. The commodity inventory data processing method according to claim 2, characterized in that: Before generating the target order, the following steps are also included: If the target product inventory is less than the preset inventory, the number of users waiting to purchase is obtained; If the number of users to be purchased is greater than a preset user number threshold, the time when the order request is sent by the users to be purchased is obtained, and the target order is generated according to the time when the order request is sent.
4. The commodity inventory data processing method according to claim 1, characterized in that: The step of receiving the order request data of the user to be purchased from the client also includes: If the user to be purchased has completed login, obtaining the frequency of the order request data sent by the user to be purchased; Compare the frequency with the frequency threshold to obtain a comparison result, and if the comparison result is abnormal, generate a verification code; If the user to be purchased completes the verification code verification, the order request data of the user to be purchased from the client is received.
5. The commodity inventory data processing method according to claim 4, characterized in that: The performing abnormality detection on the newly added inventory change data includes: Obtaining the purchase quantity of the goods in the paid order, and comparing the purchase quantity of the goods in the paid order with the newly added inventory change data; If the purchase quantity of the goods in the paid order is the same as the newly added inventory change data, the detection result is normal; If the purchase quantity of the goods in the paid order is different from the newly added inventory change data, the detection result is abnormal.
6. A commodity inventory data processing device, characterized in that: The commodity inventory data processing device comprises: The inventory acquisition module is used to receive order request data from a user to be purchased from a client, wherein the order request data includes an identifier of the commodity to be purchased and a purchase quantity of the commodity to be purchased, and acquire the inventory quantity of the commodity to be purchased stored in the cache database according to the identifier of the commodity to be purchased; A commodity matching module, configured to obtain the commodity category of the commodity to be purchased if the purchase quantity of the commodity to be purchased is greater than the inventory quantity of the commodity to be purchased, and match a replacement commodity according to the commodity category of the commodity to be purchased; An order generation module is used to obtain the matching degree between the commodity to be purchased and the substitute commodity, determine the target commodity according to the matching degree, and generate a target order, wherein the target order includes the target commodity identifier and the target commodity purchase quantity; wherein obtaining the matching degree between the commodity to be purchased and the substitute commodity includes obtaining the commodity parameters of the commodity to be purchased and the commodity parameters of the substitute commodity, determining the similarity between the commodity to be purchased and the substitute commodity, and obtaining the target similarity; obtaining the data of the user to be purchased, and obtaining the preference of the user to be purchased for the substitute commodity according to the data of the user to be purchased, wherein the data of the user to be purchased includes historical purchase data, historical click data, and historical evaluation data; determining the matching degree between the commodity to be purchased and the substitute commodity according to the target similarity and the preference; Obtaining the preference of the user to be purchased for the substitute product according to the user to be purchased data, including: setting a target weight according to a preset preference rule, wherein the target weight includes: purchase weight, click weight and evaluation weight; Determining the preference degree according to the to-be-purchased user data and the target weight; The mathematical expression of the preference is: X=A1*B1+A2*B2+A3*B3; Wherein, X is the preference of the user to be purchased for the alternative product, A1 is the historical purchase data, B1 is the purchase weight, A2 is the historical click data, B2 is the click weight, A3 is the historical evaluation data, and B3 is the evaluation weight; the payment status acquisition module is used to obtain the target product inventory stored in the cache database according to the target product identifier, lock the target product inventory, and obtain the payment status of the target order within a preset time period; The inventory deduction module is used to deduct the target commodity inventory according to the target commodity purchase quantity if the payment status is paid, unlock the target commodity inventory, obtain new inventory change data, and perform abnormal detection on the new inventory change data. If the detection result is normal, the deducted target commodity inventory is returned to the client. The inventory acquisition module, the commodity matching module, the order generation module, the payment status acquisition module and the inventory deduction module are connected.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
