|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Components\ErrorPush;
|
|
|
use App\Feature;
|
|
|
use App\Jobs\HandlePastBill;
|
|
|
use App\Owner;
|
|
|
@@ -20,6 +21,7 @@ use App\Traits\ServiceAppAop;
|
|
|
class OwnerPriceOperationService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
+ use ErrorPush;
|
|
|
protected $modelClass=OwnerPriceOperation::class;
|
|
|
/**
|
|
|
* @param Builder $builder
|
|
|
@@ -271,7 +273,7 @@ class OwnerPriceOperationService
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
|
- LogService::log(__CLASS__,"即时账单满减处理失败",$exception->getMessage());
|
|
|
+ $this->push(__METHOD__."->".__LINE__,"即时账单满减处理失败",$exception->getMessage()." 参数".json_encode(array($rule, $owner, $result)));
|
|
|
}
|
|
|
//进入历史单处理
|
|
|
if ($pivot && $sign)dispatch(new HandlePastBill(array($rule,$owner,$discountIndex,$pivot)));
|
|
|
@@ -396,6 +398,7 @@ class OwnerPriceOperationService
|
|
|
*/
|
|
|
private function resetChildNodeMapping($matchObject,&$columnMapping)
|
|
|
{
|
|
|
+ dump($matchObject,$columnMapping);
|
|
|
$need = "";
|
|
|
foreach (Feature::TYPE_NODE as $index){
|
|
|
if (!$need)$need=strstr($columnMapping[$index],".",true);
|
|
|
@@ -426,7 +429,7 @@ class OwnerPriceOperationService
|
|
|
*
|
|
|
* @return double
|
|
|
*/
|
|
|
- private function matchItem($obj, $columnMapping, $matchObject, $units, $ownerId, $result)
|
|
|
+ public function matchItem($obj, $columnMapping, $matchObject, $units, $ownerId, $result)
|
|
|
{
|
|
|
$matchObject = $this->resetChildNodeMapping($matchObject->toArray(),$columnMapping);
|
|
|
if (!$matchObject)return -1;
|
|
|
@@ -535,30 +538,33 @@ class OwnerPriceOperationService
|
|
|
*/
|
|
|
public function handlePastBill($rule, $owner, $discountIndex, $pivot)
|
|
|
{
|
|
|
+ DB::beginTransaction();
|
|
|
try{
|
|
|
- DB::beginTransaction();
|
|
|
$month = date("Y-m");
|
|
|
$day = date("t",strtotime($month));
|
|
|
- $units = app("UnitService")->getUnitMapping(["件","箱"]); //获取单位映射集
|
|
|
- foreach (OwnerFeeDetail::query()->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
|
|
|
- ->where("owner_id",$owner)
|
|
|
- ->whereBetween("worked_at",[$month."-01",$month."-".$day])->get() as $detail){
|
|
|
- $order = $detail->order;
|
|
|
-
|
|
|
- $logistic_fee = 0;
|
|
|
- if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
|
|
|
-
|
|
|
- $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);
|
|
|
+ $query = OwnerFeeDetail::query()->where("owner_id",$owner)->whereBetween("worked_at",[$month."-01",$month."-".$day]);
|
|
|
+ $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"]); //获取单位映射集
|
|
|
+ $exe = function ($mapping,$object,$detail)use($rule,$units,$owner,$discountIndex){
|
|
|
+ $money = $this->matchItem($rule,$mapping,$object,$units,$owner,[$discountIndex=>true]);
|
|
|
+ if ($money>0)$detail->update(["work_fee"=>$money,"work_tax_fee"=>$money*($rule->taxRate->value/100)]);
|
|
|
+ else $this->push(__METHOD__."->".__LINE__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money.";参数列表:".json_encode(array($rule, $owner, $discountIndex)));
|
|
|
};
|
|
|
+ if ($rule->operation_type=='入库'){
|
|
|
+ foreach ($query->with(["store.storeItems.commodity","store.warehouse"])
|
|
|
+ ->where("outer_table_name",'stores')->get() as $detail)
|
|
|
+ $exe(Feature::MAPPING["store"],$detail->store,$detail);
|
|
|
+ }else{
|
|
|
+ foreach ($query->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
|
|
|
+ ->where("outer_table_name",'orders')->get() as $detail)
|
|
|
+ $exe(Feature::MAPPING["order"],$detail->order,$detail);
|
|
|
+ }
|
|
|
DB::commit();
|
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
|
//处理失败回退标记
|
|
|
DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE owner_price_operation_id = ? AND owner_id = ?"),
|
|
|
[$pivot->discount_date,$pivot->target_value,$rule->id,$owner]);
|
|
|
- LogService::log(__CLASS__,"处理历史即时账单时发生系统错误","计费模型主键:".$rule->id."; 错误信息".$e->getMessage());
|
|
|
+ $this->push(__METHOD__."->".__LINE__,"处理历史即时账单时发生系统错误","计费模型主键:".$rule->id."; 错误信息".$e->getMessage().";参数列表:".json_encode(array($rule, $owner, $discountIndex,$pivot)));
|
|
|
}
|
|
|
}
|
|
|
}
|