|
|
@@ -381,9 +381,9 @@ Class CommodityService
|
|
|
public function getCommodityByOwnerCodeAndSKU($ownerCode, $sku)
|
|
|
{
|
|
|
$commodity_key = "owner_code_{$ownerCode}_sku_{$sku}";
|
|
|
- return Cache::remember($commodity_key,config('cache.expirations.forever'),function()use($ownerCode,$sku){
|
|
|
- $commodity = Commodity::query()->where('sku',$sku)->whereHas('owner',function($query)use($ownerCode){
|
|
|
- $query->where('code',$ownerCode);
|
|
|
+ return Cache::remember($commodity_key, config('cache.expirations.forever'), function () use ($ownerCode, $sku) {
|
|
|
+ $commodity = Commodity::query()->where('sku', $sku)->whereHas('owner', function ($query) use ($ownerCode) {
|
|
|
+ $query->where('code', $ownerCode);
|
|
|
})->first();
|
|
|
if (isset($commodity)) return $commodity;
|
|
|
$basSKu = app('OracleBasSkuService')->first(['sku' => $sku, 'customerid' => $ownerCode]);
|
|
|
@@ -420,13 +420,10 @@ Class CommodityService
|
|
|
$last_time = $basSkus->first()['addtime'];
|
|
|
$last_records = $basSkus->where('addtime', $last_time);
|
|
|
if (!$basSkus) return;
|
|
|
- $addBasSkus = $this->getLastRecordsByRedis($create_set, $create_key, $basSkus);
|
|
|
- if (count($addBasSkus) > 0) {
|
|
|
- $this->syncCreateCommodity($addBasSkus);
|
|
|
+ $this->syncCreateCommodity($basSkus);
|
|
|
$this->deleteCacheKey($create_set, $create_keys);
|
|
|
$this->setLastRecordsByRedis($create_key, $create_set, $create_keys, $last_records);
|
|
|
$this->setAsnLastSyncAt($created_at, $last_time);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
public function syncCommodityUpdated()
|
|
|
@@ -442,13 +439,10 @@ Class CommodityService
|
|
|
$last_time = $basSkus->first()['edittime'];
|
|
|
$last_records = $basSkus->where('edittime', $last_time);
|
|
|
if (!$basSkus) return;
|
|
|
- $addBasSkus = $this->getLastRecordsByRedis($update_set, $update_key, $basSkus);
|
|
|
- if (count($addBasSkus) > 0) {
|
|
|
- $this->syncUpdateCommodity($addBasSkus);
|
|
|
+ $this->syncUpdateCommodity($basSkus);
|
|
|
$this->deleteCacheKey($update_set, $update_keys);
|
|
|
$this->setLastRecordsByRedis($update_key, $update_set, $update_keys, $last_records);
|
|
|
$this->setAsnLastSyncAt($updated_at, $last_time);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
public function syncCreateCommodity($addBasSkus)
|
|
|
@@ -464,18 +458,18 @@ Class CommodityService
|
|
|
|
|
|
public function insertCommodities($insert_params)
|
|
|
{
|
|
|
- if (count($insert_params)<1) return;
|
|
|
- $ownerIds=array_unique(data_get($insert_params,'*.owner_id'));
|
|
|
+ if (count($insert_params) < 1) return;
|
|
|
+ $ownerIds = array_unique(data_get($insert_params, '*.owner_id'));
|
|
|
sort($ownerIds);
|
|
|
- $skus=array_unique(data_get($insert_params,'*.sku'));
|
|
|
+ $skus = array_unique(data_get($insert_params, '*.sku'));
|
|
|
sort($skus);
|
|
|
try {
|
|
|
$bool = Commodity::query()->insert($insert_params);
|
|
|
if ($bool) {
|
|
|
app('LogService')->log(__METHOD__, __FUNCTION__, "批量添加 Commodity Success " . count($insert_params) . ' || ' . json_encode($insert_params));
|
|
|
- $commodities = Commodity::query()->with('owner')->whereIn('owner_id',$ownerIds)->whereIn('sku',$skus)->get();
|
|
|
+ $commodities = Commodity::query()->with('owner')->whereIn('owner_id', $ownerIds)->whereIn('sku', $skus)->get();
|
|
|
$md5 = md5(json_encode([$skus, $ownerIds]));
|
|
|
- if (Cache::has('commodity_'.$md5)) Cache::forget('commodity_'.$md5);
|
|
|
+ if (Cache::has('commodity_' . $md5)) Cache::forget('commodity_' . $md5);
|
|
|
$this->pushToCache($commodities);
|
|
|
} else app('LogService')->log(__METHOD__, __FUNCTION__, "批量添加 Commodity FAILED " . ' || ' . json_encode($insert_params));
|
|
|
} catch (\Exception $e) {
|
|
|
@@ -652,9 +646,6 @@ Class CommodityService
|
|
|
}
|
|
|
if (count($insert_params) > 0) $this->insertCommodities($insert_params);
|
|
|
if (count($updateParams) > 0) $this->updateCommodities($updateParams);
|
|
|
-// if (count($updateParams) > 0) $this->batchUpdate($updateParams);
|
|
|
-// $commodities = Commodity::query()->with('owner')->whereIn('owner_id', data_get($updateParams, '*.owner_id'))->whereIn('sku', data_get($updateParams, '*.sku'))->get();
|
|
|
-// $this->pushToCache($commodities);
|
|
|
/** @var CommodityBarcodeService $commodityBarcodeService */
|
|
|
$commodityBarcodeService = app(CommodityBarcodeService::class);
|
|
|
$commodityBarcodeService->updateBarcodeByWms($addBasSkus);
|
|
|
@@ -665,7 +656,7 @@ Class CommodityService
|
|
|
if (count($commodities) < 1) return null;
|
|
|
foreach ($commodities as $commodity) {
|
|
|
$commodity_key = "owner_code_{$commodity['owner']['code']}_sku_{$commodity['sku']}";
|
|
|
- Cache::put($commodity_key,$commodity);
|
|
|
+ Cache::put($commodity_key, $commodity);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -694,20 +685,6 @@ Class CommodityService
|
|
|
LogService::log(__METHOD__, __FUNCTION__, '修改或更新' . $key . json_encode($asnLastSyncAt));
|
|
|
return $asnLastSyncAt;
|
|
|
}
|
|
|
-
|
|
|
- public function getLastRecordsByRedis($set, $prefixKey, $basSkus)
|
|
|
- {
|
|
|
- if (Cache::get($set)) {
|
|
|
- $addBasSkus = collect();
|
|
|
- foreach ($basSkus as $basSku) {
|
|
|
- if (Cache::get($prefixKey . $basSku->customerid . '_' . $basSku->sku)) continue;
|
|
|
- $addBasSkus->add($basSku);
|
|
|
- }
|
|
|
- return $addBasSkus;
|
|
|
- }
|
|
|
- return $basSkus;
|
|
|
- }
|
|
|
-
|
|
|
public function deleteCacheKey($set, $keys)
|
|
|
{
|
|
|
if (Cache::get($set)) {
|
|
|
@@ -733,15 +710,15 @@ Class CommodityService
|
|
|
|
|
|
function updateCommodities($updateParams)
|
|
|
{
|
|
|
- if (count($updateParams) <1) return;
|
|
|
- $ownerIds=array_unique(data_get($updateParams,'*.owner_id'));
|
|
|
+ if (count($updateParams) < 1) return;
|
|
|
+ $ownerIds = array_unique(data_get($updateParams, '*.owner_id'));
|
|
|
sort($ownerIds);
|
|
|
- $skus=array_unique(data_get($updateParams,'*.sku'));
|
|
|
+ $skus = array_unique(data_get($updateParams, '*.sku'));
|
|
|
sort($skus);
|
|
|
$this->batchUpdate($updateParams);
|
|
|
$md5 = md5(json_encode([$skus, $ownerIds]));
|
|
|
- if (Cache::has('commodity_'.$md5)) Cache::forget('commodity_'.$md5);
|
|
|
- $commodities = Commodity::query()->with('owner')->whereIn('owner_id',$ownerIds)->whereIn('sku',$skus)->get();
|
|
|
+ if (Cache::has('commodity_' . $md5)) Cache::forget('commodity_' . $md5);
|
|
|
+ $commodities = Commodity::query()->with('owner')->whereIn('owner_id', $ownerIds)->whereIn('sku', $skus)->get();
|
|
|
$this->pushToCache($commodities);
|
|
|
}
|
|
|
|
|
|
@@ -756,7 +733,7 @@ Class CommodityService
|
|
|
* @param int $page
|
|
|
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed|null
|
|
|
*/
|
|
|
- function get_(array $ownerIds = [], array $skus = [], array $barcodes = [],$isSyncWms = false, $paginate = 100, $page = 1)
|
|
|
+ function get_(array $ownerIds = [], array $skus = [], array $barcodes = [], $isSyncWms = false, $paginate = 100, $page = 1)
|
|
|
{
|
|
|
if ($paginate < 100 || fmod($paginate, 100) != 0) return null; //$paginate小于100,或取余数100不为0,异常 //取余函数fmod()
|
|
|
$time = config('cache.expirations.forever');
|
|
|
@@ -778,19 +755,16 @@ Class CommodityService
|
|
|
}
|
|
|
$bas_skus = OracleBasSKU::query()
|
|
|
->select('customerid', 'sku', 'descr_c', 'alternate_sku1', 'alternate_sku2', 'alternate_sku3', 'skulength', 'skuwidth', 'skuhigh', 'cube', 'packid', 'addtime', 'edittime')
|
|
|
- ->whereIn('customerid',$ownerCodes)->whereIn('sku',$skus)
|
|
|
+ ->whereIn('customerid', $ownerCodes)->whereIn('sku', $skus)
|
|
|
->get();
|
|
|
if (!$bas_skus) return null;
|
|
|
$this->syncUpdateCommodity($bas_skus);
|
|
|
}
|
|
|
sort($skus);
|
|
|
//在取出的记录用 $ownerIds和$barcodes筛选
|
|
|
- $sku_md5 = md5(json_encode([$skus]));
|
|
|
- $commodities = Cache::remember('commodity_' . $sku_md5, $time, function () use ($skus) {
|
|
|
- return Commodity::query()
|
|
|
- ->with(['barcodes', 'owner'])
|
|
|
- ->whereIn('sku', $skus)->get();
|
|
|
- });
|
|
|
+ $commodities = Commodity::query()
|
|
|
+ ->with(['barcodes', 'owner'])
|
|
|
+ ->whereIn('sku', $skus)->get();
|
|
|
if ($ownerIds) {
|
|
|
sort($ownerIds);
|
|
|
$md5 = md5(json_encode([$skus, $ownerIds]));
|
|
|
@@ -814,14 +788,11 @@ Class CommodityService
|
|
|
|
|
|
case $status == '有条码没SKU':
|
|
|
sort($barcodes);
|
|
|
- $barcodes_md5 = md5(json_encode([$barcodes]));
|
|
|
- $commodities = Cache::remember('commodity_' . $barcodes_md5, $time, function () use ($barcodes) {
|
|
|
- return Commodity::query()
|
|
|
- ->with(['barcodes', 'owner'])
|
|
|
- ->whereHas('barcodes', function ($query) use ($barcodes) {
|
|
|
- $query->whereIn('code', $barcodes);
|
|
|
- })->get();
|
|
|
- });
|
|
|
+ $commodities = Commodity::query()
|
|
|
+ ->with(['barcodes', 'owner'])
|
|
|
+ ->whereHas('barcodes', function ($query) use ($barcodes) {
|
|
|
+ $query->whereIn('code', $barcodes);
|
|
|
+ })->get();
|
|
|
if ($ownerIds) {
|
|
|
sort($ownerIds);
|
|
|
$barcodes_ownerIds_md5 = md5(json_encode([$barcodes, $ownerIds]));
|
|
|
@@ -841,7 +812,7 @@ Class CommodityService
|
|
|
$commodities = Commodity::query()
|
|
|
->with(['barcodes', 'owner'])
|
|
|
->whereIn('owner_id', $ownerIds)
|
|
|
- ->orderBy('owner_id','asc')
|
|
|
+ ->orderBy('owner_id', 'asc')
|
|
|
->paginate($paginate, '*', 'page', $page);
|
|
|
Cache::add($key, $commodities->items());
|
|
|
return $commodities;
|