Przeglądaj źródła

修复即时账单的错误读取

Zhouzhendong 4 lat temu
rodzic
commit
fd8082b356

+ 46 - 4
app/Http/Controllers/TestController.php

@@ -3,13 +3,19 @@
 namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
+use App\Components\ErrorPush;
 use App\ErrorTemp;
+use App\Feature;
+use App\Owner;
+use App\OwnerFeeDetail;
+use App\OwnerPriceOperation;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
 
 class TestController extends Controller
 {
-    use AsyncResponse;
+    use AsyncResponse,ErrorPush;
     const ASNREFERENCE_2 = 'ASNREFERENCE2';
     private $data = [];
 
@@ -38,8 +44,44 @@ class TestController extends Controller
     }
     public function test()
     {
-dd(        ErrorTemp::query()->where("title","库存处理异常")->where("content",'like','修改了:0行%')
-    ->delete()
-    );    }
+        ini_set('max_execution_time',-1);
+        $rule = OwnerPriceOperation::query()->with("items")->find(205);
+        $owner = 3;$discountIndex = 0;
+        $pivot = new \stdClass();
+        $pivot->owner_price_operation_id = 205;
+        $pivot->owner_id = 3;
+        $pivot->discount_date = "2021-08-01";
+        $pivot->target_value = 0;
+        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"]); //获取单位映射集
+            $exe = function ($mapping,$object,$detail)use($rule,$units,$owner,$discountIndex){
+                $money = app("OwnerPriceOperationService")->matchItem($rule,$mapping,$object,$units,$owner,[$discountIndex=>true]);
+                $rate = $rule->taxRate ?: (Owner::query()->with("taxRate")->find($owner)->taxRate ?? null);
+                if ($money>0)$detail->update(["work_fee"=>$money,"work_tax_fee"=>$rate ? ($money*($rate->value/100)) : null]);
+                else dd($money);
+            };
+            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();
+            dd("OK");
+        }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]);
+            dd($e);
+        }
+    }
 
 }

+ 2 - 1
app/Services/OwnerPriceOperationService.php

@@ -545,7 +545,8 @@ class OwnerPriceOperationService
             $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)]);
+                $rate = $rule->taxRate ?: (Owner::query()->with("taxRate")->find($owner)->taxRate ?? null);
+                if ($money>0)$detail->update(["work_fee"=>$money,"work_tax_fee"=>$rate ? ($money*($rate->value/100)) : null]);
                 else $this->push(__METHOD__."->".__LINE__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money.";参数列表:".json_encode(array($rule, $owner, $discountIndex)));
             };
             if ($rule->operation_type=='入库'){