|
|
@@ -104,11 +104,10 @@ Class OwnerPriceOperationService
|
|
|
* @param array $columnMapping key-val
|
|
|
* @param string $owner_id
|
|
|
* @param string $type
|
|
|
- * @param string $sku
|
|
|
* @return double
|
|
|
* 错误代码: -1:无匹配对象 -2:无计费模型 -3:未知单位 -4:sku为空 -5:货主未找到 -6:无箱规 -7:未匹配到计费模型
|
|
|
*/
|
|
|
- public function matchRule($matchObject, $columnMapping, $owner_id, $sku = null, $type = '出库')
|
|
|
+ public function matchRule($matchObject, $columnMapping, $owner_id, $type = '出库')
|
|
|
{
|
|
|
$unitModels = Unit::query()->whereIn("name",["件","箱","单"])->get();
|
|
|
$units = [];
|
|
|
@@ -144,7 +143,12 @@ Class OwnerPriceOperationService
|
|
|
if ($bool === true){
|
|
|
if (!isset($units[$rule->ownerInStorageRule->unit_id])) return -3;
|
|
|
if ($units[$rule->ownerInStorageRule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
|
|
|
- $sum = $this->changeUnit($sum,$owner_id,$sku);
|
|
|
+ $sumTemp = 0;
|
|
|
+ $packageColumn = $columnMapping["packages"] ?? "packages";
|
|
|
+ foreach ($matchObject[$packageColumn] as $commodity){
|
|
|
+ $sumTemp += $this->changeUnit($sum,$owner_id,$commodity["sku"]);
|
|
|
+ }
|
|
|
+ $sum = $sumTemp;
|
|
|
if ($sum<0)return $sum;
|
|
|
}
|
|
|
if ($units[$rule->ownerInStorageRule->unit_id] == '单')$sum = 1; //为单时数量设为1;
|
|
|
@@ -153,7 +157,12 @@ Class OwnerPriceOperationService
|
|
|
}else{
|
|
|
if (!isset($units[$rule->ownerInStorageRule->unit_id])) return -3;
|
|
|
if ($units[$rule->ownerInStorageRule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
|
|
|
- $sum = $this->changeUnit($sum,$owner_id,$sku);
|
|
|
+ $sumTemp = 0;
|
|
|
+ $packageColumn = $columnMapping["packages"] ?? "packages";
|
|
|
+ foreach ($matchObject[$packageColumn] as $commodity){
|
|
|
+ $sumTemp += $this->changeUnit($sum,$owner_id,$commodity["sku"]);
|
|
|
+ }
|
|
|
+ $sum = $sumTemp;
|
|
|
if ($sum<0)return $sum;
|
|
|
}
|
|
|
if ($units[$rule->ownerInStorageRule->unit_id] == '单')$sum = 1; //为单时数量设为1;
|
|
|
@@ -168,11 +177,11 @@ Class OwnerPriceOperationService
|
|
|
if ($rule->strategy == '特征'){
|
|
|
$bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);//匹配特征
|
|
|
if ($bool === true){
|
|
|
- $money = $this->matchOutStorage($rule->ownerOutStorageRules,$columnMapping,$matchObject,$units,$owner_id,$sku);
|
|
|
+ $money = $this->matchOutStorage($rule->ownerOutStorageRules,$columnMapping,$matchObject,$units,$owner_id);
|
|
|
if ($money>0)return $money;
|
|
|
};
|
|
|
}else{
|
|
|
- $money = $this->matchOutStorage($rule->ownerOutStorageRules,$columnMapping,$matchObject,$units,$owner_id,$sku);
|
|
|
+ $money = $this->matchOutStorage($rule->ownerOutStorageRules,$columnMapping,$matchObject,$units,$owner_id);
|
|
|
if ($money>0)return $money;
|
|
|
};
|
|
|
}
|
|
|
@@ -186,7 +195,7 @@ Class OwnerPriceOperationService
|
|
|
return ceil($amount/$pack);
|
|
|
}
|
|
|
|
|
|
- private function matchOutStorage($rules, $columnMapping, $matchObject, $units, $owner_id, $sku)
|
|
|
+ private function matchOutStorage($rules, $columnMapping, $matchObject, $units, $owner_id)
|
|
|
{
|
|
|
$amountColumn = $columnMapping["amount"] ?? "amount";
|
|
|
$packageColumn = $columnMapping["packages"] ?? "packages";
|
|
|
@@ -200,7 +209,7 @@ Class OwnerPriceOperationService
|
|
|
case "特征":
|
|
|
foreach ($packages as &$package){
|
|
|
if ($package["price"] ?? false)continue;
|
|
|
- if (!app("FeatureService")->matchFeature($rule->feature,["商品名称"=>"commodity"],["commodity"=>$package[$commodityColumn] ?? ''])) continue;
|
|
|
+ if (!app("FeatureService")->matchFeature($rule->feature,["商品名称"=>$commodityColumn],["commodity"=>$package[$commodityColumn] ?? ''])) continue;
|
|
|
|
|
|
if (!$unitName)$unitName = $units[$rule->unit_id];
|
|
|
else {
|
|
|
@@ -210,7 +219,12 @@ Class OwnerPriceOperationService
|
|
|
$package["price"] = $rule->unit_price;
|
|
|
if (!isset($units[$rule->unit_id]) || $units[$rule->unit_id] == '单')return -3;
|
|
|
if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
|
|
|
- $amount = $this->changeUnit($package[$amountColumn],$owner_id,$sku);
|
|
|
+ $sumTemp = 0;
|
|
|
+ $packageColumn = $columnMapping["packages"] ?? "packages";
|
|
|
+ foreach ($matchObject[$packageColumn] as $commodity){
|
|
|
+ $sumTemp += $this->changeUnit($package[$amountColumn],$owner_id,$commodity["sku"]);
|
|
|
+ }
|
|
|
+ $amount = $sumTemp;
|
|
|
if ($amount<0)return $amount;
|
|
|
$package[$amountColumn] = $amount;
|
|
|
}
|
|
|
@@ -228,7 +242,12 @@ Class OwnerPriceOperationService
|
|
|
$package["price"] = $rule->unit_price;
|
|
|
if (!isset($units[$rule->unit_id]) || $units[$rule->unit_id] == '单')return -3;
|
|
|
if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
|
|
|
- $amount = $this->changeUnit($package[$amountColumn],$owner_id,$sku);
|
|
|
+ $sumTemp = 0;
|
|
|
+ $packageColumn = $columnMapping["packages"] ?? "packages";
|
|
|
+ foreach ($matchObject[$packageColumn] as $commodity){
|
|
|
+ $sumTemp += $this->changeUnit($package[$amountColumn],$owner_id,$commodity["sku"]);
|
|
|
+ }
|
|
|
+ $amount = $sumTemp;
|
|
|
if ($amount<0)return $amount;
|
|
|
$package[$amountColumn] = $amount;
|
|
|
}
|