栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

创建折扣代码系统(MySQL / php)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

创建折扣代码系统(MySQL / php)

实际上,这实际上是一类功能。您需要一个看起来像这样的类接口

 class ProductDiscount {      static public function create($pre, $discount, $options = NULL);      static public function validate($pre);   private $_pre;     // string   private $_discount; // float   private $_expire;   // unix timestamp (see time()) or null if unlimited   private $_count;    // int or null if unlimited   private function __construct();   public function getCode();      // return string   public function getDiscount();  // return float   public function isLimited();    // return bool; true if $_count || $_expire is not null   public function getCount();     // returns int; how many of this discount is left or null if unlimited   public function getExpireDate();// returns int (unix timestamp) or null if unlimited   public function consume();      // apply this discount now   public function consumeAll();   // invalidate this discount for future use}

数据库表可能如下所示

id UNSIGNED INT(10) NOT NULL AUTOINCREMENT  -- (Primary Key)pre VARCHAr(12) NOT NULL        -- (Indexed, unique)discount UNSIGNED INT(3) NOT NULL-- percent value 0..100expire DATETIME DEFAULT NULL     -- unlimited by defaultcount INT(10) DEFAULT 1          -- can be NULL

注意: 验证过程可能只是一个简单的

SELECt
声明:

SELECT *   FROM tblproductdiscount WHERe pre = {$pre}       -- $pre = mysql_real_escape_string($pre)   AND (count IS NULL OR count > 0)   AND (expire IS NULL or expire > NOW())

然后,只需在验证结帐表单时使用此类即可。例如,

if (!empty($discountCode)) {   $discount = ProductDiscount::validate($discountCode);   if ($discount !== null) {      $price *= (1 - $discount->getDiscount());      $discount->consume();   }}

好吧,这就是我要怎么做。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426286.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号