|
|
@@ -14,6 +14,12 @@ use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
Class CommodityService
|
|
|
{
|
|
|
+ /** @var CacheService $cacheService */
|
|
|
+ private $cacheService;
|
|
|
+ function __construct(){
|
|
|
+ $this->cacheService=app('CacheService');
|
|
|
+ }
|
|
|
+
|
|
|
public function firstOrCreate($param,$column = null):Commodity{
|
|
|
if ($column) return Commodity::query()->firstOrCreate($param,$column);
|
|
|
return Commodity::query()->firstOrCreate($param);
|
|
|
@@ -332,4 +338,41 @@ Class CommodityService
|
|
|
if ($query->count() > 0)return true;
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ public function getCommoditiesByMap($map)
|
|
|
+ {
|
|
|
+ /** @var OwnerService $ownerService */
|
|
|
+ $ownerService = app('OwnerService');
|
|
|
+ $owner_codes = [];
|
|
|
+ foreach ($map as $item) {
|
|
|
+ $owner_codes[$item['owner_code']] = $item['owner_code'];
|
|
|
+ }
|
|
|
+ $owners = $ownerService->getOwnerByCodes($owner_codes);
|
|
|
+ $owner_map = [];
|
|
|
+ $owners->each(function ($owner)use(&$owner_map){
|
|
|
+ $owner_map[$owner['code']] = $owner;
|
|
|
+ });
|
|
|
+ $collect = collect();
|
|
|
+ if(count($map) == 0) return $collect;
|
|
|
+ $date = Carbon::now();
|
|
|
+ foreach ($map as $item) {
|
|
|
+ $collect->push($this->cacheService->getOrExecute("owner_code_{$item['owner_code']}_sku_{$item['sku']}",function()use($item,$owner_map,$date){
|
|
|
+ $owner = $owner_map[$item['owner_code']];
|
|
|
+ $commodity = Commodity::query()->where('owner_id',$owner['id'])->where('sku',$item['sku'])->first();
|
|
|
+ if($commodity)return $commodity;
|
|
|
+ $basSku = OracleBasSKU::query()->where('SKU',$item['sku'])->where('CustomerID',$item['owner_code'])->first();
|
|
|
+ return Commodity::query()->create([
|
|
|
+ 'owner_id' => $owner['id'],
|
|
|
+ 'sku' => $basSku['sku'],
|
|
|
+ 'name' =>$basSku['descr_c'],
|
|
|
+ 'created_at' => $date,
|
|
|
+ 'updated_at' => $date,
|
|
|
+ 'length' => $basSku['skulength'],
|
|
|
+ 'width' => $basSku['skuwidth'],
|
|
|
+ 'height' => $basSku['skuhigh'],
|
|
|
+ 'volumn' => $basSku['cube']]);
|
|
|
+ },config('cache.expirations.forever')));
|
|
|
+ }
|
|
|
+ return $collect;
|
|
|
+ }
|
|
|
}
|