From 9e182dcfe01b176aa5fe3a6f4f2c589c5f44d0e7 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Fri, 25 Feb 2022 18:17:23 +0800 Subject: [PATCH] setter --- app/controller/api/Business.php | 2 +- app/model/CouponMain.php | 11 ++++++++- app/traits/CouponTrait.php | 41 ++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index 6a0d99f..52d5970 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -389,7 +389,7 @@ class Business extends Base $data["content"] = (string)$couponMain->content; - //未登录可以领取 0可领取 1已领取 + //未登录可以领取 0可领取 1已领取 2 已领完 if (empty($account)) { $data["receiveStatus"] = CouponMain::COMMON_OFF;//领取状态 }else{ diff --git a/app/model/CouponMain.php b/app/model/CouponMain.php index 6381155..a9c02f0 100644 --- a/app/model/CouponMain.php +++ b/app/model/CouponMain.php @@ -23,7 +23,16 @@ class CouponMain extends Base const on_screen_yes = 1;//展示到商圈大屏 const on_screen_no = 0;//不展示到商圈大屏 - const min_consumer_money = 0.3;//红包最小金额 + const min_consumer_money = 0.3;// + + const receive_status_over = 2;//领取状态 已领完 + const receive_status_received = 1;//领取状态 已领完 + const receive_status_default = 0;//领取状态 可领取 + + + + + public function business() { diff --git a/app/traits/CouponTrait.php b/app/traits/CouponTrait.php index 261145b..96a9ac4 100644 --- a/app/traits/CouponTrait.php +++ b/app/traits/CouponTrait.php @@ -66,38 +66,47 @@ trait CouponTrait */ public function getCouponReceiveStatus($accountCode,CouponMain $couponMain ) { + + //如果 领取数量==总数 + if($couponMain['received_count'] == $couponMain['count'] ){ + return CouponMain::receive_status_over; + } + + //没有领取记录就可以领取 $ReceiveCount = Coupon::where("coupon_id",$couponMain->id) ->where("consumer_code",$accountCode) ->count(); if($ReceiveCount <= 0){ - return CouponMain::COMMON_OFF; + return CouponMain::receive_status_default; + }else{ + return CouponMain::receive_status_received; } //确定使用规则 - $usingRule =UsingRule::where("coupon_id",$couponMain->id)->find(); - if(empty($usingRule)){ - return CouponMain::COMMON_OFF; - } + //$usingRule =UsingRule::where("coupon_id",$couponMain->id)->find(); + //if(empty($usingRule)){ + // return CouponMain::COMMON_OFF; + //} //单人日限量 - $todayReceivesCount = Coupon::where("coupon_id",$couponMain->id) - ->where("consumer_code",$accountCode) - ->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")]) - ->count(); + //$todayReceivesCount = Coupon::where("coupon_id",$couponMain->id) + // ->where("consumer_code",$accountCode) + // ->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")]) + // ->count(); - if($todayReceivesCount >= $usingRule->person_day_total ){ + //if($todayReceivesCount >= $usingRule->person_day_total ){ - return CouponMain::COMMON_ON; - } + //return CouponMain::COMMON_ON; + //} //单人总限量 - if($ReceiveCount >= $usingRule->person_total ){ - return CouponMain::COMMON_ON; - } + //if($ReceiveCount >= $usingRule->person_total ){ + // return CouponMain::COMMON_ON; + //} + - return CouponMain::COMMON_OFF; }