Floor recommendations
1. Add Table field
Product List
Classification table
2. Modify the commodity model and the classification model receive field Is_floor
3, modify the product and classification related forms
4, backstage Production recommendation method
4.1 The method of obtaining foreground floor data in the classification model
/** * * * Get the data ********** in the front page floor*/ Public functionFloordata () {$floorData= S (' Floordata '); if($floorData) return $floorData; Else { //first take out the top categories recommended to the floor $ret=$this->where (Array( ' parent_id ' =Array(' eq ', 0), ' is_floor ' =Array(' eq ', ' yes ') ))-Select (); //var_dump ($ret);d ie; $goodsModel= D (' Admin/goods '); //cycle each floor to take out data from the floor foreach($ret as $k=$v) { /*********** The brand data in this floor *************/ //first take out all the product IDs under this floor. $goodsId=$goodsModel->getgoodsidbycatid ($v[' ID ']); //and then take out the brands used in these products. $ret[$k[' brand '] =$goodsModel->alias (' a ') -Join(' left JOIN __brand__ b on A.brand_id=b.id ') ->field (' DISTINCT Brand_id,b.brand_name,b.logo ') ->where (Array( ' a.ID ' =Array(' in ',$goodsId), ' a.brand_id ' =Array(' Neq ', 0), ))->limit (9)Select (); //var_dump ($ret [0][' brand ']);d ie; /** * * Remove the non-recommended level two category and save it to the subcat field in this top-level category * * **/ $ret[$k[' subcat '] =$this->where (Array( ' parent_id ' =Array(' eq ',$v[' ID ']), ' is_floor ' =Array(' eq ', ' no '), ))-Select (); //var_dump ($ret [0][' subcat ']);d ie; /** * * * Remove the recommended class two classification and save it to the subcat field in this top-level category *******/ $ret[$k[' recsubcat '] =$this->where (Array( ' parent_id ' =Array(' eq ',$v[' ID ']), ' is_floor ' =Array(' eq ', ' yes '), ))-Select (); //var_dump ($ret [0][' Recsubcat ']);d ie; /** * * * Recycle each of the recommended two-level categories out of 8 items recommended to the floor * * **/ foreach($ret[$k[' Recsubcat '] as $k 1= &$v 1) { //Remove the ID of all items in this category and return the one-dimensional array $gid=$goodsModel->getgoodsidbycatid ($v 1[' ID ']); $gids=implode(",",$gid); //var_dump ($gids);d ie; And then take out the product details according to the product ID. $v 1[' goods '] =$goodsModel->field (' Id,mid_logo,goods_name,shop_price ') ->where (Array( ' Is_on_sale ' =Array(' eq ', ' 1 '), ' is_floor ' =Array(' eq ', ' yes '), ' id ' = =Array(' in ',$gids), ))->order (' Sort_num ASC ')->limit (8)Select (); //var_dump ($v 1[' goods ');d ie;}} S (' Floordata ',$ret, 5); return $ret; } }
4.2 Extracting data from the IndexController.class.php controller
4.3 In the home cycle output ==> including brand information
5. Generate cache for foreground page
Extension: Solving the avalanche problem of TP frame
Generate a static cache avalanche problem : If the number of concurrent sites is 100 "100 refreshes per second", in the event of a cache page failure, 100 concurrent access to the backend database at the same time may cause the database to crash.
Workaround: Modify the bottom source of TP, add lock when generating static cache page, let only one client enter the controller ==> PHP file lock when the cache fails
PHP.51-TP Framework Mall Application example-Front desk 3-floor recommendation, TP frame avalanche problem