No Description

CustomerController.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2019/12/3
  6. * Time: 16:00
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Customer;
  10. use App\CustomerCoupons;
  11. use App\CustomerGiftReceives;
  12. use App\CustomerMonthGift;
  13. use App\CustomerVip;
  14. use App\Goods;
  15. use App\GoodsSkus;
  16. use App\Http\Controllers\Controller;
  17. use Illuminate\Http\Request;
  18. class CustomerController extends Controller
  19. {
  20. /**
  21. * 获取买家收货人地址列表
  22. * @param Request $request
  23. * @return array
  24. */
  25. public function getAddressList(Request $request) {
  26. $phone = $request->input('phone',null);
  27. if(is_null($phone)){
  28. return self::returnValue(['买家手机号必填'],2000);
  29. }
  30. $list = Customer::select('receiverState','receiverCity','receiverAddress','fanTime','phone','name','buyerName')->where('buyerMobile',$phone)->get();
  31. $list = json_decode(json_encode($list),true);
  32. $info = CustomerVip::getCustomerInformation($phone);
  33. if(!$info){
  34. $status = 0;
  35. } else {
  36. $status = 1;
  37. }
  38. $data['address_list'] = $list;
  39. $data['vip_status'] = $status;
  40. return self::returnValue($data,200);
  41. }
  42. /**
  43. * 获取用户会员信息
  44. * @param Request $request
  45. * @return array
  46. */
  47. public function getVipInformation(Request $request) {
  48. $phone = $request->input('phone',null);
  49. if(is_null($phone)){
  50. return self::returnValue(['买家手机号必填'],2000);
  51. }
  52. #判断该用户是否为会员
  53. $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone);
  54. if(!$flag){
  55. return self::returnValue(['该用户还不是会员'],2014);
  56. }
  57. $customerInfo = CustomerVip::getCustomerInformation($phone);
  58. $currentDate = date('Y-m-d',time());
  59. $customer['vip_end_time'] = $customerInfo->vip_end_time;
  60. $customer['name'] = $customerInfo->name;
  61. $customer['birthday'] = date('m-d',strtotime($customerInfo->birthday));
  62. $mtime = date('Y-m-01');
  63. //生日套餐
  64. $birthdayGift = CustomerGiftReceives::getCustomerReceivesLog($phone,1);
  65. //判断生日礼
  66. $birth_stime = date('m-01', strtotime($customerInfo->birthday));
  67. $birth_etime = date('m-t', strtotime($customerInfo->birthday));
  68. $today = date('m-d');
  69. if($today>=$birth_stime && $today<=$birth_etime){
  70. //生日期内,判断是否已领
  71. $if_b_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first();
  72. if(empty($if_b_gift)){
  73. $birthdayGiftStatus = 1;
  74. } else {
  75. $birthdayGiftStatus = 0;
  76. }
  77. }
  78. if($birthdayGift){
  79. $birthdayGiftNumber = 0;
  80. } else {
  81. $birthdayGiftNumber = 1;
  82. }
  83. //每月礼包
  84. $num = CustomerGiftReceives::getCustomerResidualTimes($phone,$customerInfo->vip_end_time);
  85. $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first();
  86. if(empty($if_m_gift) && ($num >0)){
  87. $monthGiftStatus = 1;
  88. } else {
  89. $monthGiftStatus = 0;
  90. }
  91. //代金券
  92. $coupons = CustomerCoupons::where('phone',$phone)->where('is_use',0)->where('end_time','>=',$currentDate)->count();
  93. if($coupons > 0){
  94. $couponStatus = 1;
  95. } else {
  96. $couponStatus = 0;
  97. }
  98. $customer['coupon_status'] = $couponStatus;//能否使用代金券
  99. $customer['coupon_number'] = $coupons;//剩余代金券张数
  100. $customer['birthday_gift_status'] = $birthdayGiftStatus;//能否领取生日礼包
  101. $customer['birthday_gift_number'] = $birthdayGiftNumber;//生日礼包是否领取
  102. $customer['month_gift_number'] = $num;//每月礼包剩余次数
  103. $customer['month_gift_status'] = $monthGiftStatus;//能否领取当月礼包
  104. return self::returnValue($customer,200);
  105. }
  106. /**
  107. * 获取用户礼包商品列表
  108. * @param Request $request
  109. * @return array
  110. */
  111. public function getMonthGiftList(Request $request) {
  112. $type = $request->input('type',0);
  113. $phone = $request->input('phone',null);
  114. if(($type == 1) && is_null($phone)){
  115. return self::returnValue(['买家手机号必填'],2000);
  116. }
  117. #判断该用户是否为会员
  118. $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone);
  119. if(!$flag){
  120. return self::returnValue(['该用户还不是会员'],2014);
  121. }
  122. #判断该用户能否领取当月礼包
  123. $flag = CustomerGiftReceives::judgeWhetherTheUserReceivesTheGiftBag($phone,$type);
  124. if(!$flag){
  125. return self::returnValue(['不能领取当月礼包'],2015);
  126. }
  127. //当月礼品
  128. $mtime = date('Y-m-01');
  129. if($type == 1){
  130. $gift_info = CustomerMonthGift::where('type',1)->get();
  131. } else {
  132. $gift_info = CustomerMonthGift::where('mtime',$mtime)->where('type',0)->get();
  133. }
  134. $gift_info = json_decode(json_encode($gift_info), true);
  135. $m_gift=array();
  136. $b_gift=array();
  137. foreach($gift_info as $k=>$v) {
  138. //获取礼品信息
  139. $goods_info = Goods::where('id', $v['goods_id'])->where('is_del',0)->first();
  140. $sku = GoodsSkus::where('id', $v['sku_id'])->where('is_del', 0)->where(function ($query) {
  141. $query->where('is_white', 1)->orWhere('quantity', '>', 0);
  142. })->first();
  143. if (empty($sku)) continue;
  144. //计算实际库存 -还未到卖家云的量
  145. $quantity = GoodsSkus::actualQuantity($v['sku_id']);
  146. if ($quantity <= 0) {
  147. continue;
  148. }
  149. $data = array();
  150. $data['id'] = $v['id'];
  151. $data['goods_name'] = $goods_info->name;
  152. $data['propsName'] = $sku['propsName'];
  153. $data['price'] = $sku['price'];
  154. $data['picUrl'] = $goods_info->picUrl;
  155. if ($v['type'] == 0) {
  156. $m_gift[] = $data;
  157. } else {
  158. $b_gift[] = $data;
  159. }
  160. }
  161. if($type == 1){
  162. return self::returnValue($b_gift,200);
  163. } else {
  164. return self::returnValue($m_gift,200);
  165. }
  166. }
  167. /**
  168. * 获取用户优惠券列表
  169. * @param Request $request
  170. * @return array
  171. */
  172. public function getCouponsList(Request $request) {
  173. $phone = $request->input('phone',null);
  174. if(is_null($phone)){
  175. return self::returnValue(['买家手机号必填'],2000);
  176. }
  177. #判断该用户是否为会员
  178. $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone);
  179. if(!$flag){
  180. return self::returnValue(['该用户还不是会员'],2014);
  181. }
  182. $list = CustomerCoupons::getCustomerCouponsLog($phone);
  183. $list = array_map(function($value){
  184. $item['id'] = $value['id'];
  185. $item['coupon_price'] = $value['coupon_price'];
  186. $item['end_time'] = date('Y-m-d',strtotime($value['end_time']));
  187. $item['is_use'] = $value['is_use'];
  188. $item['order_id'] = $value['order_id'];
  189. if($value['is_use'] == 1){
  190. $item['status'] = 1;
  191. } else if(time() <= strtotime($value['end_time'])){
  192. $item['status'] = 0;
  193. } else {
  194. $item['status'] = 1;
  195. }
  196. $item['use_time'] = $value['use_time'];
  197. return $item;
  198. },$list);
  199. return self::returnValue($list,200);
  200. }
  201. }