Zhouzhendong 4 éve
szülő
commit
d735ce99f1

+ 14 - 2
app/Console/Commands/CreateOwnerBillReport.php

@@ -3,6 +3,7 @@
 namespace App\Console\Commands;
 
 use App\OwnerAreaReport;
+use App\OwnerFeeStorage;
 use App\OwnerPriceSystem;
 use App\Services\LogService;
 use Carbon\Carbon;
@@ -51,18 +52,29 @@ class CreateOwnerBillReport extends Command
         $sql = "SELECT owner_id,SUM(IFNULL(work_fee,0)) AS work_fee,SUM(IFNULL(logistic_fee,0)) AS logistic_fee FROM owner_fee_details WHERE worked_at LIKE ? AND ((type = '发货' AND logistic_fee IS NOT NULL AND work_fee IS NOT NULL) OR (type <> '发货' AND work_fee IS NOT NULL))  GROUP BY owner_id";
         $billDetails = DB::select(DB::raw($sql),[$year."-".$lastMonth."%"]);
 
-        $areas = OwnerAreaReport::query()->with(["ownerStoragePriceModel.timeUnit","ownerStoragePriceModel.taxRate"])->where("counting_month","like",$year."-".$lastMonth."%")->get();
+        $areas = OwnerAreaReport::query()->with(["ownerStoragePriceModel.timeUnit","ownerStoragePriceModel.taxRate","ownerStoragePriceModel.unit"])
+            ->where("counting_month","like",$year."-".$lastMonth."%")->get();
         $map = [];
         $mapTax = [];
         foreach($areas as $area){
             if (!$area->ownerStoragePriceModel)continue;
-            $GLOBALS["FEE_INFO"] = "";
+            //信息提取模板
+            $GLOBALS["FEE_INFO"] = [
+                "area_id"           =>$area->id,
+                "counting_type"     =>$area->ownerStoragePriceModel->counting_type,
+                "using_type"        =>$area->ownerStoragePriceModel->using_type,
+                "fee_description"   =>"",
+                "total"             =>0,
+            ];
             $key = $area->owner_id."_".$area->counting_month;
             if (!isset($map[$key]))$map[$key] = $mapTax[$key] = 0;
             list($money,$taxFee) = app('OwnerStoragePriceModelService')
                 ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
             $map[$key] += $money;
             $mapTax[$key] += $taxFee;
+
+            $GLOBALS["FEE_INFO"]["total"] = $money;
+            OwnerFeeStorage::query()->create($GLOBALS["FEE_INFO"]);
         }
         foreach (OwnerPriceSystem::query()->with(["timeUnit","taxRate"])->select("owner_id","usage_fee")->whereNull("operation")->orWhere("operation","")->get() as $system){
             list($systemFee[$system->owner_id],$systemTaxFee[$system->owner_id]) = $this->systemFee($system,$year."-".$lastMonth);

+ 10 - 1
app/Services/OwnerStoragePriceModelService.php

@@ -105,15 +105,20 @@ class OwnerStoragePriceModelService
     }
 
     //暂时不考虑单位换算问题:后期可能存在多单位换算,此处仅视为单位为 m²,m³
-    public function calculationAmount(OwnerStoragePriceModel $model, $area, $owner_id = null, $month = null)
+    public function calculationAmount(OwnerStoragePriceModel $model, $area, $owner_id = null, $month = null):array
     {
         /** @var \stdClass $model */
         if (!$model || !$area || $model->operation) return array(0,null);
         if ($area < $model->minimum_area) $area = $model->minimum_area;
+
+        $GLOBALS["FEE_INFO"]["fee_description"] .= "起租面积:".$model->minimum_area;
+
         switch ($model->discount_type){
             case "按单减免":
+                $GLOBALS["FEE_INFO"]["fee_description"] .= ",按单减免";
                 if ($owner_id && $month){
                     if ($model->timeUnit->name == '月'){
+                        $GLOBALS["FEE_INFO"]["fee_description"] .= ":每".$model->discount_value."单/月 减免1".$model->unit->name ?? 'm²';
                         $report = OwnerReport::query()->select("id",DB::raw("(to_business_quantity+to_customer_quantity) AS total"))
                             ->where("owner_id",$owner_id)
                             ->where("counting_month","like",$month."%")->first();
@@ -125,6 +130,7 @@ class OwnerStoragePriceModelService
                         $logisticSql = "(''";
                         foreach ($logistics as $logistic)$logisticSql.=",".$logistic;
                         $logisticSql .= ")";
+                        $GLOBALS["FEE_INFO"]["fee_description"] .= ":每".$model->discount_value."单/".$model->timeUnit->name." 减免1".$model->unit->name ?? 'm²';
                         for($i=1;$i<=$days;$i++){
                             $d = $i<10 ? "0".$i : $i;
                             $query = DB::raw("SELECT COUNT(1) c FROM orders WHERE logistic_id IN {$logisticSql} AND wms_status = ? AND wms_edittime BETWEEN ? AND ?");
@@ -135,6 +141,7 @@ class OwnerStoragePriceModelService
                 }
                 break;
             case "固定减免":
+                $GLOBALS["FEE_INFO"]["fee_description"] .= ",固定减免:每".$model->timeUnit->name."减免".$model->discount_value.($model->unit->name ?? 'm²');
                 if ($model->timeUnit->name == '月'){
                     $area -= $model->discount_value;
                 }else{
@@ -151,8 +158,10 @@ class OwnerStoragePriceModelService
                 if ($total>=$model->amount_interval[$i])$index = $i;
             }
         }
+        $GLOBALS["FEE_INFO"]["fee_description"] .= ",单价: ".$model->price[$index]."/".($model->unit->name ?? 'm²')."/".$model->timeUnit->name;
         $money = $area>0 ? $area*$model->price[$index] : 0;
         $taxFee = app("OwnerService")->getTaxRateFee($model, $owner_id, $money);
+        $GLOBALS["FEE_INFO"]["fee_description"] .= ",税费: ".$taxFee;
         return array($money,$taxFee);
     }
 }