No Description

CustomerController.php 8.1KB

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