@@ -82,6 +82,8 @@ public function getInfo($id)
8282 $ info ['addressCode ' ] = $ code ['addressCode ' ];
8383 $ info ['address ' ] = is_array ($ addressInfo ) ? implode ($ addressInfo ) : '' ;
8484 $ info ['birthdayCode ' ] = date ('Y-m-d ' , strtotime ($ code ['birthdayCode ' ]));
85+ $ info ['constellation ' ] = $ this ->_getConstellation ($ code ['birthdayCode ' ]);
86+ $ info ['chineseZodiac ' ] = $ this ->_getChineseZodiac ($ code ['birthdayCode ' ]);
8587 $ info ['sex ' ] = ($ code ['order ' ] % 2 === 0 ? 0 : 1 );
8688 $ info ['length ' ] = $ code ['type ' ];
8789 $ info ['checkBit ' ] = $ code ['checkBit ' ];
@@ -188,6 +190,51 @@ private function _getAddressInfo($addressCode)
188190 }
189191 }
190192
193+ public function _getConstellation ($ birthdayCode )
194+ {
195+
196+ $ constellationList = $ this ->_getConstellationList ();
197+
198+ $ time = strtotime ($ birthdayCode );
199+ $ year = substr ($ birthdayCode , 0 ,4 );
200+ $ month = substr ($ birthdayCode , 4 , 2 );
201+ $ day = substr ($ birthdayCode , 6 ,2 );
202+
203+
204+ // 1月份与12月份特殊处理
205+ if ( ( $ month == 1 && $ day < 20 ) || ( $ month == 12 && $ day > 21 ) ){
206+ return $ constellationList [12 ]['name ' ];
207+ }else if ( $ month == 1 ){
208+ return $ constellationList [1 ]['name ' ];
209+ }else if ( $ month == 12 ){
210+ return $ constellationList [12 ]['name ' ];
211+ }
212+
213+ $ startDate = $ year .'- ' .$ constellationList [$ month ]['start_date ' ];
214+ $ endDate = $ year .'- ' .$ constellationList [$ month ]['end_date ' ];
215+ if ( strtotime ( $ startDate ) <= $ time && strtotime ( $ endDate ) >= $ time ){
216+ return $ constellationList [$ month ]['name ' ];
217+ }
218+ $ startDate = $ year .'- ' .$ constellationList [$ month -1 ]['start_date ' ];
219+ $ endDate = $ year .'- ' .$ constellationList [$ month -1 ]['end_date ' ];
220+ if ( strtotime ( $ startDate ) <= $ time && strtotime ( $ endDate ) >= $ time ){
221+ return $ constellationList [$ month -1 ]['name ' ];
222+ }
223+
224+ return '' ;
225+ }
226+
227+ public function _getChineseZodiac ($ birthdayCode )
228+ {
229+ $ chineseZodiacList = $ this ->_getChineseZodiacList ();
230+ $ start = 1900 ; // 子鼠
231+ $ end = substr ($ birthdayCode , 0 , 4 );
232+ $ key = ($ end - $ start ) % 12 ;
233+ $ key = $ key >= 0 ? $ key : ($ key + 12 );
234+ return $ chineseZodiacList [$ key ];
235+ }
236+
237+
191238 /**
192239 * 检查并拆分身份证号.
193240 *
@@ -361,4 +408,73 @@ private function _generatorBirthdayCode()
361408
362409 return $ birthdayCode ;
363410 }
411+
412+ /**
413+ * @return array
414+ */
415+ private function _getChineseZodiacList ()
416+ {
417+ return ['子鼠 ' , '丑牛 ' , '寅虎 ' , '卯兔 ' , '辰龙 ' , '巳蛇 ' , '午马 ' , '未羊 ' , '申猴 ' , '酉鸡 ' , '戌狗 ' , '亥猪 ' ];
418+ }
419+
420+ /**
421+ * @return array
422+ */
423+ private function _getConstellationList ()
424+ {
425+ return [
426+ '01 ' => [
427+ 'name ' => '水瓶座 ' ,
428+ 'start_date ' => '01-20 ' ,
429+ 'end_date ' => '02-18 '
430+ ],
431+ '02 ' => [
432+ 'name ' => '双鱼座 ' ,
433+ 'start_date ' => '02-19 ' ,
434+ 'end_date ' => '03-20 '
435+ ],
436+ '03 ' => [
437+ 'name ' => '白羊座 ' ,
438+ 'start_date ' => '03-21 ' ,
439+ 'end_date ' => '04-19 '
440+ ],
441+ '04 ' => [
442+ 'name ' => '金牛座 ' ,
443+ 'start_date ' => '04-20 ' ,
444+ 'end_date ' => '05-20 '
445+ ], '05 ' => [
446+ 'name ' => '双子座 ' ,
447+ 'start_date ' => '05-21 ' ,
448+ 'end_date ' => '06-21 '
449+ ], '06 ' => [
450+ 'name ' => '巨蟹座 ' ,
451+ 'start_date ' => '06-22 ' ,
452+ 'end_date ' => '07-22 '
453+ ], '07 ' => [
454+ 'name ' => '狮子座 ' ,
455+ 'start_date ' => '07-23 ' ,
456+ 'end_date ' => '08-22 '
457+ ], '08 ' => [
458+ 'name ' => '处女座 ' ,
459+ 'start_date ' => '08-23 ' ,
460+ 'end_date ' => '09-22 '
461+ ], '09 ' => [
462+ 'name ' => '天秤座 ' ,
463+ 'start_date ' => '09-23 ' ,
464+ 'end_date ' => '10-23 '
465+ ], '10 ' => [
466+ 'name ' => '天蝎座 ' ,
467+ 'start_date ' => '10-24 ' ,
468+ 'end_date ' => '11-22 '
469+ ], '11 ' => [
470+ 'name ' => '射手座 ' ,
471+ 'start_date ' => '11-23 ' ,
472+ 'end_date ' => '12-21 '
473+ ], '12 ' => [
474+ 'name ' => '水瓶座 ' ,
475+ 'start_date ' => '12-22 ' ,
476+ 'end_date ' => '01-19 '
477+ ]
478+ ];
479+ }
364480}
0 commit comments