20240120-ljl-routeConfig
ljl 10 months ago
parent 8edcbf13ba
commit 2a12e38857

@ -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();
}
}

@ -0,0 +1,10 @@
<?php
namespace Dao\Goods;
use Dao\AbstractDao;
use StatusConst;
class SyncGoodsInfoDao extends AbstractDao {
protected $pk = 'mall_id';
}

@ -0,0 +1,27 @@
<?php
namespace Dao\Goods;
use Dao\AbstractDao;
use StatusConst;
class SyncGoodsTaskDao extends AbstractDao {
public function checkSyncingGoodsTask($mallId) {
if (is_array($mallId) && !empty($mallId)) {
$where = $this->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;
}
}

@ -0,0 +1,8 @@
<?php
namespace Dao\Goods;
use Dao\AbstractDao;
class SyncGoodsTaskGoodsLogDao extends AbstractDao {
}

@ -0,0 +1,77 @@
<?php
namespace Service\FulfillmentOrder;
use CommonTool;
use Dao\Goods\SyncGoodsInfoDao;
use Dao\Goods\SyncGoodsTaskDao;
use Exception\CheckClientException;
use Service\AbstractService;
use StatusConst;
use SyncConst;
use ZcDbEval;
class RsyncGoodsService extends AbstractService {
private $syncGoodsTaskDao;
private $syncGoodsInfoDao;
protected function __construct() {
$this->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);
}
}
Loading…
Cancel
Save