418 lines
16 KiB
PHP
418 lines
16 KiB
PHP
<?php
|
||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||
|
||
/*
|
||
* 测试广告投放用
|
||
*/
|
||
|
||
class Pop extends CI_Controller
|
||
{
|
||
private $cityid_default = 350100;
|
||
private $cityid_arr = [350100, 350200];
|
||
private $city_map = array(
|
||
350100 => '福州',
|
||
350200 => '厦门',
|
||
350300 => '莆田',
|
||
350500 => '晋江',
|
||
350600 => '漳州',
|
||
350900 => '宁德',
|
||
);
|
||
private $redis_key = 'pop_mobile_';
|
||
private $of_id = 6;
|
||
private $of2_id_default = 69;
|
||
private $tag_map = array(
|
||
'dongfeng' => array('t_id'=>2, 't_name'=>'东风EV'),
|
||
'hozon' => array('t_id'=>3, 't_name'=>'哪吒'),
|
||
'leap' => array('t_id'=>4, 't_name'=>'零跑'),
|
||
);
|
||
private $referer_deault = 'domian';
|
||
private $referer_arr = array(
|
||
'baidu.com' => array('of2_id'=>61, 'name'=>'百度'),
|
||
'weixin' => array('of2_id'=>68, 'name'=>'官网加微信'),
|
||
'domain' => array('of2_id'=>69, 'name'=>'官网'),
|
||
);
|
||
# $arr[6] = ['name' => '官网/SEM', 'list' => [' 61' => '百度', ' 68' => '官网加微信', ' 69' => '官网'];
|
||
# 保留: 62 搜狗, 63 神马, 64 360, 65 头条,
|
||
|
||
private $dongfeng_data = array(
|
||
350100 => array(
|
||
'method' => 'dongfeng',
|
||
'act_img' => '', // 活动图
|
||
'dian_map_img' => '', // 门店地图
|
||
'dian_wx_code_img' => '', // 门店微信二维码
|
||
'dian_img' => '', // 门店图片
|
||
'imgs' => array(), //其他图片
|
||
'tuan_arr' => array(
|
||
array('id' => 1, 'title' => 'title', 'img' => '', 'url' => ''),
|
||
array('id' => 2, 'title' => 'title', 'img' => ''),
|
||
),
|
||
'seo_title' => '', //seo_title 公共配置,各cityid可独立配置
|
||
'seo_keyword' => '',//seo_keyword 公共配置,各cityid可独立配置
|
||
'seo_desc' =>'', //seo_desc 公共配置,各cityid可独立配置
|
||
'wx_code_img' => '',//微信二维码 公共配置
|
||
),
|
||
350200 => array(),
|
||
);
|
||
|
||
private $hozon_data = array(
|
||
);
|
||
|
||
|
||
public function __construct(){
|
||
parent::__construct();
|
||
|
||
}
|
||
|
||
public function index(){
|
||
var_dump('pop index');
|
||
//var_dump($this->input->request_headers());
|
||
//var_dump($_SERVER);
|
||
|
||
/*if($this->checkrobot()){
|
||
echo '蜘蛛';
|
||
}else{
|
||
echo '人类';
|
||
}
|
||
var_dump($this->get_spider());
|
||
if($this->is_mobile()){
|
||
echo 'mobile';
|
||
}else{
|
||
echo 'pc';
|
||
}
|
||
var_dump($this->get_referer());
|
||
*/
|
||
|
||
$referer = $this->get_referer();
|
||
$referer = $referer ? $this->referer_arr[$referer] : array();
|
||
!$referer && $referer = $this->referer_arr[$this->referer_deault];
|
||
$of2_id = $this->of2_id_default;
|
||
$cf_clues = '官网';
|
||
if ($referer){
|
||
$of2_id = $referer['of2_id'];
|
||
$cf_clues = $referer['name'];
|
||
}
|
||
$cf_clues .= $this->is_mobile() ? 'H5' : 'PC';
|
||
# 如何区分seo还是sem?
|
||
var_dump($of2_id);var_dump($cf_clues);var_dump(date('Y-m-d H:i:s', time()));var_dump(get_client_ip());var_dump(strtotime(date('Y-m-d') . ' 00:00:00'));
|
||
//header("Location: ./pop/dongfeng");
|
||
}
|
||
|
||
public function dongfeng(){
|
||
$params = $this->input->get();
|
||
$cityid = $this->get_cityid($params); var_dump('pop dongfeng');var_dump($params);var_dump($cityid);
|
||
$params['cityid'] = $cityid;
|
||
$data['params'] = $params;
|
||
$data['info'] = $this->dongfeng_data[$cityid];
|
||
$view = $this->is_mobile() ? '/pop/dongfeng_h5' : '/pop/dongfeng';
|
||
$this->load->view($view, $data);
|
||
}
|
||
|
||
public function hozon(){
|
||
$params = $this->input->get();
|
||
$cityid = $this->get_cityid($params); var_dump('pop hozon');var_dump($params);var_dump($cityid);
|
||
$params['cityid'] = $cityid;
|
||
$data['params'] = $params;
|
||
$data['info'] = $this->dongfeng_data[$cityid];
|
||
$view = $this->is_mobile() ? '/pop/dongfeng_h5' : '/pop/dongfeng';
|
||
$this->load->view($view, $data);
|
||
}
|
||
|
||
private function get_cityid($params){
|
||
$cityid = $params['cityid'] ? intval($params['cityid']) : $this->cityid_default;
|
||
!in_array($cityid, $this->cityid_arr) && $cityid = $this->cityid_default;
|
||
return $cityid;
|
||
}
|
||
|
||
public function post(){
|
||
if ($this->input->method() != 'post') {
|
||
return $this->show_json(0, '参数错误');
|
||
}
|
||
$params = $this->input->post(); var_dump('pop post');var_dump($params);
|
||
$method = $params['method']; // dongfeng, hozon
|
||
$cityid = $this->get_cityid($params);
|
||
$mobile = $params['mobile'];
|
||
$code = $params['code'];
|
||
$name = $params['name'];
|
||
#$method = 'dongfeng';$cityid=$this->cityid_default;$mobile='13959279487';$code='123456';$name='三个土豆';
|
||
|
||
if (!$name) {
|
||
return $this->show_json(0, '请输入姓名');
|
||
}
|
||
if (!$mobile) {
|
||
return $this->show_json(0, '请输入手机号');
|
||
}
|
||
if (!$code) {
|
||
return $this->show_json(0, '请输入验证码');
|
||
}
|
||
|
||
// $redis = &load_cache('redis');
|
||
// $key = $this->redis_key.$mobile;
|
||
// $code_redis = $redis->get($key);
|
||
// if (!$code_redis) {
|
||
// return $this->show_json(0, '验证码已过期');
|
||
// }
|
||
// if ($code_redis != $code) {
|
||
// return $this->show_json(0, '验证码错误');
|
||
// }
|
||
|
||
# tag
|
||
$t_id = 0;
|
||
$t_name = '';
|
||
if ($tag = $this->tag_map[$method]) {
|
||
$t_id = $tag['t_id'];
|
||
$t_name = $tag['t_name'];
|
||
}
|
||
|
||
$referer = $this->get_referer();
|
||
$referer = $referer ? $this->referer_arr[$referer] : array();
|
||
!$referer && $referer = $this->referer_arr[$this->referer_deault];
|
||
$of2_id = $this->of2_id_default;
|
||
$cf_clues = '官网';
|
||
if ($referer){
|
||
$of2_id = $referer['of2_id'];
|
||
$cf_clues = $referer['name'];
|
||
}
|
||
$cf_clues .= $this->is_mobile() ? 'PC' : 'H5';
|
||
|
||
$city_name = $this->city_map[$cityid] ? $this->city_map[$cityid] : '';
|
||
$c_time = time();
|
||
|
||
# 用户的那些信息要记录? ip...
|
||
$ip = get_client_ip();
|
||
|
||
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
||
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
|
||
$this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
|
||
|
||
if ($cus = $this->customers_model->get(['mobile'=>$mobile])){
|
||
$c_id = $cus['id'];
|
||
$jsondata = json_decode($cus['jsondata'],true);
|
||
$jsondata['sem'] = date('Y-m-d H:i:s', $c_time)."通过 {$cf_clues} 报名购买 {$t_name}";
|
||
$jsondata['sem_last'] = date('Y-m-d H:i:s', $c_time);
|
||
$jsondata['sem_ip'] = $ip;
|
||
$jsondata['sem_city_name'] = $city_name;
|
||
$jsondata['sem_cf_clues'] = $cf_clues;
|
||
$jsondata['sem_t_name'] = $t_name;
|
||
$update = array(
|
||
'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE),
|
||
);
|
||
if (in_array($cus['status'], array(-1, 3))){
|
||
$update['status'] = 0;
|
||
}
|
||
#$cus['name'] != $name && $update['name'] = $name;
|
||
$this->customers_model->update($update, array('id'=>$c_id));
|
||
|
||
# 检查今日是否报名过
|
||
$alert = "";
|
||
if (!$this->customer_oplogs_model->get(array('customer_id' => $c_id, 'cf_platform' => 'pop', 'c_time >' => strtotime(date('Y-m-d') . ' 00:00:00')))){
|
||
$alert = "{$city_name} {$name} ({$mobile}) 通过 {$cf_clues} 报名购买 {$t_name}";
|
||
$alert = trim($alert);
|
||
}
|
||
|
||
$logdata = array(
|
||
'customer_id' => $c_id,
|
||
'uid' => 0,
|
||
'uname' => '',
|
||
'type' => 0,
|
||
'log' => "通过 {$cf_clues} 报名购买 {$t_name}",
|
||
'cf_platform' => 'pop',
|
||
'c_time' => $c_time
|
||
);
|
||
$this->customer_oplogs_model->add($logdata);
|
||
}
|
||
else{
|
||
$jsondata = array();
|
||
$jsondata['sem'] = date('Y-m-d H:i:s', $c_time)."通过 {$cf_clues} 报名购买 {$t_name}";
|
||
$jsondata['sem_last'] = date('Y-m-d H:i:s', $c_time);
|
||
$jsondata['sem_ip'] = $ip;
|
||
$jsondata['sem_city_name'] = $city_name;
|
||
$jsondata['sem_cf_clues'] = $cf_clues;
|
||
$jsondata['sem_t_name'] = $t_name;
|
||
$adddata = array(
|
||
'rid' => 0,
|
||
'name' => $name,
|
||
'mobile' => $mobile,
|
||
'biz_id' => 0,
|
||
'sales_id' => 0,
|
||
'level' => 'H',
|
||
'cf_title' => 'SEM',
|
||
'cf_clues' => $cf_clues,
|
||
'of_id' => $this->of_id,
|
||
'of2_id' => $of2_id,
|
||
'city_id' => $cityid,
|
||
'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE),
|
||
'c_time' => $c_time
|
||
);
|
||
$c_id = $this->customers_model->add($adddata);
|
||
|
||
$logdata = array(
|
||
'customer_id' => $c_id,
|
||
'uid' => 0,
|
||
'uname' => '',
|
||
'type' => 3,
|
||
'log' => "创建客户档案, 通过 {$cf_clues} 报名购买 {$t_name}",
|
||
'cf_platform' => 'pop',
|
||
'c_time' => $c_time
|
||
);
|
||
$this->customer_oplogs_model->add($logdata);
|
||
$alert = "新客户 {$city_name} {$name} ({$mobile}) 通过 {$cf_clues} 报名购买 {$t_name}";
|
||
}
|
||
|
||
# 写tagdata
|
||
if ($t_id && !$this->mdCustomerTagdata->get(array('c_id'=>$c_id, 't_id'=>$t_id))){
|
||
$tagdata = array(
|
||
'c_id' => $c_id,
|
||
't_id' => $t_id,
|
||
'c_time' => $c_time
|
||
);
|
||
$this->mdCustomerTagdata->add($tagdata);
|
||
}
|
||
|
||
// $redis->delete($key);
|
||
|
||
# 报名成功后,如何通知到客服/销售,确保尽快与客户沟通
|
||
if ($alert){
|
||
var_dump($alert);
|
||
}
|
||
|
||
return $this->show_json(1, '报名成功');
|
||
}
|
||
|
||
//获取验证码
|
||
public function get_code(){
|
||
if ($this->input->method() != 'post') {
|
||
return $this->show_json(0, '参数错误');
|
||
}
|
||
|
||
$mobile = $this->input->post('mobile', true);
|
||
if (!$mobile){
|
||
return $this->show_json(0, '请输入手机号');
|
||
}
|
||
|
||
$redis = &load_cache('redis');
|
||
$key = $this->redis_key.$mobile;
|
||
$code = $redis->get($key);
|
||
if (!$code){
|
||
$code = rand(100000, 999999);
|
||
$redis->save($key, $code, 60*5*24);
|
||
}
|
||
|
||
send_sms($mobile, $code);
|
||
return $this->show_json(1, '请查收验证码');
|
||
}
|
||
|
||
// 判断设备类型
|
||
private function is_mobile(){
|
||
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
|
||
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
|
||
return true;
|
||
}
|
||
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
|
||
if (isset($_SERVER['HTTP_VIA'])) {
|
||
// 找不到为flase,否则为true
|
||
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
|
||
}
|
||
// 脑残法,判断手机发送的客户端标志,兼容性有待提高。其中'MicroMessenger'是电脑微信
|
||
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
||
$clientkeywords = array('nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile','MicroMessenger');
|
||
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
|
||
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
|
||
return true;
|
||
}
|
||
}
|
||
// 协议法,因为有可能不准确,放到最后判断
|
||
if (isset ($_SERVER['HTTP_ACCEPT'])) {
|
||
// 如果只支持wml并且不支持html那一定是移动设备
|
||
// 如果支持wml和html但是wml在html之前则是移动设备
|
||
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 获取referer
|
||
private function get_referer() {
|
||
$referer = strtolower($_SERVER['Referer']);
|
||
$referer = strtolower($referer);
|
||
$referer = 'https://www.baidu.com/link?url=GBiyUtphXCoxbtEa7bBKLUXZj4PRhfHZ3rLLMJDiNWa&wd=&eqid=9f100bf80008f3f1000000066462ee90';
|
||
$referers = array(
|
||
'baidu.com' => '百度',
|
||
'sogou.com' => '搜狗',
|
||
'sm.cn' => '神马',
|
||
'so.com' => '360',
|
||
'toutiao.com' => '头条',
|
||
);
|
||
|
||
foreach ($referers as $key => $val) {
|
||
if (strpos($referer, $key) !== false) {
|
||
return $key;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
protected function show_json($code = 0, $msg = 'success', $url = '', $wait = 0){
|
||
header('Content-Type:application/json; charset=utf-8');
|
||
echo json_encode(array('data' => $this->data, 'code' => $code, 'msg' => $msg, 'url' => $url, 'wait' => $wait), JSON_UNESCAPED_UNICODE);
|
||
return false;
|
||
}
|
||
|
||
// 是否蜘蛛访问
|
||
private function checkrobot($useragent='') {
|
||
static $kw_spiders = array('bot', 'crawl', 'spider', 'slurp', 'sohu-search', 'lycos', 'robozilla');
|
||
static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');
|
||
|
||
$useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
|
||
if (strpos($useragent, 'http://') === false && $this->dstrpos($useragent, $kw_browsers))
|
||
return false;
|
||
if ($this->dstrpos($useragent, $kw_spiders))
|
||
return true;
|
||
return false;
|
||
}
|
||
private function dstrpos($string, $arr, $returnvalue = false) {
|
||
if (empty($string))
|
||
return false;
|
||
foreach ((array) $arr as $v) {
|
||
if (strpos($string, $v) !== false) {
|
||
$return = $returnvalue ? $v : true;
|
||
return $return;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 蜘蛛类型
|
||
private function get_spider() {
|
||
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||
$spiders = array(
|
||
'Baiduspider', // 百度 baidu.com
|
||
'Sogou', // 搜狗 sogou.com
|
||
'YisouSpider', // 神马 (UC浏览器默认搜索sm.cn的蜘蛛)
|
||
'360Spider', // 360 so.com
|
||
'HaosouSpider', // 360 so.com
|
||
'Bytespider', // 头条 toutiao.com
|
||
'AspiegelBot', // 华为
|
||
|
||
'EasouSpider', // 宜搜
|
||
'YoudaoBot', // 有道
|
||
'YodaoBot', // 有道
|
||
|
||
'Googlebot', // google
|
||
'bingbot', // 必应
|
||
'msnbot', // msn
|
||
'Yahoo', // Yahoo
|
||
'YandexBot', // Yandex
|
||
);
|
||
|
||
foreach ($spiders as $spider) {
|
||
$spider = strtolower($spider);
|
||
if (strpos($userAgent, $spider) !== false) {
|
||
return $spider;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
}
|