diff --git a/app/libs/controller/common/class.OverallController.php b/app/libs/controller/common/class.OverallController.php index b896ae3..fba0436 100644 --- a/app/libs/controller/common/class.OverallController.php +++ b/app/libs/controller/common/class.OverallController.php @@ -4,6 +4,7 @@ use Exception\CheckClientException; use Service\Common\AreaService; use Service\FdsOrder\FdsOrderService; use Service\FulfillmentOrder\RsyncFulfillmentOrderService; +use Service\FulfillmentOrder\RsyncGoodsService; use Service\Mall\MallService; use Service\Order\RsyncOrderService; use Service\OrderPrint\LogisticsService; @@ -15,6 +16,7 @@ class OverallController extends AbstractApiController { private $fdsOrderService; private $rsyncFulfillmentOrderService; private $logisticsService; + private $rsyncGoodsService; public function __construct($route) { parent::__construct($route); @@ -24,6 +26,7 @@ class OverallController extends AbstractApiController { $this->fdsOrderService = FdsOrderService::instance(); $this->rsyncFulfillmentOrderService = RsyncFulfillmentOrderService::instance(); $this->logisticsService = LogisticsService::instance(); + $this->rsyncGoodsService = RsyncGoodsService::instance(); } /** @@ -46,7 +49,7 @@ class OverallController extends AbstractApiController { /** * @api POST 获取地址信息 - * @param string[] orderSns 订单编号 + * @param string orderSns 订单编号 */ public function rsyncOrder() { // $orderSns = array_map('trim', explode(',', $_POST['orderSns'])); @@ -99,11 +102,29 @@ class OverallController extends AbstractApiController { /** * @api POST 同步全量跨境托管订单 - * @param string[] fulfillmentSns 订单编号 + * @param string fulfillmentSns 订单编号 */ public function rsyncFulfillmentOrder() { // TODO 同步接口 return $this->renderSuccess(); } + + /** + * @api POST 同步全量商品 + * @param int rsyncOrderDate 同步天数 + */ + public function syncGoodsAll() { + $this->rsyncGoodsService->syncGoodsAll($this->mallId); + return $this->renderSuccess(); + } + + /** + * @api POST 同步全量跨境托管订单 + * @param string searchKeyword 商品ID + */ + public function syncGoodsSingle() { + // TODO 同步接口 + return $this->renderSuccess(); + } } diff --git a/app/libs/daos/Goods/SyncGoodsInfoDao.php b/app/libs/daos/Goods/SyncGoodsInfoDao.php new file mode 100644 index 0000000..5703f10 --- /dev/null +++ b/app/libs/daos/Goods/SyncGoodsInfoDao.php @@ -0,0 +1,10 @@ +prepare('mall_id in %li', $mallId); + } else { + $where = $this->prepare('mall_id = %i', $mallId); + } + + $task = $this->queryFirstRow("SELECT * FROM %b WHERE %l AND status IN %ls ORDER BY sync_goods_task_id DESC LIMIT 1", $this->getTable(), $where, [ + StatusConst::wait, + StatusConst::waitRetry, + StatusConst::processing, + StatusConst::partProcessing, + ]); + if (!empty($task)) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/app/libs/daos/Goods/SyncGoodsTaskGoodsLogDao.php b/app/libs/daos/Goods/SyncGoodsTaskGoodsLogDao.php new file mode 100644 index 0000000..5178f7a --- /dev/null +++ b/app/libs/daos/Goods/SyncGoodsTaskGoodsLogDao.php @@ -0,0 +1,8 @@ +syncGoodsTaskDao = SyncGoodsTaskDao::instance(); + $this->syncGoodsInfoDao = SyncGoodsInfoDao::instance(); + } + + public function syncGoodsSingle($mallId, $searchKeyword) { + $goodsIds = $this->getGoodsIdsBySearchKeyword($searchKeyword); + if (empty($goodsIds)) { + throw new CheckClientException('请输入正确的商品ID'); + } + // TODO 接口 + } + + private function getGoodsIdsBySearchKeyword($searchKeyword) { + $goodsIds = CommonTool::splitStrToArr($searchKeyword); + $goodsIdsNew = array(); + foreach ($goodsIds as $goodsId) { + $goodsId = trim($goodsId); + if (!empty($goodsId) && is_numeric($goodsId)) { + $goodsIdsNew[] = $goodsId; + } + } + + return $goodsIdsNew; + } + + public function syncGoodsAll($mallId) { + $this->tryStartSyncGoodsTask($mallId, SyncConst::syncTypeFullSync); + } + + public function tryStartSyncGoodsTask($mallId, $type = SyncConst::syncTypeIncrement) { + $ts = $this->getSyncGoodsTs(); + if ($type === SyncConst::syncTypeFullSync) { + $syncGoodsInfo = $this->syncGoodsInfoDao->getById($mallId); + if ($syncGoodsInfo && (time() - strtotime($syncGoodsInfo['gmtLastFullSync']) < SyncConst::fullSyncMaxTimeSpan)) { + $type = SyncConst::syncTypeIncrement; + } + } + $taskInfo = array( + 'mall_id' => $mallId, + 'status' => StatusConst::wait, + 'type' => $type, + 'ts' => $ts, + 'page_size' => 100, // 最大为100 + 'locked' => '0', + 'gmt_exec' => ZcDbEval::now(), + ); + return $this->addSyncGoodsTask($taskInfo, $mallId); + } + + private function getSyncGoodsTs() { + return date('YmdHis'); + } + + public function addSyncGoodsTask($taskInfo, $mallId) { + $isSyncing = $this->syncGoodsTaskDao->checkSyncingGoodsTask($mallId); + if ($isSyncing) { + return true; + } + return $this->syncGoodsTaskDao->insert($taskInfo); + } +} \ No newline at end of file