|
|
@@ -83,7 +83,7 @@ class OwnerPriceOperationService
|
|
|
$model->load("items");
|
|
|
/** @var \stdClass $model */
|
|
|
foreach ($model->items as $item){
|
|
|
- $columns = ["strategy","amount","unit_id","unit_price","feature","priority","discount_price"];
|
|
|
+ $columns = ["strategy","amount","unit_id","unit_price","feature","priority","discount_price","odd_price"];
|
|
|
if ($items[$item->id] ?? false){
|
|
|
foreach ($columns as $column){
|
|
|
if (!array_key_exists($column,$items[$item->id]))$items[$item->id][$column] = $item[$column];
|
|
|
@@ -107,6 +107,7 @@ class OwnerPriceOperationService
|
|
|
$arr["unit_id"] = $item["unit_id"];
|
|
|
$arr["unit_price"] = $item["unit_price"];
|
|
|
$arr["feature"] = $item["feature"] ?? null;
|
|
|
+ $arr["odd_price"] = $item["odd_price"] ?? null;
|
|
|
$arr["priority"] = $item["priority"] ?? 0;
|
|
|
$arr["discount_price"] = isset($item["discount_price"]) ? (is_array($item["discount_price"]) ? implode(",",$item["discount_price"]) : $item["discount_price"]) : null;
|
|
|
$insert[] = $arr;
|
|
|
@@ -287,7 +288,7 @@ class OwnerPriceOperationService
|
|
|
*
|
|
|
* 2:没有总数量存在,都为子项内数量
|
|
|
*
|
|
|
- * @param array|object $matchObject key-val
|
|
|
+ * @param array|object|Model $matchObject key-val
|
|
|
* @param array $columnMapping key-val
|
|
|
* @param string $ownerId
|
|
|
* @param string $type
|
|
|
@@ -307,13 +308,16 @@ class OwnerPriceOperationService
|
|
|
* 区分单据类型,增加字段
|
|
|
* 六. 2021-03-23 zzd
|
|
|
* 不严格区分入库出库差异 统一模型
|
|
|
+ * 七. 2021-03-30 zzd
|
|
|
+ * 增加一级二级特征,零头价,满减按总件,附加费用等
|
|
|
*/
|
|
|
public function matching($matchObject, $columnMapping, $ownerId, $type = '出库', $typeMark = null)
|
|
|
{
|
|
|
$units = app("UnitService")->getUnitMapping(["件","箱"]); //获取单位映射集
|
|
|
$rules = $this->getOwnerPriceOperation($ownerId,$type,$typeMark);//货主下的全部规则
|
|
|
if (!$rules)return -2; //规则不存在跳出
|
|
|
- $total = app("OrderService")->getOrderQuantity($ownerId);//获取该货主本月C端单量
|
|
|
+ if ($type == '出库') $total = app("OrderService")->getOrderQuantity($ownerId);//获取该货主本月C端单量
|
|
|
+ else $total = app("StoreService")->getStoreAmount($ownerId);//获取该货主本月入库件数
|
|
|
foreach ($rules as $rule){
|
|
|
if (!$rule->items)continue; //不存在子规则跳出
|
|
|
|
|
|
@@ -323,34 +327,32 @@ class OwnerPriceOperationService
|
|
|
if ($rule->strategy == '特征'){
|
|
|
if (app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject)){
|
|
|
if ($rule->total_price)return ["id"=>$rule->id,"money"=>$result ? explode(",",$rule->total_discount_price)[key($result)] : $rule->total_price];//按单计价存在,直接返回单总价或减免总价
|
|
|
- $money = $this->matchItem($rule->items,$columnMapping,$matchObject,$units,$ownerId,$result);
|
|
|
+ $money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);
|
|
|
if ($money>0)return ["id"=>$rule->id,"money"=>$money];
|
|
|
};
|
|
|
}else{
|
|
|
if ($rule->total_price)return ["id"=>$rule->id,"money"=>$result ? explode(",",$rule->total_discount_price)[key($result)] : $rule->total_price]; //按单计价存在,直接返回单总价或减免总价
|
|
|
- $money = $this->matchItem($rule->items,$columnMapping,$matchObject,$units,$ownerId,$result);
|
|
|
+ $money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);
|
|
|
if ($money>0)return ["id"=>$rule->id,"money"=>$money];
|
|
|
};
|
|
|
}
|
|
|
return $money ?? -7;
|
|
|
}
|
|
|
/**
|
|
|
- * 根据货主 sku寻找箱规并将指定数量切换为箱
|
|
|
- * 不满一箱视为一箱
|
|
|
+ * 根据货主 sku寻找箱规并将指定数量切换为箱 返回箱规
|
|
|
*
|
|
|
- * @param integer $amount
|
|
|
* @param integer $ownerId
|
|
|
* @param null|object $commodity
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
- private function changeUnit($amount,$ownerId,$commodity)
|
|
|
+ private function changeUnit($ownerId,$commodity)
|
|
|
{
|
|
|
if (!$commodity)return -4;
|
|
|
- if ($commodity->pack_spec)return ceil($amount/$commodity->pack_spec);
|
|
|
+ if ($commodity->pack_spec)return $commodity->pack_spec;
|
|
|
$pack = app("CommodityService")->getPack($ownerId,$commodity->sku);
|
|
|
if (!$pack)return -6;
|
|
|
- return ceil($amount/$pack);
|
|
|
+ return $pack;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -384,23 +386,28 @@ class OwnerPriceOperationService
|
|
|
/**
|
|
|
* 匹配子策略
|
|
|
*
|
|
|
- * @param array $rules 策略对象组
|
|
|
+ * @param Model|\stdClass $obj 策略对象
|
|
|
* @param array $columnMapping 映射对象
|
|
|
- * @param array $matchObject 被匹配对象
|
|
|
+ * @param Model $matchObject 被匹配对象
|
|
|
* @param array $units 单位集
|
|
|
* @param integer $ownerId 货主ID
|
|
|
* @param bool|array $result 满减信息
|
|
|
*
|
|
|
* @return double
|
|
|
*/
|
|
|
- private function matchItem($rules, $columnMapping, $matchObject, $units, $ownerId, $result)
|
|
|
+ private function matchItem($obj, $columnMapping, $matchObject, $units, $ownerId, $result)
|
|
|
{
|
|
|
- /** @var Collection $matchObject */
|
|
|
$matchObject = $this->resetChildNodeMapping($matchObject->toArray(),$columnMapping);
|
|
|
if (!$matchObject)return -1;
|
|
|
-
|
|
|
+ $total = 0; //商品总数
|
|
|
+ foreach ($matchObject as $commodity)$total += $commodity[$columnMapping[8]]; //取对象内商品数量总数将其当作子属性插入原对象
|
|
|
+ $surcharge = 0;
|
|
|
$unitName = "";
|
|
|
- foreach ($rules as $rule){
|
|
|
+ if ($obj->surcharge_unit_id && $obj->surcharge && isset($units[$rule->surcharge_unit_id])){
|
|
|
+ if ($units[$obj->surcharge_unit_id] == '件')$surcharge += $obj->surcharge*$total;
|
|
|
+ else $surcharge += $obj->surcharge;
|
|
|
+ }//耗材附加费
|
|
|
+ foreach ($obj->items as $rule){
|
|
|
if ($result)$rule->unit_price = explode(",",$rule->discount_price)[key($result)]; //满足满减条件,单价调整为满减单价
|
|
|
|
|
|
if ($rule->strategy=='起步'){
|
|
|
@@ -410,25 +417,34 @@ class OwnerPriceOperationService
|
|
|
if ($startNumber)$matchObject=$this->settingCount($matchObject,$columnMapping[8],$startNumber);
|
|
|
if ($matchObject)foreach ($matchObject as $package)$money += $package[$columnMapping[8]] * $package["price"];
|
|
|
if (!$startNumber && $money<$rule->unit_price)$money = $rule->unit_price;
|
|
|
- return $money;
|
|
|
+ return $money+$surcharge;
|
|
|
}
|
|
|
foreach ($matchObject as &$package){
|
|
|
if ($package["price"] ?? false)continue;
|
|
|
if (!isset($units[$rule->unit_id]))return -3;
|
|
|
if (!$unitName)$unitName = $units[$rule->unit_id];
|
|
|
else if ($unitName != $units[$rule->unit_id]) return -3;
|
|
|
- if ($rule->strategy=='特征')if (!app("FeatureService")->matchFeature($rule->feature,$columnMapping,$package)) continue;
|
|
|
+ if ($rule->strategy=='特征'){
|
|
|
+ $package[$columnMapping[10]] = $total; //设置一个不存在的总数进入原对象
|
|
|
+ if (!app("FeatureService")->matchFeature($rule->feature,$columnMapping,$package)) continue;
|
|
|
+ }
|
|
|
$package["price"] = $rule->unit_price;
|
|
|
}
|
|
|
if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
|
|
|
$amount = 0;
|
|
|
- foreach ($matchObject as $commodity)$amount += $this->changeUnit($commodity[$columnMapping[8]],$ownerId,$commodity[$columnMapping[9]]);
|
|
|
+ foreach ($matchObject as $commodity){
|
|
|
+ $pack = $this->changeUnit($ownerId,$commodity[$columnMapping[9]]);
|
|
|
+ if ($rule->odd_price){
|
|
|
+ $amount += floor($amount/$pack);
|
|
|
+ $surcharge += $rule->odd_price * ($amount%$pack); //零头附加费
|
|
|
+ }else$amount += ceil($amount/$pack);
|
|
|
+ }
|
|
|
if ($amount<0)return $amount;
|
|
|
$package[$columnMapping[8]] = $amount;
|
|
|
}
|
|
|
}
|
|
|
if ($matchObject){
|
|
|
- $money = 0;
|
|
|
+ $money = $surcharge;
|
|
|
foreach ($matchObject as $package)if ($package["price"])$money += $package[$columnMapping[8]] * $package["price"];
|
|
|
}
|
|
|
return $money ?? -7;
|
|
|
@@ -481,7 +497,7 @@ class OwnerPriceOperationService
|
|
|
$logistic_fee = 0;
|
|
|
if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
|
|
|
|
|
|
- $money = $this->matchItem($rule->items,Feature::MAPPING["order"],$order,$units,$owner,[$discountIndex=>true]);
|
|
|
+ $money = $this->matchItem($rule,Feature::MAPPING["order"],$order,$units,$owner,[$discountIndex=>true]);
|
|
|
if ($money>0)$detail->update(["work_fee"=>$money]);
|
|
|
else LogService::log(__CLASS__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money);
|
|
|
};
|