/** * 增加money产生的公共动作 * @param string $descript * @throws Exception_BllErrorException */ private function addMoneyCommon($descript = '') { // 上线前判断余额 Jackin $userId = Bll_Broker_MainBusiness::getDataByEsfId($this->params['ajk_broker_id'])->memberId; try { $balanceInfo = Bll_Service_Payment::balance(Const_PaymentApp::HZ_DEFAULT, array('userId' => $userId)); } catch (Exception $e) { throw new Exception_BllErrorException(sprintf('调用api失败: %s userId=%d broker_id=%d ajk_broker_id=%d', $e->getMessage(), $userId, $this->params['broker_id'], $this->params['ajk_broker_id'])); } if ($balanceInfo['status'] == 'error') { throw new Exception_BllErrorException(sprintf('%s ajkBrokerId(%d) 获取余额失败', $descript, $this->params['ajk_broker_id'])); } elseif ($balanceInfo['data']['balance'] <= 0) { throw new Exception_BllErrorException(sprintf('%s ajkBrokerId(%d) 余额(%d)不足', $descript, $this->params['ajk_broker_id'], $balanceInfo['data']['balance'])); } $this->allReturn = array(sprintf('hz:%s ajkBrokerId(%d) 当前余额(%d) ', $descript, $this->params['ajk_broker_id'], $balanceInfo['data']['balance'])); //获取刷爆$descript的计划 $plans = Dao_Broker_HzPlan::get_broker_plan($this->params['broker_id'], 7); if (empty($plans)) { $this->allReturn[] = '没有获取到 status=7 的计划'; return; } $plan_ids = array(); foreach ($plans as $plan) { $plan_ids[] = $plan['id']; } // 获取所有房子并上线 $plans_props = Bll_HzFixPlan::get_plan_props($plan_ids, $this->params['city_id']); if (empty($plans_props)) { $this->allReturn[] = sprintf('没有获取到计划(%s)的房源', implode(',', $plan_ids)); return; } foreach ($plans_props as $plan_id => $props) { // 更新计划状态 if (Bll_HzPropBll::switchUpOrDown()) { if (!Dao_Broker_HzPlan::update_plan_status($plan_id, Const_HzPlan::SPREAD)) { $this->allReturn[] = "更新计划[{$plan_id}]数据失败"; } } else { $this->allReturn[] = "开关关闭,计划[{$plan_id}]数据不再更新"; } // 记录计划上线日志 $data = Bll_HzFixPlanBll::build_plan_log($this->params, 8, "{$descript},计划上线", $this->params['broker_id']); if (!Model_House_UpDown_PlanLog::create($data, date('m'))->save()) { $this->allReturn[] = "{$descript},计划[{$plan_id}]上线写入失败"; } else { $this->allReturn[] = "{$descript},计划[{$plan_id}]上线写入"; } foreach ($props['props'] as $prop) { if (Bll_HzPropBll::switchUpOrDown()) { if (Dao_Broker_HzProp::change_prop_status($prop['proid'], Const_HzStatus::ONLINE) && Model_Plan_HzPlanning::updatePlanningByPropId($prop['proid'], Const_HzPlan::SPREAD, Const_HzPlan::SPREAD_TYPE)) { $this->allReturn[] = "房源{$prop['proid']}上线成功"; } else { $this->allReturn[] = "房源{$prop['proid']}上线失败"; } } else { $all_return[] = "开关关闭,房源[{$prop['proid']}]状态不改变"; } $data = Bll_HzPropBll::build_prop_log($this->params, 5, "房源上线", $this->params['broker_id']); $data['planId'] = $plan_id; $data['houseId'] = $prop['proid']; if (!Model_Log_HouseLogNew::create($data, date('Ymd'))->save()) { $this->allReturn[] = "房源{$prop['proid']}上线日志写入失败"; } else { $this->allReturn[] = "房源{$prop['proid']}上线日志写入"; } } } }
/** * 租房精选房源取消推广 * 1. 维护计划状态 * 2. 通知solr上下 */ public static function choicePropOutBid($broker_id, $proid) { $flag_array = array('status' => 0, 'msg' => ''); //获取精选 房源、计划关系表信息(promotion_prop_planning) $planning = Dao_Broker_HzPlan::get_prop_all_planning($proid, Const_HzPlan::BID_TYPE); if (empty($planning)) { $flag_array['msg'] = Const_HzErrorInfo::PROPFIXNULL; return $flag_array; } //根据计划查询精选计划的信息 $plan_info = Dao_Broker_HzPlan::get_plan($planning[0]['plan_id']); if (empty($plan_info)) { $flag_array['msg'] = Const_HzErrorInfo::NULLPLAN; return $flag_array; } //判断计划是否为该经纪人的 if ($plan_info['user_id'] != $broker_id) { $flag_array['msg'] = Const_HzErrorInfo::PLANINFOERROR; return $flag_array; } //获取精选计划的冻结号 $sn = Dao_Broker_HzPlan::get_bid_sn($plan_info['id']); $sn = $sn['sn']; if (empty($sn)) { $flag_array['msg'] = Const_HzErrorInfo::PROPERROR; return $flag_array; } //获取精选花费 // $amount = $plan_info['total_consume']; $amount = $plan_info['amount'] - $plan_info['total_consume']; $note = urlencode('推广房源' . $proid); $user_id = Bll_HzBroker::get_userid_by_hzbrokerid($broker_id); /** 精选结算 调用3次 */ $charge_sn = false; $unfreezeOrderData = array('userId' => $user_id, 'proId' => $proid, 'serialNumber' => $sn, 'planId' => $plan_info['id'], 'amount' => $amount); $unfreezeOrder = Bll_Ppc_BidUnfreeze::createHzOrder($unfreezeOrderData); for ($i = 0; $i < 3 && !$charge_sn; $i++) { $charge_sn = Bll_PayAccount::cancel_frozen($user_id, $amount, $proid, Const_PaymentApp::HZ_CHOICE, $sn, $note, true); } if (!$charge_sn) { $unfreezeOrder->fail(); $flag_array['msg'] = Const_HzErrorInfo::CHARGEFAIL; // 此处不需要block,由job保证此处解冻正确 //return $flag_array; } else { $unfreezeOrder->complete(); } //查询房源信息 $proInfo = Model_House_HzProp::get_prop_info_by_prop_id($proid); //房源违规的、删除的不能更新房源状态 $prop_status = $proInfo['contentBasic']['status']; // 兼容新套餐 $ajkBrokerId = Model_Broker_HzMapping::get_ajk_broker_id($broker_id); if (Bll_Broker_HzBroker::isComboBroker($ajkBrokerId)) { /** 判断房源是否在套餐推广中 */ if (!Bll_Combo_HouseRelation::getOnlineRelationByHouseId($proid, Bll_Combo_HouseRelation::SITE_TYPE_HZ)) { $prop_status = Const_HzStatus::OUTLINE; } } else { //查询房源是否在计划里面 $fix_planning = Dao_Broker_HzPlan::get_prop_planning($proid, Const_HzPlan::SPREAD_TYPE); if (!in_array($proInfo['contentBasic']['status'], array(Const_HzStatus::VERIFY, Const_HzStatus::REMOVE, Const_HzStatus::EXPIRED))) { if (empty($fix_planning)) { //房源不在计划里面 $prop_status = Const_HzStatus::OUTLINE; //房源不在计划里面 } elseif ($fix_planning[0]['is_valid'] == Const_HzPlan::SPREAD) { $prop_status = Const_HzStatus::ONLINE; //定价正在推广 } elseif ($fix_planning[0]['is_valid'] == Const_HzPlan::UPPERLIMIT) { //定价非推广(没钱状态) $prop_status = Const_HzStatus::NOCASH; //房源没钱 } else { $prop_status = Const_HzStatus::MANUALLY; //房源状态更新为9手动停止 } } } //维护精选关联关系 if (!Dao_Broker_HzPlan::update_planning($planning[0]['id'], Const_HzPlan::MENUOVER)) { $flag_array['msg'] = Const_HzErrorInfo::UPDATAPLANNINGFAIL; return $flag_array; } //维护计划状态 if (!Dao_Broker_HzPlan::update_plan_status($plan_info['id'], Const_HzPlan::MENUOVER)) { $flag_array['msg'] = Const_HzErrorInfo::UPDATAPLANFAIL; return $flag_array; } //通知solr if ($prop_status == Const_HzStatus::ONLINE) { //定价正在推广 Dao_Broker_HzProp::into_prop_lucene($proid, $planning[0]['city_id'], 1); //竞价下,定价还在线。则更新上 } else { Dao_Broker_HzProp::into_prop_lucene($proid, $planning[0]['city_id'], 2); //下线房源 } $flag_array['status'] = 1; return $flag_array; }
/** * 206 计划限额不足(后端触发) * 查询计划信息 * 如果计划status!=1 return 记录计划限额不足停止日志 * 更新计划状态为status=2 限额不足 * 查询房源计划关系 * 如果不存在 return * 记录第二天推广日志 */ private function plan_budget_top() { $planInfo = $this->checkPlanIsEmpty(); if (!$planInfo['status'] != Const_HzPlan::SPREAD) { $this->writePlanLog(6, '计划限额不足停止'); return; } // 更新计划状态 if (!Dao_Broker_HzPlan::update_plan_status($this->params['plan_id'], Const_HzPlan::AUTOOVER)) { throw new Exception_BllErrorException("更新计划数据失败"); } $plannings = Dao_Broker_HzPlan::get_planning($this->params['plan_id']); if (empty($plannings)) { return; } foreach ($plannings as $planning) { //更新房源计划信息 //Dao_Broker_HzProp::change_prop_status($planning['proid'], Const_HzStatus::PLANCASH); //更新房源状态 // 维护房子状态 Bll_HzPropBll::bulidHzProStatu($planning['proid']); if (in_array($planning['is_valid'], array(Const_HzPlan::AUTOOVER, Const_HzPlan::UPPERLIMIT, Const_HzPlan::MANUALLY_PAUSE))) { continue; } if (!Dao_Broker_HzPlan::update_planning($planning['id'], Const_HzPlan::AUTOOVER)) { throw new Exception_BllErrorException("更新关系为限额上限失败,关系id={$planning['id']}"); } $this->params['pro_id'] = $planning['proid']; $this->writePropLog(6, '下线'); } }
/** * 删除经纪人定价组 * @param $broker_id * @param $plan_id * @return array */ public static function delete_broker_plan($broker_id, $plan_id) { //删除价组 条件判断 $flag_array = array('status' => 0, 'msg' => ''); if (empty($broker_id) || empty($plan_id)) { $flag_array['msg'] = Const_HzErrorInfo::PARAMS; return $flag_array; } $plan_info = Dao_Broker_HzPlan::get_plan($plan_id); if (empty($plan_info)) { $flag_array['msg'] = Const_HzErrorInfo::NULLPLAN; return $flag_array; } if ($plan_info['user_id'] != $broker_id) { $flag_array['msg'] = Const_HzErrorInfo::PLANINFOERROR; return $flag_array; } // 已删除 if ($plan_info['status'] == Const_HzPlan::MANUALLY_PAUSE) { $flag_array['msg'] = Const_HzErrorInfo::PLANINFOERROR; return $flag_array; } $plannings = Dao_Broker_HzPlan::get_planning($plan_id); $proids = array(); foreach ($plannings as $planning) { $proids[] = $planning['proid']; } $prop_option = Const_HzLog::DELPLANPROP; $status = Const_HzStatus::OUTLINE; // 房源更新状态 $plan_status = Const_HzPlan::MANUALLY_PAUSE; // 计划状态 $plan_option = Const_HzLog::DELPLAN; $proids_str = implode(',', $proids); $proinfo = Dao_Broker_HzProp::get_prop($proids); foreach ($plannings as $planning) { $basic_info = $proinfo[$planning['proid']]['content_basic']; //更新房源计划信息 if (Dao_Broker_HzProp::change_prop_status($planning['proid'], $status)) { //更新房源状态 if (Dao_Broker_HzPlan::update_planning($planning['id'], $plan_status)) { //更新关联关系 Dao_Broker_HzPlan::add_prop_log($planning['proid'], $prop_option, $basic_info['userid'], $plan_id, $basic_info['status'], $status); //记房源日志 // TODO 停止竞价 // TODO 下solr //记录房源下线日志 if ($status != Const_HzStatus::ONLINE && $basic_info['status'] == Const_HzStatus::ONLINE) { Dao_Broker_HzProp::ezft_assistant_log($planning['proid'], $basic_info['userid'], Const_HzPlan::SPREAD_TYPE, $basic_info['spread_type']); } //房源上下线日志 Dao_Broker_HzProp::add_updown_log($planning['proid'], $plan_id, Const_HzStatus::GOONLINE, $prop_option); } } } //更新计划 Dao_Broker_HzPlan::update_plan_status($plan_id, $plan_status); //计划日志 Dao_Broker_HzPlan::add_plan_log($plan_id, $proids_str, $plan_option, 1, $broker_id, 0, $plan_info['status'], $plan_status); $flag_array['status'] = 1; return $flag_array; }
/** * 动作 7 * 房源移出定价计划,导致竞价停止(房源日志发起) * 结算 * 更新计划为停止状态 * 通知solr下(停止的房源) * 记录房源日志(停止的房源) * 根据停止的房源,取出坑位里面的推广、排队房源 * 计算排名 * 更新计划状态(坑位里面的异动房源更新状态) * 通知solr(坑位里面的异动房源通知solr) * 记房源日志(坑位里面的房源异动日志) * @param array $params * @return array|bool */ public static function removeFixPlanForBid($params = array()) { self::$qInfo = $params; // 检查参数 $checkParams = self::checkParams($params); if (!$checkParams['status']) { return $checkParams; } // 获取信息,组装$params $joinParams = self::joinParams($params); if (!$joinParams['status']) { return $joinParams; } $all_return = array(); //判断竞价计划是否删除 if ($params['flag'] != 1) { return Bll_HzPropBll::build_return(0, '无效的竞价计划' . json_encode($params)); } //非推广的计划 if ($params['status'] != 1) { return Bll_HzPropBll::build_return(0, '非推广的竞价计划' . json_encode($params)); } // 非精选判断 if ($params['bidVersion'] == 2) { return Bll_HzPropBll::build_return(0, '房源为精选' . json_encode($params)); } //获取竞价计划的冻结号 $sn = Dao_Broker_HzPlan::get_bid_sn($params['planId']); $sn = $sn['sn']; if (empty($sn)) { return Bll_HzPropBll::build_return(0, Const_HzErrorInfo::PROPERROR . json_encode($params)); } //获取竞价花费 $amount = $params['totalConsume']; $note = urlencode('推广房源' . $params['proId']); $user_id = Bll_HzBroker::get_userid_by_hzbrokerid($params['']); /** 竞价结算 调用3次 */ $charge_sn = false; $unfreezeOrderData = array('userId' => $user_id, 'proId' => $params['proId'], 'serialNumber' => $sn, 'planId' => $params['planId'], 'amount' => $amount); $unfreezeOrder = Bll_Ppc_BidUnfreeze::createHzOrder($unfreezeOrderData); for ($i = 0; $i < 3 && !$charge_sn; $i++) { $charge_sn = Bll_PayAccount::cancel_frozen($user_id, $amount, '', Const_PaymentApp::HZ_BID, $sn, $note, true); } if (!$charge_sn) { $unfreezeOrder->fail(); $flag_array['msg'] = Const_HzErrorInfo::CHARGEFAIL; // 此处不需要block,由job保证此处解冻正确 //return $flag_array; } else { $unfreezeOrder->complete(); } //维护竞价关联关系 if (!Dao_Broker_HzPlan::update_planning($params['planId'], Const_HzPlan::DELETE)) { $flag_array['msg'] = '维护竞价关联关系,数据更新失败.'; return $flag_array; } //维护计划状态 if (!Dao_Broker_HzPlan::update_plan_status($params['planId'], Const_HzPlan::DELETE)) { $flag_array['msg'] = '维护计划状态,数据更新失败.'; return $flag_array; } // 更新计划的flag为删除状态 if (!Dao_Broker_HzPlan::update_history_bids($params['planId'])) { $flag_array['msg'] = '更新计划的flag为删除状态,数据更新失败.'; return $flag_array; } //记录房源日志 $data = array('houseId' => $params['proId'], 'planId' => $params['planId'], 'brokerId' => $params['ajkBrokerId'], 'cityId' => $params['cityId'], 'type' => 15, 'changeType' => 407, 'remark' => '房源' . $params['proId'] . '移出定价计划。竞价' . $params['planId'] . '(id)取消竞价推广。', 'addDate' => date('Y-m-d H:i:s'), 'operatorId' => $params['operationId'], 'siteType' => 2); if (!Model_Log_HouseLogNew::create($data, date('Ymd'))->save()) { return Bll_HzPropBll::build_return(0, array("日志写入失败")); } //计算房源状态 Bll_HzPropBll::bulidHzProStatu($params['proId']); return Bll_HzPropBll::build_return(1, array('竞价' . $params['planId'] . '(id)取消竞价推广。')); }