Commit b7cbd8c5 authored by liuyuzhen's avatar liuyuzhen

优惠券过期问题

parent e6b512d3
......@@ -249,14 +249,15 @@ class CouponServiceModel extends \Business\AbstractModel{
\Error\ErrorModel::throwException(\Error\CodeConfigModel::couponNoUsedTicketNum);
}
$memberCouponDao = \DAO\Coupon\MemberCouponModel::getInstance($dbName);
/*if($coupon['is_overlay']){//允许领用多张的优惠券是否存在已经领取的未使用有效优惠券
$whereSql = ' member_id ='.$memberId.' and coupon_id='.$coupon['id'].' and out_time > '.time();
if($coupon['is_overlay']){//允许领用多张的优惠券是否存在已经领取的未使用有效优惠券
$whereSql = ' coupon_state = '.\Our\ApiConst::couponUnused.' member_id ='.$memberId.' and coupon_id='.$coupon['id'].' and out_time > '.time();
//$memberCoupons = \Our\RedisHelper::cachedFunction(\Redis\Db13\MemberCouponRedisModel::getInstance(), array(&$memberCouponDao, 'getList'),array($whereSql),\Our\ApiConst::oneHour,array($where['couponId']));
$memberCoupons = $memberCouponDao->getList($whereSql);
if($memberCoupons&&count($memberCoupons)>=$coupon['get_ticket_num']){
if($memberCoupons&&count($memberCoupons)>\Our\ApiConst::zero){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::alreadyGetTheCoupon);
}
}else{//不允许领用多张的优惠券
}
/*else{//不允许领用多张的优惠券
}*/
$memberCoupons = \Our\RedisHelper::cachedFunction(\Redis\Db13\MemberCouponRedisModel::getInstance(), array(&$memberCouponDao, 'getList'),array(array('coupon_id'=>$where['couponId'],'member_id'=>$memberId)),\Our\ApiConst::oneHour,array($memberId));
......@@ -287,10 +288,22 @@ class CouponServiceModel extends \Business\AbstractModel{
public function getStoreCoupons($where,$memberId = null){
$couponDao = \DAO\Coupon\CouponModel::getInstance();
$couponDao->validStoreCouponParam($where);
$couponList = \Our\RedisHelper::cachedFunction(\Redis\Db13\CouponRedisModel::getInstance(), array(&$this, 'getStoreCouponsById'),array($where['storeId'],$memberId),\Our\ApiConst::oneHour,array($where['storeId']."_".$memberId));
if($couponList){
$couponList = \Our\RedisHelper::cachedFunction(\Redis\Db13\CouponRedisModel::getInstance(), array(&$this, 'getStoreCouponsById'),array($where['storeId'],$memberId,\Our\ApiConst::one),\Our\ApiConst::oneHour,array($where['storeId']."_".$memberId));
//var_dump($couponList);
if($couponList) {
$couponList = array_values($couponList);
$couponList =$this->sortCouponList($couponList);
$tempCouponList = array();
foreach($couponList as $tempCoupon){
if($tempCoupon['startTime']<TIMESTAMP&&$tempCoupon['endTime']>=TIMESTAMP){
unset($tempCoupon['startTime']);
unset($tempCoupon['endTime']);
$tempCouponList[] = $tempCoupon;
}
}
$couponList = $tempCouponList;
if($couponList){
$couponList =$this->sortCouponList($couponList);
}
}else{
$couponList = array();
}
......@@ -302,28 +315,37 @@ class CouponServiceModel extends \Business\AbstractModel{
$couponDao = \DAO\Coupon\CouponModel::getInstance();
$couponDao->validStoreCouponParam($where);
$couponList = \Our\RedisHelper::cachedFunction(\Redis\Db13\CouponRedisModel::getInstance(), array(&$this, 'getStoreCouponsById'),array($where['storeId'],$memberId,\Our\ApiConst::one),\Our\ApiConst::oneHour,array($where['storeId']."_".$memberId));
if($couponList){
$couponList = array_values($couponList);
$couponList = $this->sortCouponList($couponList);
if(count($couponList)>=\Our\ApiConst::defaultCouponTitleLength){
$couponTitleArray= array_slice($couponList,0,\Our\ApiConst::defaultCouponTitleLength);
}else{
$couponTitleArray= $couponList;
}
$couponTitles = array();
foreach($couponTitleArray as $coupon){
if($coupon['type'] == \Our\ApiConst::noLimitCouponType){
$couponTitles[] = $coupon['title'].\Our\DescribeConst::noLimitGoodsCouponName;
}else if($coupon['type'] == \Our\ApiConst::fullMinusCouponType){
$couponTitles[] = str_replace(\Our\DescribeConst::available,\Our\DescribeConst::minus.$coupon['title'],$coupon['subTitle']);
}else{
$couponTitles[] = $coupon['subTitle'];
}
if(!$couponList){
return array('couponsTitle'=>array(),'coupons'=>array());
}
$couponList = array_values($couponList);
$tempCouponList = array();
foreach($couponList as $tempCoupon){
if($tempCoupon['startTime']<TIMESTAMP&&$tempCoupon['endTime']>=TIMESTAMP){
$tempCouponList[] = $tempCoupon;
}
return array('couponsTitle'=>$couponTitles,'coupons'=>$couponList);
}else{
}
$couponList = $tempCouponList;
if(!$couponList){
return array('couponsTitle'=>array(),'coupons'=>array());
}
$couponList = $this->sortCouponList($couponList);
if(count($couponList)>=\Our\ApiConst::defaultCouponTitleLength){
$couponTitleArray= array_slice($couponList,0,\Our\ApiConst::defaultCouponTitleLength);
}else{
$couponTitleArray= $couponList;
}
$couponTitles = array();
foreach($couponTitleArray as $coupon){
if($coupon['type'] == \Our\ApiConst::noLimitCouponType){
$couponTitles[] = $coupon['title'].\Our\DescribeConst::noLimitGoodsCouponName;
}else if($coupon['type'] == \Our\ApiConst::fullMinusCouponType){
$couponTitles[] = str_replace(\Our\DescribeConst::available,\Our\DescribeConst::minus.$coupon['title'],$coupon['subTitle']);
}else{
$couponTitles[] = $coupon['subTitle'];
}
}
return array('couponsTitle'=>$couponTitles,'coupons'=>$couponList);
}
public function validCouponStore($where){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment