Ejemplo n.º 1
0
 /**
  *
  * 获取套餐点击量(人/天)
  * 备注:
  * 1.最多获取30天数据
  * 2.当天数据为准实时
  * 3.数据最早为半年前
  *
  * @param $brokerId 二手房经纪人id
  * @param $starDate 2014-08-08
  * @param $endDate 2014-08-18
  * @param $siteType 网站类型
  * @return array|string
  * [id] => 53
  * [brokerId] => 147536
  * [siteType] => 1
  * [date] => 20140814
  * [cnum] => 10
  * [icnum] => 0
  */
 public static function getBrokerComboClick($brokerId, $startDate, $endDate, $siteType, $boolCache = true)
 {
     /**数据初始化,时间转时间戳处理*/
     $startDate = strtotime($startDate);
     //开始时间
     $endDate = strtotime($endDate);
     //结束时间
     $nowDate = time();
     //当前时间
     /**参数判断*/
     //开始时间不能大于当前时间
     if ($startDate > $nowDate) {
         return false;
     }
     //只提供半年后的数据
     if ($startDate < $nowDate - 180 * 86400) {
         return false;
     }
     //结束时间大于当前时间,自动赋值为当前时间
     if ($endDate > $nowDate) {
         $endDate = $nowDate;
     }
     //只提供30天区间段内的数据
     if ($endDate - $startDate > 30 * 86400) {
         return false;
     }
     /**     查询参数生成   */
     //cache的key值计算(昨天之前的数据做cache)
     $keyDate = '';
     if ($endDate <= $nowDate - 86400) {
         $keyDate = date('Y.m.d', $startDate) . "-" . date('Y.m.d', $endDate);
     } else {
         $keyDate = date('Y.m.d', $startDate) . "-" . date('Y.m.d', $endDate - 86400);
     }
     //根据时间段计算落入的分表(按月分的表)
     $nowDateArr = array();
     //二位数组
     $otherDateArr = array();
     //三维数据
     $tmpOtherDateArr = array();
     //临时存储
     $tmpCalDate = $endDate;
     do {
         //参数初始化
         $formatDayTmpCalDate = date('Ymd', $tmpCalDate);
         $formatDayNowDate = date('Ymd', $nowDate);
         $formatMonthTmpCalDate = date('Ym', $tmpCalDate);
         $formatMonthNowDate = date('Ym', $nowDate);
         if ($formatDayTmpCalDate == $formatDayNowDate) {
             $nowDateArr['tableDate'] = $formatMonthTmpCalDate;
             $nowDateArr['date'][] = $formatDayTmpCalDate;
         } else {
             if (isset($tmpOtherDateArr['tableDate']) && $tmpOtherDateArr['tableDate'] == $formatMonthTmpCalDate) {
                 $tmpOtherDateArr['date'][] = $formatDayTmpCalDate;
             } else {
                 if (!empty($tmpOtherDateArr)) {
                     //数据压入
                     $otherDateArr[] = $tmpOtherDateArr;
                     $tmpOtherDateArr = array();
                 }
                 $tmpOtherDateArr['date'][] = $formatDayTmpCalDate;
                 $tmpOtherDateArr['tableDate'] = $formatMonthTmpCalDate;
             }
         }
         $tmpCalDate -= 86400;
         //时间到了,跳出循环
         if ($tmpCalDate < $startDate) {
             //数据压入
             $otherDateArr[] = $tmpOtherDateArr;
             break;
         }
     } while (true);
     /**  查询其他天的数据   */
     //cache取数据
     $otherDateValue = array();
     if ($boolCache) {
         $key = Util_MemCacheKey::get_broker_combo_click($brokerId, $keyDate . "_" . $siteType);
         $time = Util_MemCacheTime::get_broker_combo_click();
         $memcache = APF_Cache_Factory::get_instance()->get_memcache();
         $tmpValue = $memcache->get($key);
         if (!empty($tmpValue)) {
             $otherDateValue = $tmpValue;
         }
     }
     if (empty($otherDateValue)) {
         //到数据库查询
         foreach ($otherDateArr as $list) {
             //查询当天的数据
             $tmpOtherDateValue = Model_Ppc_NewPackageStatsBrokerDay::getComboClickInfoBydates($brokerId, $list['date'], $siteType, $list['tableDate']);
             foreach ($tmpOtherDateValue as $value) {
                 $otherDateValue[$value['date']] = $value;
             }
         }
         //压入cache
         if ($boolCache) {
             $memcache->set($key, $otherDateValue, 0, $time);
         }
     }
     //查询当天的数据
     $nowDateValue = array();
     if (!empty($nowDateArr['date'])) {
         $nowDateValue = Model_Ppc_NewPackageStatsBrokerDay::getComboClickInfoBydates($brokerId, $nowDateArr['date'], $siteType, $nowDateArr['tableDate']);
         foreach ($nowDateValue as $value) {
             $otherDateValue[$value['date']] = $value;
         }
     }
     //数据合并
     return $otherDateValue;
 }