|
|
@@ -103,7 +103,7 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
|
|
|
$result = null;
|
|
|
if (count($lots) == 1)$result = $lots[0];
|
|
|
else {
|
|
|
- $zone = ["拣货","存储","虚拟"];
|
|
|
+ $zone = ["存储","拣货","虚拟"];
|
|
|
$zones = [[],[],[]];
|
|
|
foreach ($lots as $lot){
|
|
|
foreach ($zone as $ind=>$str){
|
|
|
@@ -114,9 +114,15 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
|
|
|
}
|
|
|
}
|
|
|
foreach ($zones as $zl){
|
|
|
- $result = $this->matching($zl,$item["数量"]);
|
|
|
+ $result = $this->matchingMax($zl,$item["数量"]);
|
|
|
if ($result)break;
|
|
|
}
|
|
|
+ if (!$result){
|
|
|
+ foreach ($zones as $zl){
|
|
|
+ $result = $this->matchingMin($zl,$item["数量"]);
|
|
|
+ if ($result)break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if ($result){
|
|
|
try{
|
|
|
@@ -170,19 +176,29 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
|
|
|
Cache::put("commodityAssign",["success"=>true,"data"=>$models,"errors"=>$errors]);
|
|
|
}
|
|
|
|
|
|
- private function matching($lots, $amount)
|
|
|
+ private function matchingMax($lots, $amount)
|
|
|
{
|
|
|
if (!$lots) return null;
|
|
|
- $min = null;
|
|
|
$max = null;
|
|
|
$map = [];
|
|
|
foreach ($lots as $i => $l){
|
|
|
$qty = (int)$l->qty;
|
|
|
$map[$qty] = $i;
|
|
|
if (($qty >= $amount && $qty<=$max) || $max===null)$max = $qty;
|
|
|
- if (($qty < $amount && $qty>=$min) || $min===null)$min = $qty;
|
|
|
}
|
|
|
if ($max !== null)return $lots[$map[$max]];
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ private function matchingMin($lots, $amount)
|
|
|
+ {
|
|
|
+ if (!$lots) return null;
|
|
|
+ $min = null;
|
|
|
+ $map = [];
|
|
|
+ foreach ($lots as $i => $l){
|
|
|
+ $qty = (int)$l->qty;
|
|
|
+ $map[$qty] = $i;
|
|
|
+ if (($qty < $amount && $qty>=$min) || $min===null)$min = $qty;
|
|
|
+ }
|
|
|
if ($min !== null)return $lots[$map[$min]];
|
|
|
return null;
|
|
|
}
|