public static function todayBidClickAndCost($ajkBrokerId, $date = '') { $date = empty($date) ? date('Y-m-d') : $date; $click = $cost = 0; $jpMemberId = Model_Broker_JpBroker::getJpBrokerInfoByAjkBrokerId($ajkBrokerId); // 获取金铺brokerId $jpMemberId = $jpMemberId->id; if (!empty($jpMemberId)) { $re = Model_Log_JpCharge::data_access()->filter('member_id', $jpMemberId)->filter_by_op('create_time', '>=', $date . ' 00:00:00')->filter_by_op('create_time', '<=', $date . ' 23:59:59')->filter('spread_type', 2)->filter('charge_type', 0)->get_all(); if (!empty($re)) { foreach ($re as $r) { $click++; $cost += round($r['real_cost'] / 100, 2); } } } return array('click' => $click, 'cost' => $cost); }
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('处理完成...'); } }
public static function get7DaysHouseClick($propId) { if (empty($propId)) { return array(); } $return = $clickInfo = array(); $cache = APF_Cache_Factory::get_instance()->get_memcache(); $time = time(); for ($i = 0; $i < 7; $i++) { $date = date('Y-m-d', $time - $i * 86400); if ($i == 0) { $clicks = Model_Log_JpCharge::data_access()->filter('house_id', $propId)->filter_by_op('create_time', '>=', date('Y-m-d') . ' 00:00:00')->filter_by_op('create_time', '<=', date('Y-m-d') . ' 23:59:59')->filter('charge_type', 0)->get_all(); $clickFormat = array(1 => array('num' => 0, 'cost' => 0), 2 => array('num' => 0, 'cost' => 0)); if (!empty($clicks)) { foreach ($clicks as $click) { $clickFormat[$click['spread_type']]['num']++; $clickFormat[$click['spread_type']]['cost'] += $click['real_cost']; } } } else { $key = __CLASS__ . __FUNCTION__ . $propId . '_' . $date; $clickFormat = $cache->get($key); if ($clickFormat === false) { $clicks = Model_Log_JpCharge::data_access()->filter('house_id', $propId)->filter_by_op('create_time', '>=', $date . ' 00:00:00')->filter_by_op('create_time', '<=', $date . ' 23:59:59')->filter('charge_type', 0)->get_all(); $clickFormat = array(1 => array('num' => 0, 'cost' => 0), 2 => array('num' => 0, 'cost' => 0)); if (!empty($clicks)) { foreach ($clicks as $click) { $clickFormat[$click['spread_type']]['num']++; $clickFormat[$click['spread_type']]['cost'] += $click['real_cost']; } } $cache->set($key, $clickFormat, 7200); } } $return[$date] = $clickFormat; } return $return; }