123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2019/12/3
- * Time: 16:00
- */
- namespace App\Http\Controllers\Api;
- use App\Customer;
- use App\CustomerCoupons;
- use App\CustomerGiftReceives;
- use App\CustomerMonthGift;
- use App\CustomerVip;
- use App\Goods;
- use App\GoodsSkus;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class CustomerController extends Controller
- {
- /**
- * 获取买家收货人地址列表
- * @param Request $request
- * @return array
- */
- public function getAddressList(Request $request) {
- $phone = $request->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);
- }
- }
|