商城优惠卷相关 ,优惠卷异步创建,优惠卷领取使用, 优惠卷领取系统里提取的优惠卷相关代码。
部分代码
https://gitee.com/blackeybaord/coupon.git
/**
* 开始处理创建优惠券
*/
public function create()
{
$queue_name = "handel_coupon_queue";
$redis_obj = new redisMq();
$message_length = $redis_obj->getMessageLength($queue_name);
if ($redis_obj->hasError()) {
$this->logObj->cliWrite('error', array("读取redis队列失败:" . var_export($redis_obj->getError(), true)));
exit;
}
if (empty($message_length)) {
exit;
}
//可以配置每次消费几条
for ($i = 0; $i < $this->limit; $i++) {
$result = $redis_obj->pop($queue_name);
//如果发生异常
if ($redis_obj->hasError()) {
$this->logObj->cliWrite('error', array("读取redis队列失败:" . var_export($redis_obj->getError(), true)));
exit;
}
//有内容的时候则进行处理
if ($result['msg_id']) {
$data = json_decode($result['msg_body'], true);
//进行功能逻辑处理
if ($data) {
$couponData = array(
'coupon_group_id' => $data['coupon_group_id'],
'code' => $data['code'],
'send_type' => $data['send_type'],
'create_time' => $data['create_time'],
);
$couponDb = new IModel('coupon');
$couponDb->setData($couponData);
$couponId = $couponDb->add();
if ($couponId === false) {
$this->logObj->cliWrite('error', array("优惠券生成失败!" . var_export($couponData, true)));
}
}
$redis_obj->remove($queue_name, $result['msg_id']);;
} else {
break;
}
}
}数据库CREATE TABLE `iwebshop_coupon` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表id',
`coupon_group_id` int(11) NOT NULL DEFAULT '0' COMMENT '优惠券 对应coupon_group表id',
`code` varchar(36) DEFAULT '' COMMENT '优惠券兑换码',
`send_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '发放类型,0:默认未设置,1:当成商品销售,2:作为奖品/奖励',
`create_time` datetime NOT NULL COMMENT '优惠卷生成时间',
`update_time` datetime DEFAULT NULL COMMENT '优惠卷更新时间',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '优惠券状态:0禁用,1可用,2已被领取,3已被使用,4已过期,5退款中,6是已经退款',
PRIMARY KEY (`id`),
KEY `cid` (`coupon_group_id`),
KEY `code` (`code`),
KEY `status` (`status`),
KEY `is_send` (`send_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠卷,卷码使用详细表';
CREATE TABLE `iwebshop_coupon_update_log` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表id',
`coupon_group_id` int(11) NOT NULL DEFAULT '0' COMMENT '优惠券 对应coupon_group表id',
`change_sum` int(11) NOT NULL DEFAULT '0' COMMENT '变更的总数量',
`create_time` datetime NOT NULL COMMENT '修改时间',
PRIMARY KEY (`id`),
KEY `cid` (`coupon_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='当成商品销售的优惠,后台变更优惠卷数表';
CREATE TABLE `iwebshop_coupon_groups` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表id',
`use_channels` tinyint(1) NOT NULL DEFAULT '1' COMMENT '使用渠道 1:线上使用',
`type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '优惠券类型 1:抵用券',
`use_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '优惠使用类型,1是积分加钱购,2是纯积分兑换',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '优惠券名字',
`discount_point` int(11) NOT NULL DEFAULT '0' COMMENT '优惠积分额度',
`discount_money` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '优惠金钱额度',
`condition` tinyint(1) NOT NULL DEFAULT '1' COMMENT '使用条件 1:不限制,2限制',
`full_point` int(11) NOT NULL DEFAULT '0' COMMENT '满多少积分方可用',
`full_money` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '满多少钱方可使用',
`start_time` datetime NOT NULL COMMENT '开始时间',
`end_time` datetime NOT NULL COMMENT '结束时间',
`description` varchar(255) NOT NULL DEFAULT '' COMMENT '优惠卷使用说明',
`goods_sale` tinyint(1) NOT NULL DEFAULT '0' COMMENT '优惠卷发放方式 1 当成商品销售',
`goods_sale_num` int(11) NOT NULL DEFAULT '0' COMMENT '当成商品销售数量',
`prop_sale` tinyint(1) NOT NULL DEFAULT '0' COMMENT '优惠卷发放方式 1 作为奖品/奖励',
`props_id` int(11) NOT NULL DEFAULT '0' COMMENT '加入到道具的优惠,道具返回的id,默认0是没有加入',
`seller_id` int(11) NOT NULL DEFAULT '0' COMMENT '商家ID',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '优惠状态1是正常,2是过期,3删除',
`image1` varchar(255) DEFAULT '' COMMENT '道具图片1',
`image2` varchar(255) DEFAULT '' COMMENT '道具图片2',
`create_time` datetime NOT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `seller_id` (`seller_id`),
KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠卷信息表';
CREATE TABLE `iwebshop_coupon_user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
`coupon_group_id` int(11) NOT NULL COMMENT '优惠活动id',
`coupon_id` int(11) NOT NULL COMMENT '优惠券id',
`coupon_code` char(24) NOT NULL COMMENT '优惠券码',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`redeem_time` datetime DEFAULT NULL COMMENT '领取时间',
`is_used` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否被使用:0未使用,1已使用',
`order_no` varchar(20) NOT NULL DEFAULT '' COMMENT '使用优惠卷订单编号',
`receive_order_no` varchar(20) NOT NULL DEFAULT '' COMMENT '领取优惠卷订单号(商品销售)',
`use_time` datetime DEFAULT NULL COMMENT '使用时间',
`remark` varchar(255) DEFAULT '' COMMENT '优惠卷使用情况备注',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `order_no` (`order_no`),
KEY `receive_order_no` (`receive_order_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券领用表';
CREATE TABLE `iwebshop_goods_coupon` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表id',
`coupon_group_id` int(11) NOT NULL DEFAULT '0' COMMENT '优惠券 对应coupon_group表id',
`goods_id` int(11) unsigned NOT NULL COMMENT '货品ID',
PRIMARY KEY (`id`),
KEY `cid` (`coupon_group_id`),
KEY `goods_id` (`goods_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠活动关联商品ID表'; 