|
|
@@ -105,6 +105,8 @@ class OwnerPriceOperationService
|
|
|
* 三. 2021-01-28 zzd
|
|
|
* 增加满减策略:子策略匹配时不再考虑单,仅件箱换算,满减满足后标记模型修改历史对账单
|
|
|
* 增加按订单计价策略:主匹配模型增加字段量价,该字段存在时视为按单计价,价格为该值
|
|
|
+ * 四. 2021-02-18 zzd
|
|
|
+ * 满减多阶段匹配 满减字段由单值改为字符串多值 匹配时转数组寻找最相近
|
|
|
*/
|
|
|
public function matching($matchObject, $columnMapping, $owner_id, $type = '出库')
|
|
|
{
|
|
|
@@ -126,7 +128,16 @@ class OwnerPriceOperationService
|
|
|
foreach ($rules as $rule){
|
|
|
if (!$rule->items)continue; //不存在子规则跳出
|
|
|
$isDiscount = false; //是否存在满减
|
|
|
- if ($type=='出库' && $rule->discount_count > 0 && $total >= $rule->discount_count)$isDiscount = true;//满足满减条件
|
|
|
+ $discountIndex = 0;
|
|
|
+ if ($type=='出库' && $rule->discount_count){
|
|
|
+ foreach (array_reverse(explode(",",$rule->discount_count),true) as $index=>$discount){
|
|
|
+ if ($total >= $rule->discount_count){
|
|
|
+ $isDiscount = true; //第一个满足满减条件
|
|
|
+ $discountIndex = $index;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//满减存在且未被标记过处理时间或处理时间不为本月,处理历史即时账单
|
|
|
if ($isDiscount && (!$rule->discount_date || substr($rule->discount_date,0,7)!=date("Y-m"))){
|
|
|
try{
|
|
|
@@ -159,7 +170,7 @@ class OwnerPriceOperationService
|
|
|
$mapping = ["packages"=>"commodities","商品名称"=>"commodity_name",
|
|
|
"承运商"=>"logistic_name", "店铺类型"=>"shop_name",
|
|
|
"订单类型"=>"order_type","波次类型"=>"batch_type"];
|
|
|
- $money = $this->matchItem($rule->items,$mapping,$object,$units,$owner_id,'出库',$isDiscount);
|
|
|
+ $money = $this->matchItem($rule->items,$mapping,$object,$units,$owner_id,false,$isDiscount,$discountIndex);
|
|
|
if ($money>0)$detail->update(["work_fee"=>$money]);
|
|
|
else LogService::log(__CLASS__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money);
|
|
|
};
|
|
|
@@ -173,13 +184,13 @@ class OwnerPriceOperationService
|
|
|
if ($rule->strategy == '特征'){//特征策略匹配
|
|
|
$bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);
|
|
|
if ($bool === true){
|
|
|
- if ($rule->total_price)return ["id"=>$rule->id,"money"=>$isDiscount ? $rule->total_discount_price : $rule->total_price]; //按单计价存在,直接返回单总价或减免总价
|
|
|
- $money = $this->matchItem($rule->items,$columnMapping,$matchObject,$units,$owner_id,$type=='入库' ? true : false,$isDiscount);
|
|
|
+ if ($rule->total_price)return ["id"=>$rule->id,"money"=>$isDiscount ? explode(",",$rule->total_discount_price)[$discountIndex] : $rule->total_price]; //按单计价存在,直接返回单总价或减免总价
|
|
|
+ $money = $this->matchItem($rule->items,$columnMapping,$matchObject,$units,$owner_id,$type=='入库' ? true : false,$isDiscount,$discountIndex);
|
|
|
if ($money>0)return ["id"=>$rule->id,"money"=>$money];
|
|
|
};
|
|
|
}else{//默认策略匹配
|
|
|
- if ($rule->total_price)return ["id"=>$rule->id,"money"=>$isDiscount ? $rule->total_discount_price : $rule->total_price]; //按单计价存在,直接返回单总价或减免总价
|
|
|
- $money = $this->matchItem($rule->items,$columnMapping,$matchObject,$units,$owner_id,$type=='入库' ? true : false,$isDiscount);
|
|
|
+ if ($rule->total_price)return ["id"=>$rule->id,"money"=>$isDiscount ? explode(",",$rule->total_discount_price)[$discountIndex] : $rule->total_price]; //按单计价存在,直接返回单总价或减免总价
|
|
|
+ $money = $this->matchItem($rule->items,$columnMapping,$matchObject,$units,$owner_id,$type=='入库' ? true : false,$isDiscount,$discountIndex);
|
|
|
if ($money>0)return ["id"=>$rule->id,"money"=>$money];
|
|
|
};
|
|
|
}
|
|
|
@@ -213,10 +224,11 @@ class OwnerPriceOperationService
|
|
|
* @param integer $owner_id 货主ID
|
|
|
* @param bool $isIn 是否为入库单
|
|
|
* @param bool $isDiscount 是否为满减单
|
|
|
+ * @param int $discountIndex 阶梯满减所处下标 满减价格此处应为 1,2,3 解析为数组后根据此下标寻找对应值
|
|
|
*
|
|
|
* @return double
|
|
|
*/
|
|
|
- private function matchItem($rules, $columnMapping, $matchObject, $units, $owner_id, $isIn, $isDiscount)
|
|
|
+ private function matchItem($rules, $columnMapping, $matchObject, $units, $owner_id, $isIn, $isDiscount, $discountIndex)
|
|
|
{
|
|
|
$amountColumn = $columnMapping["amount"] ?? "amount";
|
|
|
$packageColumn = $columnMapping["packages"] ?? "packages";
|
|
|
@@ -226,7 +238,7 @@ class OwnerPriceOperationService
|
|
|
|
|
|
$unitName = "";
|
|
|
foreach ($rules as $rule){
|
|
|
- if ($isDiscount)$rule->unit_price = $rule->discount_price; //满足满减条件,单价调整为满减单价
|
|
|
+ if ($isDiscount)$rule->unit_price = explode(",",$rule->discount_price)[$discountIndex]; //满足满减条件,单价调整为满减单价
|
|
|
switch ($rule->strategy){
|
|
|
case "特征":
|
|
|
$inMoney = 0;
|