Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
97b829c1
Commit
97b829c1
authored
Dec 01, 2018
by
liuyuzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
省市测试
parent
9c8220ac
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
144 additions
and
0 deletions
+144
-0
Home.php
application/controllers/Home.php
+20
-0
AreaUtil.php
application/library/Area/AreaUtil.php
+66
-0
ApiConst.php
application/library/Our/ApiConst.php
+7
-0
Common.php
application/library/Our/Common.php
+42
-0
NameConst.php
application/library/Our/NameConst.php
+9
-0
No files found.
application/controllers/Home.php
View file @
97b829c1
...
...
@@ -192,4 +192,24 @@ class HomeController extends \Our\Controller_AbstractIndex{
$otherGoods
=
$goodsCommonService
->
getIndexHotSalesGoods
(
$currentAddress
);
$this
->
success
(
$otherGoods
);
}
public
function
testCityAction
(){
$cityCode
=
\Area\AreaUtil
::
getInstance
()
->
getIpCityInfo
();
var_dump
(
$cityCode
);
$cityCode1
=
\Area\AreaUtil
::
getInstance
()
->
getIpCityInfo
(
'218.195.219.255'
);
var_dump
(
$cityCode1
);
$cityCode2
=
\Area\AreaUtil
::
getInstance
()
->
getIpCityInfo
(
'61.244.148.166'
);
var_dump
(
$cityCode2
);
$cityCode3
=
\Area\AreaUtil
::
getInstance
()
->
getIpCityInfo
(
'60.246.233.219'
);
var_dump
(
$cityCode3
);
$cityCode4
=
\Area\AreaUtil
::
getInstance
()
->
getIpCityInfo
(
'59.125.39.5'
);
var_dump
(
$cityCode4
);
$cityCode5
=
\Area\AreaUtil
::
getInstance
()
->
getIpCityInfo
(
'169.235.24.133'
);
var_dump
(
$cityCode5
);
}
}
\ No newline at end of file
application/library/Area/AreaUtil.php
0 → 100644
View file @
97b829c1
<?php
namespace
Area
;
/**
* User: liuyuzhen
* Date: 2018/12/3
* Time: 16:52
* Description:
*/
class
AreaUtil
{
public
function
getIpCityInfo
(
$ip
=
false
){
if
(
$ip
==
false
){
$ip
=
\Our\Common
::
getIP
();
}
$cityData
=
\Our\Common
::
getIpCity
(
$ip
);
$provinceId
=
\Our\ApiConst
::
zero
;
$cityId
=
\Our\ApiConst
::
zero
;
switch
(
$cityData
[
'country'
]){
case
\Our\NameConst
::
China
:
if
(
$cityData
[
'region'
]){
$province
=
mb_substr
(
$cityData
[
'region'
],
0
,
2
);
$provinceObj
=
\DAO\AreaModel
::
getInstance
()
->
getOne
(
array
(
'area_deep'
=>
1
,
'area_name'
=>
array
(
'like'
,
$province
.
'%'
)),
'area_id,area_name'
);
if
(
$provinceObj
){
$provinceId
=
$provinceObj
[
'area_id'
];
$city
=
trim
(
$cityData
[
'city'
]);
if
(
$city
){
$cityObj
=
\DAO\AreaModel
::
getInstance
()
->
getOne
(
array
(
'area_parent_id'
=>
$provinceId
,
'area_name'
=>
$city
),
'area_id,area_name'
);
$cityObj
&&
$cityId
=
$cityObj
[
'area_id'
];
}
}
}
break
;
case
\Our\NameConst
::
Macao
:
$provinceId
=
\Our\ApiConst
::
MacaoCode
;
break
;
case
\Our\NameConst
::
Hongkong
:
$provinceId
=
\Our\ApiConst
::
HongkongCode
;
break
;
case
\Our\NameConst
::
Taiwan
:
$provinceId
=
\Our\ApiConst
::
TaiwanCode
;
break
;
default
:
$provinceId
=
\Our\ApiConst
::
otherCountryCode
;
break
;
}
return
array
(
'member_provinceid'
=>
$provinceId
,
'member_cityid'
=>
$cityId
);
}
/**
* 类实例
*
*/
private
static
$_instance
=
null
;
/**
* 单例模式获取类实例
*
*/
public
static
function
getInstance
()
{
if
(
!
(
self
::
$_instance
instanceof
self
))
{
self
::
$_instance
=
new
self
();
}
return
self
::
$_instance
;
}
}
\ No newline at end of file
application/library/Our/ApiConst.php
View file @
97b829c1
...
...
@@ -462,6 +462,13 @@ class ApiConst
const
arrBegin
=
0
;
const
TaiwanCode
=
32
;
const
HongkongCode
=
33
;
const
MacaoCode
=
34
;
const
otherCountryCode
=
35
;
...
...
application/library/Our/Common.php
View file @
97b829c1
...
...
@@ -575,4 +575,46 @@ class Common
return
$price_format
;
}
/**
* 获取当前访问用户地址
* @return string
*/
public
static
function
getIP
(){
static
$realip
;
if
(
isset
(
$_SERVER
)){
if
(
isset
(
$_SERVER
[
"HTTP_X_FORWARDED_FOR"
])){
$realip
=
$_SERVER
[
"HTTP_X_FORWARDED_FOR"
];
}
else
if
(
isset
(
$_SERVER
[
"HTTP_CLIENT_IP"
]))
{
$realip
=
$_SERVER
[
"HTTP_CLIENT_IP"
];
}
else
{
$realip
=
$_SERVER
[
"REMOTE_ADDR"
];
}
}
else
{
if
(
getenv
(
"HTTP_X_FORWARDED_FOR"
)){
$realip
=
getenv
(
"HTTP_X_FORWARDED_FOR"
);
}
else
if
(
getenv
(
"HTTP_CLIENT_IP"
))
{
$realip
=
getenv
(
"HTTP_CLIENT_IP"
);
}
else
{
$realip
=
getenv
(
"REMOTE_ADDR"
);
}
}
return
$realip
;
}
/**
* 获取用户所在地区
* @param $ip
* @return array|bool
*/
public
static
function
getIpCity
(
$ip
){
$url
=
"http://ip.taobao.com/service/getIpInfo.php?ip="
.
$ip
;
$ip
=
json_decode
(
file_get_contents
(
$url
));
if
((
string
)
$ip
->
code
==
'1'
){
return
false
;
}
$data
=
(
array
)
$ip
->
data
;
return
$data
;
}
}
application/library/Our/NameConst.php
View file @
97b829c1
...
...
@@ -185,6 +185,15 @@ class NameConst {
const
bySeller
=
'bySeller'
;
const
bySelf
=
'bySelf'
;
const
China
=
'中国'
;
const
Hongkong
=
'香港'
;
const
Taiwan
=
'台湾'
;
const
Macao
=
'澳门'
;
const
otherCountry
=
'海外'
;
}
?>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment