You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
368 lines
15 KiB
PHP
368 lines
15 KiB
PHP
<?php
|
|
|
|
class DdcRequestClient {
|
|
private $db;
|
|
|
|
private $logger;
|
|
private $errorLogger;
|
|
private $curl;
|
|
private $spider;
|
|
private $appName;
|
|
|
|
public function __construct() {
|
|
$this->db = Zc::getDb();
|
|
|
|
$this->logger = Zc::getLog('tool/ddc/request');
|
|
$this->errorLogger = Zc::getLog('tool/ddc/request_err');
|
|
$this->curl = CommonTool::getCurl(30);
|
|
$this->spider = new PageSpider(array(), null, $_SERVER['REMOTE_ADDR']);
|
|
$this->appName = Zc::C('appName');
|
|
}
|
|
|
|
public function lockSourceSyncGoodsQueue($timerLockId, $filter) {
|
|
return $this->requestUrl('post', RouteConst::openDdcLockSourceSyncGoodsQueue, array(
|
|
'timerLockId' => $timerLockId,
|
|
'filter' => serialize($filter),
|
|
), '', false);
|
|
}
|
|
|
|
public function updateSourceSyncGoodsQueue($mallId, $queueId, $fillDataInfo) {
|
|
return $this->requestUrl('post', RouteConst::openDdcUpdateSourceSyncGoodsQueue, array(
|
|
'mallId' => $mallId,
|
|
'queueId' => $queueId,
|
|
'fillDataInfo' => serialize($fillDataInfo),
|
|
), '', false);
|
|
}
|
|
|
|
public function getGoodsDetailFromPdd($goodsId, $accessToken, $isSimple = 0) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetGoodsDetailFromPdd, array(
|
|
'goodsId' => $goodsId,
|
|
'atk' => $accessToken,
|
|
'isSimple' => $isSimple,
|
|
), '', false);
|
|
}
|
|
|
|
public function getGoodsInfoFromPdd($goodsId, $accessToken) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetGoodsInfoFromPdd, array(
|
|
'goodsId' => $goodsId,
|
|
'atk' => $accessToken,
|
|
), '', false);
|
|
}
|
|
|
|
public function getGoodsListFromPdd($filter, $accessToken) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetGoodsListFromPdd, array(
|
|
'filter' => serialize($filter),
|
|
'atk' => $accessToken,
|
|
), '', false);
|
|
}
|
|
|
|
public function getGoodsDetailListFromPdd($goodsList) {
|
|
$getRet = $this->requestUrl('post', RouteConst::openDdcGetGoodsDetailListFromPdd, array(
|
|
'goodsList' => serialize($goodsList),
|
|
), '', false);
|
|
return $getRet['gdlMap'] ? : [];
|
|
}
|
|
|
|
public function getGoodsInfoListFromPdd($goodsList) {
|
|
$getRet = $this->requestUrl('post', RouteConst::openDdcGetGoodsInfoListFromPdd, array(
|
|
'goodsList' => serialize($goodsList),
|
|
), '', false);
|
|
return $getRet['gilMap'] ? : [];
|
|
}
|
|
|
|
public function checkAvailableCopyAndGetMoveConfigId($mallId, $needAddCnt, $showSimpleTip = false) {
|
|
return $this->requestUrl('post', RouteConst::openDdcCheckAvailableCopyAndGetMoveConfigId, array(
|
|
'mallId' => $mallId,
|
|
'needAddCnt' => $needAddCnt,
|
|
'showSimpleTip' => $showSimpleTip,
|
|
), '', false);
|
|
}
|
|
|
|
public function getAuthMallApp($mallId, $authMallId, $authGroupId, $authCode) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetAuthMallApp, array(
|
|
'mallId' => $mallId,
|
|
'authMallId' => $authMallId,
|
|
'authGroupId' => $authGroupId,
|
|
'authCode' => $authCode,
|
|
), '', false);
|
|
}
|
|
|
|
public function switchAuthShop($authMallId, $authGroupId, $authCode) {
|
|
return $this->requestUrl('post', RouteConst::userMallAuthSwitchAuthShop, array(
|
|
'authMallId' => $authMallId,
|
|
'authGroupId' => $authGroupId,
|
|
'authCode' => $authCode,
|
|
));
|
|
}
|
|
|
|
public function lockGoodsAddQueue($timerLockId, $filter) {
|
|
return $this->requestUrl('post', RouteConst::openDdcLockGoodsAddQueue, array(
|
|
'timerLockId' => $timerLockId,
|
|
'filter' => serialize($filter),
|
|
'hostname' => gethostname(),
|
|
), '', false);
|
|
}
|
|
|
|
public function getMoveSetting($mallId, $moveMallSettingId) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetMoveSetting, array(
|
|
'mallId' => $mallId,
|
|
'moveMallSettingId' => $moveMallSettingId,
|
|
), '', false);
|
|
}
|
|
|
|
public function getSourceCategoryMap($mallId) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetSourceCategoryMap, array(
|
|
'mallId' => $mallId,
|
|
), '', false);
|
|
}
|
|
|
|
public function checkMultiShopValid($mallId, $authMallIds) {
|
|
return $this->requestUrl('post', RouteConst::openDdcCheckMultiShopValid, array(
|
|
'mallId' => $mallId,
|
|
'authMallIds' => serialize($authMallIds),
|
|
), '', false);
|
|
}
|
|
|
|
public function getMoveGroupTaskDetailWaitCount($mallId) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetMoveGroupTaskDetailWaitCount, array(
|
|
'mallId' => $mallId,
|
|
), '', false);
|
|
}
|
|
|
|
public function addMoveGroupTask($mallId, $taskInfo) {
|
|
return $this->requestUrl('post', RouteConst::openDdcAddMoveGroupTask, array(
|
|
'mallId' => $mallId,
|
|
'taskInfo' => serialize($taskInfo),
|
|
), '', false);
|
|
}
|
|
|
|
public function lockFillMoveGroupTask($timerLockId, $filter) {
|
|
return $this->requestUrl('post', RouteConst::openDdcLockFillMoveGroupTask, array(
|
|
'timerLockId' => $timerLockId,
|
|
'filter' => serialize($filter),
|
|
), '', false);
|
|
}
|
|
|
|
public function fillMoveGroupTask($operatorMallId, $moveGroupTaskId, $fillDataInfo) {
|
|
return $this->requestUrl('post', RouteConst::openDdcFillMoveGroupTask, array(
|
|
'operatorMallId' => $operatorMallId,
|
|
'moveGroupTaskId' => $moveGroupTaskId,
|
|
'fillDataInfo' => serialize($fillDataInfo),
|
|
));
|
|
}
|
|
|
|
public function lockFillMoveGroupTaskQueue($timerLockId, $filter) {
|
|
return $this->requestUrl('post', RouteConst::openDdcLockFillMoveGroupTaskQueue, array(
|
|
'timerLockId' => $timerLockId,
|
|
'filter' => serialize($filter),
|
|
), '', false);
|
|
}
|
|
|
|
public function fillMoveGroupTaskQueue($mallId, $queueId, $fillDataInfo) {
|
|
return $this->requestUrl('post', RouteConst::openDdcFillMoveGroupTaskQueue, array(
|
|
'mallId' => $mallId,
|
|
'queueId' => $queueId,
|
|
'fillDataInfo' => serialize($fillDataInfo),
|
|
), '', false);
|
|
}
|
|
|
|
public function lockSolidRedisQueue($timerLockId, $queueName, $redisQueueName, $bufferPrimaryColumn) {
|
|
return $this->requestUrl('post', RouteConst::openDdcLockSolidRedisQueue, array(
|
|
'timerLockId' => $timerLockId,
|
|
'queueName' => $queueName,
|
|
'redisQueueName' => $redisQueueName,
|
|
'bufferPrimaryColumn' => $bufferPrimaryColumn,
|
|
), '', false);
|
|
}
|
|
|
|
public function saveImportTaskDetail($mallId, $taskDetail) {
|
|
return $this->requestUrl('post', RouteConst::openDdcSaveImportTaskDetail, array(
|
|
'mallId' => $mallId,
|
|
'taskDetail' => serialize($taskDetail),
|
|
));
|
|
}
|
|
|
|
public function clearImportTaskQueue($queueId, $moveImportTaskId, $parseSeconds, $mallId) {
|
|
return $this->requestUrl('post', RouteConst::openDdcClearImportTaskQueue, array(
|
|
'queueId' => $queueId,
|
|
'moveImportTaskId' => $moveImportTaskId,
|
|
'parseSeconds' => $parseSeconds,
|
|
'mallId' => $mallId,
|
|
));
|
|
}
|
|
|
|
public function handleMoveConfigSkipConditions($queueMsg, $sourceItemData) {
|
|
$mallId = $queueMsg['mall_id'];
|
|
$queueMsg = ZcArrayHelper::filterColumns($queueMsg, ['move_collect_goods_add_queue_id', 'mall_id', 'priority', 'move_collect_task_id', 'move_collect_task_detail_id', 'source', 'site', 'source_item_id', 'move_group_task_detail_id', 'is_move_speed', 'move_try_times']);
|
|
|
|
return $this->requestUrl('post', RouteConst::openDdcHandleMoveConfigSkipConditions, array(
|
|
'mallId' => $mallId,
|
|
'queueMsg' => serialize($queueMsg),
|
|
'sourceItemData' => serialize($sourceItemData),
|
|
), '', false);
|
|
}
|
|
|
|
public function processAfterAddGoodsToPdd($queueMsg, $addGoodsRet, $goodsDetailBase, $preprocessMoveData, $accessToken) {
|
|
$mallId = $queueMsg['mall_id'];
|
|
$queueMsg = ZcArrayHelper::filterColumns($queueMsg, ['move_collect_goods_add_queue_id', 'condition', 'mall_id', 'priority', 'move_collect_task_id', 'move_collect_task_detail_id', 'source', 'site', 'source_item_id', 'move_group_task_detail_id', 'is_move_speed', 'move_try_times']);
|
|
$queueMsg['condition'] = ZcArrayHelper::filterColumns($queueMsg['condition'], ['onsale_now', 'is_build_out_sku_sn', 'is_create_white_bg_img', 'white_bg_img_use_carousel_index']);
|
|
$goodsDetailBase = ZcArrayHelper::filterColumns($goodsDetailBase, ['sku_list']);
|
|
$preprocessMoveData = ZcArrayHelper::filterColumns($preprocessMoveData, ['sourcePriceRange', 'postFee']);
|
|
return $this->requestUrl('post', RouteConst::openDdcProcessAfterAddGoodsToPdd, array(
|
|
'mallId' => $mallId,
|
|
'queueMsg' => serialize($queueMsg),
|
|
'addGoodsRet' => serialize($addGoodsRet),
|
|
'goodsDetailBase' => serialize($goodsDetailBase),
|
|
'preprocessMoveData' => serialize($preprocessMoveData),
|
|
'atk' => $accessToken,
|
|
));
|
|
}
|
|
|
|
public function clearGoodsAddQueue($queueMsg, $addGoodsRet, $publishCostSeconds) {
|
|
$mallId = $queueMsg['mall_id'];
|
|
$queueMsg = ZcArrayHelper::filterColumns($queueMsg, ['move_collect_goods_add_queue_id', 'mall_id', 'priority', 'move_collect_task_id', 'move_collect_task_detail_id', 'source', 'site', 'source_item_id', 'move_group_task_detail_id', 'is_move_speed', 'move_try_times']);
|
|
return $this->requestUrl('post', RouteConst::openDdcClearGoodsAddQueue, array(
|
|
'mallId' => $mallId,
|
|
'queueMsg' => serialize($queueMsg),
|
|
'addGoodsRet' => serialize($addGoodsRet),
|
|
'publishCostSeconds' => $publishCostSeconds,
|
|
));
|
|
}
|
|
|
|
public function clearMoveGroupTask($taskInfo, $processRet) {
|
|
return $this->requestUrl('post', RouteConst::openDdcClearMoveGroupTask, array(
|
|
'taskInfo' => serialize($taskInfo),
|
|
'processRet' => serialize($processRet),
|
|
));
|
|
}
|
|
|
|
public function processShopUrlHistory($mallId, $shopUrl, $source, $seller) {
|
|
return $this->requestUrl('post', RouteConst::openDdcProcessShopUrlHistory, array(
|
|
'mallId' => $mallId,
|
|
'shopUrl' => $shopUrl,
|
|
'source' => $source,
|
|
'seller' => $seller,
|
|
));
|
|
}
|
|
|
|
public function getMoveSettingBigFieldInfosByQueryIds($mallId, $queryIds) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetMoveSettingBigFieldInfosByQueryIds, array(
|
|
'mallId' => $mallId,
|
|
'queryIds' => serialize($queryIds),
|
|
), '', false);
|
|
}
|
|
|
|
public function checkAuthMallIdsHasPermission($mallId, $authMallIds, $preMallIdList) {
|
|
return $this->requestUrl('post', RouteConst::openDdcCheckAuthMallIdsHasPermission, array(
|
|
'mallId' => $mallId,
|
|
'authMallIds' => serialize($authMallIds),
|
|
'preMallIdList' => serialize($preMallIdList),
|
|
), '', false);
|
|
}
|
|
|
|
public function getHasMovedSourceItemIds($mallIds, $sourceItemIds, $source) {
|
|
return $this->requestUrl('post', RouteConst::openDdcGetHasMovedSourceItemIds, array(
|
|
'mallIds' => serialize($mallIds),
|
|
'sourceItemIds' => serialize($sourceItemIds),
|
|
'source' => $source,
|
|
), '', false);
|
|
}
|
|
|
|
public function generateSign($params, $mallId, $sessionId) {
|
|
ksort($params);
|
|
$signStr = $mallId;
|
|
foreach ($params as $key => $value) {
|
|
$signStr .= $key . $value;
|
|
}
|
|
$signStr .= $sessionId;
|
|
return strtoupper(md5($signStr));
|
|
}
|
|
|
|
public function requestUrl($type, $route, $params, $sessionId = '', $needRetry = true) {
|
|
if (!AppConst::isShAppCategory()) {
|
|
return CommonTool::successResult();
|
|
}
|
|
if (AppConst::isDuoDuoCloud()) {
|
|
return CommonTool::successResult();
|
|
}
|
|
|
|
$ddcDomain = AppConst::getDuoDuoCloudHost(true, false, true);
|
|
if (empty($ddcDomain)) {
|
|
$this->errorLogger->info("ddcDomain empty. route[$route] param:" . print_r($params, true));
|
|
return CommonTool::failResult('获取ddc域名失败');
|
|
}
|
|
|
|
$mallId = $params['mallId'] ? : '';
|
|
if (empty($sessionId)) {
|
|
$sessionId = session_id();
|
|
}
|
|
|
|
$headers = array (
|
|
'token:' . Zc::C('ddcToken'),
|
|
'sign:' . $this->generateSign($params, $mallId, $sessionId),
|
|
);
|
|
$this->curl->setCurlOpt(CURLOPT_HTTPHEADER, $headers);
|
|
$this->curl->setHeaderCookie(Zc::C('sessionName') . '=' . $sessionId);
|
|
|
|
$startTs = ZcNumberHelper::microtimeFloat(3);
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
$ts = ZcNumberHelper::microtimeFloat(3);
|
|
if ($type == 'get') {
|
|
$url = Zc::url($route, $params, 'http', $ddcDomain);
|
|
$url = str_replace(':443', '', $url); //zc的bug 这边临时修复
|
|
$ret = $this->curl->get($url);
|
|
} else {
|
|
$url = Zc::url($route, array(), 'http', $ddcDomain);
|
|
$url = str_replace(':443', '', $url); //zc的bug 这边临时修复
|
|
$ret = $this->curl->post($url, $params);
|
|
}
|
|
|
|
if ($ret) {
|
|
break;
|
|
}
|
|
$us = bcsub(ZcNumberHelper::microtimeFloat(3), $ts, 3);
|
|
$this->logger->info(sprintf('%s | %s | %s | %s', $url, $us, ($ret ? 'success' : 'fail'), $i));
|
|
$this->errorLogger->info("$us request from ddc failed[$i], url: $url, params: " . print_r($params, true) . ", ret: " . print_r($ret, true));
|
|
sleep(1);
|
|
}
|
|
|
|
$useTs = bcsub(ZcNumberHelper::microtimeFloat(3), $startTs, 3);
|
|
$this->logger->info(sprintf('%s | %s | %s | %s', $_GET['route'], $url, $useTs, ($ret ? 'success' : 'fail')));
|
|
|
|
if ($ret) {
|
|
$jsonRet = json_decode($ret, true);
|
|
if (!CommonTool::isSuccessRet($jsonRet)) {
|
|
$this->errorLogger->info("requestUrl type $type url $url params " . count($params) . "ret " . print_r($jsonRet, true));
|
|
}
|
|
return $jsonRet;
|
|
} else {
|
|
$this->errorLogger->info('curlInfo: ' . print_r($this->curl->getInfo(), true));
|
|
$this->addDdcRequestRetryQueue($mallId, $type, $route, $params, $sessionId, $needRetry);
|
|
return FetchClientTool::failResult('操作失败,请联系客服或稍后重试。');
|
|
}
|
|
}
|
|
|
|
public function addDdcRequestRetryQueue($mallId, $type, $route, $params, $sessionId, $needRetry) {
|
|
if (!$needRetry) {
|
|
return ;
|
|
}
|
|
|
|
$this->db->insert('ddc_request_retry_queue', array(
|
|
'mall_id' => $mallId,
|
|
'type' => $type,
|
|
'route' => $route,
|
|
'params' => serialize($params),
|
|
'session_id' => $sessionId,
|
|
'locked' => 0,
|
|
'gmt_exec' => date('Y-m-d H:i:s', strtotime('+10 seconds')),
|
|
'gmt_create' => ZcDbEval::now(),
|
|
'gmt_modified' => ZcDbEval::now(),
|
|
));
|
|
}
|
|
|
|
public function crawl($urls) {
|
|
$this->spider->setCurlOptions(array(CURLOPT_COOKIE => 'ddcToken=' . Zc::C('ddc.token')));
|
|
return $this->spider->crawl($urls);
|
|
}
|
|
}
|