No Description

CustomerGiftReceives.php 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2019/12/2
  6. * Time: 15:26
  7. */
  8. namespace App;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Support\Facades\DB;
  11. class CustomerGiftReceives extends Model
  12. {
  13. protected $table = 'customer_gift_receives';
  14. public $timestamps = false;
  15. public static function getCustomerReceivesLog($phone,$type) {
  16. $self = new self();
  17. $log = $self->where('phone',$phone)->where('gift_type',$type)->where('is_del',0)->get();
  18. $log = json_decode(json_encode($log),true);
  19. return $log;
  20. }
  21. /**
  22. * 获取会员用户每月礼包剩余领取次数
  23. * @param $phone
  24. */
  25. public static function getCustomerResidualTimes($phone,$endTime) {
  26. $self = new self();
  27. $times = 0;
  28. #判断本月有没有领取过
  29. $info = $self->where('phone',$phone)->where('gift_type',0)->where('dtime','>=',date('Y-m-01',time()))->where('is_del',0)->first();
  30. if(!$info){
  31. $times++;
  32. #判断现在距离会员结束还有几个月,最后一个月不算
  33. $start = new \DateTime(date('Y-m-t',time()));
  34. $end = new \DateTime(date('Y-m-d',strtotime($endTime.' -1 day')));
  35. $diff = $start->diff($end);
  36. $diff_month = $diff->format('%y')*12+$diff->format('%m');
  37. $times += $diff_month;
  38. return $times;
  39. } else {
  40. #判断现在距离会员结束还有几个月,最后一个月不算
  41. $start = new \DateTime(date('Y-m-t',time()));
  42. $end = new \DateTime(date('Y-m-d',strtotime($endTime.' -1 day')));
  43. $diff = $start->diff($end);
  44. $diff_month = $diff->format('%y')*12+$diff->format('%m');
  45. $times += $diff_month;
  46. return $times;
  47. }
  48. }
  49. /**
  50. * 判断用户是否能够领取礼包
  51. * @param $phone
  52. * @param $type
  53. * @return bool
  54. */
  55. public static function judgeWhetherTheUserReceivesTheGiftBag($phone,$type){
  56. $self = new self();
  57. $mtime = date('Y-m-01');
  58. if($type == 0){
  59. $customerInfo = CustomerVip::getCustomerInformation($phone);
  60. $num = CustomerGiftReceives::getCustomerResidualTimes($phone,$customerInfo->vip_end_time);
  61. $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first();
  62. if(empty($if_m_gift) && ($num >0)){
  63. return true;
  64. } else {
  65. return false;
  66. }
  67. } else {
  68. #判断本月有没有领取过
  69. $customerInfo = CustomerVip::getCustomerInformation($phone);
  70. //判断生日礼
  71. $birth_stime = date('m-01', strtotime($customerInfo->birthday));
  72. $birth_etime = date('m-t', strtotime($customerInfo->birthday));
  73. $today = date('m-d');
  74. if($today>=$birth_stime && $today<=$birth_etime){
  75. //生日期内,判断是否已领
  76. $if_b_gift = $self::where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first();
  77. if(empty($if_b_gift)){
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. return false;
  84. }
  85. }
  86. }