|
|
@@ -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,44 +337,90 @@ 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);//满减存在
|
|
|
-
|
|
|
- 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);
|
|
|
+ $this->handleDiscount($rule,$ownerId,$result);
|
|
|
+
|
|
|
+ $taxRate = app("OwnerService")->getTaxRateFee($rule, $ownerId);//获取税率
|
|
|
+
|
|
|
+ if (!$rule->total_price){
|
|
|
+ $money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);//匹配子项获取详细报价
|
|
|
+ if ($rule->max_fee&&$money>$rule->max_fee){
|
|
|
+ $money = $rule->max_fee;//封顶费
|
|
|
+ foreach ($GLOBALS["FEE_INFO"] as $index=>$info){
|
|
|
+ foreach ($GLOBALS["FEE_INFO"][$index]["details"] as &$item)$item["price"] = 0;
|
|
|
+ $GLOBALS["FEE_INFO"][$index]["tax_rate"] = $taxRate;
|
|
|
+ if ($index==0){
|
|
|
+ $GLOBALS["FEE_INFO"][$index]["total_fee"] = $rule->max_fee;
|
|
|
+ $GLOBALS["FEE_INFO"][$index]["fee_description"] = "订单费用超出封顶费,封顶费:".$rule->max_fee
|
|
|
+ ."(详:".$GLOBALS["FEE_INFO"][$index]["fee_description"].")";
|
|
|
+ $GLOBALS["FEE_INFO"][$index]["details"][] = [
|
|
|
+ "name" => "封顶费",
|
|
|
+ "amount" => 1,
|
|
|
+ "price" => $rule->max_fee,
|
|
|
+ "unit_id" => array_flip($units)["单"],
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $GLOBALS["FEE_INFO"][$index]["total_fee"] = 0;
|
|
|
+ $GLOBALS["FEE_INFO"][$index]["fee_description"] = "封顶费平摊"
|
|
|
+ ."(详:".$GLOBALS["FEE_INFO"][$index]["fee_description"].")";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- break;
|
|
|
+ } else{
|
|
|
+ $money = $result ? explode(",",$rule->total_discount_price)[key($result)] : $rule->total_price;//按单计价存在,直接返回单总价或减免总价
|
|
|
+ $arr = $this->resetChildNodeMapping($matchObject->toArray(),$columnMapping);
|
|
|
+ if ($arr)$this->extractInfo($arr,$money,$result,array_flip($units),$taxRate);
|
|
|
}
|
|
|
+
|
|
|
+ if ($money<=0)$money=null;//计算失误
|
|
|
+ $taxFee = $money*($taxRate/100);
|
|
|
+ return array($rule->id,$money,$taxFee);
|
|
|
+ }
|
|
|
+ return array(null,null,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提取信息插入超全局变量中
|
|
|
+ */
|
|
|
+ private function extractInfo(array $arr, $money, $result, $flip, $taxRate)
|
|
|
+ {
|
|
|
+ foreach ($arr as $index => $item){
|
|
|
+ $details = [
|
|
|
+ "name" => "单价",
|
|
|
+ "amount" => $item["amount"] ?? 0,
|
|
|
+ "price" => 0,
|
|
|
+ "unit_id" => $flip["件"],
|
|
|
+ ];
|
|
|
+ if ($index==0){
|
|
|
+ $feeDescription = "按单计价".($result ? '('.value($result).')' : '').':'.$money.'元';
|
|
|
+ $details[] = [
|
|
|
+ "name" => "按单计费",
|
|
|
+ "amount" => 1,
|
|
|
+ "price" => $money,
|
|
|
+ "unit_id" => $flip["单"],
|
|
|
+ ];
|
|
|
+ }else $feeDescription = '该单已被按单计费,续费0元';
|
|
|
+ $GLOBALS["FEE_INFO"][] = [
|
|
|
+ "commodity_id" => $item["commodity_id"] ?? 0,
|
|
|
+ "total_fee" => $money,
|
|
|
+ "tax_rate" => $taxRate,
|
|
|
+ "fee_description" => $feeDescription,
|
|
|
+ "details" => $details
|
|
|
+ ];
|
|
|
}
|
|
|
- return array($id,$money,$taxFee);
|
|
|
}
|
|
|
/**
|
|
|
* 根据货主 sku寻找箱规并将指定数量切换为箱 返回箱规
|
|
|
*
|
|
|
* @param integer $ownerId
|
|
|
- * @param null|object $commodity
|
|
|
+ * @param null|object|array $commodity
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
- private function changeUnit($ownerId,$commodity)
|
|
|
+ private function changeUnit(int $ownerId,$commodity):int
|
|
|
{
|
|
|
if (!$commodity)return -4;
|
|
|
if ($commodity["pack_spec"])return $commodity["pack_spec"];
|
|
|
@@ -394,9 +435,9 @@ class OwnerPriceOperationService
|
|
|
* @param object|array $matchObject
|
|
|
* @param array $columnMapping
|
|
|
*
|
|
|
- * @return array
|
|
|
+ * @return array|null
|
|
|
*/
|
|
|
- private function resetChildNodeMapping($matchObject,&$columnMapping)
|
|
|
+ private function resetChildNodeMapping($matchObject, array &$columnMapping):?array
|
|
|
{
|
|
|
$need = "";
|
|
|
foreach (Feature::TYPE_NODE as $index){
|
|
|
@@ -421,128 +462,186 @@ 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;
|
|
|
- $total = 0; //商品总数
|
|
|
+ $total = $surcharge = $oddMoney = $surchargeAmount = 0; //商品总数 附加费 零头附加费
|
|
|
+
|
|
|
foreach ($matchObject as $commodity)$total += $commodity[$columnMapping[8]]; //取对象内商品数量总数将其当作子属性插入原对象
|
|
|
- $unitName = "";
|
|
|
- $surcharge = 0;
|
|
|
if ($obj->surcharge_unit_id && $obj->surcharge){
|
|
|
- if ($units[$obj->surcharge_unit_id] == '件')$surcharge += $obj->surcharge*$total;
|
|
|
- else $surcharge += $obj->surcharge;
|
|
|
+ $surchargeAmount = $units[$obj->surcharge_unit_id] == '件' ? $total : 1;
|
|
|
+ $surcharge += $obj->surcharge*$surchargeAmount;
|
|
|
}//耗材附加费
|
|
|
-
|
|
|
+ $flip = array_flip($units);
|
|
|
+ $exe = function ($package,$index,$partMoney,$startNumber,$rule)use($columnMapping,$flip,$surcharge,$surchargeAmount,$obj,$units){
|
|
|
+ $details = $package["fee_info"] ?? []; //获取在匹配过程中记录的费用,例:零头费
|
|
|
+ $fee_description = $details ? "箱装包含零头附加费" : '';
|
|
|
+ $details[] = [
|
|
|
+ "name" => "单价",
|
|
|
+ "amount" => $package[$columnMapping[8]],
|
|
|
+ "price" => $package["price"],
|
|
|
+ "unit_id" => $package["unitId"] ?? $flip["件"],
|
|
|
+ ];
|
|
|
+ if ($index==0){
|
|
|
+ if ($surcharge){
|
|
|
+ $details[] = [
|
|
|
+ "name" => "耗材附加费",
|
|
|
+ "amount" => $surchargeAmount,
|
|
|
+ "price" => $obj->surcharge,
|
|
|
+ "unit_id" => $obj->surcharge_unit_id,
|
|
|
+ ];
|
|
|
+ $fee_description .= ",包含耗材附加费".$surcharge."元";
|
|
|
+ $partMoney += $surcharge;
|
|
|
+ }
|
|
|
+ if ($startNumber){
|
|
|
+ $details[] = [
|
|
|
+ "name" => "起步费",
|
|
|
+ "amount" => $startNumber,
|
|
|
+ "price" => $rule->unit_price,
|
|
|
+ "unit_id" => $rule->unit_id,
|
|
|
+ ];
|
|
|
+ $fee_description .= ",包含起步费({$startNumber}/{$units[$rule->unit_id]})".$rule->unit_price."元";
|
|
|
+ $partMoney += $rule->unit_price;
|
|
|
+ }
|
|
|
+ }else if ($startNumber) $fee_description .= "数量被起步数平摊";
|
|
|
+ $GLOBALS["FEE_INFO"][] = [
|
|
|
+ "commodity_id" => $package["commodity_id"] ?? 0,
|
|
|
+ "total_fee" => $partMoney,
|
|
|
+ "tax_rate" => 0,
|
|
|
+ "fee_description" => ltrim($fee_description,","),
|
|
|
+ "details" => $details
|
|
|
+ ];
|
|
|
+ };
|
|
|
foreach ($obj->items as $rule){
|
|
|
-
|
|
|
if ($result)$rule->unit_price = explode(",",$rule->discount_price)[key($result)]; //满足满减条件,单价调整为满减单价
|
|
|
|
|
|
if ($rule->strategy=='起步'){
|
|
|
$startNumber = $rule->amount;
|
|
|
$money = 0;
|
|
|
- if ($unitName && $startNumber && $rule->unit_id && $unitName != $units[$rule->unit_id])return -3; //校验单位是否一致
|
|
|
-
|
|
|
- if ($startNumber){
|
|
|
+ if ($startNumber){ //起步数存在 重设数量
|
|
|
$money = $rule->unit_price;
|
|
|
- $matchObject=$this->settingCount($matchObject,$columnMapping[8],$startNumber);
|
|
|
+ $matchObject=$this->settingCount($matchObject,$columnMapping[8],$startNumber,$rule->unit_id);
|
|
|
+ }
|
|
|
+ //费用计算
|
|
|
+ if ($matchObject)foreach ($matchObject as $index=>$package){
|
|
|
+ if (!isset($package["price"]))$package["price"] = 0;
|
|
|
+ $partMoney = $package[$columnMapping[8]] * $package["price"];
|
|
|
+ $money += $partMoney;
|
|
|
+ $exe($package,$index,$partMoney,$startNumber,$rule); //向信息提取器输入信息
|
|
|
}
|
|
|
- if ($matchObject)foreach ($matchObject as $package)if ($package["price"] ?? false)$money += $package[$columnMapping[8]] * $package["price"];
|
|
|
- if (!$startNumber && $money<$rule->unit_price)$money = $rule->unit_price;
|
|
|
- return $money+$surcharge;
|
|
|
+ //起步费存在 验证重设
|
|
|
+ if (!$startNumber && $money<$rule->unit_price){
|
|
|
+ $diffMoney = $rule->unit_price-$money;
|
|
|
+ if ($GLOBALS["FEE_INFO"]){
|
|
|
+ $GLOBALS["FEE_INFO"][0]["fee_description"] .= ",低于起步费".$rule->unit_price."元,加收差费".$diffMoney;
|
|
|
+ $GLOBALS["FEE_INFO"][0]["details"][] = [
|
|
|
+ "name" => "起步费补差",
|
|
|
+ "amount" => 1,
|
|
|
+ "price" => $diffMoney,
|
|
|
+ "unit_id" => $flip["单"],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $money += $diffMoney;
|
|
|
+ }
|
|
|
+ return $money+$surcharge+$oddMoney;
|
|
|
}
|
|
|
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 (isset($package["price"]))continue; //单价存在 跳过
|
|
|
+ if (!isset($units[$rule->unit_id]))return -3;//单位未知 跳出
|
|
|
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] != '件'){ //非件时改变商品数量 此时数量可能为小数
|
|
|
- foreach ($matchObject as &$commodity){
|
|
|
- switch ($units[$rule->unit_id]){
|
|
|
- case "箱"://为箱时同步商品寻找箱规并改变商品数量
|
|
|
- $pack = $this->changeUnit($ownerId,$commodity[$columnMapping[9]]);
|
|
|
- if ($rule->odd_price){
|
|
|
- $amount = floor($commodity[$columnMapping[8]]/$pack);
|
|
|
- $surcharge += $rule->odd_price * ($amount%$pack); //零头附加费
|
|
|
- }else$amount = ceil($commodity[$columnMapping[8]]/$pack);
|
|
|
- if ($amount<0)return $amount;
|
|
|
- $commodity[$columnMapping[8]] = $amount;
|
|
|
- break;
|
|
|
- case "m³":
|
|
|
- $commodity[$columnMapping[8]] = $commodity["bulk"] ?? 0;
|
|
|
- break;
|
|
|
- case "kg":
|
|
|
- $commodity[$columnMapping[8]] = $commodity["weight"] ?? 0;
|
|
|
- break;
|
|
|
- case "T":
|
|
|
- $commodity[$columnMapping[8]] = ($commodity["weight"]/1000) ?? 0;
|
|
|
- break;
|
|
|
- }
|
|
|
+ $package["unitId"] = $rule->unit_id;
|
|
|
+ $package["fee_info"] = [];
|
|
|
+ switch ($units[$rule->unit_id]){
|
|
|
+ case "箱"://为箱时同步商品寻找箱规并改变商品数量
|
|
|
+ $pack = $this->changeUnit($ownerId,$package[$columnMapping[9]]);
|
|
|
+ if ($pack<=0)return $pack;
|
|
|
+ if ($rule->odd_price){
|
|
|
+ $amount = $package[$columnMapping[8]];
|
|
|
+ $odd = $amount%$pack;
|
|
|
+ $amount = floor($amount/$pack);
|
|
|
+ $oddMoney += $rule->odd_price * $odd; //零头附加费
|
|
|
+ $package["fee_info"][] = [
|
|
|
+ "name" => "零头附加费",
|
|
|
+ "amount" => $odd,
|
|
|
+ "price" => $rule->odd_price,
|
|
|
+ "unit_id" => $flip["件"],
|
|
|
+ ];
|
|
|
+ }else $amount = ceil($package[$columnMapping[8]]/$pack);
|
|
|
+ if ($amount<0)return $amount;
|
|
|
+ $package[$columnMapping[8]] = $amount;
|
|
|
+ break;
|
|
|
+ case "m³":
|
|
|
+ $package[$columnMapping[8]] = $package["bulk"] ?? 0;
|
|
|
+ break;
|
|
|
+ case "kg":
|
|
|
+ $package[$columnMapping[8]] = $package["weight"] ?? 0;
|
|
|
+ break;
|
|
|
+ case "T":
|
|
|
+ $package[$columnMapping[8]] = ($package["weight"]/1000) ?? 0;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $money = $surcharge;
|
|
|
- foreach ($matchObject as $mo)if ($mo["price"] ?? false)$money += $mo[$columnMapping[8]] * $mo["price"];
|
|
|
- return $money ?? -7;
|
|
|
+ $money = $surcharge+$oddMoney;
|
|
|
+ foreach ($matchObject as $index=>$mo){
|
|
|
+ if (!isset($mo["price"]))$mo["price"] = 0;
|
|
|
+ $partMoney = $mo[$columnMapping[8]] * $mo["price"];
|
|
|
+ $money += $partMoney;
|
|
|
+ $exe($mo,$index,$partMoney,0,null);
|
|
|
+ }
|
|
|
+ return $money ?: -7;
|
|
|
}
|
|
|
- //递归式重新设置数量
|
|
|
- private function settingCount($packages,$amountColumn,$startNumber)
|
|
|
+ //递归式重新设置数量 只设置单位匹配对象
|
|
|
+ private function settingCount($packages,$amountColumn,$startNumber,$unitId)
|
|
|
{
|
|
|
if (!$packages) return null;
|
|
|
$maxPrice = 0;
|
|
|
- $index = null;
|
|
|
foreach ($packages as $i => $package){
|
|
|
- if ($package[$amountColumn] <= 0){
|
|
|
- unset($packages[$i]);continue;
|
|
|
- }
|
|
|
- if (!($package["price"] ?? false)){
|
|
|
- $package["price"] = 0;
|
|
|
- $packages[$i]["price"] = 0;
|
|
|
- }
|
|
|
- if ($package["price"] > $maxPrice || ($package["price"]==0 && $maxPrice==0)){
|
|
|
- $maxPrice = $package["price"];
|
|
|
- $index = $i;
|
|
|
- }
|
|
|
+ if ($package[$amountColumn] <= 0){$package["price"] = 0;$packages[$i]["price"] = 0;continue;}
|
|
|
+ if (!isset($package["price"])){$package["price"] = 0;$packages[$i]["price"] = 0;}
|
|
|
+ if (isset($package["unitId"]) && $package["unitId"]!=$unitId)continue;//单位不一致 跳过
|
|
|
+ if ($package["price"] > $maxPrice || ($package["price"]==0 && $maxPrice==0)){$maxPrice = $package["price"];$index = $i;}
|
|
|
}
|
|
|
+ if (!isset($index))return $packages;
|
|
|
if ($packages[$index][$amountColumn] >= $startNumber){
|
|
|
$packages[$index][$amountColumn] -= $startNumber;
|
|
|
return $packages;
|
|
|
}else{
|
|
|
$startNumber -= $packages[$index][$amountColumn];
|
|
|
- unset($packages[$index]);
|
|
|
- $this->settingCount($packages,$amountColumn,$startNumber);
|
|
|
+ $packages[$index]["price"] = 0;
|
|
|
+ $this->settingCount($packages,$amountColumn,$startNumber,$unitId);
|
|
|
}
|
|
|
+ return $packages;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 处理历史账单
|
|
|
*
|
|
|
- * @param object $rule
|
|
|
+ * @param Model|\stdClass $rule
|
|
|
* @param int $owner
|
|
|
* @param int $discountIndex
|
|
|
- * @param object $pivot
|
|
|
+ * @param \stdClass|object $pivot
|
|
|
*/
|
|
|
- public function handlePastBill($rule, $owner, $discountIndex, $pivot)
|
|
|
+ public function handlePastBill($rule, int $owner, int $discountIndex, $pivot)
|
|
|
{
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
$month = date("Y-m");
|
|
|
$day = date("t",strtotime($month));
|
|
|
$query = OwnerFeeDetail::query()->where("owner_id",$owner)->whereBetween("worked_at",[$month."-01",$month."-".$day]);
|
|
|
- $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"]); //获取单位映射集
|
|
|
+ $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"],true); //获取单位映射集
|
|
|
$exe = function ($mapping,$object,$detail)use($rule,$units,$owner,$discountIndex){
|
|
|
$money = $this->matchItem($rule,$mapping,$object,$units,$owner,[$discountIndex=>true]);
|
|
|
$rate = $rule->taxRate ?: (Owner::query()->with("taxRate")->find($owner)->taxRate ?? null);
|