mtopcard.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace mtopcard;
  3. #用户卡的类型
  4. const UnknownCard = 0;
  5. const PetroChinaCard = 1; //中石油
  6. const SinopecCard = 2; //中石化
  7. const PhoneCard = 3; //手机卡
  8. const ChinaMobileCard = 4; //手机卡
  9. const ChinaUnicomCard = 5; //手机卡
  10. const ChinaTelecomCard = 6; //手机卡
  11. #卡的状态
  12. const CardNormal = 1;
  13. const CardDeled = 2;
  14. #限制参数
  15. const UserMaxCards = 10;
  16. const CardMaxUsers = 5;
  17. #card_key参数设置
  18. const UnusedCard = 0;
  19. const ReserveCard = 1;
  20. const AssignedCard = 2;
  21. const FreezedCard = 3;
  22. #充值卡类型
  23. const OilCardPaper = 1;
  24. const PhoneCardPaper = 2;
  25. function month_stamp($time=null) : int {
  26. $date = getdate($time);
  27. $stamp = $date['year'] * 100 + $date['mon'];
  28. return $stamp;
  29. }
  30. function topcard_type($str_type)
  31. {
  32. if(empty($str_type)) {
  33. return UnknownCard;
  34. }
  35. $str_type = trim(strtolower($str_type));
  36. if($str_type == 'petrochina') { //中石油
  37. return PetroChinaCard;
  38. }
  39. elseif ($str_type == 'sinopec') { //中石化
  40. return SinopecCard;
  41. }
  42. elseif($str_type == 'phone') { //手机卡
  43. return PhoneCard;
  44. }
  45. else {
  46. return UnknownCard;
  47. }
  48. }
  49. function scard_type($card_type)
  50. {
  51. if($card_type == PetroChinaCard) { //中石油
  52. return 'petrochina';
  53. }
  54. elseif ($card_type == SinopecCard) { //中石化
  55. return 'sinopec';
  56. }
  57. elseif($card_type == PhoneCard) { //手机卡
  58. return 'phone';
  59. }
  60. else {
  61. return 'unknown';
  62. }
  63. }
  64. require_once(BASE_HELPER_PATH . '/mtopcard/topcard.php');
  65. require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php');
  66. require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php');
  67. require_once(BASE_HELPER_PATH . '/mtopcard/cards_helper.php');
  68. function priority_cards($member_id, $page_type = '')
  69. {
  70. if($page_type == 'oil') {
  71. $types = [PetroChinaCard,SinopecCard];
  72. }
  73. elseif($page_type == 'phone') {
  74. $types = [PhoneCard];
  75. }
  76. else {
  77. $types = [PetroChinaCard,SinopecCard,PhoneCard];
  78. }
  79. $user_cards = new user_topcards($member_id);
  80. return $user_cards->priority_cards($types);
  81. }
  82. function topcard_format($card_list)
  83. {
  84. $ret = [];
  85. foreach ($card_list as $item) {
  86. $card = new topcard($item);
  87. $item = $card->format();
  88. $item['card_type'] = scard_type($item['card_type']);
  89. $ret[] = $item;
  90. }
  91. return $ret;
  92. }
  93. function card_type($cardno)
  94. {
  95. if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
  96. return SinopecCard;
  97. }
  98. elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
  99. return PetroChinaCard;
  100. }
  101. elseif(preg_match( '/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]19[578])\d{8}$/',$cardno,$matches)) {
  102. return ChinaMobileCard;
  103. }
  104. elseif(preg_match( '/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/',$cardno,$matches)) {
  105. return ChinaUnicomCard;
  106. }
  107. elseif(preg_match( '/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/',$cardno,$matches)) {
  108. return ChinaTelecomCard;
  109. }
  110. else {
  111. return UnknownCard;
  112. }
  113. }
  114. function oil_type($cardno)
  115. {
  116. if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
  117. return SinopecCard;
  118. }
  119. elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
  120. return PetroChinaCard;
  121. }
  122. else {
  123. return UnknownCard;
  124. }
  125. }