Commit 8eedf62a authored by zhuwei's avatar zhuwei

推广手机号码记录

parent 625d9696
...@@ -29,47 +29,41 @@ class SpreadUser extends Basic ...@@ -29,47 +29,41 @@ class SpreadUser extends Basic
* User: 朱伟 * User: 朱伟
* Date: 2018-11-21 * Date: 2018-11-21
* Time: 10:43:58 * Time: 10:43:58
*http://showdoc.tonglianjituan.com/index.php?s=/1&page_id=686
*/ */
public function addSpreadUser(){ public function addSpreadUser(){
$params = $this->params; $params = $this->params;
$user_ip = $this->ip(); $params["ip"] = $this->getUserIp();
/*$params = array(
$params = array(
"type" => 1, "type" => 1,
"phone" => 18112347151, "phone" => 18112347152,
"ip" => $user_ip "ip" => $params["ip"]
); );*/
if (!isset($params["phone"]) or !isset($params["ip"])) { if (!isset($params["phone"]) or !isset($params["ip"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
} }
//先判断是否已经存在数据 //先判断是否已经存在数据
$field = 'phone,ip,create_time'; $field = 'phone,ip,create_time';
$where['ip'] = $params["ip"]; $where['ip'] = $params["ip"];
$where_or['phone'] = $params["phone"]; $where_or['phone'] = $params["phone"];
$res = $this->uSpreadUser->getSpreadUser($field,$where,$where_or); $res = $this->uSpreadUser->getSpreadUser($field,$where,$where_or);
if($res){//如果存在 if($res){//如果存在
dump($res); if($res[0]['phone'] == $params["phone"]){
if($res){ return $this->response("101", "手机号已存在");
}elseif(($res[0]['ip'] == $params["ip"]) and ((time() - strtotime($res[0]['create_time'])) < (60*30))){
}else{
}
return $this->response("101", "30分钟内不允许重复提交"); return $this->response("101", "30分钟内不允许重复提交");
}else{//不存在则新增数据 }
}
$insert["phone"] = $params['phone']; $insert["phone"] = $params['phone'];
$insert["ip"] = $params['ip']; $insert["ip"] = $params['ip'];
$insert["type"] = $params['type']; $insert["type"] = $params['type'];
$res = $this->uSpreadUser->saveSpreadUser($insert);//int(1) $res = $this->uSpreadUser->saveSpreadUser($insert);//int(1)
}
if ($res) { if ($res) {
return $this->response("200", "成功"); return $this->response("200", "成功");
} else { } else {
...@@ -79,8 +73,11 @@ class SpreadUser extends Basic ...@@ -79,8 +73,11 @@ class SpreadUser extends Basic
} }
/**
public function ip() { * 获取用户提交IP
* @return string
*/
public function getUserIp() {
//strcasecmp 比较两个字符,不区分大小写。返回0,>0,<0。 //strcasecmp 比较两个字符,不区分大小写。返回0,>0,<0。
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$ip = getenv('HTTP_CLIENT_IP'); $ip = getenv('HTTP_CLIENT_IP');
...@@ -93,7 +90,6 @@ class SpreadUser extends Basic ...@@ -93,7 +90,6 @@ class SpreadUser extends Basic
} }
$res = preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : ''; $res = preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
return $res; return $res;
//dump(phpinfo());//所有PHP配置信息
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment