August 2018

Why?

Why to develop the integral mall?

Because we used the service of cash bar before, which is not bad

However, if you know that the free version of the service will be closed in the second half of this year (2018), you need to pay for the professional version or the flagship version

Of course, the staff of the exchange bar have also contacted us, and they can offer preferential prices. If the business advocates each other, they must say "OK, we will discuss and consider it."

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

start

I looked at their product management as a whole and subtracted some functions that were not related to our business

The main function is the exchange method. They use Pure points, points + RMB strategy I added one RMB payment Method (not troublesome), the functions of parcel post and freight are subtracted (because we are all inclusive)

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

Here's payment. I believe you can learn the documents of Alipay and wechat.

Design

We've started our table structure design

The classification table should be the easiest. The general structure is auto increment ID, name, image (classification with pictures), display order and status.

The watch should look like this below

 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 'displays the order 0 Max', 
 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 name, value, description information, pictures, inventory quantity, and number of convertible times.

The table structure analyzed is like this

 create table if not exists `score_ shop_ goods` (
    `id` int(11) unsigned AUTO_ Increment, 
menuid ` int (11) not null default 0 comment 'belongs to category', ` good '_ Type ` varchar (32) not null default 'object' comment 'distinguish between physical goods and virtual commodities_ Name ` varchar (100) not null default 'comment' product 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 stock','exchange '_ Type ` tinyint (4) not null default 0 comment 'commodity category 0 points 1 RMB 2 points + RMB', 
exchange_ Info ` text not null comment 'information about commodity prices', ` exchange_ No limit for 'create' or 'default' users_ 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;

This set of integral mall structure should be independent of the payment table, which does not conflict with the previous payment table, but needs to have related 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 'purchased item ID','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, unit score ','score ` int (11) unsigned not null default 0 comment' payment 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) not signed 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 recharge failed, 1 recharge succeeded, 2 shipped, 3 client paid successfully, 4 client cancelled payment', 
 primary key (` ID ')) engine = InnoDB default charset = utf8;

there status In order to be compatible with app payment, this system is H5 payment on the web

Prepare to write a small question and answer before writing a bug

Q: What are some of the stupid net friends

I: it doesn't matter if you don't understand it. You can understand it after studying. Try your best????

Q: Source code

Me: the article code ≈ source code. (you should write the source code when you want to install it)

Q: In the front table design, I didn't see the items stored, showing the price

Me: finally, an old brother asked a serious question. Look score_ shop_ goods Inside and outside exchange_ info Field, which describes "information about commodity price". Here is a JSON string, which is convenient to expand information and make the table structure not too confusing

 //RMB (unit: points) 
 {price ": 199, 
" discount ": 0, 
" goods ": {coin": 20 / / the commodities exchanged are 20 gold coins 
}} 
 / / points 
 {score ": 5999999, 
" discount ": 85, //Here I have introduced a discount, which can be converted into a car with id = 81 (which can be expanded at will) 
 (points + RMB), so please talk about it well What we should pay attention to here is that one point is equal to one cent. How to adjust and issue points is your business 
 / / under normal circumstances, the exchange price given by an 8999 value SLR camera is 40000 points + 8599 yuan. Here, we introduce a new function: users have more points than 40000 points and can adjust the exchanged points to offset RMB by using points, This requires strict control of integral. Of course, it's not a random adjustment by the user, so we can't recover the cost of the camera. Therefore, two threshold values are added, the maximum score and the minimum RMB. The value of the user's adjustment points can not exceed the maximum score, which not only gives the user the right to be independent, but also controls our loss. It is also more friendly for us to write bugs later than the actual payment value_ score":50000,
    "price":859900,
    "min_ price":849900,
    "discount":95, "goods": {
 "camera": 78 / / exchange for a set of id = 78???}} 
 / / discount calculation: (converted into RMB multiplied by 100) / / total value 40000 + 859900 = 899900 
 / / total value of discount (40000 + 859900) * 0.95 = 854905 
 / / users need to pay (((40000 + 859900) * 0.95) - 40000) = 814905 
 / / discount price 859900-814905 = 44995// Discount plus maximum available points is equivalent to 1000 yuan cheaper...

Write a bug

The front end requires several operations:

  • Read classification (this can be combined with Read classified items Merge into a home page interface)
  • Read classified items
  • Read product information
  • Exchange commodities
  • Read all exchange records
  • Read single exchange record
  • Query exchange record status (polling)

The front end here does not specifically refer to web, but Android, IOS, web and desktop applications

The back-end implements the above interfaces, in addition, it needs to integrate payment, Focus on the interface of exchange commodities

 technological process

The execution part of the code, here I will take pseudo code to write

 If the item ID of $10 is not enough, check if the item ID is not available; Price information of 
 $commodity = JSON decoding ($product - > exchange)_ Info); 
 
 $goods payment method = $goods - > exchange_ Type; 
 $user = $user table - > Search ($user ID); 
 / / the user does not have points, and the payment method of the product does not need points 
 ($product price information - > score > $user - > score) & & ($product payment method = = 0 | $product payment method = = 2) 
 return insufficient points; 
 $exchange times = $payment table - > Search (user id = $user ID, Commodity id = $commodity ID, payment status = 2) - > statistics times 
 / / check exchange times_ Num! = = 0 
 if $exchange times > = $commodity > = $commodity > exchange times 
 return exceeds the number of exchange; 
 / / check the validity of the amount 
; price information of $commodity - > price = = does not exist? 0: price information of $commodity - > price; price information of $commodity - > score = > price information of $commodity - > score = = does not exist? 0: price information of $commodity - > score; 
 if ($payment RMB + $payment points)! = ((price information of $commodity - > price information of $commodity - > score) 
 return the amount required for exchange is incorrect; 
 switch {case 0: //Credit payment 
 $payment table write id = $payment table > write (payment points, payment time, waiting for shipment status); 
 / / deduct user points 
 $user table - > Search ($user ID) - > Update ($user - > score - $payment points); / / update the inventory of goods 
 $commodity Table > > Search ($commodity ID) - > Update ($commodity - > stock - 1); 
 / / the logic of sending items needs to be implemented by yourself 
; 
 / / the logic of sending items needs to be implemented by oneself 
 
; 
 if sending items fails 
 $payment table > 
 
 return exchange succeeded;; Break; 
 case 1: 
 / / RMB payment 
 if $payment type! = = 0 & $payment type! = = 1 - & $payment type! = = 2 
 return please select the payment method correctly; 
 / / the delivery status here needs to be processed in the callback of Alipay or wechat, we can only preset the status to be delivered $payment table > write (payment points, payment time, waiting for shipment status); 
 
 $payment parameter = $payment SDK - > generate order; 
 / / to process transaction logic of Alipay or wechat, you need to implement it yourself 
 if $payment parameter = = = order not generated 
 return failed to obtain payment parameters; 
 else Return 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 the amount and score range 
 / if $pay RMB < $commodity price information - > min_ Price 
 pay RMB = $price information of goods - > min_ Price = $10 of the price_ Score; 
 else if $pay RMB > $price information of $goods - > price 
 pay RMB = $price information of $goods - > price; 
 $payment points = $price information of $goods - > score; 
 / / the delivery status here needs to be processed in the callback of Alipay or wechat, we can only preset the status to be delivered $payment table > write (payment points, payment time, waiting for shipment status); 
 
 $payment parameter = $payment SDK - > generate order; 
 / / to process transaction logic of Alipay or wechat, you need to implement it yourself 
 if $payment parameter = = = order not generated 
 return failed to obtain payment parameters; 
 else Return successfully converted; 
break; 
}}}

last

After the code process is completed, other issues need to be considered if the bug is actually written, such as: one item is exchanged by two people at the same time, only one person is sent, reducing the query burden, and handling the database to hang up in the exchange process

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

A long way to go

My little fish, do you know the morning when you are asleep?
You said last night,
May the night never open,
It's slipping off your cheek,
Is it your tears, or my tears?
The season of kissing goodbye,
Didn't you already cry?
My fingertips still remember,
Your flustered heartbeat, gentle body fragrance,
The long hair was flying.

My little fish, do you wake up and remember the night?
You said in the morning,
May the dawn never fall,
The edge of your long hair glides by,
Is it his hand or mine?
Isn't it a deep sleep,
I thought you were the same.

My little fish, did you leave alone
From under the snowing lake,
You said goodbye,
For a better goodbye,
I can't stand the picture of parting,
And choose!
And choice,
My little fish, will you come back?
Do you still know me?
You once said,
What changes is time, what remains unchanged is you and me,
You walk with you,
Is it your own heart? It's the heart of others.
Isn't it far away?
I'm still watching 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,
The change is time, but also you and me.
Watch me at dawn,
Waiting for the dawn.
My little fish,
Should I go, too,
I know morning
Remember you said,
May the night never open,
It's slipping off your cheek,
It's my tears,
I've been crying in that season.
I remember on my fingertips,
Your flustered heartbeat, gentle body fragrance,
The long hair was flying.

My little fish,
Where are you going,
I've already set out.

--The rise of Kuiba III God of war

The battle song of Yuantian, welcome back, dear Kuiba!

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