mtopcard.php 8.5 KB

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