示例#1
0
 public static function &getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * 向主推房源表插入主推房源信息
  * @param $brokerId
  * @param $cityId
  * @param array $propIds
  * @param $type
  * @return array|bool|int 返回结果是一个数组status==false表示验证不通过,不通过信息在msg里面;status==true表示验证通过
  */
 public function insertAdProsInfo($brokerId, $cityId, $propIds = array(), $type = Const_ShowcaseOrders::SALE_DB)
 {
     $res = array('status' => false, 'msg' => '');
     if (!in_array($type, array(Const_ShowcaseOrders::SALE_DB, Const_ShowcaseOrders::RENT_DB))) {
         $res['msg'] = '没有开通相应的业务!';
         return $res;
     }
     //房源最大个数
     if ($type == Const_ShowcaseOrders::SALE_DB) {
         $proMaxCount = Const_ShowcaseOrders::SALE_PRO_MAX_COUNT;
     } else {
         $proMaxCount = Const_ShowcaseOrders::RENT_PRO_MAX_COUNT;
     }
     if (empty($propIds)) {
         $propIds = array();
     } elseif (is_numeric($propIds)) {
         //支持传入一个房源ID
         $propIds = array($propIds);
     } elseif (!is_array($propIds)) {
         $res['msg'] = '房源ID参数错误!';
         return $res;
     }
     //房源超出范围
     if (!empty($propIds) && count($propIds) > $proMaxCount) {
         $res['msg'] = '最多只能选择' . $proMaxCount . '套房源!';
         return $res;
     }
     //删除经纪人主推房源信息
     if ($type == Const_ShowcaseOrders::SALE_DB) {
         $brokerAdPro = $this->getBrokerAdSalePropInfo($brokerId);
     } else {
         $brokerAdPro = $this->getBrokerAdRentPropInfo($brokerId);
     }
     if (!empty($brokerAdPro)) {
         foreach ($brokerAdPro as $brokerAdProVal) {
             //删除
             $brokerAdProVal->delete();
             //插入日志表
             $logData = array();
             $logData['brokerId'] = $brokerId;
             $logData['cityId'] = $cityId;
             $logData['propId'] = $brokerAdProVal->propId;
             $logData['reason'] = Const_ShowcaseOrders::PRO_CHANGE_LOG_REASON_CHANGE;
             $logData['type'] = Const_ShowcaseOrders::PRO_CHANGE_LOG_TYPE_SELF;
             $logData['flag'] = Const_ShowcaseOrders::PRO_CHANGE_LOG_FLAG_OUT;
             $logData['createTime'] = time();
             if ($type == Const_ShowcaseOrders::SALE_DB) {
                 Model_Broker_AdPropsChangeSaleLog::getInstance()->insertOne($logData);
             } else {
                 Model_Broker_AdPropsChangeRentLog::getInstance()->insertOne($logData);
             }
         }
     }
     //开始插入数据
     if (!empty($propIds)) {
         foreach ($propIds as $propIdVal) {
             $insertData = array();
             $insertData['brokerId'] = $brokerId;
             $insertData['cityId'] = $cityId;
             $insertData['propId'] = $propIdVal;
             $insertData['createTime'] = time();
             if ($type == Const_ShowcaseOrders::SALE_DB) {
                 $inserRes = Model_Broker_AdPropsSetSale::getInstance()->insertData($insertData);
             } else {
                 $inserRes = Model_Broker_AdPropsSetRent::getInstance()->insertData($insertData);
             }
             if ($inserRes) {
                 //插入日志表
                 $logData = array();
                 $logData['brokerId'] = $brokerId;
                 $logData['cityId'] = $cityId;
                 $logData['propId'] = $propIdVal;
                 $logData['reason'] = Const_ShowcaseOrders::PRO_CHANGE_LOG_REASON_UP;
                 $logData['type'] = Const_ShowcaseOrders::PRO_CHANGE_LOG_TYPE_SELF;
                 $logData['flag'] = Const_ShowcaseOrders::PRO_CHANGE_LOG_FLAG_IN;
                 $logData['createTime'] = time();
                 if ($type == Const_ShowcaseOrders::SALE_DB) {
                     Model_Broker_AdPropsChangeSaleLog::getInstance()->insertOne($logData);
                 } else {
                     Model_Broker_AdPropsChangeRentLog::getInstance()->insertOne($logData);
                 }
             }
         }
     }
     $res['status'] = true;
     return $res;
 }