mtopcard.php 8.0 KB

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