Design Points Mall
Why?
If we use it, you won't see this article 23333
start
Design
create table if not exists `score_shop_classify` ( `id` int(11) unsigned AUTO_INCREMENT, `Name ` varchar (191) not null DEFAULT '' comment 'menu name', `Img ` text comment 'menu picture', `Show_order ` int (11) not null DEFAULT 0 comment 'Display order 0 maximum', PRIMARY KEY (`id`) ) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table if not exists `score_shop_goods` ( `id` int(11) unsigned AUTO_INCREMENT, `Menuid ` int (11) not null DEFAULT 0 comment 'Category', `Good_type ` varchar (32) not null DEFAULT 'object' comment 'Distinguish physical goods from virtual goods object virtual virtual goods coupon', `Good_name ` varchar (100) not null DEFAULT '' comment 'commodity name', `Good_icon ` text not null comment 'commodity icon', `Good_pic ` text not null comment 'Product picture', `Good_desc ` text comment 'Product description', `Good_stock ` int (11) not null DEFAULT 0 comment 'Commodity inventory', `Exchange_type ` tinyint (4) not null DEFAULT 0 comment 'Product type 0 points 1 RMB 2 points+RMB', `Exchange_info ` text not null comment 'Information about commodity prices', `Exchange_num ` int (11) unsigned not null DEFAULT 1 comment, `Created_time ` int (11) unsigned not null DEFAULT 0 comment 'Creation time', `Updated_time ` int (11) unsigned not null DEFAULT 0 comment 'Update time', PRIMARY KEY (`id`) ) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table if not exists `score_shop_pay_record` ( `id` int(11) unsigned AUTO_INCREMENT, `User_id ` int (11) unsigned not null DEFAULT 0 comment 'User ID', `Pay_id ` int (11) unsigned not null DEFAULT 0 comment 'ID of purchased goods', `Oid ` varchar (50) not null DEFAULT 0 comment 'Order ID', `Pay_type ` tinyint (4) not null DEFAULT 0 comment 'payment type, 1 WeChat payment, 2 Alipay payment', `Money ` int (11) unsigned not null DEFAULT 0 comment 'Payment amount, in minutes', `Score ` int (11) unsigned not null DEFAULT 0 comment 'Pay points', `Log ` varchar (255) not null DEFAULT '' comment 'Remarks', `Pay_time ` int (10) unsigned not null DEFAULT 0 comment 'Payment time', `Created_time ` int (10) unsigned not null DEFAULT 0 comment 'Create order time', `Updated_time ` int (10) unsigned not null DEFAULT 0 comment 'Update order time', `Status ` tinyint (4) not null DEFAULT 0 comment 'Payment status, 0 failed to recharge, 1 failed to recharge, 2 failed to ship, 3 shipped, 3 paid successfully by the client, 4 canceled payment by the client', PRIMARY KEY (`id`) ) engine=InnoDB DEFAULT CHARSET=utf8;
there status To be compatible with app payment, this system is the h5 payment on the web side
Q&A before preparing to write the bug
//RMB (unit: minute) { "price":199, "discount":0, "goods":{ "Coin": 20//The exchanged commodity is 20 gold coins } } //Integral { "score":5999999, "discount":85, //Here I introduce a discount to exchange for "?"???? 15% off "goods":{ "Car": 81//The exchanged product is a car with id=81 (can be expanded at will) } } //Points+RMB, please talk about it //PS: What should be noticed here is that 1 point is equal to 1 cent. How to adjust the distribution of points is your business //Normally, the exchange price of an 8999 value SLR camera is 40000 points+8599 yuan. Here, we introduce a new function that users can adjust the exchanged points by themselves if they have more points than 40000 points to offset RMB with points. This requires strict control over points. Of course, it is not adjusted by the user at will, so our camera will not recover the cost. Therefore, two threshold values, the maximum score and the minimum RMB, are added. The value of the user's adjustment score cannot exceed the maximum score, which not only gives the user independent rights, but also controls our losses. It is also friendly to the actual payment value after we write the bug { "score":40000, "max_score":50000, "price":859900, "min_price":849900, "discount":95, "goods":{ "Camera": 78//Exchange a camera with ID=78???? } } //Discount calculation: (converted into RMB multiplied by 100) //Total value 40000+859900=899900 //Total discounted value (40000+859900) * 0.95=854905 //The user needs to pay (((40000+859900) * 0.95) - 40000)=814905 //The discounted price is 859900-814905=44995 //Discount plus maximum available points is equivalent to 1000 yuan cheaper...
Write bugs
-
Read classification (this can be compared with Read classified goods Merge into one homepage interface) -
Read classified goods -
Read commodity information -
Exchange goods -
Read all exchange records -
Read a single exchange record -
Query the status of exchange record (polling)
The front end here does not specifically refer to the web, but refers to android, ios, web and desktop applications
Function convertGoods ($User ID, $Product ID, $Payment Type, $Payment RMB, $Payment Points){ $commodity=$commodity table ->search ($commodity ID); //Check whether $item exists or is wrong If $commodity===does not exist Return does not exist; //Check inventory of $item<=0 If $commodity ->stock<=0 Return Insufficient inventory, stop exchanging; Price information of $commodity=JSON decoding ($commodity ->exchange_info); Payment method of $commodity=$commodity ->exchange_type; $user=$user table ->search ($user ID); //Users do not have points, and the payment method of goods does not need points If (price information of $commodity ->score>$user ->score)&&(payment method of $commodity==0 | | payment method of $commodity==2) Return Insufficient points; $redemption times=$payment table ->search (user ID=$user ID, commodity ID=$commodity ID, payment status=2) ->statistics times //Check redemption times If $commodity ->exchange_num! == 0 If $exchange times>=$goods ->exchange times Return Exceeds the exchange times; //Check the legality of the amount Price information of $commodity ->price=price information of $commodity ->price=does not exist? 0: price information of $goods ->price; Price information of $commodity ->score=price information of $commodity ->score=does not exist? 0: price information of $goods ->score; If ($to pay RMB+$to pay points)! =(Price information of $commodity ->price+price information of $commodity ->score) Return The amount required for exchange is incorrect; Switch (payment method of $goods){ case 0: //Point payment $payment table write ID=$payment table ->write (payment points, payment time, waiting for delivery status); //Deduct user points $User Table ->Search ($User ID) ->Update ($User ->score - $Pay Points); //Update commodity inventory $commodity table ->search ($commodity ID) ->update ($commodity ->stock - 1); //The logic of sending items needs to be implemented by yourself If Failed to send the article $Payment Table ->Search ($Payment Table Write ID) Return The exchange is successful; break; case 1: //Payment in RMB If $payment type! ==0&&$payment type! ==1&&$payment type! == 2 Return Please select the payment method correctly; //The shipment status here needs to be processed in the callback of Alipay or WeChat, and we can only preset it to the status of pending shipment $payment table ->write (payment points, payment time, waiting for delivery status); $payment parameter=$payment SDK ->generate order; //The transaction logic of Alipay or WeChat needs to be realized by yourself If $payment parameter===Order not generated Return Failed to obtain payment parameters; else Return The exchange is successful; break; case 2: //Points+RMB payment If $payment type! ==0&&$payment type! ==1&&$payment type! == 2 Return Please select the payment method correctly; //Check amount and credit range If $payment RMB<$commodity price information ->min_price $payment in RMB=$price information of goods ->min_price; $payment points=$commodity price information ->max_score; Else if $Pay RMB>$Price information of goods ->price $payment in RMB=price information of $goods ->price; $payment points=$price information of goods ->score; //The shipment status here needs to be processed in the callback of Alipay or WeChat, and we can only preset it to the status of pending shipment $payment table ->write (payment points, payment time, waiting for delivery status); $payment parameter=$payment SDK ->generate order; //The transaction logic of Alipay or WeChat needs to be realized by yourself If $payment parameter===Order not generated Return Failed to obtain payment parameters; else Return The exchange is successful; break; } }
last