Keine Beschreibung

CustomerGiftReceives.php 2.8KB

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