Product recommendation
{snapped, new, boutique, hot} The effect is as follows
1, in the commodity table to increase the promotion price and promotion start time and end time Three fields, the field recommended floor and sorting in the back to use
Note: When adding a DateTime Type field, add the default value {DateTime range:1000-01-01 00:00:00 to 9999-12-31 23:59:59}; and turn off MySQL strict mode, Because Promote_price (decimal (10,2)) cannot insert a null value, it is recommended that the development phase be open
2. Form and Time Plugin
3. Modify the product model to allow receiving fields
4, the front desk to take out the recommended products
//Take out the item currently being promoted Public functionGetpromotegoods ($limit= 5) { $today=Date(' y-m-d h:i '); return $this->field (' ID, goods_name, Mid_logo, Promote_price ') ->where (Array( ' Is_on_sale ' =Array(' eq ', ' 1 '), ' promote_price ' =Array(' GT ', 0), ' promote_start_date ' =Array(' ELT ',$today), ' promote_end_date ' =Array(' Egt ',$today), ))->limit ($limit) -Select (); } //out of three recommendations {hot, boutique, new} Public functionGetrecgoods ($recType) { return $this->field (' Id,goods_name,mid_logo,shop_price ') ->where (Array( ' Is_on_sale ' =Array(' eq ', ' 1 '), "$recType"=Array(' eq ', ' yes ') )) ->limit ($limit) ->order (' Sort_num ') //Sort by sort_num field -Select (); }
5. Remove from the home/indexcontroller.class.php controller
6, index.html page loop output
Note: in order to be able to sort the goods more accurately , we can add a field sort_numfor the item, this field holds a number, the smaller the number , the higher the front
PHP.50-TP Framework Mall Application Example-Front desk 2-product recommendation