August 2018

Why?

Why do you want to develop the points mall?

Because we used to use the exchange bar service, it was pretty good

However, we learned that the free version of the service will be closed in the second half of this year (2018), and we need to pay for the professional version or flagship version to use

Of course, the staff of the exchange bar also contacted us, and they could give us a preferential price. The business must say to each other, "OK, we will discuss it."

If we use it, you won't see this article 23333

start

I reviewed their product management as a whole and subtracted some functions unrelated to our business

The main function is exchange. They use The strategy of pure points, points+RMB , I just added one Payment in RMB Method (not troublesome), package and freight functions are subtracted (because we are package)

The main function items that need to be developed are Classified management Commodity management payment

I believe that you can learn the documents of Alipay and WeChat.

Design

We started to design the table structure

The classification table should be the easiest. The general structure is self increasing ID, name, image (classification with images), display order, and status.

The table should look like this

 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;

Then there is the commodity table. By analyzing the display information on the operation interface, you can roughly understand the commodity name, value, description information, pictures, inventory quantity, and convertible times.

The analyzed table structure is as follows

 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;

The structure of this set of points store should be a separate payment table, which does not conflict with the previous payment table, but needs to have correlation points. This is for reference only

 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

Q: What's the number of silly netizens

Me: It doesn't matter if you don't understand it. You can understand it after learning. Work hard to????

Q: Seeking source code

Me: The code in the article ≈ source code. (The source code should be written and sent out when you want to install the force)

Q: In the front design of the watch, I didn't see the items stored. The price is displayed

Me: Finally, an old man is asking serious questions. Look score_shop_goods Exterior exchange_info Field, which describes "information about commodity prices". Here is a json string, which is convenient for expanding information and makes the table structure look less chaotic

 //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

The front end needs several operations:

  • 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

The back-end implements the above interfaces and needs to integrate payment, Focus on commodity exchange interface

 technological process

The execution part of the code is written here with pseudo code

 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

The code process is completed. If you actually write a bug, you need to consider other issues, such as: two people can exchange an item at the same time and only one person can send it to reduce the query burden, and the processing database hangs up during the exchange process

There is no index in the database. If there are more and more goods or payments, the query will take longer

There is a long way to go to optimize

My little fish, you are asleep. Do you still know the morning?
Last night you said,
May the night never open,
The edge of your gills slipped gently,
Is it your tears or mine?
The season of kissing goodbye,
Didn't you cry already?
My fingertips still remember,
With your flustered heartbeat and gentle body fragrance,
That wisp of long hair is fluttering.

My little fish, did you wake up, remember the night?
In the morning you said,
May the dawn never fall,
The edge of your long hair slides gently,
Is it his hand or mine?
Didn't I fall asleep,
I thought you were the same.

Did you leave my little fish alone
Leaving under the snowy lake,
You said goodbye,
For a better goodbye,
I can't stand the picture of parting,
But choose!
Instead, choose,
Will you come back, my little fish?
Do you still know me?
You once said,
Time changes, but you and I remain unchanged,
You walked with you,
Is it your own heart? It is the heart of others.
Isn't it far away?
I'm still looking at the sunset,
Looking at his elongated figure,
My little fish, you won't come back.

I don't recognize you,
I can't remember what I said,
It is time that changes, and it is you and me.
I am watching the dawn,
Waiting for the dawn.
My little fish,
Should I go, too,
I know Morning
Remember you said,
May the night never open,
The edge of your gills slipped gently,
It's my tears,
I have cried in that season.
My fingertips still remember,
Your flustered heartbeat, gentle body fragrance,
That wisp of long hair is fluttering.

My little fish,
Where are you going,
I have already started.

--The Rise of Quebec III God of War

Faraway battle song, welcome back, dear Kuiba!

Official activities : https://mourl.cc/uDGKyH