where('phone',$phone)->where('gift_type',$type)->where('is_del',0)->get(); $log = json_decode(json_encode($log),true); return $log; } /** * 获取会员用户每月礼包剩余领取次数 * @param $phone */ public static function getCustomerResidualTimes($phone,$endTime) { $self = new self(); $times = 0; #判断本月有没有领取过 $info = $self->where('phone',$phone)->where('gift_type',0)->where('dtime','>=',date('Y-m-01',time()))->where('is_del',0)->first(); if(!$info){ $times++; #判断现在距离会员结束还有几个月,最后一个月不算 $start = new \DateTime(date('Y-m-t',time())); $end = new \DateTime(date('Y-m-d',strtotime($endTime.' -1 day'))); $diff = $start->diff($end); $diff_month = $diff->format('%y')*12+$diff->format('%m'); $times += $diff_month; return $times; } else { #判断现在距离会员结束还有几个月,最后一个月不算 $start = new \DateTime(date('Y-m-t',time())); $end = new \DateTime(date('Y-m-d',strtotime($endTime.' -1 day'))); $diff = $start->diff($end); $diff_month = $diff->format('%y')*12+$diff->format('%m'); $times += $diff_month; return $times; } } /** * 判断用户是否能够领取礼包 * @param $phone * @param $type * @return bool */ public static function judgeWhetherTheUserReceivesTheGiftBag($phone,$type){ $self = new self(); $mtime = date('Y-m-01'); if($type == 0){ $customerInfo = CustomerVip::getCustomerInformation($phone); $num = CustomerGiftReceives::getCustomerResidualTimes($phone,$customerInfo->vip_end_time); $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first(); if(empty($if_m_gift) && ($num >0)){ return true; } else { return false; } } else { #判断本月有没有领取过 $customerInfo = CustomerVip::getCustomerInformation($phone); //判断生日礼 $birth_stime = date('m-01', strtotime($customerInfo->birthday)); $birth_etime = date('m-t', strtotime($customerInfo->birthday)); $today = date('m-d'); if($today>=$birth_stime && $today<=$birth_etime){ //生日期内,判断是否已领 $if_b_gift = $self::where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first(); if(empty($if_b_gift)){ return true; } else { return false; } } return false; } } }