PHP.30-TP Framework Mall Application Example-backstage 6-Product membership-price, level

Source: Internet
Author: User
Tags html form

First clarify the needs analysis

The main implementation of two functions

1, member management, set to become a member of the requirements

2, add products, you can set the member preferential prices

Specific Implementation

1, the table "member level limit table P39_member_level{id, level name, lower limit of points, points limit}, member price list p39_member_price{member price, point ID, Product ID}"

if exists p39_member_level;create table P39_member_level (    null auto_increment comment ' Id ',     level_name varchar (null comment ' level name ',    null comment ' integral lower limit ',      null comment ' integral cap ',    key  (ID)) enginedefault Charset=utf8 comment ' membership level ';
P39_member_level
if exists p39_member_price;create table P39_member_price (Price    decimal (null comment ' member prices ',      null comment ' level id ',    null comment ' Product ID ',    key level_id (level_id),    key  goods_id (goods_id)) engine default Charset=utf8 comment ' member Price ';
P39_member_price

2. Use the GII to generate code

Configure code Generation Profile/gii/table_configs/p39_member_level.php "The number of levels is too small to search for forms"

Test

3, in the Add Product page can set the membership price

3.1 Modify the controller goodscontroller.class.php-add () so that the Add page prints all the membership levels

3.2 Modify add.html form, loop output "because it is a multiple membership level, and name needs to be plugged into the library, it should be a membership level ID, so use an array to store multiple member prices"

3.3 Submission Form, member price data Insert Member Price list {Member Price, point ID, item ID}

Note: Because the product is inserted into the member price, the product ID needs to be obtained, and the product ID is only generated after the product has been added successfully, so use the hook function _after_insert ()

1, the price must be a number, forced conversion to float; 2, the price must be greater than 0, countless values can not be inserted, if ($_v>0)

//Hook Method _after_insert: Add operation after successful execution        protected function_after_insert ($data,$option)        {$MP= I (' Post.member_price ');//receive the member price data submitted by post            $mpModel= D (' Member_price '); foreach($MP  as $k=$v)            {                $_v= (float)$v;//force to float to avoid error data such as inserting characters//set member price >0 INSERT INTO table                if($_v> 0)                {                    $mpModel->add (Array(                        ' Price ' =$_v, ' level_id ' =$k,//level ID' goods_id ' =$data[' ID '],                    )); }            }        }

$data = = will insert data in the Product table

Test

Optimize product Add Form JS

Manage homepage, left button connect to page

PHP.30-TP Framework Mall Application Example-backstage 6-Product membership-price, level

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.