mtopcard.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. namespace mtopcard;
  3. require_once(BASE_HELPER_PATH . '/mtopcard/card_query.php');
  4. require_once(BASE_HELPER_PATH . '/mtopcard/topcard.php');
  5. require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php');
  6. require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php');
  7. require_once(BASE_HELPER_PATH . '/mtopcard/cards_helper.php');
  8. #用户卡的类型
  9. const UnknownCard = 0;
  10. const PetroChinaCard = 1; //中石油
  11. const SinopecCard = 2; //中石化
  12. const PhoneCard = 3; //手机卡
  13. const ChinaMobileCard = 4; //手机卡
  14. const ChinaUnicomCard = 5; //手机卡
  15. const ChinaTelecomCard = 6; //手机卡
  16. const ThirdRefillCard = 7; //三方账号充值
  17. //三方产品类型
  18. const ThirdOnlineProduct = 1;
  19. const ThirdElectricProduct = 2;
  20. const ThirdSMSProduct = 3;
  21. //三方卡号类型:1 手机号,2 QQ号,3 微信号,4 电卡
  22. const ThirdCardPhone = 1;
  23. const ThirdCardQQ = 2;
  24. const ThirdCardWexin = 3;
  25. const ThirdCardElect = 4;
  26. const ElectricCompanyTypes = ['nation', 'south'];
  27. const ElectricUseTypes = ['home', 'commerce', 'pedlar'];
  28. const CardidVerifyLength = 6;
  29. #卡的状态
  30. const CardNormal = 1;
  31. const CardDeled = 2;
  32. #限制参数
  33. const UserMaxCards = 10;
  34. const CardMaxUsers = 5;
  35. #card_key参数设置
  36. const UnusedCard = 0;
  37. const ReserveCard = 1;
  38. const AssignedCard = 2;
  39. const FreezedCard = 3;
  40. #充值卡类型
  41. const OilCardPaper = 1;
  42. const PhoneCardPaper = 2;
  43. const ThirdCardPaper = 3;
  44. #省份列表
  45. const ProvinceList = [
  46. 1 => '北京',
  47. 2 => '天津',
  48. 3 => '河北',
  49. 4 => '山西',
  50. 5 => '内蒙古',
  51. 6 => '辽宁',
  52. 7 => '吉林',
  53. 8 => '黑龙江',
  54. 9 => '上海',
  55. 10 => '江苏',
  56. 11 => '浙江',
  57. 12 => '安徽',
  58. 13 => '福建',
  59. 14 => '江西',
  60. 15 => '山东',
  61. 16 => '河南',
  62. 17 => '湖北',
  63. 18 => '湖南',
  64. 19 => '广东',
  65. 20 => '广西',
  66. 21 => '海南',
  67. 22 => '重庆',
  68. 23 => '四川',
  69. 24 => '贵州',
  70. 25 => '云南',
  71. 26 => '西藏',
  72. 27 => '陕西',
  73. 28 => '甘肃',
  74. 29 => '青海',
  75. 30 => '宁夏',
  76. 31 => '新疆'
  77. ];
  78. const Prov2Noes = [
  79. '北京' => 1,
  80. '天津' => 2,
  81. '河北' => 3,
  82. '山西' => 4,
  83. '内蒙古' => 5,
  84. '辽宁' => 6,
  85. '吉林' => 7,
  86. '黑龙江' => 8,
  87. '上海' => 9,
  88. '江苏' => 10,
  89. '浙江' => 11,
  90. '安徽' => 12,
  91. '福建' => 13,
  92. '江西' => 14,
  93. '山东' => 15,
  94. '河南' => 16,
  95. '湖北' => 17,
  96. '湖南' => 18,
  97. '广东' => 19,
  98. '广西' => 20,
  99. '海南' => 21,
  100. '重庆' => 22,
  101. '四川' => 23,
  102. '贵州' => 24,
  103. '云南' => 25,
  104. '西藏' => 26,
  105. '陕西' => 27,
  106. '甘肃' => 28,
  107. '青海' => 29,
  108. '宁夏' => 30,
  109. '新疆' => 31,
  110. ];
  111. #空号拦截状态
  112. const CardState = [
  113. 0 => '空号',
  114. 1 => '实号',
  115. 2 => '停机',
  116. 3 => '库无',
  117. 4 => '沉默号',
  118. 5 => '风险号'
  119. ];
  120. function month_stamp($time=null) : int {
  121. $date = getdate($time);
  122. $stamp = $date['year'] * 100 + $date['mon'];
  123. return $stamp;
  124. }
  125. function topcard_type($str_type)
  126. {
  127. if(empty($str_type)) {
  128. return UnknownCard;
  129. }
  130. $str_type = trim(strtolower($str_type));
  131. if($str_type == 'petrochina') { //中石油
  132. return PetroChinaCard;
  133. }
  134. elseif ($str_type == 'sinopec') { //中石化
  135. return SinopecCard;
  136. }
  137. elseif ($str_type == 'chinamobile') { //中石化
  138. return ChinaMobileCard;
  139. }
  140. elseif($str_type == 'chinaunicom') { //手机卡
  141. return ChinaUnicomCard;
  142. }
  143. elseif($str_type == 'chinatelecom') { //手机卡
  144. return ChinaTelecomCard;
  145. }
  146. elseif($str_type == 'phone') { //手机卡
  147. return PhoneCard;
  148. }
  149. elseif($str_type == 'third') {
  150. return ThirdRefillCard;
  151. }
  152. else {
  153. return UnknownCard;
  154. }
  155. }
  156. function scard_type($card_type)
  157. {
  158. if($card_type == PetroChinaCard) { //中石油
  159. return 'petrochina';
  160. }
  161. elseif ($card_type == SinopecCard) { //中石化
  162. return 'sinopec';
  163. }
  164. elseif ($card_type == ChinaMobileCard) { //中石化
  165. return 'chinamobile';
  166. }
  167. elseif($card_type == ChinaUnicomCard ) { //手机卡
  168. return 'chinaunicom';
  169. }
  170. elseif($card_type == ChinaTelecomCard) { //手机卡
  171. return 'chinatelecom';
  172. }
  173. elseif($card_type == PhoneCard) { //手机卡
  174. return 'phone';
  175. }
  176. elseif($card_type == ThirdRefillCard) {
  177. return 'third';
  178. }
  179. else {
  180. return 'unknown';
  181. }
  182. }
  183. function priority_cards($member_id, $page_type = '')
  184. {
  185. if($page_type == 'oil') {
  186. $types = [PetroChinaCard,SinopecCard];
  187. }
  188. elseif($page_type == 'phone') {
  189. $types = [PhoneCard];
  190. }
  191. else {
  192. $types = [PetroChinaCard,SinopecCard,PhoneCard];
  193. }
  194. $user_cards = new user_topcards($member_id);
  195. return $user_cards->priority_cards($types);
  196. }
  197. function topcard_format($card_list)
  198. {
  199. $ret = [];
  200. foreach ($card_list as $item) {
  201. $card = new topcard($item);
  202. $item = $card->format();
  203. $item['card_type'] = scard_type($item['card_type']);
  204. $ret[] = $item;
  205. }
  206. return $ret;
  207. }
  208. function simple_card_type($cardno)
  209. {
  210. if (preg_match('/^1[0-9]{18}$/', $cardno, $matches)) {
  211. return SinopecCard;
  212. } elseif (preg_match('/^9[0-9]{15}$/', $cardno, $matches)) {
  213. return PetroChinaCard;
  214. } elseif (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|15[012789]|17[28]|18[23478]|19[578])\d{8}$/', $cardno, $matches)) {
  215. return ChinaMobileCard;
  216. } elseif (preg_match('/^(?:13[0-2]|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
  217. return ChinaUnicomCard;
  218. } elseif (preg_match('/^(?:133|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
  219. return ChinaTelecomCard;
  220. } elseif (preg_match('/^(1349)\d{7}$/', $cardno, $matches)) {
  221. return ChinaTelecomCard;
  222. } elseif (preg_match('/^1\d{10}$/', $cardno, $matches)) {
  223. return PhoneCard;
  224. } else {
  225. return UnknownCard;
  226. }
  227. }
  228. function card_type($cardno,&$regin_no)
  229. {
  230. $regin_no = -1;
  231. if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
  232. return SinopecCard;
  233. }
  234. elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
  235. return PetroChinaCard;
  236. }
  237. elseif(preg_match('/^1\d{10}$/',$cardno,$matches))
  238. {
  239. $regin_no = -1;
  240. if (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|15[012789]|17[28]|18[23478]|19[578])\d{8}$/', $cardno, $matches)) {
  241. return ChinaMobileCard;
  242. }
  243. elseif (preg_match('/^(?:13[0-2]|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
  244. return ChinaUnicomCard;
  245. }
  246. elseif (preg_match('/^(?:133|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
  247. return ChinaTelecomCard;
  248. }
  249. elseif (preg_match('/^(1349)\d{7}$/', $cardno, $matches)) {
  250. return ChinaTelecomCard;
  251. }
  252. else {
  253. return UnknownCard;
  254. }
  255. }
  256. else {
  257. return UnknownCard;
  258. }
  259. }
  260. function oil_type($cardno)
  261. {
  262. if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
  263. return SinopecCard;
  264. }
  265. elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
  266. return PetroChinaCard;
  267. }
  268. else {
  269. return UnknownCard;
  270. }
  271. }
  272. function is_validate($status)
  273. {
  274. if (in_array($status, [0,5])) {
  275. return false;
  276. } else {
  277. return true;
  278. }
  279. }
  280. function valid_phone($card_no)
  281. {
  282. $query = new card_query();
  283. return $query->validate($card_no);
  284. }
  285. function electric_product_code($company_type,$use_type,$refill_amount)
  286. {
  287. // const ElectricCompanyTypes = ['nation', 'south'];
  288. // const ElectricUseTypes = ['home', 'commerce', 'pedlar'];
  289. return "DF_{$company_type}_{$use_type}_{$refill_amount}";
  290. }
  291. function is_alpha($text) {
  292. return is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
  293. };
  294. function electric_exists($product) {
  295. static $products = [];
  296. return in_array($product,$products);
  297. }