Esempio n. 1
0
 public function handle_request()
 {
     $refundClickList = Model_Stats_JpBlackVppv::scanByClickDt($this->_startId, $this->_date, self::BATCH_LIMIT);
     foreach ($refundClickList as $refundClick) {
         $this->setFlag(array('id' => $refundClick['id']));
         $this->setLogContentPrefix($refundClick['id']);
         $this->setLog(sprintf('点击信息:%s', json_encode($refundClick)));
         $chargeLog = Model_Log_JpCharge::getRowById($refundClick['id']);
         if (empty($chargeLog)) {
             $this->setLog('没有获取到点击的扣费信息');
             continue;
         }
         $this->setLog(sprintf('扣费信息: %s', json_encode($chargeLog)));
         if (Model_Log_JpCharge::CHARGE_TYPE_0 != $chargeLog[Model_Log_JpCharge::CHARGE_TYPE]) {
             $this->setLog('不是扣费记录');
             continue;
         }
         if ($chargeLog['spread_type'] != Model_Log_JpCharge::SPREAD_TYPE_2) {
             $this->setLog('非精选扣费');
             continue;
         }
         if ($chargeLog['is_refund'] != Model_Log_JpCharge::IS_REFUND_0) {
             $this->setLog('已经退费过了');
             continue;
         }
         /** 执行退费逻辑 调用 Java API */
         $jpMemberInfo = Model_Broker_JpBroker::getBrokerInfoById($refundClick['memberId'], array('ajkMemberId', 'id', 'isDelete', 'source'));
         if (empty($jpMemberInfo)) {
             $this->setLog(sprintf('没有获取到用户[%d]的信息', $refundClick['memberId']));
             continue;
         }
         $this->setLog(sprintf('用户[%d]的信息: %s', $refundClick['memberId'], json_encode($jpMemberInfo)));
         $ajkUserId = Model_Broker_AjkBrokerExtend::getUserIdByBrokerId($jpMemberInfo['ajkMemberId']);
         if ($ajkUserId == 0) {
             $this->setLog(sprintf('没有获取到用户[jp:%d ajk:%d]的user id', $refundClick['memberId'], $jpMemberInfo['ajkMemberId']));
             continue;
         }
         $this->setLog(sprintf('用户[jp:%d ajk:%d]的userId=%d', $refundClick['memberId'], $jpMemberInfo['ajkMemberId'], $ajkUserId));
         $params = array('reqId' => $refundClick['id'], 'userId' => $ajkUserId, 'amount' => $chargeLog['real_cost'], 'note' => sprintf('房源[%d]精选点击退费', $refundClick['proId']));
         $this->setLog(sprintf('请求的参数:%s', http_build_query($params)));
         $refundSuccess = false;
         for ($i = 0; $i < 3; $i++) {
             /**
              * @var Bll_Service_Client_HttpResponse $apiResponse
              */
             $apiResponse = Bll_Service_Payment::refund(Const_PaymentApp::JP_SITE, $params);
             $this->setLog(sprintf('调用API退费返回值:%s', json_encode($apiResponse->getResponse())));
             if ($apiResponse->isSucceeded() && isset($apiResponse['result']) && $apiResponse['result'] == true) {
                 $refundSuccess = true;
                 break;
             }
         }
         if ($refundSuccess == false) {
             $this->setLog('调用API退费失败');
             continue;
         }
         /** 更新扣费日志状态 */
         if (false == Model_Log_JpCharge::refund($chargeLog['id'])) {
             $this->setLog(sprintf('[%d] 修改表 Model_Log_JpCharge.is_refund 失败', $chargeLog['id']));
         } else {
             $this->setLog(sprintf('[%d] 修改表 Model_Log_JpCharge.is_refund 成功', $chargeLog['id']));
         }
     }
     if (count($refundClickList) < self::BATCH_LIMIT) {
         $this->removeFlag();
         $this->setShStopFlag();
         $this->setLog('处理完成...');
     }
 }