public function dealTask($task) { $brokerId = $task['brokerId']; $createTime = date('Ymd', $task['createTime']); //获取订单信息 $brokerOrderInfo = Bll_Broker_ShowcaseOrders::getInstance()->getBrokerOrders(array('brokerId' => $brokerId), $this->_dataBase); if (empty($brokerOrderInfo)) { $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '还没有购买橱窗')); return true; } // 判断该经纪人橱窗是否过期 if ($createTime > $brokerOrderInfo['endDate']) { $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '还购买的橱窗已过期')); return true; } //判断该经纪人当天是否已经扣费 //default没有扣费记录 $requestTimes = 0; $siteType = 1; if ($this->_dataBase == Const_ShowcaseOrders::RENT_DB) { $siteType = 2; } $condition = array('brokerId' => $brokerId, 'siteType' => $siteType, 'consumeDate' => $createTime); $limit = 1; $sort = array('id', 'desc'); $brokerConsumeInfo = Bll_Broker_ShowcaseAdConsumeQueue::getBrokerIsConsume($condition, $limit, $sort); //有扣费记录 if (!empty($brokerConsumeInfo)) { //待扣费 if ($brokerConsumeInfo['status'] == 0) { $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗待扣费')); return true; } elseif ($brokerConsumeInfo['status'] == 3) { //已经扣费 $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗已经扣费')); return true; } elseif ($brokerConsumeInfo['status'] == 2) { //扣费失败 $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗扣费调用api失败')); return true; } elseif ($brokerConsumeInfo['status'] == 1) { //余额不足,继续写入扣费记录 $requestTimes = $brokerConsumeInfo['requestTimes'] + 1; } } //获取扣费price $tmpArr = array('cityId' => $task['cityId'], 'status' => 1, 'startDate' => $createTime); $tmpCityPrice = Bll_Broker_ConfigCityPrice::getInstance()->getCityPrice($tmpArr, $this->_dataBase); if ($tmpCityPrice) { $cityPrice = $tmpCityPrice->discountPrice > 0 ? $tmpCityPrice->discountPrice : 0; } if (empty($cityPrice)) { $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗扣费价格为0')); return true; } // 写扣费记录 $adConsumeArr = array('brokerId' => $brokerId, 'amount' => $cityPrice, 'consumeDate' => $createTime, 'status' => 0, 'siteType' => $siteType, 'requestTimes' => $requestTimes, 'createTime' => time()); Bll_Broker_ShowcaseAdConsumeQueue::dataInsert($adConsumeArr); $this->setLog(sprintf('[%s] remark: %s', date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗扣费记录插入成功,请求次数:' . $requestTimes)); return true; }
/** * @param $task * @return bool */ public function dealTask($task) { $brokerId = $task['brokerId']; //获取订单信息 $brokerOrderInfo = Bll_Broker_ShowcaseOrders::getInstance()->getBrokerOrders(array('brokerId' => $brokerId), $this->_dataBase); if (empty($brokerOrderInfo)) { printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '还没有购买橱窗'); return true; } // 判断该经纪人橱窗是否过期 if ($this->currentYMD > $brokerOrderInfo['endDate']) { printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '购买的橱窗已过期'); return true; } //TODO 查询该经纪人当前推广房源数是否小于0 if ($this->_dataBase == Const_ShowcaseOrders::SALE_DB) { $comboList = Bll_Combo_HouseRelation::getHouseRelations($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_AJK, 1); } else { $comboList = Bll_Combo_HouseRelation::getHouseRelations($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_HZ, 1); } if (empty($comboList)) { printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '当前还没有推广房源'); return true; } //判断该经纪人当天是否已经扣费 //default没有扣费记录 $requestTimes = 0; $siteType = 1; if ($this->_dataBase == Const_ShowcaseOrders::RENT_DB) { $siteType = 2; } $condition = array('brokerId' => $brokerId, 'siteType' => $siteType, 'consumeDate' => $this->currentYMD); $limit = 1; $sort = array('id', 'desc'); $brokerConsumeInfo = Bll_Broker_ShowcaseAdConsumeQueue::getBrokerIsConsume($condition, $limit, $sort); //有扣费记录 if (!empty($brokerConsumeInfo)) { //待扣费 if ($brokerConsumeInfo['status'] == 0) { printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗待扣费'); return true; } elseif ($brokerConsumeInfo['status'] == 3) { //已经扣费 printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗已经扣费'); return true; } elseif ($brokerConsumeInfo['status'] == 2) { //扣费失败 printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗扣费调用api失败'); return true; } elseif ($brokerConsumeInfo['status'] == 1) { //余额不足,继续写入扣费记录 $requestTimes = $brokerConsumeInfo['requestTimes'] + 1; } } //获取扣费price $tmpArr = array('cityId' => $task['cityId'], 'status' => 1, 'startDate' => $this->currentYMD); $tmpCityPrice = Bll_Broker_ConfigCityPrice::getInstance()->getCityPrice($tmpArr, $this->_dataBase); if ($tmpCityPrice) { $cityPrice = $tmpCityPrice->discountPrice > 0 ? $tmpCityPrice->discountPrice : 0; } if (empty($cityPrice)) { printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗扣费价格为0'); return true; } // 写扣费记录 $adConsumeArr = array('brokerId' => $brokerId, 'amount' => $cityPrice, 'consumeDate' => $this->currentYMD, 'status' => 0, 'siteType' => $siteType, 'requestTimes' => $requestTimes, 'createTime' => time()); Bll_Broker_ShowcaseAdConsumeQueue::dataInsert($adConsumeArr); printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '经纪人' . $brokerId . '橱窗扣费记录插入成功,请求次数:' . $requestTimes); return true; }
/** * @param $task * @return bool */ public function dealTask($task) { $brokerId = $task['brokerId']; $amount = $task['amount']; $siteType = Const_ShowcaseOrders::SALE_DB; if ($task['siteType'] == 2) { $siteType = Const_ShowcaseOrders::RENT_DB; } $requestId = Bll_Broker_ShowcaseAdConsumeQueue::getPaymentRequestId($task['id'], $this->currentYMD, $siteType); //获取账户余额 $ajkBrokerData = Model_Broker_AjkBrokerExtend::getDataByBrokerId($brokerId); $userId = !empty($ajkBrokerData) ? $ajkBrokerData->userId : 0; $cityId = $ajkBrokerData->cityId; $balance = Bll_Broker_ShowcaseOrders::getInstance()->getBrokerMoney($userId); $balance = $balance * 100; if ($balance < $amount) { //余额不足,停止橱窗订单,更新订单操作日志. $this->stopShowCase($task, $siteType, $cityId); //TODO 更新扣费队列状态 $updateArr = array('status' => 1, 'requestId' => $requestId, 'remark' => json_encode(array('balance' => $balance, 'remark' => '余额不足'))); } else { //余额足够,调用扣费API $apiResult = Bll_Broker_ShowcaseConsumeQuery::getInstance()->callCosumeApi($userId, $requestId, $amount, $task['consumeDate'], $siteType); //扣费成功 if ($apiResult['status'] === true) { $updateArr = array('status' => 3, 'requestId' => $requestId, 'remark' => json_encode(array('balance' => $balance, 'apiData' => $apiResult['apiData']))); } else { $updateArr = array('status' => 2, 'requestId' => $requestId, 'remark' => json_encode(array('balance' => $balance, 'apiData' => $apiResult['apiData']))); } } //更新扣费队列状态 Bll_Broker_ShowcaseAdConsumeQueue::updateConsumeInfo($updateArr, array('id' => $task['id'])); return true; }