Преглед изворни кода

增加临时重要错误推送
增加超管“yang”
即时账单计费:历史账单分类BUG

Zhouzhendong пре 4 година
родитељ
комит
9f3cfa026e

+ 13 - 0
app/Components/ErrorPush.php

@@ -0,0 +1,13 @@
+<?php
+
+
+namespace App\Components;
+
+
+trait ErrorPush
+{
+    public function push(string $path, string $title, string $content)
+    {
+        app("ErrorPushService")->push($path,$title,$content);
+    }
+}

+ 17 - 0
app/ErrorTemp.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+
+class ErrorTemp extends Model
+{
+    use ModelLogChanging;
+
+    protected $fillable=[
+        "position","title","content","created_at"
+    ];
+    public $timestamps=false;
+}

+ 17 - 3
app/Http/Controllers/TestController.php

@@ -49,6 +49,7 @@ use App\Owner;
 use App\OwnerAreaReport;
 use App\OwnerFeeDetail;
 use App\OwnerMaterial;
+use App\OwnerPriceOperation;
 use App\Package;
 use App\Procurement;
 use App\ProcurementCheckSheet;
@@ -148,9 +149,22 @@ class TestController extends Controller
     }
     public function test()
     {
-        $a = Waybill::query()->where("id","3252")->get();
-        $a->load("owner");
-        dd($a);
+        $a = function ($a){
+          dump($a);
+        };
+        $a(true);
+        dd(2);
+        $fee = OwnerFeeDetail::query()->with(["order.logistic","order.shop",
+            "order.packages.commodities.commodity","order.batch"])
+            ->find(3183469);
+
+        $rule = OwnerPriceOperation::query()->with(["items"=>function($query){
+            /** @var Builder $query */
+            $query->orderByRaw("CASE strategy  WHEN '起步' THEN 1 WHEN '默认' THEN 2 WHEN '特征' THEN 3 END DESC,priority");
+        }])->find(82);dd($rule->toArray());
+        $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"]); //获取单位映射集
+        $money = app("OwnerPriceOperationService")->matchItem($rule,Feature::MAPPING["order"],$fee->order,$units,2,[0=>true]);
+        dd($money);
     }
     public function orderCreateBill()
     {

+ 10 - 0
app/Interfaces/ErrorPush.php

@@ -0,0 +1,10 @@
+<?php
+
+
+namespace App\Interfaces;
+
+
+interface ErrorPush
+{
+    public function push(string $path, string $title, string $content): bool;
+}

+ 1 - 2
app/Jobs/HandlePastBill.php

@@ -7,11 +7,10 @@ use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
-use Illuminate\Queue\SerializesModels;
 
 class HandlePastBill implements ShouldQueue
 {
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    use Dispatchable, InteractsWithQueue, Queueable;
 
     protected $arr;
     /**

+ 4 - 0
app/OwnerFeeDetail.php

@@ -59,6 +59,10 @@ class OwnerFeeDetail extends Model
     {   //出库单
         return $this->belongsTo(Order::class,"outer_id","id");
     }
+    public function store()
+    {   //入库单
+        return $this->belongsTo(Store::class,"outer_id","id");
+    }
     public function items()
     {   //快递费子项
         return $this->hasMany(OwnerFeeDetailLogistic::class,"owner_fee_detail_id","id");

+ 2 - 0
app/Providers/AppServiceProvider.php

@@ -150,6 +150,7 @@ use App\Services\OwnerBillReportArchiveService;
 use App\Services\SettlementBillsAreaFeeService;
 use App\Services\DbOpenService;
 use App\Services\DeliveryTypeService;
+use App\Services\ErrorPushService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -239,6 +240,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('DemandService',DemandService::class);
         app()->singleton('DepositoryService',DepositoryService::class);
         app()->singleton('DischargeTaskService',DischargeTaskService::class);
+        app()->singleton('ErrorPushService',ErrorPushService::class);
         app()->singleton('FacilitatorService',FacilitatorService::class);
         app()->singleton('FeatureService',FeatureService::class);
         app()->singleton('ForeignHaiRoboticsService',ForeignHaiRoboticsService::class);

+ 20 - 0
app/Services/ErrorPushService.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Services;
+
+use App\ErrorTemp;
+use App\Interfaces\ErrorPush;
+
+class ErrorPushService implements ErrorPush
+{
+    public function push(string $path, string $title, string $content): bool
+    {
+        ErrorTemp::query()->create([
+            "position" => $path,
+            "title" => $title,
+            "content" => $content,
+            "created_at" => date("Y-m-d H:i:s")
+        ]);
+        return true;
+    }
+}

+ 22 - 16
app/Services/OwnerPriceOperationService.php

@@ -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)));
         }
     }
 }

+ 1 - 1
config/users.php

@@ -1,7 +1,7 @@
 <?php
 
 return [
-    'superAdmin' => ['ldaaww','baoshi56','周亚萍','shiyao','zhouzhendong','胡浩','zengjun','阿珺','huhao',env('SUPER_ADMIN',"")],
+    'superAdmin' => ['ldaaww','baoshi56','周亚萍','shiyao','zhouzhendong','zengjun',"yang",'huhao',env('SUPER_ADMIN',"")],
     'token_expire_minutes'=>7200,
     'token_check_in_expire_minutes'=>432000, //打卡过期时间,单位为秒
     'cookie_expire_minutes'=>7200,//cookie过期时间,单位分钟

+ 34 - 0
database/migrations/2021_07_14_151459_create_error_temps_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateErrorTempsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('error_temps', function (Blueprint $table) {
+            $table->id();
+            $table->string("position");
+            $table->string("title");
+            $table->text("content");
+            $table->timestamp("created_at");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('error_temps');
+    }
+}