Commit 18ed1e2e authored by fangliyan's avatar fangliyan

合并分支 'subscribe2.0' 到 'master'

Subscribe2.0

查看合并请求 !29
parents 2c286207 2e0d36c7
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -52,6 +52,7 @@ $active_record = TRUE;
//$dsn_esf = "dbdriver://$conf_db_user:$conf_db_password@$conf_db_host/$conf_db_name?char_set=$conf_db_charset&dbcollat=utf8_general_ci&cache_on=false";
$IpHostAllow =explode('.',get_ip());
if($IpHostAllow['0']=='127')
{
$conf_db_host ='njesfdbmastervip.house365.com';
......@@ -123,23 +124,6 @@ $db['dsn_esfbak']['swap_pre'] = '';
$db['dsn_esfbak']['autoinit'] = FALSE;
$db['dsn_esfbak']['stricton'] = FALSE;
$db['dsn_esfuser_dev']['hostname'] = '192.168.105.107';
$db['dsn_esfuser_dev']['username'] = 'root';
$db['dsn_esfuser_dev']['password'] = 'd53b21ffb24d9c34';
$db['dsn_esfuser_dev']['database'] = 'user';
$db['dsn_esfuser_dev']['dbdriver'] = 'mysql';
$db['dsn_esfuser_dev']['dbprefix'] = '';
$db['dsn_esfuser_dev']['pconnect'] = FALSE;
$db['dsn_esfuser_dev']['db_debug'] = FALSE;
$db['dsn_esfuser_dev']['cache_on'] = FALSE;
$db['dsn_esfuser_dev']['cachedir'] = '';
$db['dsn_esfuser_dev']['char_set'] = 'gbk';
$db['dsn_esfuser_dev']['dbcollat'] = 'gbk';
$db['dsn_esfuser_dev']['swap_pre'] = '';
$db['dsn_esfuser_dev']['autoinit'] = FALSE;
$db['dsn_esfuser_dev']['stricton'] = FALSE;
if(GB_CITY=='nj')
{
$db['dsn_esfhouse']['hostname'] = $conf_db_host;
......@@ -174,22 +158,6 @@ if(GB_CITY=='nj')
$db['dsn_esfhousebak']['autoinit'] = FALSE;
$db['dsn_esfhousebak']['stricton'] = FALSE;
$db['dsn_esfhouse_dev']['hostname'] = '192.168.105.107';
$db['dsn_esfhouse_dev']['username'] = 'root';
$db['dsn_esfhouse_dev']['password'] = 'd53b21ffb24d9c34';
$db['dsn_esfhouse_dev']['database'] = 'house';
$db['dsn_esfhouse_dev']['dbdriver'] = 'mysql';
$db['dsn_esfhouse_dev']['dbprefix'] = '';
$db['dsn_esfhouse_dev']['pconnect'] = FALSE;
$db['dsn_esfhouse_dev']['db_debug'] = FALSE;
$db['dsn_esfhouse_dev']['cache_on'] = FALSE;
$db['dsn_esfhouse_dev']['cachedir'] = '';
$db['dsn_esfhouse_dev']['char_set'] = 'gbk';
$db['dsn_esfhouse_dev']['dbcollat'] = 'gbk';
$db['dsn_esfhouse_dev']['swap_pre'] = '';
$db['dsn_esfhouse_dev']['autoinit'] = FALSE;
$db['dsn_esfhouse_dev']['stricton'] = FALSE;
}elseif(GB_CITY=='hf'){
$db['dsn_esfhouse']['hostname'] = $conf_db_host;
$db['dsn_esfhouse']['username'] = 'root';
......
......@@ -17,8 +17,6 @@ class MY_Model extends CI_Model
$this->db_esfhouse = $this->load->database('dsn_esfhouse',true);
$this->db_esfhousebak = $this->load->database('dsn_esfhousebak',true);
$this->db_esfhousedev = $this->load->database('dsn_esfhouse_dev',true);
$this->db_esfuserdev = $this->load->database('dsn_esfuser_dev',true);
$this->load->library('server',array('appName'=>NS_SELL,'strCheckMethod'=>"",'returnMethod'=>"ary",'returnCharSet'=>"gbk"),'server_sell');
......@@ -306,14 +304,6 @@ class MY_Model extends CI_Model
$this->db = $this->db_esfhousebak;
break;
case 'esfhousedev':
$this->db = $this->db_esfhousedev;
break;
case 'esfuserdev':
$this->db = $this->db_esfuserdev;
break;
default:
$this->db = $this->db_esf;
}
......
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* @author cxf
*/
class Dev_User_class
{
public function __construct()
{
}
function user_login($result,$password='',$telno='',$name='')
{
//隐藏手机号部分数字
$pattern = "/(1\d{1,2})\d\d(\d{0,3})/";
$replacement = "\$1*****\$3";
$telno2 = preg_replace($pattern, $replacement, trim($telno));
$showname = $telno2 ? $telno2 : $name ;
$CI = &get_instance();
$CI->load->model('user_model');
$esfmesnum = $CI->user_model->getmessagenumbyuidwd($result);
if($telno=='')
{
$temp = $CI->user_model->getuserdetailUcenter($result);
$telno = $temp['telno'];
}
$password_encrypt = passport_encrypt($password);
//设置COOKIE
vbsetcookie("esfuserid","",1);
vbsetcookie("esfpassword","",1);
vbsetcookie("esfstyleid","",1);
vbsetcookie("esfusertelno","",1);
vbsetcookie("esfusername","",1);
vbsetcookie("esfshowname","",1);
vbsetcookie("esfmesnum","",1);
vbsetcookie("ckinfo","",1);
vbsetcookie("sessionhash","",1);
vbsetcookie("esfuserid",$result);
vbsetcookie("esfpassword",$password);
vbsetcookie("esfusername",$name);
vbsetcookie("esfusertelno",$telno);
vbsetcookie("esfusercity",GB_CITY);
vbsetcookie('lastvisit','',0);
vbsetcookie("esfshowname",$showname);
vbsetcookie("esf".GB_CITY."mesnum",$esfmesnum);
//逐步替代password,最终去掉password的cookie,增加安全性
vbsetcookie("esf_encrypt",$password_encrypt);
//登录SESSION
$array = array( 'esfuserid'=>$result , 'esfpassword'=>$password ,'esfusername'=>$name , 'esfusertelno'=>$telno ,'esfusercity'=>GB_CITY,'esfshowname'=>$showname,'esfmesnum'=>$esfmesnum);
$CI->load->library('session');
$CI->session->set_userdata($array);
/* 登录日志记录 */
$CI->load->model('user_statistic_model');
//初始化用户信息
$CI->user_statistic_model->set_uid($result);
$CI->user_statistic_model->set_city(GB_CITY);
//提交登录信息
$CI->user_statistic_model->sub_login_log();
$CI->load->model('user_model');
//查询上次登录时间
$last_logintime = $CI->user_model->getuserdetailUcenter($result);
if(date("Y-m-d",$last_logintime['lastlogintime']) != date("Y-m-d"))
{
//查询小区是否有新房源
$msg1 = $CI->user_model->getnewblockhouse($result,$last_logintime['lastlogintime']);
$CI->load->library("apply_class");
if(is_array($msg1) && !empty($msg1))
{
$string = implode(',',$msg1);
//发送消息
$subject = '您关注的小区有新的房源。';
$msg = '您关注的小区“'.$string.'”有新的房源发布,<a href="'.USER_CENTER.'user/blocklist">点击查看</a>。';
$CI->apply_class->send_systemmsg($result,$subject,$msg,2,GB_CITY);
}
//查询找房条件是否有新房源
$result = $CI->user_model->getnewtjhouse($result,$last_logintime['lastlogintime']);
if($result == 1)
{
//发送消息
$subject = '您关注的找房条件有新的房源。';
$msg = '您关注的找房条件有新的房源。<a href="'.USER_CENTER.'user/sell_condition">点击查看</a>。';
$CI->apply_class->send_systemmsg($result,$subject,$msg,2,GB_CITY);
}
}
return 1;
}
}
\ No newline at end of file
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class dev_block_model extends MY_Model
{
function __construct()
{
parent::__construct();
$this->memkey='block'.GB_CITY;
}
/**
* 获取街道名称
* @param type $streetid
* @return string
*/
function getstreetname($streetid)
{
$key = $this->memkey.'_getstreetname_'.$streetid;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$return = $this->memcached_class->get($key);
if(isset($_GET['wmc'])){
var_dump($this->memcached_class); exit;
}
if( empty($return) )
{
$return = $this->get_data(array('form_name' => 'street','where'=>array('id'=>$streetid),'select'=>array('streetname')),'esfhousebak');
$this->memcached_class->add($key, $return,3600);
}
if(!empty($return[0]))
{
return $return[0];
}else{
return 0;
}
}
/**
* 获取地铁站点名称
* @param type $stid
* @return string
*/
function getstname($stid)
{
$key = $this->memkey.'getstname'.$stid;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$return = $this->memcached_class->get($key);
if( empty($return) )
{
$return = $this->get_data(array('form_name' => 'traffic','where'=>array('bid'=>$stid),'select'=>array('station')),'esfhousebak');
$this->memcached_class->add($key, $return,3600);
}
if(!empty($return[0]['station']))
{
return $return[0]['station'];
}else{
return 0;
}
}
/**
* 获取小区详细信息
* @param array $blockname
* @return array
*/
function getblockdetailbyname($blockname,$select)
{
$key = $this->memkey.'getblockdetailbyname'.$blockname.serialize($select);
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$block = $this->memcached_class->get($key);
if( empty($block) )
{
$block = $this->get_data(array('form_name' => 'block','where'=>array('blockname'=>trim($blockname)),'where'=>array('esta'=>2),'select'=>$select),'esfhousebak');
$this->memcached_class->add($key, $block,3600);
}
if(!empty($block[0]))
{
return $block[0];
}
else
{
return 0;
}
}
/**
* 获取板块详细信息
* @param array $blockname
* @return array
*/
function getstreetdetailbyname($streetname,$select)
{
$key = $this->memkey.'getstreetdetailbyname'.$streetname.serialize($select);
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$street = $this->memcached_class->get($key);
if( empty($street) )
{
$street= $this->get_data(array('form_name' => 'street','where'=>array('streetname'=>trim($streetname)),'select'=>$select),'esfhousebak');
$this->memcached_class->add($key, $block,3600);
}
if(!empty($street[0]))
{
return $street[0];
}
else
{
return 0;
}
}
/**
* 获取地铁站点名称
* @param type $stid
* @return string
*/
function getline()
{
$key = $this->memkey.'getline';
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$arr_list_line = $this->memcached_class->get($key);
if(empty($arr_list_line) )
{
$sql = "select bid,sid,station,line,tofor from traffic where type=1 ORDER BY line ASC , sid ASC ";
$query = $this->db_esfhousebak->query($sql);
$arr = $query->result_array();
$num = count($arr);
if(!empty($arr)){
for ($i=0;$i<$num;$i++){
$bid = $arr[$i]['bid'];
$sid = $arr[$i]['sid'];
$line = $arr[$i]['line'];
$station_info [$line]['bid']= $arr[$i]['bid'];
$station_info [$line]['line']= $arr[$i]['line'];
$station = $arr[$i]['station'];
if($arr[$i]['tofor'] == 1){
$station_info[$line]['bus_up'][$sid] = $station;
}elseif($arr[$i]['tofor'] == 2){
$station_info[$line]['bus_down'][$sid] = $station;
}elseif($arr[$i]['tofor'] == 3){
$station_info[$line]['single'][$sid] = $station;
}
}
}
$arr_list_line = array();
$j = 1;
if($station_info){
foreach($station_info as $key => $value){
if(isset($value['bus_up']) && $value['bus_up']){
$st_station = csubstr2(array_shift($value['bus_up']),8);
$end_station = csubstr2(array_pop($value['bus_up']),8);
$arr_list_line[$key.'1'] = '('.$st_station.'-'.$end_station.')';
$arr_list_line[$j] = $key;
$arr_list_line[$key.'1k'] = $j;
$arr_list_line[$j.'tf'] = 1;
$j++;
}
if(isset($value['bus_down']) && $value['bus_down']){
$st_station = csubstr2(array_shift($value['bus_down']),8);
$end_station = csubstr2(array_pop($value['bus_down']),8);
$arr_list_line[$key.'2'] = '('.$st_station.'-'.$end_station.')';
$arr_list_line[$j] = $key;
$arr_list_line[$key.'2k'] = $j;
$arr_list_line[$j.'tf'] = 2;
$j++;
}
if(isset($value['single']) && $value['single']){
$st_station = csubstr2(array_shift($value['single']),8);
$end_station = csubstr2(array_pop($value['single']),8);
$arr_list_line[$key.'3'] = '('.$st_station.'-'.$end_station.')';
$arr_list_line[$j] = $key;
$arr_list_line[$key.'3k'] = $j;
$arr_list_line[$j.'tf'] = 3;
$j++;
}
}}
$this->memcached_class->add($key, $arr_list_line,3600);
}
return $arr_list_line;
}
/**
* 获取小区的统计信息
* @param int $id 小区id号
* @param date $updateDate 日期
* @return array
*/
public function getBlockHouseNumById($id, $updateDate = '') {
//默认取前一天的数据
if ($updateDate == '') {$updateDate = date('Y-m-d');}
$key = $this->memkey.'block_count_'.$updateDate.'_'.$id;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$arrBlockCountDetail = $this->memcached_class->get($key);
if(!isFullArray($arrBlockCountDetail))
{
$arrBlockCountDetail = $this->get_data(array('form_name' => 'block_count','where'=>array('blockid'=>$id,'updatedate'=>$updateDate)),'esfhousebak');
$this->memcached_class->add($key, $arrBlockCountDetail,600);
}
return $arrBlockCountDetail;
}
public function getBlockPriceById($id) {
//默认取前一天的数据
//if ($updateDate == '') {$updateDate = date('Y-m-d');}
$key = $this->memkey.'block_count_'.'_'.$id;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$arrBlockCountDetail = $this->memcached_class->get($key);
if(!isFullArray($arrBlockCountDetail))
{
$arrBlockCountDetail = $this->get_data(array('form_name' => 'block_price','where'=>array('blockid'=>$id)),'esfhousebak');
//print_r($arrBlockCountDetail);die;
$this->memcached_class->add($key, $arrBlockCountDetail,600);
}
return $arrBlockCountDetail;
}
/**
* 获取小区详细信息
* @param type $blockid
* @return array
*/
function getblockdetail($blockid,$select)
{
$block = $this->get_data(array('form_name' => 'block','where'=>array('id'=>$blockid),'select'=>$select),'esfhousebak');
if(!empty($block[0]))
{
return $block[0];
}else{
return 0;
}
}
/**
* 获取小区详细信息
* @param array $blockids
* @return array
*/
function getarrayblockdetail($blockids,$select)
{
$block = $this->get_data(array('form_name' => 'block','where_in'=>array('id',$blockids),'where'=>array('esta'=>2),'select'=>$select),'esfhousebak');
return $block;
}
/**
* 获取小区附近小区
* @param arary $blockid 查询的小区编号
* @param array $hidden_bid_arr 应该排除的小区
* @param int $num 查询个数
* @return array
*/
function getsearchBlockNearly( $blockid , $hidden_bid_arr , $num = 4 )
{
//查询到的小区编号
$serach_ids = '';
$blockid = intval($blockid);
if( $blockid <= 0)
{
return $serach_ids;
}
//获取小区信息
$Info = $this->getblockdetail( $blockid , array('id','b_map_x','b_map_y'));
if( $Info['id'] > 0 )
{
$b_map_x = $Info['b_map_x'];
$b_map_y = $Info['b_map_y'];
$map_x_min = $b_map_x > 0 ? $b_map_x - 0.01 : 0 ;
$map_x_max = $b_map_x > 0 ? $b_map_x + 0.01 : 0 ;
$map_y_min = $b_map_y > 0 ? $b_map_y - 0.01 : 0 ;
$map_y_max = $b_map_y > 0 ? $b_map_y + 0.01 : 0 ;
//需要过滤小区个数,多查num+count(排除小区)个小区
$search_num = $num + count($hidden_bid_arr);
$blockNearly = $this->getBlockInfoByMap( $map_x_min , $map_x_max , $map_y_min , $map_y_max , $search_num );
if(is_array($blockNearly)&& !empty($blockNearly) )
{
$i = 0;
foreach($blockNearly as $key => $vlaue)
{
if( $i >= $num)
{
break;
}
//过滤需要隐藏的小区本身
if( !in_array( $vlaue['id'] , $hidden_bid_arr) )
{
//查询出来的小区ID
$serach_ids .= $serach_ids != '' ? ','.$vlaue['id'] : $vlaue['id'];
$i++;
}
}
}
}
return $serach_ids;
}
/**
*根据地图坐标获取小区
*@param float $map_x_min 最要的经度坐标
*@param float $map_x_max 最大的经度坐标
*@param float $map_y_min 最小的纬度坐标
*@param float $map_y_max 最大的纬度坐标
*@param int $count 获取的小区的个数
*@return array 信息数组
*@author xue
*@since 2013-12-2
**/
public function getBlockInfoByMap( $map_x_min , $map_x_max , $map_y_min , $map_y_max , $count=8)
{
$cond_where = " WHERE b_map_x >= '".$map_x_min."' AND b_map_x <= '".$map_x_max."' AND b_map_y >= '".$map_y_min."' AND b_map_y <= '".$map_y_max."' AND esta = 2";
$cond_limit = " LIMIT 0, ".intval($count);
$cond_order = ' ORDER BY id DESC ';
$sql = " SELECT id,blockname FROM block ";
$sql .= $cond_where . $cond_order . $cond_limit;
$query = $this->db_esfhousebak->query($sql);
$blockInfo = $query->result_array();
return $blockInfo;
}
/**
*找出小区最高最低价
*@param int $school 学校id
*@param array $blockArr 小区数组
*@return array 信息数组
*@author xue
**/
public function getBlockPrice($school,$blockArr)
{
$key = $this->memkey.'get_school_block_price_'.$school;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$price = $this->memcached_class->get($key);
if(empty($price) )
{
if(is_array($blockArr)&&!empty($blockArr))
{
$blockPrice = $this->getarrayblockdetail($blockArr,array('averprice'));//block_model要改成this
$maxPrice = $this->getPrice($blockPrice,'max');
$minPrice = $this->getPrice($blockPrice,'min');
$price = array('min'=>$minPrice,'max'=>$maxPrice);
}
$this->memcached_class->add($key, $price,3600);
}
return $price;
}
/**
*找到最低最高价
*@param string $type 最高或最低
*@param array $blockPrice 小区数组
*@return array 信息数组
*@author xue
**/
private function getPrice($blockPrice,$type)
{
$re = 0;
if($blockPrice)
{
foreach($blockPrice as $k=>$b)
{
if($type == 'max')
{
$x = $b['averprice'] > $re;
}
if($type == 'min')
{
$x = $b['averprice'] < $re;
}
if($k == 0)
{
$re = $b['averprice'];
}
if( $x && intval($b['averprice']) )
{
$re = $b['averprice'];
}
}
return $re;
}
else
{
return false;
}
}
}
\ No newline at end of file
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class dev_broker_model extends MY_Model
{
function __construct()
{
parent::__construct();
}
/**
* ȡ
* @param type $uid
* @return array
*/
function getbrokerdetail($uid)
{
$key = $this->memkey.'_getbrokerdetail_'.$uid;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$broker = $this->memcached_class->get($key);
if( empty($broker) )
{
$broker = $this->get_data(array('form_name' => 'broker','where'=>array('uid'=>$uid),'select'=>array('uid','truename','agentcode','username','telno','smallphoto')),'esfhousebak');
if(isset($broker[0]['agentcode']) && !empty($broker[0]['agentcode']))
{
$agent = $this->get_data(array('form_name' => 'agency','where'=>array('agentcode'=>$broker[0]['agentcode']),'select'=>array('agid','agentshortname')),'esfhousebak');
$broker[0]['agentshortname'] = $agent[0]['agentshortname'];
$broker[0]['agid'] = $agent[0]['agid'];
}
$this->memcached_class->add($key, $broker,3600);
}
if(!empty($broker[0]))
{
return $broker[0];
}else{
return 0;
}
}
}
\ No newline at end of file
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Dev_House_model extends MY_Model
{
function __construct()
{
parent::__construct();
$this->load->model("house_statistic_model");
}
/**
* 验证房源的可刷新次数
* @param type $uid,房源id $id
* @return array
*/
function yzrefrshnum($uid,$id,$tbl='sell')
{
//获得可刷新次数
//flag=1代表上传图片刷新, 2代表付费刷新
$num1 = $this->get_data(array('form_name' => 'personal_refresh','where'=>array('uid'=>$uid,'rowid'=>$id,'tbl'=>$tbl,'esta'=>1,'flag'=>1),'select'=>array('refresh_num')),'esfbak');
$num2 = $this->get_data(array('form_name' => 'personal_refresh','where'=>array('rowid'=>$id,'tbl'=>$tbl,'flag'=>2,'esta'=>1,'begin_time <'=>time(),'end_time >'=>time()),'select'=>array('refresh_num')),'esfbak');
if(!empty($num1[0]['refresh_num']) && !empty($num2[0]['refresh_num']))
{
$num = $num1[0]['refresh_num']+$num2[0]['refresh_num'];
}elseif(!empty($num1[0]['refresh_num']))
{
$num = $num1[0]['refresh_num'];
}elseif(!empty($num2[0]['refresh_num']))
{
$num = $num2[0]['refresh_num'];
}
if(!empty($num))
{
return $num;
}else{
return 0;
}
}
/**
* 验证房源的可刷新次数
* @param type $uid,房源id $id
* @return array
*/
function yzrefrsh($uid,$id,$tbl='sell',$flag=1)
{
//获得可刷新次数
$result = $this->get_data(array('form_name' => 'personal_refresh','where'=>array('uid'=>$uid,'rowid'=>$id,'tbl'=>$tbl,'esta'=>1),'select'=>array('id')),'esfbak');
if(!empty($result))
{
return $result;
}else{
return 0;
}
}
/**
* 验证房源的可刷新次数
* @param $telno 手机号,$arr 匹配信息,$tbl 表
* @return array
*/
function yzsamehouse($telno , $arr , $tbl = 'sell')
{
$total_num = 0;
if( in_array( $tbl , array('sell','rent') ) && !empty($telno) )
{
$sql = "SELECT id FROM $tbl ";
$where_cond = " WHERE esta = '1' AND infofrom = '1' AND ischarge = '0' AND telno='".$telno."'";
if(is_array($arr) && !empty($arr))
{
foreach($arr as $key=>$value)
{
$value = addslashes(strip_tags($value));
$where_cond .= " AND ".$key." = '".$value."'";
}
}
//echo '<!--'.$sql . $where_cond.'-->';
$query = $this->db_esfhousebak->query($sql . $where_cond);
$result = $query->result_array();
if( isset($result[0]['id']) )
{
$return = 1;
}else{
$return = 0;
}
}
return $return;
}
/**
* 添加房源的可刷新次数
* @param type $uid,房源id $id,添加刷新次数 $num,城市 $city_name
* @return array
*/
function addrefrshnum($uid,$id,$tbl='sell',$num,$city_name,$flag=1)
{
//验证是否有刷新次数
$result = $this->yzrefrsh($uid,$id,$tbl,$flag);
if($result >0 )
{
$this->updaterefrshnum($uid,$id,$num,$tbl,$flag,$city_name);
}
else
{
$arr['uid'] = $uid;
$arr['rowid'] = $id;
$arr['tbl'] = $tbl;
$arr['refresh_num'] = $num;
$arr['cityname'] = $city_name;
//设置表
$this->house_model->set_table('personal_refresh');
//过滤表结构
$result = $this->house_model->add($arr,'esf');
}
}
/**
* 刷新房源更新时间
* @param type $telno 手机号码 $validcode 验证码
* @return string
*/
function updatehouse($id,$tbl,$up)
{
if( $id > 0)
{
$arr = array( 'id' => $id );
$this->set_table($tbl);
$result = $this->save($arr,$up,'esfhouse');
if($tbl=='rent')
{
$housedetail = $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('telno','infotype')),'esfhousebak');
$telno =$housedetail[0]['telno'];
$infotype =$housedetail[0]['infotype'];
if($infotype==1)
{
$ip =get_ip();
if(isset($up) && $up['esta']==2)
{
$arr = array( 'rowid' => $id );
$this->set_table('rent_of_zhizu');
$this->save($arr,array('status'=>2),'esfhouse');
//echo "http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=2";die;
get_api("http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=2");
if(GB_CITY=='nj')
{
$value_url ="http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=2";
//记录日志
$msg = "************************************************ \n";
$msg .= date('Y-m-d H:i:s').var_export($value_url,true)." \n";
$log = dirname(__FILE__)."/log/house_update_record_".$_SERVER['REMOTE_ADDR'].'.log';
file_put_contents($log,$msg,FILE_APPEND );
}
}
else
{
get_api("http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=1");
if(GB_CITY=='nj')
{
$value_url ="http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=1";
//记录日志
$msg = "************************************************ \n";
$msg .= date('Y-m-d H:i:s').var_export($value_url,true)." \n";
$log = dirname(__FILE__)."/log/house_update_record_".$_SERVER['REMOTE_ADDR'].'.log';
file_put_contents($log,$msg,FILE_APPEND );
}
}
}
}
}
return $result;
}
/**
* 再发布房源
* @param type $telno 手机号码 $validcode 验证码
* @return string
*/
function republishhouse($id,$tbl,$up,$conf_city)
{
if( $id > 0)
{
// 2017-3-28 添加再发布匹配小区图片 功能 --- start ----->
$housedetail_pic_info = $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('pic1','blockid','telno')),'esfhousebak');
if(empty($housedetail_pic_info['0']['pic1']))
{
$blockid =$housedetail_pic_info['0']['blockid'];
$pic_url_lm = $this->get_block_pic_by_type($blockid , 52);
if( $pic_url_lm != '')
{
$filename = $pic_url_lm;
}
else
{
$filename = $this->get_block_pic_by_type( $blockid , 0);
}
if( $filename != '')
{
$title = '';
$sort = 1;
$blockid = $blockid;
$createtime = time();
$upload_name = get_upload_tblname($tbl,$id);
$sql = "INSERT INTO $upload_name(`tbl`,`rowid`,`position`,`filename`,`title` ,`blockid`,`sort`,`createtime`,`isfrom`) VALUES('$tbl',$id,'pic1','$filename','$title','$blockid','$sort','$createtime','1')";
//echo $sql;die;
$this->db_esfhouse->query($sql);
$sql = "UPDATE $tbl SET pic1 = '".$filename."',lucupdatetime=lucupdatetime+1 WHERE id = '".$id."' ";
//echo $sql;die;
$this->db_esfhouse->query($sql);
}
}
// 2017-3-28 添加再发布匹配小区图片 功能 --- end ----->
$arr = array( 'id' => $id );
$this->set_table($tbl);
$result = $this->save($arr,$up,'esfhouse');
if($conf_city=='nj' || $conf_city=='wh' || $conf_city=='hf' || $conf_city=='wx')
{
if($tbl=='sell')
{
$tbl_tmp =0;
}
else
{
$tbl_tmp =1;
}
$again_date =date('Y-m-d');
$again_info =$this->get_data(array('form_name' => 'house_again_publish_stat','where'=>array('ctime'=>$again_date,'source'=>'0','type'=>$tbl_tmp),'select'=>array('id','num')),'esfhousebak');
if(!empty($again_info[0]['num']))
{
$this->db_esfhouse->query("update house_again_publish_stat set num=num+1 where ctime='$again_date' and source=0 and type=$tbl_tmp");
}
else
{
$this->db_esfhouse->query("insert into house_again_publish_stat (num,type,source,ctime) values ('1','$tbl_tmp','0','$again_date')");
}
############# 2018-9-5 再发布 添加再审核 ###########
$ctime_now =time();
$telno =$housedetail_pic_info['0']['telno'];
$this->db_esfhouse->query("insert into house_again_check (rowid,tbl,telno,ctime) values ($id,'$tbl',$telno,'$ctime_now')");
############# 2018-9-5 再发布 添加再审核 ###########
############# 2016-7-26 再发布删除 sell_delete_app_person start ###########
$this->db_esfhouse->query("DELETE FROM sell_delete_app_person WHERE tbl='$tbl' AND rowid = $id");
############# 2016-7-26 再发布删除 sell_delete_app_person end ###########
############2016-12-21 再发布传数据给直租######################
if($tbl=='rent')
{
$housedetail = $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('telno')),'esfhousebak');
$telno =$housedetail[0]['telno'];
$ip =get_ip();
if(isset($up) && $up['esta']==1)
{
$arr = array( 'rowid' => $id );
$this->set_table('rent_of_zhizu');
$this->save($arr,array('status'=>0),'esfhouse');
get_api("http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=0");
}
}
$value_url ="http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=0";
//记录日志
$msg = "************************************************ \n";
$msg .= date('Y-m-d H:i:s').var_export($value_url,true)." \n";
$log = dirname(__FILE__)."/log/house_republish_record_".$_SERVER['REMOTE_ADDR'].'.log';
file_put_contents($log,$msg,FILE_APPEND );
############2016-12-21 再发布传数据给直租######################
}
}
//再发布更新已经激活的同样条件的房源
$housedetail = $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('blockshowname','buildarea','price','floor','telno')),'esfhousebak');
if(!empty($housedetail[0]['telno']))
{
//更新此条件下其他房源
$this->db_esfhouse->query("update $tbl set esta=-5,note='系统打为重复' where telno='".$housedetail[0]['telno']."' AND esta = '1' AND infofrom = '1' AND ischarge!='1' AND id!=$id AND blockshowname='".$housedetail[0]['blockshowname']."' AND buildarea='".$housedetail[0]['buildarea']."' AND floor='".$housedetail[0]['floor']."' AND updatetime>'".strtotime(date('Y-m-d'))."'");
$this->db_esfhouse->query("update $tbl set esta=2,note='系统打为失效' where telno='".$housedetail[0]['telno']."' AND esta = '1' AND infofrom = '1' AND ischarge!='1' AND id!=$id AND blockshowname='".$housedetail[0]['blockshowname']."' AND buildarea='".$housedetail[0]['buildarea']."' AND floor='".$housedetail[0]['floor']."' AND updatetime<'".strtotime(date('Y-m-d'))."'");
}
return $result;
}
function get_block_pic_by_type($blockid , $bi_type)
{
$where_cond = "WHERE bi_blockid = '".$blockid."'";
if( $bi_type > 0 )
{
$where_cond .= " AND bi_type = '".$bi_type."' limit 1";
}
else
{
$where_cond .= " AND bi_type IN (51,52,53) limit 1";
}
$sql = "SELECT bi_img as pic FROM block_img ".$where_cond .$order_cond;
$query = $this->db_esfhousebak->query($sql);
$result = $query->result_array();
return $result[0]['pic'];
}
/**
* 更新可用刷新次数
* @param type $telno 手机号码 $validcode 验证码 $num刷新次数 $tbl 表
* @return string
*/
function updaterefrshnum($uid,$id,$num,$tbl='sell',$flag=1,$city = '')
{
if(!empty($city))
{
$query = $this->db_esf->query("UPDATE `personal_refresh` SET `refresh_num` = '$num' WHERE `rowid` = '$id' AND `uid` = '$uid' AND `tbl` = '$tbl' AND `flag` = '$flag' AND `cityname`='$city'");
if(!$query)
{
file_put_contents('test.log',"edit:会员id=".$uid." 房源id=".$id." 刷新次数=".$num." 城市=".$city." 房源类型tbl=".$tbl." 标记flag=".$flag." 记录时间=".date('Y-m-d H:i:s')."\r\n",FILE_APPEND);
}
}
else
{
$query = $this->db_esf->query("UPDATE `personal_refresh` SET `refresh_num` = '$num' WHERE `rowid` = '$id' AND `uid` = '$uid' AND `tbl` = '$tbl' AND `flag` = '$flag'");
}
return 1;
}
/**
* 根据用户id获取房源数量
* @param type $uid
* @return array
*/
function gethousenumbyuid( $uid , $tbl='sell' , $esta=0)
{
if($esta == 1)
{
$housenum = $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'esta'=>'1','infofrom'=>'1'),'select'=>array('count(id) as num')),'esfhousebak');
}else{
$housenum = $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'esta !='=>'4','infofrom'=>'1'),'select'=>array('count(id) as num')),'esfhousebak');
}
//print_r($housenum);
return $housenum[0]['num'];
}
/**
* 根据用户id获取房源信息
* @param type $uid
* @return array
*/
function gethousebyuid($uid,$tbl='sell',$select,$offset=0,$pagesize=0)
{
$this->load->model("pic_model");
$housearray = $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'infofrom'=>'1','esta !='=>4),'select'=>$select,'order_by'=>'creattime desc','limit'=>$offset,'offset'=>$pagesize),'esfhousebak');
//echo $this->db->last_query();
$day_now = date('Y-m-d');
if(GB_CITY=='nj'){
//获取数组的个数,再把图片的数量插入数组中
$housearray_number =count($housearray);
for($i=0;$i<$housearray_number;$i++)
{
$sell_house_id =$housearray[$i]['id'];
$this->load->helper('function');
$uploadtbl = get_upload_tblname($tbl,$sell_house_id);
$pic_number = $this->pic_model->getPicNum($tbl,$sell_house_id,$uploadtbl);
$housearray[$i]['pic_num'] =$pic_number;
$housearray[$i]['city_name']=GB_CITY;
//计算当前房源是否参与推广,以及参与推广套餐 最后的
//被删除或者审核中的 则不计算,直接跳过
if($tbl == 'sell'){
$house_type = 1;
}else{
$house_type = 2;
}
$now_time = time();
$promote = $this->db_esfhousebak->from('personal_house_promote')->where(array('house_id'=>$sell_house_id,'house_type'=>$house_type,'status'=>1))->where('start_time <=',$now_time)->where('end_time >=',$now_time)->order_by('end_time','desc')->limit(1)->get()->row_array();
$housearray[$i]['between_day'] ='';
$housearray[$i]['$between_hour']='';
$housearray[$i]['between']='';
if($promote && $promote['order_id']){
$package_type = $promote['package_type'];
$order = $this->db_esfhousebak->from('personal_house_orders')->where(array('id'=>$promote['order_id'],'pay_status'=>1))->where('pay_time <>','')->get()->row_array();
//$pay_time = $order['pay_time'];
//$hours = date('H:i:s',$pay_time);
if($order){
//$endT = date('Y-m-d H:i:s',strtotime('-1 day',$promote['end_time']));
//$endT = $endtime.' '.$hours;
$day_overdue = $promote['end_time'];
if($day_overdue >time() ){
$between_time = $day_overdue-time();//相差的 秒数
$between_day = floor($between_time/24/3600);//相差天数
$h = ($between_time%(3600*24))/3600;
$between_hour = floor($h);
$housearray[$i]['between_day'] = $between_day;
$housearray[$i]['between_hour']= $between_hour;
if($between_day<1 ){
if($between_hour<1){
$housearray[$i]['between'] = '剩余不足1小时';
}else{
$housearray[$i]['between'] = '剩余'.$between_hour.'小时';
}
}else{
if($between_hour>1){
$housearray[$i]['between']='剩余'.$between_day.'天'.$between_hour.'小时';
}else{
$housearray[$i]['between']='剩余'.$between_day.'天';
}
}
}
}
}
}
}
return $housearray;
}
/**
* 根据所传数组获取房源信息
* @param type $where
* @return array
*/
function gethousebywhere($where,$tbl='sell',$select,$offset=0,$pagesize=0)
{
$housearray = $this->get_data(array('form_name' => $tbl,'where'=>$where,'select'=>$select,'order_by'=>'updatetime desc','limit'=>$offset,'offset'=>$pagesize),'esfhousebak');
return $housearray;
}
/**
* 获取房源联系人手机号
* @param $house_id
*/
function getHouseTel($house_id,$tbl='sell_ext'){
$telarray = $this->get_data(array('form_name' => $tbl,'where'=>array('house_id'=>$house_id),'select'=>array('telno')),'esfhousebak');
return empty($telarray) ? '' : $telarray[0]['telno'];
}
/**
* 根据所传数组获取房源信息
* @param type $where
* @return array
*/
function get_house_num_by_where($where,$tbl='sell')
{
$house_info = $this->get_data(array('form_name' => $tbl,'where'=>$where,'select'=>array('count(id) as num')),'esfhousebak');
$house_num = isset($house_info[0]['num']) ? $house_info[0]['num'] : 0;
return $house_num;
}
/**
* 更改房源的uid
* @param type $uid
* @return array
*/
function updatehouseuid( $uid , $newuid , $tbl = 'sell')
{
$uid = intval($uid);
$newuid = intval($newuid);
if( $uid > 0 && $newuid > 0 && in_array( $tbl , array('sell','rent') ) )
{
$sql = "UPDATE $tbl SET uid = '$newuid' WHERE uid = '$uid' AND infofrom = '1'";
$this->db_esfhouse->query($sql);
$msg = 1;
}
else
{
$msg = 0;
}
return $msg;
}
/**
* 添加个人房源匹配求购求租信息
* @param string $want_type 求购求租类型(buy/rentwant)
* @param int $want_id 求购求租信息编号
* @param int $want_uid 求购求租人账号
* @param int $match_id 匹配房源编号
* @param int $uid 匹配人账号编号
* @return array 添加结果
*/
public function add_match_info( $want_type , $want_id , $want_uid , $match_id , $uid )
{
if( in_array( $want_type, array('buy','rentwanted') ) )
{
if( $want_type == 'buy')
{
$tbl_want = 'buy';
$tbl_match = 'buy_match';
}
else if( $want_type == 'rentwanted' )
{
$tbl_want = 'rentwanted';
$tbl_match = 'rentwanted_match';
}
//提交的日志数据
$data = array(
'match_id' => $match_id,
'match_uid' => $uid,
'want_id' => $want_id,
'want_uid' => $want_uid,
'infofrom' => 1, //个人
'esta' => 0, //匹配状态
'isread' => 0, //是否已经查看
'creattime' => time()
);
//是否已经添加过匹配
$is_matched = $this->_check_is_matched( $tbl_match , $want_id , $want_uid , $match_id , $uid);
if( !$is_matched )
{
$today_num_matched = $this->_get_matched_num_today( $tbl_match , $want_id , 1 );
//每天10条匹配信息
if( $today_num_matched <= 10)
{
$this->set_table( $tbl_match );//插入数据
$insert_id = $this->add( $data , 'esfhouse' );
if( $insert_id > 0 )
{
//修改求租房源新匹配个数
$sql = " UPDATE $tbl_want SET matched_num = matched_num + 1 WHERE id = ".$want_id;
$query = $this->db_esfhouse->query($sql);
$result['is_ok'] = 1;
$result['insert_id'] = $insert_id;
$result['msg'] = '匹配房源信息插入成功';
}
else
{
$result['is_ok'] = 0;
$result['msg'] = '匹配房源信息插入失败';
}
}
else
{
$result['is_ok'] = 2;
$result['msg'] = '今日个人匹配已达到上限';
}
}
else
{
$result['is_ok'] = 3;
$result['msg'] = '匹配信息已经存在';
}
}
return $result;
}
/**
* 判断某条求购求租的匹配信息是否已经存在
* @param string $tbl_match 房源匹配表(buy/rentwant)
* @param int $want_id 求购求租信息编号
* @param int $want_uid 求购求租用户编号
* @param int $match_id 匹配房源编号
* @param int $match_uid 匹配人账号编号
* @param int $infofrom 匹配房源来源
* @return boolean 是否已经添加(true-已匹配/false)
*/
private function _check_is_matched( $tbl_match , $want_id , $want_uid , $match_id , $match_uid , $infofrom = 1)
{
$is_matched = false;
if( $tbl_match != '')
{
$where_cond = "want_id = '".$want_id."' AND match_id = '".$match_id."'
AND want_uid = '".$want_uid."' AND match_uid = '".$match_uid."' AND infofrom = '".$infofrom."' ";
$this->db_esfhouse->where( $where_cond );
$this->db_esfhouse->from($tbl_match);
$total_num = $this->db_esfhouse->count_all_results();
//echo $this->db_esfhousebak->last_query();
if( $total_num > 0 )
{
$is_matched = true;
}
}
return $is_matched;
}
/**
* 获得某条求购求租房源已匹配的个数
* @param string $tbl_match 房源匹配表(buy/rentwanted)
* @param int $want_id 求购求租信息编号
* @param int $infofrom 匹配房源来源
* @return boolean 是否已经添加(true-已匹配/false)
*/
private function _get_matched_num_today( $tbl_match , $want_id , $infofrom = '')
{
$total_num = 0;
if( $tbl_match != '')
{
$where_cond = "want_id = '".$want_id."' ";
if( intval($infofrom) > 0 )
{
$where_cond .= " AND infofrom = '".$infofrom."' ";
}
//$where_cond .= " AND esta = 0 ";
$this->db_esfhouse->where( $where_cond );
$this->db_esfhouse->from( $tbl_match );
$total_num = $this->db_esfhouse->count_all_results();
//echo $this->db_esfhousebak->last_query();
}
return $total_num;
}
/**
* 获取昨日新增个人有效房源
* @param string $tbl 房源表('sell','rent')
* @return int 新发布个数
*/
function get_personal_house_num_yesterday($tbl)
{
$total_num = 0;
if( in_array( $tbl , array('sell','rent') ) )
{
$yesterday = date('Y-m-d' , strtotime('-1 day'));
$yesterday_time = strtotime($yesterday);
$yesterday_time_end = $yesterday_time + 86400;
$sql = "SELECT id FROM $tbl";
$where_cond = " WHERE esta = '1' AND infofrom = '1' AND creattime >= '".$yesterday_time."'
AND creattime <= '".$yesterday_time_end."' luc";
if( $tbl == 'sell')
{
$total_info = $this->server_sell->query( $sql . $where_cond);
}
else if( $tbl == 'rent')
{
$total_info = $this->server_rent->query( $sql . $where_cond);
}
if( isset($total_info['TOTAL']) )
{
$total_num = intval($total_info['TOTAL']);
}
}
return $total_num;
}
/**
* 获取昨日新增个人有效房源
* @param string $tbl 房源表('sell','rent')
* @param string $offset 偏移量
* @param string $limit 每次显示个数
* @param string $order 排序
* @return array 新发布房源数组
*/
function get_personal_house_yesterday( $tbl , $offset , $limit , $order = 'desc' )
{
$houseinfo = array();
if( in_array( $tbl , array('sell','rent') ) )
{
$yesterday = date('Y-m-d' , strtotime('-1 day'));
$yesterday_time = strtotime($yesterday);
$yesterday_time_end = $yesterday_time + 86400;
$where_cond = " WHERE esta = '1' AND infofrom = '1' AND creattime >= '".$yesterday_time."'
AND creattime <= '".$yesterday_time_end."' ";
$order_cond = " ORDER BY creattime " . $order ;
$limit_cond = " LIMIT ". $offset .",". $limit;
if( $tbl == 'sell')
{
$sql = "SELECT id,uid,infotype,streetid,buildarea,price,buildyear FROM $tbl";
$record_info = $this->server_sell->query( $sql . $where_cond . $order_cond . $limit_cond .' luc');
}
else if( $tbl == 'rent')
{
$sql = "SELECT id,uid,infotype,streetid,buildarea,price,renttype FROM $tbl";
$record_info = $this->server_rent->query( $sql . $where_cond . $order_cond . $limit_cond .' luc');
}
if( isset($record_info['TOTAL']) && isset($record_info['Record']) )
{
$houseinfo = $record_info['Record'];
}
}
return $houseinfo;
}
/**
* 获取房源符合哪些求购信息
* @param string $infotype 房源信息
* @param string $streetid 板块
* @param string $buildarea 建筑面积
* @param string $price 价格
* @param string $buildyear 建筑年代
* @return array 符合条件的个人求购房源
*/
function get_buy_want_by_house ( $infotype , $streetid , $buildarea , $price , $buildyear , $order ='asc')
{
$tbl_want = 'buy';
$nowtime = time();
if( $tbl_want != '')
{
$where_cond = "esta = '1' AND allow_match = '1' AND expiretime > '".$nowtime."' AND
infofrom IN ('0','1') AND infotype = '".$infotype."' AND( street = '".$streetid."' OR street1 = '".$streetid."' OR street2 = '".$streetid."' ) AND buildarea1*0.9 <= '".$buildarea."' AND buildarea2 >= '".$buildarea."' AND price1*0.9 <= '".$price."' AND price2 >= '".$price."' AND buildyear1 <= '".$buildyear."' AND buildyear2 >= '".$buildyear."'";
$this->db_esfhousebak->select('id , uid ,address');
$this->db_esfhousebak->where($where_cond);
$this->db_esfhousebak->order_by( 'creattime' , $order );
$arr_data = $this->db_esfhousebak->get($tbl_want)->result_array();
}
return $arr_data;
}
/**
* 获取房源符合哪些求租信息
* @param string $infotype 房源信息
* @param string $streetid 板块
* @param string $buildarea 建筑面积
* @param string $price 价格
* @param string $renttype 建筑年代
* @return array 符合条件的个人求购房源
*/
function get_rent_want_by_house( $infotype , $streetid , $buildarea , $price , $renttype , $order ='asc')
{
$tbl_want = 'rentwanted';
$nowtime = time();
if( $tbl_want != '')
{
$where_cond = "esta = '1' AND allow_match = '1' AND expiretime > '".$nowtime."' AND
infofrom IN ('0','1') AND infotype = '".$infotype."' AND( street = '".$streetid."' OR street1 = '".$streetid."' OR street2 = '".$streetid."' ) AND buildarea1*0.9 <= '".$buildarea."' AND buildarea2 >= '".$buildarea."' AND price1*0.9 <= '".$price."' AND price2 >= '".$price."' AND renttype = '".$renttype."' ";
$this->db_esfhousebak->select('id , uid , address');
$this->db_esfhousebak->where($where_cond);
$this->db_esfhousebak->order_by( 'creattime' , $order );
$arr_data = $this->db_esfhousebak->get($tbl_want)->result_array();
}
return $arr_data;
}
/**
* 失效过期的求购/求租房源
* @param void
* @return array 符合条件的个人求购房源
*/
function invalid_buy_rentwanted_info( $tbl )
{
$now_time = time();
if( isset ( $tbl ) && in_array( $tbl , array('buy' , 'rentwanted')) )
{
$sql = "UPDATE $tbl SET esta = 2 WHERE expiretime <= '".$now_time."' AND esta IN (0,1)";
$result = $this->db_esfhouse->query($sql);
}
if( $result )
{
$result['is_ok'] = 1;
$result['msg'] = '更新完成';
}
else
{
$result['is_ok'] = 0;
$result['msg'] = '更新失败';
}
return $result;
}
/**
* 更新房源为收费,并更新房源过期时间
* @param string $tbl
* @param string $id
* @return mixed
*/
function updateHouseCharge( $tbl = '1', $id = '0' )
{
$tbl = intval($tbl);
$id = intval($id);
$tableArray = array( 1 => 'sell' , 2 => 'rent');
$tableName = $tableArray[$tbl];
$addTime = 30 * 24 * 60 * 60;
$sql = "UPDATE $tableName SET ischarge = '1',expiretime = expiretime + $addTime , lucupdatetime=". time() ." WHERE id = $id";
$result = $this->db_esfhouse->query($sql);
return $result;
}
/**
* 更新房源为收费,并更新房源过期时间 - 租房个人房源
* @param $id
* @param $days
*/
function updatePersonalHouseCharge($id,$days){
$id = intval($id);
$days = intval($days);
if(!$id || !$days) return false;
$housedetail = $this->get_data(array('form_name' => 'rent','where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('expiretime')),'esfhouse');
if(!$housedetail) return false;
$housedetail = $housedetail[0];
$expiretime = 0;
$expiretime_ = time() + $days * 24 * 60 * 60;
if($expiretime_ > $housedetail['expiretime']){
$expiretime = $expiretime_;
}
$edit = array('ischarge'=>'1','lucupdatetime'=>time());
if($expiretime > 0){
$edit['expiretime'] = $expiretime;
}
$this->set_table('rent');
$result = $this->save(array('id'=>$id),$edit,'esfhouse');
return $result;
}
/**
* 房源详情
* @param $house_id
* @param array $fields
* @return array
*/
function getHouse($house_id,$fields=array()){
$fields = $fields ? $fields : array('infofrom');
$housedetail = $this->get_data(array('form_name' => 'rent', 'where' => array('id' => $house_id), 'select' => $fields), 'esfhouse');
return empty($housedetail) ? array() : $housedetail[0];
}
}
\ No newline at end of file
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class dev_push_model extends MY_Model
{
function __construct()
{
parent::__construct();
$this->memkey='mypush'.GB_CITY;
$this->load->model("dev_user_model");
$this->load->model("dev_house_model");
$this->load->model("dev_block_model");
$this->load->model("dev_broker_model");
}
/**
* 查找是否有求购信息加入推送表
* @param type $uid
* @return array
*/
function addbuy($uid,$city=GB_CITY,$sendtime)
{
global $house;
$buydetail = $this->user_model->get_buy_by_uid($uid,0,1,$sendtime);
if(is_array($buydetail) && !empty($buydetail) && $buydetail[0]['infofrom']!=1){
$arr['uid'] = $uid;
$arr['addtime'] = time();
$arr['level'] = 5;
$content['address'] = $buydetail[0]['address'];
$content['infotype'] = $house['infotype'][$buydetail[0]['infotype']];
$content['buildarea'] = $buydetail[0]['buildarea1'].'-'.$buydetail[0]['buildarea2'];
$content['price'] = $buydetail[0]['price1'].'-'.$buydetail[0]['price2'];
$content['buildyear'] = $buydetail[0]['buildyear1'].'-'.$buydetail[0]['buildyear2'];
$content['remark'] = $buydetail[0]['remark'];
$content['priceunit'] = '万元';
$arr['content'] = serialize($content);
$arr['telno'] = $buydetail[0]['telno'];
$arr['sendid'] = $buydetail[0]['id'];
$arr['sendkind'] = 1;
$arr['tbl'] = 'sell';
$arr['cityname'] = GB_CITY;
$return = $this->addpush($arr);
if($return>0)
{
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 查找是否有求购信息加入推送表
* @param type $uid
* @return array
*/
function addrentwanted($uid,$city=GB_CITY,$sendtime)
{
global $house;
$rentwantdetail = $this->user_model->get_rentwant_by_uid($uid,0,1,$sendtime);
if(is_array($rentwantdetail) && !empty($rentwantdetail) && $rentwantdetail[0]['infofrom']!=1){
$arr['uid'] = $uid;
$arr['addtime'] = time();
$arr['level'] = 5;
$content['address'] = $rentwantdetail[0]['address'];
$content['infotype'] = $house['infotype'][$rentwantdetail[0]['infotype']];
$content['buildarea'] = $rentwantdetail[0]['buildarea1'].'-'.$rentwantdetail[0]['buildarea2'];
$content['price'] = $rentwantdetail[0]['price1'].'-'.$rentwantdetail[0]['price2'];
$content['priceunit'] = '元/月';
$content['renttype'] = $house['renttype'][$rentwantdetail[0]['renttype']];
$content['remark'] = $rentwantdetail[0]['remark'];
$arr['content'] = serialize($content);
$arr['telno'] = $rentwantdetail[0]['telno'];
$arr['sendid'] = $rentwantdetail[0]['id'];
$arr['sendkind'] = 1;
$arr['tbl'] = 'rent';
$arr['cityname'] = GB_CITY;
$return = $this->addpush($arr);
if($return>0)
{
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 查找是否有求购信息加入推送表
* @param type $uid
* @return array
*/
function addseehouse($uid,$telno,$sendtime)
{
global $house;
$seehousedetail = $this->user_model->get_seehouse_by_telno($telno,$sendtime);
if(!empty($seehousedetail)){
//获取房源信息
$where = array('id'=>$seehousedetail[0]['rowid']);
if($seehousedetail[0]['tbl']=='sell'){
$select = array('id','infotype','uid','infofrom','district','streetid','blockshowname','price','buildarea','floor','subfloor','totalfloor','room','hall','toilet','kitchen','fitment','buildyear');
$housedetail = $this->house_model->gethousebywhere($where,'sell',$select,0,1);
}else{
$select = array('id','infotype','uid','infofrom','district','streetid','blockshowname','price','buildarea','floor','subfloor','totalfloor','room','hall','toilet','kitchen','fitment','renttype','priceunit');
$housedetail = $this->house_model->gethousebywhere($where,'rent',$select,0,1);
}
if(empty($housedetail)) return 0;
//获取街道和经纪人信息
$streetname = $this->block_model->getstreetname($housedetail[0]['streetid']);
$brokername = $this->broker_model->getbrokerdetail($housedetail[0]['uid']);
$arr['uid'] = $uid;
$arr['addtime'] = time();
$arr['level'] = 5;
$content['infotype'] = $house['infotype'][$housedetail[0]['infotype']];
$content['brokername'] = $brokername['truename'];
$content['district'] = $housedetail[0]['district'];
$content['streetname'] = $streetname['streetname'] ;
$content['blockshowname'] = $housedetail[0]['blockshowname'];
$content['buildarea'] = $housedetail[0]['buildarea'];
$content['floor'] = empty($housedetail[0]['subfloor'])?$housedetail[0]['floor'].'/'.$housedetail[0]['totalfloor'].'层':$housedetail[0]['subfloor'].'-'.$housedetail[0]['floor'].'/'.$housedetail[0]['totalfloor'].'层';
$content['room'] = $housedetail[0]['room']?$housedetail[0]['room'].'室':'';
$content['hall'] = $housedetail[0]['hall']?$housedetail[0]['hall'].'厅':'';
$content['toilet'] = $housedetail[0]['room']?$housedetail[0]['room'].'卫':'';
$content['kitchen'] = $housedetail[0]['room']?$housedetail[0]['room'].'厨':'';
$content['fitment'] = $housedetail[0]['fitment'];
if($seehousedetail[0]['tbl']=='sell'){
$content['buildyear'] = $housedetail[0]['buildyear']?$housedetail[0]['buildyear']:'';
$content['price'] = $housedetail[0]['price']?$housedetail[0]['price']:'';
$content['priceunit'] = '万元';
$content['averprice'] = floor($housedetail[0]['price']*10000/$housedetail[0]['buildarea']).'元/平方米';
}else{
$content['price'] = $housedetail[0]['price']?$housedetail[0]['price']:'';
$content['priceunit'] = $house['priceunit'][$housedetail[0]['priceunit']];
$content['renttype'] = $housedetail[0]['renttype'];
}
$arr['content'] = serialize($content);
$arr['telno'] = $telno;
$arr['sendid'] = $seehousedetail[0]['id'];
$arr['sendkind'] = 2;
$arr['tbl'] = $seehousedetail[0]['tbl'];
$arr['cityname'] = GB_CITY;
$return = $this->addpush($arr);
if($return>0)
{
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 查找是否有关注信息加入推送表
* @param type $uid
* @return array
*/
function addcollecthouse($uid,$telno,$sendtime)
{
global $house;
$collecthousedetail = $this->user_model->get_collecthouse_by_uid($uid,GB_CITY,$sendtime);
if(!empty($collecthousedetail)){
//获取房源信息
$where = array('id'=>$collecthousedetail['collect_id']);
if($collecthousedetail['kind']=='3'){
$select = array('id','infotype','uid','infofrom','district','streetid','blockshowname','price','buildarea','floor','subfloor','totalfloor','room','hall','toilet','kitchen','fitment','buildyear');
$housedetail = $this->house_model->gethousebywhere($where,'sell',$select,0,1);
}else{
$select = array('id','infotype','uid','infofrom','district','streetid','blockshowname','price','buildarea','floor','subfloor','totalfloor','room','hall','toilet','kitchen','fitment','renttype','priceunit');
$housedetail = $this->house_model->gethousebywhere($where,'rent',$select,0,1);
}
if(empty($housedetail)) return 0;
//获取街道和经纪人信息
$streetname = $this->block_model->getstreetname($housedetail[0]['streetid']);
$brokername = $this->broker_model->getbrokerdetail($housedetail[0]['uid']);
$arr['uid'] = $uid;
$arr['addtime'] = time();
$arr['level'] = 4;
$content['infotype'] = $house['infotype'][$housedetail[0]['infotype']];
$content['brokername'] = $brokername['truename'];
$content['district'] = $housedetail[0]['district'];
$content['streetname'] = $streetname['streetname'] ;
$content['blockshowname'] = $housedetail[0]['blockshowname'];
$content['buildarea'] = $housedetail[0]['buildarea'];
$content['floor'] = empty($housedetail[0]['subfloor'])?$housedetail[0]['floor'].'/'.$housedetail[0]['totalfloor'].'层':$housedetail[0]['subfloor'].'-'.$housedetail[0]['floor'].'/'.$housedetail[0]['totalfloor'].'层';
$content['room'] = $housedetail[0]['room']?$housedetail[0]['room'].'室':'';
$content['hall'] = $housedetail[0]['hall']?$housedetail[0]['hall'].'厅':'';
$content['toilet'] = $housedetail[0]['room']?$housedetail[0]['room'].'卫':'';
$content['kitchen'] = $housedetail[0]['room']?$housedetail[0]['room'].'厨':'';
$content['fitment'] = $housedetail[0]['fitment'];
if($collecthousedetail['kind']=='3'){
$content['buildyear'] = $housedetail[0]['buildyear']?$housedetail[0]['buildyear']:'';
$content['price'] = $housedetail[0]['price']?$housedetail[0]['price']:'';
$content['priceunit'] = '万元';
$content['averprice'] = floor($housedetail[0]['price']*10000/$housedetail[0]['buildarea']).'元/平方米';
}else{
$content['price'] = $housedetail[0]['price']?$housedetail[0]['price']:'';
$content['priceunit'] = $house['priceunit'][$housedetail[0]['priceunit']];
$content['renttype'] = $housedetail[0]['renttype'];
}
$arr['content'] = serialize($content);
$arr['telno'] = $telno;
$arr['sendid'] = $collecthousedetail['id'];
$arr['sendkind'] = 3;
$arr['tbl'] = $collecthousedetail['kind']==3?'sell':'rent';
$arr['cityname'] = GB_CITY;
$return = $this->addpush($arr);
if($return>0)
{
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 查找是否有发送到手机加入推送表
* @param type $uid
* @return array
*/
function addsmshouse($uid,$telno,$sendtime)
{
global $house;
if(!$telno) return 0;
$smshousedetail = $this->user_model->get_smshouse_by_telno($telno,0,1,$sendtime);
if(!empty($smshousedetail)){
//获取房源信息
$where = array('id'=>$smshousedetail['rowid']);
if($smshousedetail['tbl']=='sell'){
$select = array('id','infotype','uid','infofrom','district','streetid','blockshowname','price','buildarea','floor','subfloor','totalfloor','room','hall','toilet','kitchen','fitment','buildyear');
$housedetail = $this->house_model->gethousebywhere($where,'sell',$select,0,1);
}else{
$select = array('id','infotype','uid','infofrom','district','streetid','blockshowname','price','buildarea','floor','subfloor','totalfloor','room','hall','toilet','kitchen','fitment','renttype','priceunit');
$housedetail = $this->house_model->gethousebywhere($where,'rent',$select,0,1);
}
if(empty($housedetail)) return 0;
//获取街道和经纪人信息
$streetname = $this->block_model->getstreetname($housedetail[0]['streetid']);
$brokername = $this->broker_model->getbrokerdetail($housedetail[0]['uid']);
$arr['uid'] = $uid;
$arr['addtime'] = time();
$arr['level'] = 4;
$content['infotype'] = $house['infotype'][$housedetail[0]['infotype']];
$content['brokername'] = $brokername['truename'];
$content['district'] = $housedetail[0]['district'];
$content['streetname'] = $streetname['streetname'] ;
$content['blockshowname'] = $housedetail[0]['blockshowname'];
$content['buildarea'] = $housedetail[0]['buildarea'];
$content['floor'] = empty($housedetail[0]['subfloor'])?$housedetail[0]['floor'].'/'.$housedetail[0]['totalfloor'].'层':$housedetail[0]['subfloor'].'-'.$housedetail[0]['floor'].'/'.$housedetail[0]['totalfloor'].'层';
$content['room'] = $housedetail[0]['room']?$housedetail[0]['room'].'室':'';
$content['hall'] = $housedetail[0]['hall']?$housedetail[0]['hall'].'厅':'';
$content['toilet'] = $housedetail[0]['room']?$housedetail[0]['room'].'卫':'';
$content['kitchen'] = $housedetail[0]['room']?$housedetail[0]['room'].'厨':'';
$content['fitment'] = $housedetail[0]['fitment'];
if($smshousedetail['tbl']=='sell'){
$content['buildyear'] = $housedetail[0]['buildyear']?$housedetail[0]['buildyear']:'';
$content['price'] = $housedetail[0]['price']?$housedetail[0]['price']:'';
$content['priceunit'] = '万元';
$content['averprice'] = floor($housedetail[0]['price']*10000/$housedetail[0]['buildarea']).'元/平方米';
}else{
$content['price'] = $housedetail[0]['price']?$housedetail[0]['price']:'';
$content['priceunit'] = $house['priceunit'][$housedetail[0]['priceunit']];
$content['renttype'] = $housedetail[0]['renttype'];
}
$arr['content'] = serialize($content);
$arr['telno'] = $telno;
$arr['sendid'] = $smshousedetail['id'];
$arr['sendkind'] = 4;
$arr['tbl'] = $smshousedetail['tbl'];
$arr['cityname'] = GB_CITY;
$return = $this->addpush($arr);
if($return>0)
{
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 查找是否有发送到手机加入推送表
* @param type $uid
* @return array
*/
function addcollectblock($uid,$telno,$sendtime)
{
$collectblockdetail = $this->user_model->getcollectbyuid($uid,2,GB_CITY,$sendtime);
$select=array('blockname','district','streetid','address','averprice');
$blockdetail = $this->block_model->getblockdetail($collectblockdetail['collect_id'],$select);
if(!empty($blockdetail)){
$streetname = $this->block_model->getstreetname($blockdetail['streetid']);
$arr['uid'] = $uid;
$arr['addtime'] = time();
$arr['level'] = 4;
$content['district'] = $blockdetail['district'];
$content['streetname'] = $streetname['streetname'];
$content['blockname'] = $blockdetail['blockname'];
$content['averprice'] = $blockdetail['averprice'];
$content['priceunit'] = '元/平';
$arr['content'] = serialize($content);
$arr['telno'] = $telno;
$arr['sendid'] = $collectblockdetail['id'];
$arr['sendkind'] = 5;
$arr['tbl'] = 'sell';
$arr['cityname'] = GB_CITY;
$return = $this->addpush($arr);
if($return>0)
{
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 加入推送表
* @param type $arr
* @return array
*/
function addpush($arr)
{
//设置表
$this->user_model->set_table('push_user');
//过滤表结构
$result = $this->user_model->add($arr,'esf');
return $result;
}
/**
* 加入备选库
* @param type $arr
* @return array
*/
function addalternatives($uid,$telno,$city=GB_CITY,$sendkind=3,$tbl='sell')
{
$arr['uid'] = $uid;
$arr['telno'] = $telno;
$arr['cityname'] = $city;
$arr['sendkind'] = $sendkind;
$arr['tbl'] = $tbl;
$arr['addtime'] = time();
//检查目前不在备选库
$alternatives_id = $this->get_data(array('form_name' => 'alternatives_user','limit'=>1,'where'=>array('telno'=>$telno),'select'=>array('id')),'esf');
if(!empty($alternatives_id[0]['id']))
{
return 0;
}
//设置表
$this->user_model->set_table('alternatives_user');
//过滤表结构
$result = $this->user_model->add($arr,'esf');
return $result;
}
/**
* 验证推送用户是否在白名单或者推送库里
* @param type $uid
* @return array
*/
function yzpush($telno){
if(empty($telno))
{
return 0;
}
//检查白名单
$whitelist_id = $this->get_data(array('form_name' => 'whitelist','limit'=>1,'where'=>array('telno'=>$telno),'select'=>array('id')),'esfbak');
if(!empty($whitelist_id[0]['id']))
{
return $whitelist_id[0]['id'];
}
//检查推送库
$user_id = $this->get_data(array('form_name' => 'push_user','limit'=>1,'where'=>array('telno'=>$telno),'select'=>array('id')),'esf');
if(!empty($user_id[0]['id']))
{
return $user_id[0]['id'];
}
//检查推送库历史库最近一个月记录
$log_id = $this->get_data(array('form_name' => 'push_user_log','limit'=>1,'where'=>array('telno'=>$telno,'sendtime >'=>time()-24*60*60*30),'select'=>array('id')),'esfbak');
if(!empty($log_id[0]['id']))
{
return $log_id[0]['id'];
}else{
return 0;
}
}
//added by bianshiwu 20141222 临时函数
function setPushLogTemp($data){
$sql = "INSERT INTO `push_log_tmp` ( `sendtime` ,`telno` ,`desc`) VALUES ('{$data['sendtime']}','{$data['telno']}','{$data['desc']}')";
$this->db_esf->query($sql);
}
//临时-导数据:wjy
function t_add()
{
$sql = "select * from push_user_log where cityname='nj' and sellnum=0 and id between 36305 and 36371";
$query = $this->db_esf->query($sql)->result_array();
echo count($query);
echo '<br><br>';
foreach($query as $value){
$id = $value['id'];
//step1. 插入push_user
$sql_ins = "INSERT INTO `push_user` (`uid` ,`level` ,`addtime` ,`content` ,`telno` ,`sendid` ,`sendkind` ,`cityname` ,`tbl`) VALUES ('"
.$value['uid']."','".$value['level']."', '".$value['addtime']."', '".$value['content']."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."', '".$value['cityname']."', '".$value['tbl']."')";
$query = $this->db_esf->query($sql_ins);
$pushid = $this->db_esf->insert_id();
//step2. 删除push_user_log ,marketing_log
if($pushid){
$del_log = $this->db_esf->query("delete from push_user_log where id=$id");
if($del_log){
$del_market = $this->db_esf->query("delete from marketing_log where pushid=$id");
}
}
echo $id; echo '<br>';
echo $pushid; echo '<br>';
var_dump($del_log); echo '<br>';
var_dump($del_market); echo '<br><br>';
die;
}
}
//竞投 手动加数据
function bidhouse()
{
$sql = "select * from growth_bid_house where `type`=2 and `bid_periods_id`=2054 ";
$growth = $this->db_esfhousebak->query($sql)->result_array();
$bid_periods_id = 2059;
$number = 0;
foreach ($growth as $k=>$v){
$str = "('".$v['type']."','".$bid_periods_id."','".$v['block_id']."','".$v['block_level']."','".$v['keyword']."','".$v['broker_level']
. "','".$v['valid']."','" .$number."', '".$v['min_score']."', '".$v['max_win_number']."','".date('Y-m-d H:i:s')."')";
$sql = "INSERT INTO `growth_bid_house` (`type` ,`bid_periods_id` ,`block_id` ,`block_level` ,`keyword` ,`broker_level`,`valid` ,`number` ,`min_score` ,`max_win_number`,`ctime`) VALUES $str";
$query = $this->db_esfhouse->query($sql);
}
}
//新的推送
function getpusharraynew()
{
//---- 日志 ----
$t1 = microtime(true);
writelog('-------- 开始 --------', 'jpushnew_'.date('d') );
$return = array();
//查出推送库
$sql = array('form_name'=>'push_user', 'where'=>array('cityname'=>'nj'), 'order_by'=>'id asc','limit'=>1);
$pushList = $this->get_data($sql, 'esfbak');
if( !empty($pushList) && is_array($pushList) ) {
foreach($pushList as $key=>$val) {
$pushid = 0;
//将信息加入推送历史表,删除推送表
$sql_ins = "INSERT INTO `push_user_log` (`pushuserid` ,`uid` ,`level` ,`sendtime` ,`content` ,`telno` ,`sendid` ,`sendkind` ,`cityname` ,`tbl`,`addtime`) VALUES ('"
.$val['id']."','".$val['uid']."','".$val['level']."','".time()."','".$val['content']."','".$val['telno']."','".$val['sendid']."','".$val['sendkind']."','".$val['cityname']."','".$val['tbl']."','".$val['addtime']."')";
$query = $this->db_esf->query($sql_ins);
$pushid = $this->db_esf->insert_id();
$sql_del = "DELETE from `push_user` where telno='".$val['telno']."'";
$query = $this->db_esf->query($sql_del);
if($val['tbl']=='rent'){
writelog('出租不推:pushid: '.$pushid, 'jpushnew_'.date('d') );
continue;
}
writelog('pushid: '.$pushid, 'jpushnew_'.date('d') );
$arr = $this->getPushDataFromLucene($val); //符合条件经纪人 id
if(empty($arr['uid'])){
$arr_count = count($arr['uid']);
writelog('第一次无数据,再跑一次'.$arr_count, 'jpushnew_'.date('d') );
$arr = $this->getPushDataFromLucene($val, 2); //第一次无数据,再跑一次
}
$arr_count = count($arr['uid']);
if( $arr_count >= 1 && $pushid){
$uidarr = $uarrnew = array();
$i = 0;
foreach($arr['uid'] as $kp => $vp){
$uidarr[] = $kp;
$i++;
$do = $i%500;
if( !$do || $i >= $arr_count ){
$uidstr = implode(',',$uidarr);
$sql = "select b.uid,b.truename,a.agid as agentid,a.agentshortname from broker b
left join agency a on b.agentcode = a.agentcode where b.uid in ($uidstr)";
$query = $this->db_esfhousebak->query($sql);
$userList = $query->result_array();
$str = '';
foreach($userList as $obj) {
if($val['tbl']=='sell') {
$type_tmp ='2';
} else {
$type_tmp ='1';
}
$str .= "('".$pushid."','".$val['uid']."','".$obj['uid']."','".$obj['truename']."','".$obj['agentid']."','".$obj['agentshortname']
."','".time()."','" .$val['telno']."', '".$val['sendid']."', '".$val['sendkind']."','".$type_tmp."'),";
}
if($str) {
$str = rtrim($str,',');
$sql = "INSERT INTO `marketing_log` (`pushid` ,`uid` ,`brokerid` ,`brokername` ,`agentid` ,`agentname`,`addtime` ,`telno` ,`sendid` ,`sendkind`,`tbl`) VALUES $str";
$query = $this->db_esf->query($sql);
}
//转编码
foreach($userList as $tv) {
$tk = $tv['uid'];
$uarrnew[$tk] = $tv;
$uarrnew[$tk]['truename']= mb_convert_encoding($tv['truename'],'utf8','gbk');
$uarrnew[$tk]['agentshortname']= mb_convert_encoding($tv['agentshortname'],'utf8','gbk');
}
$uidarr = array(); //重置一批user
}
}
$return[] = array('content'=>$pushid, 'uarr'=>$uarrnew);
$t3 = microtime(true);
$ttt = round($t3-$t1,1);
writelog('------- 中间耗时 -------- :'.$ttt.'秒' , 'jpushnew_'.date('d') );
}
//极光推送
if(!empty($arr['uid'])){
$this->jpush_uid_data($arr['uid']); //该数组没排除大于5个推送
}
}
}
//---- 日志 ----
$t2 = microtime(true);
$tt = round($t2-$t1,1);
writelog('-------- 结束 --------:耗时'.$tt.'秒' , 'jpushnew_'.date('d') );
return $return;
}
/**
* 获取推送库的信息
* @param type $uid,$remainNum 剩余推送次数
* @return array
*/
function getpusharray($remainNum)
{
if(intval($remainNum) <= 0) return array();
//---- 日志 ----
$t1 = microtime(true);
writelog('-------- 开始 --------', 'jpush_'.date('d') );
//查出推送库总数
$pushCount= $this->get_data(array('form_name' => 'push_user','where'=>array('cityname'=>'nj'),'select'=>array(' count(id) as num')),'esfbak');
$push_num = ceil($pushCount[0]['num']/$remainNum);
$push_num = 1;
//查出推送库
$pushList = $this->get_data(array('form_name' => 'push_user','where'=>array('cityname'=>'nj'), 'order_by'=>'id asc','limit'=>$push_num),'esfbak');
$return = $logdata = $jpush_uid = array();
if( !empty($pushList) && is_array($pushList) ) {
foreach($pushList as $key=>$value) {
$pushid = 0;
//将信息加入推送历史表,删除推送表
$sql_ins = "INSERT INTO `push_user_log` (`pushuserid` ,`uid` ,`level` ,`sendtime` ,`content` ,`telno` ,`sendid` ,`sendkind` ,`cityname` ,`tbl`,`addtime`) VALUES ('"
.$value['id']."','".$value['uid']."','".$value['level']."', '".time()."', '".$value['content']."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."', '".$value['cityname']."', '".$value['tbl']."', '".$value['addtime']."')";
$query = $this->db_esf->query($sql_ins);
$pushid = $this->db_esf->insert_id();
$sql_del = "DELETE from `push_user` where telno='".$value['telno']."'";
$query = $this->db_esf->query($sql_del);
if($value['tbl']=='rent'){
writelog('出租不推:pushid: '.$pushid, 'jpush_'.date('d') );
continue;
}
writelog('pushid: '.$pushid, 'jpush_'.date('d') );
$arr = $this->getPushDataFromLucene($value); //符合条件经纪人 id
if( count($arr['uid'])>=1 && $pushid){
$uidstr = '';
foreach($arr['uid'] as $kp => $vp){
$uidstr .= $uidstr=='' ? $kp : ','.$kp;
}
//将经纪人加入营销表,判断是否今日已推送5条
$where = " addtime>'".strtotime(date('Y-m-d'))."' and addtime<'".(strtotime(date('Y-m-d'))+86400)."' and brokerid in ($uidstr) ";
$sql = "select count(*) as num, brokerid from marketing_log where $where group by brokerid";
$uarr_num = $this->db_esf->query($sql)->result_array();
$temp_uarr_num = array();
foreach($uarr_num as $op) {
$tp_uid = $op['brokerid'];
$temp_uarr_num[$tp_uid] = $op['num']; //今日经纪人推送条数
}
$sql = "select b.uid,b.truename,a.agid as agentid,a.agentshortname from broker b left join agency a on b.agentcode = a.agentcode where b.valid_flag = 1 and b.uid in ($uidstr)";
$query = $this->db_esfhousebak->query($sql);
$uarr = $query->result_array();
//过滤推送超过5次的经纪人
$str='';
$uarr_filter = array();
if(is_array($uarr) && !empty($uarr)){
foreach($uarr as $value2) {
if(!isset($temp_uarr_num[$value2['uid']]) || $temp_uarr_num[$value2['uid']]<500) {
$uarr_filter[] = $value2['uid'];
if($value['tbl']=='sell') {
$type_tmp ='2';
} else {
$type_tmp ='1';
}
$str .= "('".$pushid."','".$value['uid']."','".$value2['uid']."', '".$value2['truename']."', '".$value2['agentid']."', '".$value2['agentshortname']."', '".time()."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."', '".$type_tmp."'),";
}
}
}
if($str) {
$str = rtrim($str,',');
$sql = "INSERT INTO `marketing_log` (`pushid` ,`uid` ,`brokerid` ,`brokername` ,`agentid` ,`agentname`,`addtime` ,`telno` ,`sendid` ,`sendkind`,`tbl`) VALUES $str";
$query = $this->db_esf->query($sql);
}
//转编码
$uarrnew = array();
if(is_array($uarr) && !empty($uarr)) {
foreach($uarr as $key=>$value5) {
//过滤符合推送的经纪人
if(in_array($value5['uid'],$uarr_filter)) {
$uarrnew[$key]=$value5;
$uarrnew[$key]['truename']= mb_convert_encoding($value5['truename'],'utf8','gbk');
$uarrnew[$key]['agentshortname']= mb_convert_encoding($value5['agentshortname'],'utf8','gbk');
}
}
}
$contentnew = '';
$re['content'] = $contentnew;
$re['uarr'] = $uarrnew;
$return[] = $re;
$t3 = microtime(true);
$ttt = round($t3-$t1,1);
writelog('中间耗时:'.$ttt.'秒' , 'jpush_'.date('d') );
if(!empty($uarr_filter)){
$j_arr = array_flip($uarr_filter);
$this->jpush_uid_data($j_arr); //该数组 过滤 大于5个推送
//$this->jpush_uid_data($arr['uid']); //该数组没排除大于5个推送
}
}
}
}
//---- 日志 ----
$t2 = microtime(true);
$tt = round($t2-$t1,1);
writelog('-------- 结束 --------:耗时'.$tt.'秒' , 'jpush_'.date('d') );
return $return;
}
/**
* 分站获取推送库的信息
* @param type $uid,$remainNum 剩余推送次数
* @return array
*/
function getpusharraycity($remainNum,$city)
{
if(intval($remainNum) <= 0) return array();
//查出推送库总数
$push_array_num = $this->get_data(array('form_name' => 'push_user','where'=>array('cityname'=>$city),'select'=>array(' count(id) as num')),'esfbak');
$push_num = ceil($push_array_num[0]['num']/$remainNum);
$push_num = 20;
//查出推送库
$push_array = $this->get_data(array('form_name' => 'push_user','where'=>array('cityname'=>$city), 'order_by'=>'id asc','limit'=>$push_num),'esfbak');
//print_r($push_array);die;
if(is_array($push_array) && !empty($push_array))
{
foreach($push_array as $key=>$value)
{
$pushid = 0;
// if($key <4) continue;
//将信息加入推送历史表,删除推送表
$sql = "INSERT INTO `push_user_log` (`pushuserid` ,`uid` ,`level` ,`sendtime` ,`content` ,`telno` ,`sendid` ,`sendkind` ,`cityname` ,`tbl`,`addtime`) VALUES ('".$value['id']."','".$value['uid']."','".$value['level']."', '".time()."', '".$value['content']."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."', '".$value['cityname']."', '".$value['tbl']."', '".$value['addtime']."')";
//$query = $this->db_esf->query($sql);
//$pushid = $this->db_esf->insert_id();//自增id
$sql2 = "DELETE from `push_user` where telno='".$value['telno']."'";
//$query = $this->db_esf->query($sql2);
//对信息进行处理(第一次如果查询异常,再查询一次)
$arr = $this->get_luc_data($value);
if(count($arr['uid']) > 1)
{
$uidstr = '';
foreach($arr['uid'] as $key4=>$value4)
{
$uidstr .= $uidstr == '' ? $key4 : ','.$key4;
}
//记录日志
$msg = "************************************************ \n";
$msg .= date('Y-m-d H:i:s').var_export($arr['uid'],true)." \n";
$log = dirname(__FILE__)."/getpusharray.log";
file_put_contents($log,$msg,FILE_APPEND );
//将经纪人加入营销表,判断是否今日已推送5条
$sql = "select count(*) as num,brokerid from marketing_log where addtime>'".strtotime(date('Y-m-d'))."' and addtime<'".(strtotime(date('Y-m-d'))+24*60*60)."' and brokerid in ($uidstr) group by brokerid";
$query = $this->db_esf->query($sql);
$uarr_num = $query->result_array();
$temp_uarr_num = array();
if(is_array($uarr_num) && !empty($uarr_num))
{
foreach($uarr_num as $value1)
{
//今日经纪人推送条数
$temp_uarr_num[$value1['brokerid']]=$value1['num'];
}
}
$sql = "select b.uid,b.truename,a.agid as agentid,a.agentshortname from broker b left join agency a on b.agentcode = a.agentcode where b.valid_flag = 1 and b.uid in ($uidstr)";
$query = $this->db_esfhousebak->query($sql);
$uarr = $query->result_array();
//过滤推送超过5次的经纪人
$str='';
$uarr_filter = array();
if(is_array($uarr) && !empty($uarr)){
foreach($uarr as $value2)
{
if(!isset($temp_uarr_num[$value2['uid']]) || $temp_uarr_num[$value2['uid']]<5)
{
$uarr_filter[] = $value2['uid'];
$str .= "('".$pushid."','".$value['id']."','".$value2['uid']."', '".$value2['truename']."', '".$value2['agentid']."', '".$value2['agentshortname']."', '".time()."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."'),";
}
}
}
if($str)
{
$str = rtrim($str,',');
$sql = "INSERT INTO `marketing_log` (`pushid` ,`uid` ,`brokerid` ,`brokername` ,`agentid` ,`agentname`,`addtime` ,`telno` ,`sendid` ,`sendkind`) VALUES $str";
$query = $this->db_esf->query($sql);
}
//转编码
$uarrnew = array();
if(is_array($uarr) && !empty($uarr))
{
foreach($uarr as $key=>$value5)
{
//过滤符合推送的经纪人
if(in_array($value5['uid'],$uarr_filter))
{
$uarrnew[$key]=$value5;
$uarrnew[$key]['truename']= mb_convert_encoding($value5['truename'],'utf8','gbk');
$uarrnew[$key]['agentshortname']= mb_convert_encoding($value5['agentshortname'],'utf8','gbk');
}
}
}
$re['content'] = $contentnew;
$re['uarr'] = $uarrnew;
$return[] = $re;
//print_r($return);die;
$this->jpush_uid_data($arr['uid']);
}
}
return $return;
}
}
function get_luc_data($value)
{
$content = unserialize($value['content']);
$address =explode("-",$content['address']);
$street =$address['1'];
$street ="大房郢水库";
$sql_street = "select id from street where streetname='$street' limit 1";
$query_street = $this->db_esfhousebak->query($sql_street);
$street_arr = $query_street->result_array();
$street_id =$street_arr[0]['id'];
//echo $street_id;die;
$price =explode("-",$content['price']);
$price1 =$price['0'];
$price2 =$price['1'];
/*
print_r($content);die;
$sql = "select uid from sell where esta=1 and street_id='$street_id'";
$query = $this->db_esfhousebak->query($sql);
$uarr = $query->result_array();
$sql_search ="select id from sell where esta=1 luc";
*/
error_reporting(E_ALL);
ini_set('display_errors', '1');
$arr['strCheckMethod'] ="";
$arr['returnMethod'] ="ary";
$arr['returnCharSet'] ="gbk";
if($value['tbl']=='sell')
{
//print_r($value['content']);
$content = unserialize($value['content']);
$arr['appName'] =NS_SELL;
$sql_condition ="";
$server = new Server($arr,"","ary","gbk");
$sql_search ="select id from sell where esta=1 luc";
$ary = $server->query($sql_search);
print_r($ary);die;
}
else
{
$arr['appName'] =NS_RENT;
$sql_condition ="";
}
}
/**
* 获取推送库的信息
* @param type $uid,$remainNum 剩余推送次数
* @return array
*/
function getpusharraytest($remainNum){
if(intval($remainNum) <= 0) return array();
//查出推送库总数
$push_array_num = $this->get_data(array('form_name' => 'push_user','where'=>array('cityname'=>'nj'),'select'=>array(' count(id) as num')),'esfbak');
$push_num = ceil($push_array_num[0]['num']/$remainNum);
$push_num = 20;
//查出推送库
$push_array = $this->get_data(array('form_name' => 'push_user','where'=>array('cityname'=>'nj','telno'=>'18655070104'), 'order_by'=>'id asc','limit'=>$push_num),'esfbak');
//'where_in'=>array('telno',array(13813048550,15150897128,13062566161,18652058969,18260048358)),
//print_r($push_array);die;
if(is_array($push_array) && !empty($push_array)){
foreach($push_array as $key=>$value){
$pushid = 0;
// if($key <4) continue;
//将信息加入推送历史表,删除推送表
$sql = "INSERT INTO `push_user_log` (`pushuserid` ,`uid` ,`level` ,`sendtime` ,`content` ,`telno` ,`sendid` ,`sendkind` ,`cityname` ,`tbl`) VALUES ('".$value['id']."','".$value['uid']."','".$value['level']."', '".time()."', '".$value['content']."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."', '".$value['cityname']."', '".$value['tbl']."')";
$query = $this->db_esf->query($sql);
$pushid = $this->db_esf->insert_id();//自增id
$sql2 = "DELETE from `push_user` where telno='".$value['telno']."'";
$query = $this->db_esf->query($sql2);
//对信息进行处理(第一次如果查询异常,再查询一次)
//$arr = $this->get_solr_data($value);
$arr['uid']['850507']=1;
$arr['uid']['835248']=1;
if(isset($arr['blockid'])){
$arr =array();
$arr = $this->get_solr_data($value);
}
//$arr['uid']=array('835248'=>'1','822557'=>'2','857996'=>'2','857992'=>'2','850507'=>'2','827694'=>'2','827350'=>'1');
//$arr['uid']=array('850507'=>'1','860097'=>'2','860103'=>'2','860101'=>'2','860099'=>'2','827350'=>'1','859958'=>1,'857568'=>1);
//print_r($arr['uid']);die;
$this->jpush_uid_data($arr['uid']);
if(count($arr['uid']) >= 1){
$uidstr = '';
foreach($arr['uid'] as $key4=>$value4)
{
$uidstr .= $uidstr == '' ? $key4 : ','.$key4;
}
//将经纪人加入营销表,判断是否今日已推送5条
$sql = "select count(*) as num,brokerid from marketing_log where addtime>'".strtotime(date('Y-m-d'))."' and addtime<'".(strtotime(date('Y-m-d'))+24*60*60)."' and brokerid in ($uidstr) group by brokerid";
//echo $sql;die;
$query = $this->db_esf->query($sql);
$uarr_num = $query->result_array();
$temp_uarr_num = array();
if(is_array($uarr_num) && !empty($uarr_num)){
foreach($uarr_num as $value1)
{
//今日经纪人推送条数
$temp_uarr_num[$value1['brokerid']]=$value1['num'];
}
}
$sql = "select b.uid,b.truename,a.agid as agentid,a.agentshortname from broker b left join agency a on b.agentcode = a.agentcode where b.valid_flag = 1 and b.uid in ($uidstr)";
$query = $this->db_esfhousebak->query($sql);
$uarr = $query->result_array();
//过滤推送超过5次的经纪人
$str='';
$uarr_filter = array();
if(is_array($uarr) && !empty($uarr)){
foreach($uarr as $value2)
{
if(!isset($temp_uarr_num[$value2['uid']]) || $temp_uarr_num[$value2['uid']]<5)
{
$uarr_filter[] = $value2['uid'];
$str .= "('".$pushid."','".$value['id']."','".$value2['uid']."', '".$value2['truename']."', '".$value2['agentid']."', '".$value2['agentshortname']."', '".time()."', '".$value['telno']."', '".$value['sendid']."', '".$value['sendkind']."'),";
}
}
}
if($str){
$str = rtrim($str,',');
$sql = "INSERT INTO `marketing_log` (`pushid` ,`uid` ,`brokerid` ,`brokername` ,`agentid` ,`agentname`,`addtime` ,`telno` ,`sendid` ,`sendkind`) VALUES $str";
$query = $this->db_esf->query($sql);
}
//转编码
$uarrnew = array();
if(is_array($uarr) && !empty($uarr)){
foreach($uarr as $key=>$value5){
//过滤符合推送的经纪人
if(in_array($value5['uid'],$uarr_filter)){
$uarrnew[$key]=$value5;
$uarrnew[$key]['truename']= mb_convert_encoding($value5['truename'],'utf8','gbk');
$uarrnew[$key]['agentshortname']= mb_convert_encoding($value5['agentshortname'],'utf8','gbk');
}
}
}
$re['content'] = $contentnew;
$re['uarr'] = $uarrnew;
$return[] = $re;
//print_r($return);die;
}
}
//print_r($return);die;
return $return;
}
}
//按照别名 批量推送 :wjy 2019-06-18 超时不用
function jpush_uid_data_all($idsOrg)
{
$uidarr = array();
foreach($idsOrg as $key=>$val) {
if($key){
$uidarr[] = $key;
}
}
$uidstr = implode(',', $uidarr);
if(empty($uidstr)){
return true;
}
$sql = "select alias,devicetype from user_token where uid in ($uidstr)";
$query = $this->db_esfhousebak->query($sql)->result_array();
$android_list = $ios_list = $find = array();
foreach ($query as $vp){
$alias = $vp['alias'];
$device = $vp['devicetype'];
if($device && $alias && !in_array($alias, $find)) {
$find[] = $alias;
if($device=='android'){
$android_list[] = $alias;
}else{
$ios_list[] = $alias;
}
}
}
//极光推送
require_once(dirname(__FILE__)."/jpush/JPush.php");
require_once(dirname(__FILE__)."/jpush/JPushException.php");
$str = "您有新的客户可抢,手慢无!快去查看→";
$content = $title = $msg = mb_convert_encoding($str, 'utf-8', 'gbk');
$extras = array('type'=>1,'content'=>$content,'url'=>'');
$uri = array("uri"=>$extras);
$app_key = "642b9e71e51654b5aec60a04";
$master_secret = "a3e177784496e726cbb12e3e";
$logFile = './log/'.date('Ym').'/jpushlog_'.date('d').'.log';
$maxTime = 10;
//初始化
$client = new JPush($app_key, $master_secret, $logFile, $maxTime);
if($android_list){
try{
$result = $client->push()
->setPlatform(array('android'))
->addAlias($android_list)
->setMessage($msg, $title, '', $uri)
->setOptions(null, null, null, false)
->send();
}catch (APIRequestException $e){
$_push_result = $e->getMessage();
writelog('android__: '.print_r($_push_result,1), 'jpush_'.date('d') );
}
}
if($ios_list){
try{
$result = $client->push()
->setPlatform(array('ios'))
->setNotificationAlert($title)
->addAlias($ios_list)
->addAndroidNotification($msg, $title, null, $uri)
->addIosNotification($msg, null, '+1', null, null, $uri)
->setOptions(null, null, null, true)
->send();
}catch (Exception $e){
$_push_result = $e->getMessage();
writelog('ios__: '.print_r($_push_result,1), 'jpush_'.date('d') );
}
}
return true;
}
function jpush_uid_data($value)
{
$str ="";
foreach ($value as $key =>$rs) {
$str .=$key.',';
}
$uidstr =trim($str,',');
$sql = "select alias from user_token where uid in ($uidstr)";
$query = $this->db_esfhousebak->query($sql);
$uarr = $query->result_array();
$alias = array();
foreach ($uarr as $key =>$data) {
if($data['alias']) {
$alias[] =$data['alias'];
}
}
if( empty($alias) ){
return true;
}
require_once(dirname(__FILE__)."/jpush/JPush.php");
$str = "您有新的客户可抢,手慢无!快去查看→";
$content = $title = $msg = mb_convert_encoding($str, 'utf-8', 'gbk');
$extras = array('type'=>1,'content'=>$content,'url'=>'');
$uri = array("uri"=>$extras);
$app_key = "642b9e71e51654b5aec60a04";
$master_secret = "a3e177784496e726cbb12e3e";
$logFile = './log/'.date('Ym').'/jpushlog_'.date('d').'.log';
$maxTime = 5;
// 初始化
$client = new JPush($app_key, $master_secret, $logFile, $maxTime);
foreach ($alias as $key =>$rs)
{
$sql = "select devicetype from user_token where alias = '$rs'";
$aliasTest = array($rs);
$query = $this->db_esfhousebak->query($sql);
$devicetypedata = $query->result_array();
$devicetype =$devicetypedata['0']['devicetype'];
if($devicetype=='android')
{
$result = $client->push()
->setPlatform(array('android'))
//->setNotificationAlert($title)
->addAlias($aliasTest)
//->addAndroidNotification($msg, $title, null, $uri)
//->addIosNotification($msg, null, '+1', null, null, $uri)
->setMessage($msg, $title, '', $uri)
->setOptions(null, null, null, false)
->send();
}
else
{
$result = $client->push()
->setPlatform(array('ios'))
->setNotificationAlert($title)
->addAlias($aliasTest)
->addAndroidNotification($msg, $title, null, $uri)
->addIosNotification($msg, null, '+1', null, null, $uri)
//->setMessage('msg', 'title', '', array('type'=>2,'taskId'=>467,'signtype'=>1,'signId'=>1613))
->setOptions(null, null, null, true)
->send();
}
}
}
/**
* 再次通过solr获得数据
* @param type $array
* @return array
*/
function get_solr_data($value){
global $solr_conf_arr,$house;
$city = 'nj';
if($value['tbl']=='sell'){
$this->load->library('solr_class',array('api_url'=>$solr_conf_arr[$city][$value['tbl']]),'solr_sell');
$this->solr_class =$this->solr_sell;
}else{
$this->load->library('solr_class',array('api_url'=>$solr_conf_arr[$city][$value['tbl']]),'solr_rent');
$this->solr_class =$this->solr_rent;
}
$content = unserialize($value['content']);
$infotype_flip = array_flip($house['infotype']);
if($value['sendkind']==1){
$address = explode('/',$content['address']);
$streetname1 = substr(strstr($address[0],'-'),1);
$streetname2 = substr(strstr($address[1],'-'),1);
$streetname3 = substr(strstr($address[2],'-'),1);
$streetid1 = $this->block_model->getstreetdetailbyname($streetname1,array('id'));
$streetid2 = $this->block_model->getstreetdetailbyname($streetname2,array('id'));
$streetid3 = $this->block_model->getstreetdetailbyname($streetname3,array('id'));
$infotype = $infotype_flip[$content['infotype']];
//$buildarea = explode('-',$content['buildarea']);
//$buildarea1 = $buildarea[0];
//$buildarea2 = $buildarea[1];
$price = explode('-',$content['price']);
$price1 = $price[0];
$price2 = $price[1];
$buildyear = explode('-',$content['buildyear']);
$buildyear1 = $buildyear[0];
$buildyear2 = $buildyear[1];
if(!empty($content['renttype'])){
$renttype = $content['renttype'];
}
}elseif($value['sendkind']==2 or $value['sendkind']==3 or $value['sendkind']==4){
$infotype = $infotype_flip[$content['infotype']];
$blockname = $content['blockshowname'];
if($value['tbl']=='rent'){
if($content['price']<=800){
$price1 = 0;
$price2 = 1500;
}elseif($content['price']>800 && $content['price']<=1200){
$price1 = 500;
$price2 = 2000;
}elseif($content['price']>1200 && $content['price']<=2000){
$price1 = 800;
$price2 = 2500;
}elseif($content['price']>2000 && $content['price']<=3000){
$price1 = 1500;
$price2 = 3500;
}elseif($content['price']>3000 && $content['price']<=5000){
$price1 = 2000;
$price2 = 6000;
}elseif($content['price']>5000 && $content['price']<=10000){
$price1 = 4000;
$price2 = 11000;
}elseif($content['price']>=10000){
$price1 = 10000;
$price2 = 999999;
}
}else{
if($content['price']<=40){
$price1 = 0;
$price2 = 60;
}elseif($content['price']>40 && $content['price']<=60){
$price1 = 30;
$price2 = 80;
}elseif($content['price']>60 && $content['price']<=90){
$price1 = 50;
$price2 = 120;
}elseif($content['price']>90 && $content['price']<=120){
$price1 = 80;
$price2 = 150;
}elseif($content['price']>120 && $content['price']<=150){
$price1 = 100;
$price2 = 180;
}elseif($content['price']>150 && $content['price']<=200){
$price1 = 120;
$price2 = 220;
}elseif($content['price']>200 && $content['price']<=300){
$price1 = 150;
$price2 = 350;
}elseif($content['price']>300 && $content['price']<=500){
$price1 = 250;
$price2 = 600;
}elseif($content['price']>=500){
$price1 = 500;
$price2 = 999999;
}
}
}elseif($value['sendkind']==5){
$blockname = $content['blockname'];
}
if($blockname != '')
{
$this->solr_class->setQueryField(array("blockshowname"=>$blockname));
}
else
{
$this->solr_class->setQueryField("");
}
$streetarr = $ffarr = array();
$ffarr[] = array("oper"=>"NOT", "field"=>"uid", "inneroper"=>":", "value"=>0);
$ffarr[] = array("oper"=>"AND", "field"=>"esta", "inneroper"=>":", "value"=>1);
$ffarr[] = array("oper"=>"AND", "field"=>"infofrom", "inneroper"=>":", "value"=>5);
if(isset($streetid1) && $streetid1 > 0)
{
$streetarr[] = $streetid1['id'];
}
if(isset($streetid2) && $streetid2 > 0)
{
$streetarr[] = $streetid2['id'];
}
if(isset($streetid3) && $streetid3 > 0)
{
$streetarr[] = $streetid3['id'];
}
if($streetarr)
{
$ffarr[] = array("oper"=>"AND", "field"=>"streetid", "inneroper"=>"OR", "value"=>$streetarr);
}
if($infotype > 0)
{
$ffarr[] = array("oper"=>"AND", "field"=>"infotype", "inneroper"=>":", "value"=>$infotype);
}
if($buildarea1 > 0 || $buildarea2 > 0)
{
if($buildarea1 < $buildarea2)
{
$ffarr[] = array("oper"=>"AND", "field"=>"buildarea", "inneroper"=>"TO", "value"=>array($buildarea1,$buildarea2));
}
else
{
$ffarr[] = array("oper"=>"AND", "field"=>"buildarea", "inneroper"=>":", "value"=>$buildarea1);
}
}
if($buildyear1 > 0 && $buildyear2 > 0)
{
if($buildyear1 < $buildyear2)
{
$ffarr[] = array("oper"=>"AND", "field"=>"buildyear", "inneroper"=>"TO", "value"=>array($buildyear1,$buildyear2));
}
else
{
$ffarr[] = array("oper"=>"AND", "field"=>"buildyear", "inneroper"=>":", "value"=>$buildyear1);
}
}
if($price1 > 0 || $price2 > 0)
{
if($price1 < $price2)
{
$ffarr[] = array("oper"=>"AND", "field"=>"price", "inneroper"=>"TO", "value"=>array($price1,$price2));
}
else
{
$ffarr[] = array("oper"=>"AND", "field"=>"price", "inneroper"=>":", "value"=>$price1);
}
}
if($renttype != '' && $value['tbl'] == 'rent')
{
$ffarr[] = array("oper"=>"AND", "field"=>"renttype", "inneroper"=>":", "value"=>$renttype);
}
if($ffarr)
{
$this->solr_class->setFilterField($ffarr);
}
//print_r($ffarr);
$this->solr_class->setCountNum(100);
$this->solr_class->setCountField(array("uid"));
$arr = $this->solr_class->query('countgroup');
//print_r($arr);die;
return $arr;
}
/**
* 获取向经纪人推送的信息
* @param type $brokerid
* @return array
*/
function Getpushnumbybrokerid($brokerid,$ctime,$is_buy,$page=1,$pagesize=20){
if($is_buy==1){
//$sql = "select b.content,a.addtime,a.is_buy,a.is_sendtelno,a.brokerid,b.sendid,b.sendkind,b.id as pushid,b.telno,b.tbl,b.level,b.sellnum,a.cusIntention from push_user_log b left join marketing_log a on b.telno = a.telno where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."' and a.is_buy='".$is_buy."' order by b.id desc limit ".($page-1)*$pagesize.",".$pagesize."" ;
$sql = "select b.content,a.addtime,a.is_buy,a.is_sendtelno,a.brokerid,b.sendid,b.sendkind,b.id as pushid,b.telno,b.tbl,b.level,b.sellnum,a.cusIntention from push_user_log b left join marketing_log a on b.id = a.pushid where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."' and a.is_buy='".$is_buy."' order by b.id desc limit ".($page-1)*$pagesize.",".$pagesize."" ;
}else{
//$sql = "select b.content,a.addtime,a.is_buy,a.is_sendtelno,a.brokerid,b.sendid,b.sendkind,b.id as pushid,b.telno,b.tbl,b.level,b.sellnum,a.cusIntention from push_user_log b left join marketing_log a on b.telno = a.telno where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."' order by b.id desc " ;
$sql = "select b.content,a.addtime,a.is_buy,a.is_sendtelno,a.brokerid,b.sendid,b.sendkind,b.id as pushid,b.telno,b.tbl,b.level,b.sellnum,a.cusIntention from push_user_log b left join marketing_log a on b.id = a.pushid where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."' order by b.id desc " ;
}
$query = $this->db_esfbak->query($sql);
$arr = $query->result_array();
if($arr){
foreach($arr as $key=>$value)
{
$arr1[$key] = $value;
$con = unserialize($value['content']);
//wjy:处理 字符类型问题
if($con===false){
$unserialized = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $value['content'] );
$con = unserialize($unserialized);
}
if($con){
foreach($con as $key1=> $value1){
if($key1=='buildyear'){
$arr2[$key1]= mb_convert_encoding($value1.'年','utf8','gbk');
}elseif($key1=='buildarea'){
$arr2[$key1]= mb_convert_encoding($value1.'平米','utf8','gbk');
}elseif($key1=='brokername'){
}else{
$arr2[$key1]= mb_convert_encoding($value1,'utf8','gbk');
}
}
}
$arr1[$key]['content']=$arr2;
}
}
return $arr1;
}
/**
* 获取向经纪人推送的信息的数量
* @param type $brokerid
* @return array
*/
function Getpushnumbybroker($brokerid,$ctime,$is_buy){
if($is_buy==1){
//$sql = "select count(a.id) as num from push_user_log b left join marketing_log a on b.telno = a.telno where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."' and a.is_buy='".$is_buy."'";
$sql = "select count(a.id) as num from push_user_log b left join marketing_log a on b.id = a.pushid where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."' and a.is_buy='".$is_buy."'";
}else{
//$sql = "select count(a.id) as num from push_user_log b left join marketing_log a on b.telno = a.telno where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."'" ;
$sql = "select count(a.id) as num from push_user_log b left join marketing_log a on b.id = a.pushid where a.addtime>'".$ctime."' and a.brokerid='".$brokerid."'" ;
}
$query = $this->db_esfbak->query($sql);
$arr = $query->result_array();
return $arr[0];
}
/**
* 获取推送信息的出售次数和推送的经纪人
* @param type $brokerid
* @return array
*/
function Getsellnumbypush($telno,$sendid,$sendkind){
$key = $this->memkey.'_Getsellnumbypush'.$telno.$sendid.$sendkind;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$pushdetail = $this->memcached_class->get($key);
if( empty($pushdetail) )
{
$pushdetail= $this->get_data(array('form_name' => 'push_user_log','limit'=>1,'where'=>array('telno'=>$telno,'sendid'=>$sendid,'sendkind'=>$sendkind,'sendtime >'=>time()-24*60*60*30),'select'=>array('sellnum','broker','sendid','sendkind')),'esfbak');
$this->memcached_class->add($key, $pushdetail,3600);
}
return $pushdetail[0];
}
/**
* 获取推送信息详细信息
* @param type $pushid
* @return array
*/
function Getpushdetal($pushid){
$key = $this->memkey.'Getpushdetal'.$pushid;
$this->memcached_class->delete($key);
if($this->input->get('update') == 1){
$this->memcached_class->delete($key);
}
$pushdetail = $this->memcached_class->get($key);
if( empty($pushdetail) ){
$pushdetail= $this->get_data(array('form_name' => 'push_user_log','limit'=>1,'where'=>array('id'=>$pushid),'select'=>array('sellnum','broker','sendid','sendkind','telno')),'esf');
$this->memcached_class->add($key, $pushdetail,86400);
}
return $pushdetail[0];
}
/**
* 更新推送信息的出售次数
* @param type $brokerid,$type 1,更新是否电话,2更新是否购买
* @return array
*/
function Updatebrokerpush($brokerid,$type,$pushid){
//检查是否可购买次数已满,或者此经纪人已经购买过
$push_log = $this->Getpushdetal($pushid);
if($type==1){
$arr = array('brokerid' => $brokerid,'pushid'=>$pushid);
$up=array('is_sendtelno'=>1,'sendtelnotime'=>time());
$this->set_table('marketing_log');
$result = $this->save($arr,$up,'esf');
return 1;
}else{
if($push_log['sellnum'] >= 3)
{
return 'N_FULL';
}elseif(strpos($push_log['broker'],$brokerid)){
return 'N_BUY';
}
$arr = array('brokerid' => $brokerid,'pushid'=>$pushid);
$up=array('is_buy'=>1,'buytime'=>time());
$this->set_table('marketing_log');
$result = $this->save($arr,$up,'esf');
//更新推送历史表
if($result>0)
{
//删除缓存
$this->memcached_class->delete($this->memkey.'Getpushdetal'.$pushid);
$up=array('sellnum'=>($push_log['sellnum']+1),'broker'=>$push_log['broker'].'&'.$brokerid);
$arr=array('id'=>$pushid);
$this->set_table('push_user_log');
$result = $this->save($arr,$up,'esf');
}
$telno = $push_log['telno'];
$sql = "select middle_phone from middlephone_relation where call_phone='".$telno."' and `status`=1 and type=4 ";
$query = $this->db_esfhousebak->query($sql);
$middle = $query->result_array();
if($middle){
$telno = $middle[0]['middle_phone'];
}
return array('telno'=>$telno);
}
}
/**
* 删除备选库的内容
* @param type $telno,电话
* @return array
*/
function delalternatives($telno)
{
//删除备选库
$this->push_model->set_table('alternatives_user');
$result = $this->push_model->del_mul($telno,'telno','esf');
}
/**
* 通过手机获取推送历史库库的信息
* @param string $telno
* @return array
*/
function getpushlogbytelno($telno){
/*
$key = $this->memkey.'getpushlogbytelno'.$telno;
if($this->input->get('update') == 1)
{
$this->memcached_class->delete($key);
}
$pushdetail = $this->memcached_class->get($key);
*/
$pushdetail = false;
if( empty($pushdetail) ){
$pushdetail = $this->get_data(array('form_name' => 'push_user_log','where'=>array('telno'=>$telno),'select'=>array('sendtime'),'order_by'=>'sendtime desc','limit'=>1),'esf');
//$this->memcached_class->add($key, $pushdetail,3600);
}
return isset($pushdetail[0]['sendtime'])?$pushdetail[0]['sendtime']:'';
}
//测试中间件返回数据
function test_push()
{
$arr = array();
$arr['strCheckMethod'] = "";
$arr['returnMethod'] = "ary";
$arr['returnCharSet'] = "gbk";
$arr['appName'] = NS_SELL; // sell表标记 $tbl = 'sell';
$server = new Server($arr,"","ary","gbk");
$sql = "select * from sell where esta=1 and infofrom=5 and district ='浦口区' group by uid limit 0, 10000 luc";
$ary = $server->query($sql);
var_dump($ary);
}
function getPushDataFromLucene($value, $tag=0)
{
$content = unserialize($value['content']);
if($tag==2){
writelog('第二次:'.print_r($value, 1), 'jpushnew_'.date('d') );
}
//wjy:处理 字符类型问题
if($content===false){
$unserialized = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $value['content'] );
$content = unserialize($unserialized);
}
$address = explode("-",$content['address']);
$street = $address['1'];
if(strpos($street, '/')) {
$street_arr = explode("/",$street);
$street = $street_arr['0'];
}
$district = $address['0'];
$sql_street = "select id from street where streetname='$street' and district='$district' limit 1";
$query_street = $this->db_esfhousebak->query($sql_street);
$street_arr = $query_street->result_array();
$street_id = $street_arr[0]['id'];
$price = explode("-",$content['price']);
$price1 = $price['0']*0.8;
$price2 = $price['1']*1.2;
// if( empty($street_id) ){
// writelog('getPushDataFromLucene空的街道id:'.print_r($value, 1), 'jpush_'.date('d') );
// return true;
// }
if( empty($district) ){
writelog('getPushDataFromLucene空的区属:'.print_r($value, 1), 'jpushnew_'.date('d') );
return true;
}
$arr = array();
$arr['strCheckMethod'] = "";
$arr['returnMethod'] = "ary";
$arr['returnCharSet'] = "gbk";
if($value['tbl']=='sell') {
$arr['appName'] = NS_SELL;
$tbl = 'sell';
} else {
$arr['appName'] = NS_RENT;
$tbl = 'rent';
}
$infotype = $content['infotype'];
$sql_condition1 = " ";
// if($infotype=='住宅') {
// $sql_condition1 = "infotype=1 and";
// }elseif($infotype=='别墅') {
// $sql_condition1 = "infotype=2 and";
// }elseif($infotype=='写字楼') {
// $sql_condition1 = "infotype=3 and";
// }elseif($infotype=='商铺') {
// $sql_condition1 = "infotype=4 and";
// }elseif($infotype=='车库车位') {
// $sql_condition1 = "infotype=6 and";
// }elseif($infotype=='厂房仓库') {
// $sql_condition1 = "infotype=5 and";
// }
if($value['tbl']=='sell')
{
$server= new Server($arr,"","ary","gbk");
//$where = $sql_condition1." esta=1 and infofrom=5 and streetid ='$street_id' group by uid limit 0, 10000"; //district
$where = $sql_condition1." esta=1 and infofrom=5 and district ='".$district."' group by uid limit 0, 10000";
$sql = "select * from ".$tbl." where $where luc";
writelog('fromLucene:'.$sql, 'jpushnew_'.date('d') );
$ary = $server->query($sql);
$values = array();
if(count($ary['GroupRecord'])) {
if(empty($ary['GroupRecord'][0])) {
$ary['GroupRecord'] =array($ary['GroupRecord']);
}
foreach ($ary['GroupRecord'] as $key => $rs) {
$values['uid'][$rs['Group']] = $rs['Count'];
}
}
} else {
//出租 rent
$where = $sql_condition1." esta=1 and infofrom=5 and streetid ='$street_id' group by uid limit 0,200";
$sql = "select uid from ".$tbl." FORCE INDEX(infofrom_esta_infotype) where $where ";
$query = $this->db_esfhousebak->query($sql);
$result = $query->result_array();
$values = array();
foreach ($result as $vp) {
$values['uid'][$vp['uid']] = '1';
}
}
if(!empty($values)){
$tparr = array();
foreach($values['uid'] as $key => $val){
$tparr[] = $key;
}
$string = implode(',', $tparr);
// 按照登录时间排序
// $sql = sprintf('SELECT uid FROM broker WHERE uid IN(%s) ORDER BY logintime DESC limit 1000', $string);
// $loginList = $this->db_esfhousebak->query($sql)->result_array();
// $array = array();
// if($loginList){
// foreach($loginList as $op){
// $uid = $op['uid'];
// if(isset($values['uid'][$uid])){
// $array[$uid] = strval($values['uid'][$uid]);
// }
// }
// $values['uid'] = $array;
// }
writelog('count_values:'.count($values['uid']), 'jpushnew_'.date('d') );
writelog('string:'.$string, 'jpushnew_'.date('d') );
}else{
writelog('空的ary:'.print_r($ary, 1), 'jpushnew_'.date('d') );
writelog('空的count:'.count($ary['GroupRecord']), 'jpushnew_'.date('d') );
writelog('空的values:'.json_encode($values), 'jpushnew_'.date('d') );
}
//取100条
// $values['uid'] = array_slice($values['uid'], 0, 1000, true);
return $values;
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
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