public function handle_request()
 {
     // 获取
     $props = Model_House_HzProp::data_access()->sort('propId', 'asc')->limit($this->per)->find_all();
     // 筛选
     $propIds = array();
     $separateTiming = strtotime("-{$this->reserve} days", strtotime(date('Y-m-d 00:00:00')));
     foreach ($props as $prop) {
         /* @var Model_House_HzProp $prop */
         // 保留天数前更新的房源,直接删除
         if ($prop['updated'] < $separateTiming) {
             $propIds[] = $prop['propId'];
             //设置房源归档,将房源从mysql写到HBase中
             $typeId = 1;
             //个人房源
             $contentOther = $prop->getContentOther();
             if (empty($contentOther)) {
                 $typeId = 2;
                 //ppc type 2 经纪人
             }
             $res = Bll_Service_Hbase::archiveProperty($typeId, $prop->propId, $prop);
             if ($res['info']['http_code'] == '200') {
                 $this->log(sprintf("[%s] - put to hbase %d row - typeId %s - [%s] : [%s]", date('Y-m-d H:i:s'), $prop->propId, $typeId, '成功', $res['data'] . '---------' . $res['info']['url']));
             } else {
                 $this->log(sprintf("[%s] - put to hbase %d row - typeId %s - [%s] : [%s]", date('Y-m-d H:i:s'), $prop->propId, $typeId, '失败', $res['data'] . '---------' . $res['info']['url']));
             }
             continue;
         }
         // 已软删除的房源,直接删除
         // 判断房源的 status 是否存在,不存在,记录日志
         $status = $prop->getContentBasic('status');
         if (is_null($status)) {
             $this->log(sprintf("[%s] - Prop %d has no status field.", date('Y-m-d H:i:s'), $prop->propId));
             continue;
         }
         if (in_array(intval($status), array(99, 100))) {
             $propIds[] = $prop['propId'];
             continue;
         }
         // 创建时间早于保留天数前更新的房源,直接删除
         // 判断房源的 created 是否存在,不存在,记录日志
         $created = $prop->getContentBasic('created');
         if (is_null($created)) {
             $this->log(sprintf("[%s] - Prop %d has no created field.", date('Y-m-d H:i:s'), $prop->propId));
             continue;
         }
         if ($created < $separateTiming) {
             $propIds[] = $prop['propId'];
             continue;
         }
         $this->log(sprintf("[%s] - Prop %d has not delete with status: %d, created: %s, updated: %s.", date('Y-m-d H:i:s'), $prop->propId, $status, date('Y-m-d H:i:s', $created), date('Y-m-d H:i:s', $prop['updated'])));
     }
     // 删除
     if ($propIds) {
         $deleteRowCount = Model_House_HzProp::data_access()->filter('propId', $propIds)->delete();
         $this->log(sprintf("[%s] - Delete %d (%d) rows - [%s]", date('Y-m-d H:i:s'), $deleteRowCount, $this->per, implode(', ', $propIds)));
     }
     // 休眠
     $this->sleep($this->sleep, $propIds);
 }
示例#2
0
 public function get_prop_content($propId)
 {
     $da = Model_House_HzProp::data_access();
     $da->filter('propId', $propId);
     $da->sort('updated', 'desc');
     $data = $da->find();
     return $data;
 }
示例#3
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $propId = $this->_params['propId'];
     // 获取Broker Mapping
     $brokerMapping = Model_Broker_MainBusiness::getMainBusinessByAjkBrokerId($brokerId);
     if (!$brokerMapping) {
         throw new Exception('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     $data = array();
     // 获取房源和计划关系
     $planRelation = Model_Plan_HzPlanning::getPropFixPlan($propId);
     if ($planRelation) {
         $data['status'] = 1;
         //推广中
     } else {
         $data['status'] = 0;
         //未推广
     }
     // 获取房源信息
     $prop = Model_House_HzProp::data_access()->filter('propId', $propId)->find_only();
     if (!$prop) {
         throw new Exception('房源不存在', Const_APIStatus::E_PROP_NOT_EXISTS);
     }
     // 判断房源和经纪人关联关系
     $propBasic = json_decode($prop['contentBasic'], true);
     if ($propBasic['userid'] != $brokerMapping['hzBrokerid']) {
         throw new Exception('房源不属于该经纪人', Const_APIStatus::E_PROP_NOT_EXISTS);
         // TODO
     }
     // 根据房源的计划ID判断房源是否已定价推广
     $data['planId'] = '';
     if ($plan = $prop->getFixPlan()) {
         $data['planId'] = $plan['id'];
     }
     // 点击单价
     $data['clickPrice'] = round($prop->getFixClickPrice(), 2);
     $data['clickPriceUnit'] = '元';
     // 今日定价点击量
     $data['todayClicks'] = $prop->getTodayClickSums('fix');
     // 定价点击总量
     $data['totalClicks'] = $prop->getTotalClickSums('fix');
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data);
 }
示例#4
0
 /**
  * 根据房源ID获取好租prop房源信息
  * @param array $ids 房源ID,支持一个数字的房源ID或者一维数组的房源ID
  * @return array|mixed|null|string
  */
 public function getHzProInfoByIds($ids = array())
 {
     if (empty($ids)) {
         return array();
     }
     if (is_numeric($ids)) {
         try {
             return Model_House_HzProp::data_access()->find_by_pk($ids);
         } catch (Exception $e) {
             return array();
         }
     } elseif (is_array($ids)) {
         try {
             return Model_House_HzProp::data_access()->find_by_pks($ids);
         } catch (Exception $e) {
             return array();
         }
     }
     return array();
 }
示例#5
0
 /**
  * 更新房源信息
  *
  * @param $propId
  * @param array $params
  * @return bool|int
  */
 public static function updateProp($propId, $params = array())
 {
     if (!is_array($params)) {
         return false;
     }
     unset($params['propId'], $params['proid'], $params['updated']);
     if (empty($params)) {
         return false;
     }
     try {
         $oProp = Model_House_HzProp::data_access()->filter('propId', $propId);
         foreach ($params as $key => $value) {
             $oProp->set_field($key, $value);
         }
         $oProp->updated = time();
         return $oProp->update();
     } catch (Exception $e) {
         return false;
     }
 }