mtopcard.php 8.8 KB

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