Bez popisu

CustomerController.php 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 = 1;
  85. } else {
  86. $birthdayGiftNumber = 0;
  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. $status = $request->input('status',0);
  120. if(is_null($phone)){
  121. return self::returnValue(['买家手机号必填'],2000);
  122. }
  123. #判断该用户是否为会员
  124. $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone);
  125. if(!$flag){
  126. return self::returnValue(['该用户还不是会员'],2014);
  127. }
  128. #判断该用户能否领取当月礼包
  129. $flag = CustomerGiftReceives::judgeWhetherTheUserReceivesTheGiftBag($phone,$type);
  130. if(($status == 0) && (!$flag)){
  131. return self::returnValue(['不能领取当月礼包'],2015);
  132. }
  133. //当月礼品
  134. $mtime = date('Y-m-01');
  135. if($type == 1){
  136. $gift_info = CustomerMonthGift::where('type',1)->get();
  137. } else {
  138. $gift_info = CustomerMonthGift::where('mtime',$mtime)->where('type',0)->get();
  139. }
  140. $gift_info = json_decode(json_encode($gift_info), true);
  141. $m_gift=array();
  142. $b_gift=array();
  143. foreach($gift_info as $k=>$v) {
  144. //获取礼品信息
  145. $goods_info = Goods::where('id', $v['goods_id'])->where('is_del',0)->first();
  146. $sku = GoodsSkus::where('id', $v['sku_id'])->where('is_del', 0)->where(function ($query) {
  147. $query->where('is_white', 1)->orWhere('quantity', '>', 0);
  148. })->first();
  149. if (empty($sku)) continue;
  150. //计算实际库存 -还未到卖家云的量
  151. $quantity = GoodsSkus::actualQuantityByRedis($v['sku_id']);
  152. $quantity = $quantity['quantity'];
  153. if ($quantity <= 0) {
  154. continue;
  155. }
  156. $data = array();
  157. $data['id'] = $v['id'];
  158. $data['goods_name'] = $goods_info->name;
  159. $data['propsName'] = $sku['propsName'];
  160. $data['price'] = ($v['num']*$sku['price']);
  161. $data['picUrl'] = $goods_info->picUrl;
  162. if($sku['is_weigh'] == 1){
  163. $data['num'] = $v['num'];
  164. } else{
  165. $data['num'] = $v['num'];
  166. }
  167. if ($v['type'] == 0) {
  168. $m_gift[] = $data;
  169. } else {
  170. $b_gift[] = $data;
  171. }
  172. }
  173. if($type == 1){
  174. return self::returnValue($b_gift,200);
  175. } else {
  176. return self::returnValue($m_gift,200);
  177. }
  178. }
  179. /**
  180. * 获取用户优惠券列表
  181. * @param Request $request
  182. * @return array
  183. */
  184. public function getCouponsList(Request $request) {
  185. $phone = $request->input('phone',null);
  186. if(is_null($phone)){
  187. return self::returnValue(['买家手机号必填'],2000);
  188. }
  189. #判断该用户是否为会员
  190. $flag = CustomerVip::judgeWhetherTheUserIsAMember($phone);
  191. if(!$flag){
  192. return self::returnValue(['该用户还不是会员'],2014);
  193. }
  194. $list = CustomerCoupons::getCustomerCouponsLog($phone);
  195. $list = array_map(function($value){
  196. $item['id'] = $value['id'];
  197. $item['coupon_price'] = $value['coupon_price'];
  198. $item['end_time'] = date('Y-m-d',strtotime($value['end_time']));
  199. $item['is_use'] = $value['is_use'];
  200. $item['order_id'] = $value['order_id'];
  201. if($value['is_use'] == 1){
  202. $item['status'] = 1;
  203. $item['use_time'] = $value['use_time'];
  204. } else if(time() <= strtotime($value['end_time'])){
  205. $item['status'] = 0;
  206. $item['use_time'] = '';
  207. } else {
  208. $item['status'] = 1;
  209. $item['use_time'] = '';
  210. }
  211. return $item;
  212. },$list);
  213. return self::returnValue($list,200);
  214. }
  215. }