|
|
@@ -198,7 +198,7 @@ class OwnerPriceOperationService
|
|
|
* @return array|Collection
|
|
|
*
|
|
|
*/
|
|
|
- public function getOwnerPriceOperation($owner, $type, $typeMark)
|
|
|
+ public function getOwnerPriceOperation(int $owner, string $type, ?int $typeMark)
|
|
|
{
|
|
|
return Cache::tags("operationFeeOwner:".$owner)->remember("operationFee:".$owner.$type.$typeMark,config("cache.expirations.rarelyChange"),
|
|
|
function ()use($owner,$type,$typeMark){
|
|
|
@@ -227,12 +227,11 @@ class OwnerPriceOperationService
|
|
|
*
|
|
|
* @return bool|array
|
|
|
*/
|
|
|
- public function getDiscount($discount, $total)
|
|
|
+ public function getDiscount(?string $discount, int $total)
|
|
|
{
|
|
|
- if ($discount){
|
|
|
- foreach (array_reverse(explode(",",$discount),true) as $index=>$discount){
|
|
|
- if ($total >= $discount)return [$index=>$discount];
|
|
|
- }
|
|
|
+ if (!$discount)return false;
|
|
|
+ foreach (array_reverse(explode(",",$discount),true) as $index=>$discount){
|
|
|
+ if ($total >= $discount)return [$index=>$discount];
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
@@ -240,12 +239,13 @@ class OwnerPriceOperationService
|
|
|
/**
|
|
|
* 处理折扣单
|
|
|
*
|
|
|
- * @param object $rule
|
|
|
+ * @param Model|\stdClass $rule
|
|
|
* @param integer $owner
|
|
|
* @param bool|array $result
|
|
|
*/
|
|
|
- public function handleDiscount($rule, $owner, $result)
|
|
|
+ public function handleDiscount(Model $rule, int $owner, $result)
|
|
|
{
|
|
|
+ if (!$result)return;
|
|
|
$sign = false;
|
|
|
//入口仅在此处存在 缓存1000s
|
|
|
$key = "owner_price_operation_owner_".$rule->id."_".$owner;
|
|
|
@@ -287,7 +287,7 @@ class OwnerPriceOperationService
|
|
|
*
|
|
|
* @param array|object|Model $matchObject key-val
|
|
|
* @param array $columnMapping key-val
|
|
|
- * @param string $ownerId
|
|
|
+ * @param integer $ownerId
|
|
|
* @param string $type
|
|
|
* @param int|null $typeMark
|
|
|
*
|
|
|
@@ -312,16 +312,11 @@ class OwnerPriceOperationService
|
|
|
* 九. 2021-04-21 zzd
|
|
|
* 排除掉order不存在包裹情况,预设输出值为null防止返回0,历史账单处理推进队列防止超时
|
|
|
*/
|
|
|
- public function matching($matchObject, $columnMapping, $ownerId, $type = '出库', $typeMark = null)
|
|
|
+ public function matching($matchObject, array $columnMapping, int $ownerId, string $type = '出库', ?int $typeMark = null):array
|
|
|
{
|
|
|
- $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"]); //获取单位映射集
|
|
|
+ $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"],true); //获取单位映射集
|
|
|
$rules = $this->getOwnerPriceOperation($ownerId,$type,$typeMark);//货主下的全部规则
|
|
|
- if (!$rules)return -2; //规则不存在跳出
|
|
|
-
|
|
|
- //建立一组返回变量
|
|
|
- $id = null;
|
|
|
- $money = null;
|
|
|
- $taxFee = null;
|
|
|
+ if (!$rules)return array(null,null,null); //规则不存在跳出
|
|
|
|
|
|
if ($type == '出库'){
|
|
|
$total = app("OrderService")->getOrderQuantity($ownerId)+1;//获取该货主本月C端单量
|
|
|
@@ -342,34 +337,21 @@ class OwnerPriceOperationService
|
|
|
}
|
|
|
foreach ($rules as $rule){
|
|
|
if (!$rule->items)continue; //不存在子规则跳出
|
|
|
-
|
|
|
+ //第一级匹配 特征类别不符合要求跳出
|
|
|
+ if ($rule->strategy == '特征' && !app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject))continue;
|
|
|
+ //获取满减信息并处理满减
|
|
|
$result = $this->getDiscount($rule->discount_count,$total); //满减信息
|
|
|
- if ($result)$this->handleDiscount($rule,$ownerId,$result);//满减存在
|
|
|
+ $this->handleDiscount($rule,$ownerId,$result);
|
|
|
|
|
|
- if ($rule->strategy == '特征'){
|
|
|
- if (app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject)){
|
|
|
- if (!$rule->total_price)$money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);
|
|
|
- $id = $rule->id;
|
|
|
- };
|
|
|
- }else{
|
|
|
- if (!$rule->total_price)$money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);
|
|
|
- $id = $rule->id;
|
|
|
- };
|
|
|
- if ($id){
|
|
|
- if ($rule->total_price)$money = $result ? explode(",",$rule->total_discount_price)[key($result)] : $rule->total_price;//按单计价存在,直接返回单总价或减免总价
|
|
|
- $money = $rule->max_fee&&$money>$rule->max_fee ? $rule->max_fee : $money;//封顶费
|
|
|
- if ($money<=0)$money=null;//计算失误
|
|
|
- if ($rule->tax_rate_id && $rule->taxRate)$taxFee = $money*($rule->taxRate->value/100);
|
|
|
- else{
|
|
|
- /** @var Owner|\stdClass $owner */
|
|
|
- $owner = Owner::query()->with("taxRate")
|
|
|
- ->whereHas("taxRate")->find($ownerId);
|
|
|
- if ($owner)$taxFee = $money*($owner->taxRate->value/100);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
+ if ($rule->total_price)$money = $result ? explode(",",$rule->total_discount_price)[key($result)] : $rule->total_price;//按单计价存在,直接返回单总价或减免总价
|
|
|
+ else $money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);//匹配子项获取详细报价
|
|
|
+
|
|
|
+ $money = $rule->max_fee&&$money>$rule->max_fee ? $rule->max_fee : $money;//封顶费
|
|
|
+ if ($money<=0)$money=null;//计算失误
|
|
|
+ $taxFee = app("OwnerService")->getTaxRateFee($rule, $ownerId, $money);
|
|
|
+ return array($rule->id,$money,$taxFee);
|
|
|
}
|
|
|
- return array($id,$money,$taxFee);
|
|
|
+ return array(null,null,null);
|
|
|
}
|
|
|
/**
|
|
|
* 根据货主 sku寻找箱规并将指定数量切换为箱 返回箱规
|
|
|
@@ -421,14 +403,14 @@ class OwnerPriceOperationService
|
|
|
*
|
|
|
* @param Model|\stdClass $obj 策略对象
|
|
|
* @param array $columnMapping 映射对象
|
|
|
- * @param Model $matchObject 被匹配对象
|
|
|
+ * @param Model|\stdClass $matchObject 被匹配对象
|
|
|
* @param array $units 单位集
|
|
|
* @param integer $ownerId 货主ID
|
|
|
* @param bool|array $result 满减信息
|
|
|
*
|
|
|
* @return double
|
|
|
*/
|
|
|
- public function matchItem($obj, $columnMapping, $matchObject, $units, $ownerId, $result)
|
|
|
+ public function matchItem($obj, array $columnMapping, $matchObject, array $units, int $ownerId, $result)
|
|
|
{
|
|
|
$matchObject = $this->resetChildNodeMapping($matchObject->toArray(),$columnMapping);
|
|
|
if (!$matchObject)return -1;
|