20240120-ljl-routeConfig
parent
8edcbf13ba
commit
2a12e38857
@ -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…
Reference in New Issue