晓夏

北漂的女孩

Good Luck To You!

优惠券设计

浏览量:398

最近公司让我做优惠券,简单的想了一下,参考了一下别的设计,简单的做了一个数据表设计,不知道合不合适。

有意见欢迎提供。

优惠券表设计:

CREATE TABLE `coupon_temp` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `shop_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '店铺id  为0时,代表商城优惠券',
 `range` enum('all','shop','shop_list','product','product_list','category') NOT NULL DEFAULT 'all'

 COMMENT '范围',
 `range_rule` text NOT NULL COMMENT '(rangeType:all){} (rangeType:shop)   {shop_id:8} 

(rangeType:product)   {product_id:100000052} (rangeType:product_list)   {product_list:[100000052,100000052]}',
 `type` enum('none','require_money') NOT NULL DEFAULT 'none' COMMENT 'none:无条件优惠券,require_money:有条件券',
 `type_rule` text NOT NULL COMMENT '(limitRule:none)   {} (limitRule:require_money)   {require_money:100.00}',
 `title` varchar(36) NOT NULL DEFAULT '' COMMENT '优惠券标题',
 `facevalue` float(6,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '优惠券面值',
 `start_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '开始时间',
 `end_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '结束时间',
 `max_num` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '最大发行量',
 `create_num` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '已领取数量',
 `used_num` int(11) unsigned NOT NULL DEFAULT '0',
 `receive_num` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '每人限量的张数',
 `status` tinyint(2) unsigned DEFAULT '0' COMMENT '0' 正在发行 1不可用  2 时间过期  3 作废',
 `is_show` tinyint(2) unsigned DEFAULT '1' COMMENT '是否展示给买家  1 是  0 否',
 `act_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '

活动类型:0无;1 :平台其他;2:挖矿3:第三方合作;4:大促活动;5 拉新活动;

6兑换码兑换券;7 用户补偿;8 退款补贴;9 积分兑换券',

 `link` varchar(200) NOT NULL DEFAULT '' COMMENT '跳转链接',
 `mtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后修改时间',
 `operaer` varchar(30) NOT NULL DEFAULT '' COMMENT '操作人',
 `fee_type` tinyint(2) DEFAULT '0' COMMENT '成本承担方,0平台,1店铺',
 `platform` char(32) NOT NULL DEFAULT 'ccj' COMMENT '平台标记',
 PRIMARY KEY (`id`),
 KEY `usestatus` (`id`,`status`),
 KEY `shop_id` (`shop_id`,`status`) USING BTREE,
 KEY `idx_act_type` (`act_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC

用户领取优惠券表设计:

CREATE TABLE `coupon_user` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '用计数器生产id',
 `coupon_sn` char(24) NOT NULL DEFAULT '',
 `template_id` int(11) unsigned NOT NULL DEFAULT '0',
 `user_id` int(11) unsigned NOT NULL DEFAULT '0',
 `use_price` decimal(9,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '0',
 `status` tinyint(1) NOT NULL DEFAULT '0',
 `draw_time` int(11) unsigned NOT NULL COMMENT '优惠券领取或发放时间',
 `platform` char(32) NOT NULL DEFAULT 'ccj' COMMENT '平台标记',
 PRIMARY KEY (`id`),
 UNIQUE KEY `coupon_sn` (`coupon_sn`),
 KEY `user_id` (`user_id`,`status`),
 KEY `template_id` (`template_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC

发送优惠券

<?php
$data = ["227,111","223,445"];
$str = '';
foreach($data as $k=>$v){
    $staData = explode(',',$v);
    $uid = $staData[0];
    $couponId = $staData[1];
    if($couponId > 0){
        //新建优惠券的时候已经存在redis里面了
        //TODO  从缓存里获取优惠券信息
    }
    //TODO  生成用户领取 优惠券
    //生成用户领取的优惠券唯一标识
    mt_srand((double)microtime() * 10000);
    $charid = strtoupper(md5(uniqid(rand(), true)));
    $hyphen = chr(45);
    $coupon_sn = substr($charid, 0, 4) . $hyphen
        . substr($charid, 8, 4) . $hyphen
        . substr($charid, 12, 4) . $hyphen
        . substr($charid, 16, 4) . $hyphen
        . substr($charid, 20, 4);
    $time =time();
    $str .= "($coupon_sn, $couponId, $uid, '0',$time),";
}
$sqlValue = trim($str,',');
//批量插入数据库   不要太长   最好10个一组插入
$sql = "INSERT INTO `dwxk_coupon`.`cc_coupon_user` ( `coupon_sn`, `template_id`, `user_id`, `status`, `draw_time`) VALUES {$sqlValue}";

die();
?>






















神回复

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。