input('phone',null); if(is_null($phone)){ return self::returnValue(['买家手机号必填'],2000); } $list = Customer::select('receiverState','receiverCity','receiverAddress','fanTime','phone','name','receiverDistrict')->where('buyerMobile',$phone)->get(); $list = json_decode(json_encode($list),true); $info = CustomerVip::getCustomerInformation($phone); if(!$info){ $status = 0; $name = ''; } else { $status = 1; $name = $info->name; } $data['address_list'] = $list; $data['vip_status'] = $status; $data['vip_name'] = $name; return self::returnValue($data,200); } /** * 获取用户会员信息 * @param Request $request * @return array */ public function getVipInformation(Request $request) { $phone = $request->input('phone',null); if(is_null($phone)){ return self::returnValue(['买家手机号必填'],2000); } #判断该用户是否为会员 $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone); if(!$flag){ return self::returnValue(['该用户还不是会员'],2014); } $customerInfo = CustomerVip::getCustomerInformation($phone); $currentDate = date('Y-m-d',time()); $customer['vip_end_time'] = $customerInfo->vip_end_time; $customer['name'] = $customerInfo->name; $customer['birthday'] = date('m-d',strtotime($customerInfo->birthday)); $mtime = date('Y-m-01'); //生日套餐 $birthdayGift = CustomerGiftReceives::getCustomerReceivesLog($phone,1); //判断生日礼 $birth_stime = date('m-01', strtotime($customerInfo->birthday)); $birth_etime = date('m-t', strtotime($customerInfo->birthday)); $today = date('m-d'); $birthdayGiftStatus = 0; if($today>=$birth_stime && $today<=$birth_etime){ //生日期内,判断是否已领 $if_b_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first(); if(empty($if_b_gift)){ $birthdayGiftStatus = 1; } else { $birthdayGiftStatus = 0; } } if($birthdayGift){ $birthdayGiftNumber = 1; } else { $birthdayGiftNumber = 0; } //每月礼包 $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)){ $monthGiftStatus = 1; } else { $monthGiftStatus = 0; } //代金券 $coupons = CustomerCoupons::where('phone',$phone)->where('is_use',0)->where('end_time','>=',$currentDate)->count(); if($coupons > 0){ $couponStatus = 1; } else { $couponStatus = 0; } $customer['coupon_status'] = $couponStatus;//能否使用代金券 $customer['coupon_number'] = $coupons;//剩余代金券张数 $customer['birthday_gift_status'] = $birthdayGiftStatus;//能否领取生日礼包 $customer['birthday_gift_number'] = $birthdayGiftNumber;//生日礼包是否领取 $customer['month_gift_number'] = $num;//每月礼包剩余次数 $customer['month_gift_status'] = $monthGiftStatus;//能否领取当月礼包 return self::returnValue($customer,200); } /** * 获取用户礼包商品列表 * @param Request $request * @return array */ public function getMonthGiftList(Request $request) { $type = $request->input('type',0); $phone = $request->input('phone',null); $status = $request->input('status',0); if(is_null($phone)){ return self::returnValue(['买家手机号必填'],2000); } #判断该用户是否为会员 $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone); if(!$flag){ return self::returnValue(['该用户还不是会员'],2014); } #判断该用户能否领取当月礼包 $flag = CustomerGiftReceives::judgeWhetherTheUserReceivesTheGiftBag($phone,$type); if(($status == 0) && (!$flag)){ return self::returnValue(['不能领取当月礼包'],2015); } //当月礼品 $mtime = date('Y-m-01'); if($type == 1){ $gift_info = CustomerMonthGift::where('type',1)->get(); } else { $gift_info = CustomerMonthGift::where('mtime',$mtime)->where('type',0)->get(); } $gift_info = json_decode(json_encode($gift_info), true); $m_gift=array(); $b_gift=array(); foreach($gift_info as $k=>$v) { //获取礼品信息 $goods_info = Goods::where('id', $v['goods_id'])->where('is_del',0)->first(); $sku = GoodsSkus::where('id', $v['sku_id'])->where('is_del', 0)->where(function ($query) { $query->where('is_white', 1)->orWhere('quantity', '>', 0); })->first(); if (empty($sku)) continue; //计算实际库存 -还未到卖家云的量 $quantity = GoodsSkus::actualQuantityByRedis($v['sku_id']); $quantity = $quantity['quantity']; if ($quantity <= 0) { continue; } $data = array(); $data['id'] = $v['id']; $data['goods_name'] = $goods_info->name; $data['propsName'] = $sku['propsName']; $data['price'] = ($v['num']*$sku['price']); $data['picUrl'] = $goods_info->picUrl; if($sku['is_weigh'] == 1){ $data['num'] = $v['num']; } else{ $data['num'] = $v['num']; } if ($v['type'] == 0) { $m_gift[] = $data; } else { $b_gift[] = $data; } } if($type == 1){ return self::returnValue($b_gift,200); } else { return self::returnValue($m_gift,200); } } /** * 获取用户优惠券列表 * @param Request $request * @return array */ public function getCouponsList(Request $request) { $phone = $request->input('phone',null); if(is_null($phone)){ return self::returnValue(['买家手机号必填'],2000); } #判断该用户是否为会员 $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone); if(!$flag){ return self::returnValue(['该用户还不是会员'],2014); } $list = CustomerCoupons::getCustomerCouponsLog($phone); $list = array_map(function($value){ $item['id'] = $value['id']; $item['coupon_price'] = $value['coupon_price']; $item['end_time'] = date('Y-m-d',strtotime($value['end_time'])); $item['is_use'] = $value['is_use']; $item['order_id'] = $value['order_id']; if($value['is_use'] == 1){ $item['status'] = 1; $item['use_time'] = $value['use_time']; } else if(time() <= strtotime($value['end_time'])){ $item['status'] = 0; $item['use_time'] = ''; } else { $item['status'] = 1; $item['use_time'] = ''; } return $item; },$list); return self::returnValue($list,200); } }