Zhouzhendong 5 лет назад
Родитель
Сommit
083827bcb5

+ 29 - 23
app/Console/Commands/CreateOwnerBillReport.php

@@ -51,22 +51,25 @@ 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")->where("counting_month","like",$year."-".$lastMonth."%")->get();
+        $areas = OwnerAreaReport::query()->with(["ownerStoragePriceModel.timeUnit","ownerStoragePriceModel.taxRate"])->where("counting_month","like",$year."-".$lastMonth."%")->get();
         $map = [];
+        $mapTax = [];
         foreach($areas as $area){
-            if (isset($map[$area->owner_id."_".$area->counting_month])){
+            $key = $area->owner_id."_".$area->counting_month;
+            if (isset($map[$key])){
                 if (!$area->ownerStoragePriceModel)continue;
-                $map[$area->owner_id."_".$area->counting_month] += app('OwnerStoragePriceModelService')
+                list($money,$taxFee) = app('OwnerStoragePriceModelService')
                     ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
+                $map[$key] += $money;
+                $mapTax[$key] += $taxFee;
             }else{
                 if (!$area->ownerStoragePriceModel)continue;
-                $map[$area->owner_id."_".$area->counting_month] = app('OwnerStoragePriceModelService')
+                list($map[$key],$mapTax[$key]) = app('OwnerStoragePriceModelService')
                     ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
             }
         }
         foreach (OwnerPriceSystem::query()->with(["timeUnit","taxRate"])->select("owner_id","usage_fee")->whereNull("operation")->orWhere("operation","")->get() as $system){
-            if (!$system->timeUnit)$systemFee[$system->owner_id] = $system->usage_fee;
-            else $systemFee[$system->owner_id] = $this->systemFee($system,$year."-".$lastMonth);
+            list($systemFee[$system->owner_id],$systemTaxFee[$system->owner_id]) = $this->systemFee($system,$year."-".$lastMonth);
         }
         $chunks = array_chunk($billDetails,50);
         foreach ($chunks as $bills){
@@ -74,14 +77,15 @@ class CreateOwnerBillReport extends Command
             $createOwnerBillReport = [];
             foreach ($bills as $bill){
                 $key = $bill->owner_id."_".$year."-".$lastMonth;
-                $otherFee = $systemFee[$bill->owner_id] ?? null;
                 $createOwnerBillReport[] = [
                     "owner_id"          => $bill->owner_id,       //项目ID
                     "counting_month"    => $year."-".$lastMonth."-01", //结算月
                     "work_fee"          => $bill->work_fee,
                     "logistic_fee"      => $bill->logistic_fee,
                     "storage_fee"       => $map[$key] ?? 0,
-                    "other_fee"         => $otherFee,
+                    "storage_tax_fee"   => $mapTax[$key] ?? 0,
+                    "other_fee"         => $systemFee[$bill->owner_id] ?? null,
+                    "other_tax_fee"     => $systemTaxFee[$bill->owner_id] ?? null,
                     "created_at"        => $date,
                 ];
             }
@@ -96,23 +100,25 @@ class CreateOwnerBillReport extends Command
      * @param OwnerPriceSystem|\stdClass $system
      * @param string $month
      *
-     * @return double
+     * @return array
      */
     private function systemFee(OwnerPriceSystem $system,$month)
     {
-        $money = null;
-        switch ($system->timeUnit->name){
-            case "日":
-                $money = $system->usage_fee*(Carbon::parse($month)->lastOfMonth()->format("d"));
-                break;
-            case "单":
-                $money = $system->usage_fee * (app("OrderService")->getOrderQuantity($system->owner_id));
-                break;
-            case "年":
-                $money = $system->usage_fee/12;
-                break;
-            default:
-                $money = $system->usage_fee;
+        if (!$system->timeUnit)$money = $system->usage_fee;
+        else{
+            switch ($system->timeUnit->name){
+                case "日":
+                    $money = $system->usage_fee*(Carbon::parse($month)->lastOfMonth()->format("d"));
+                    break;
+                case "单":
+                    $money = $system->usage_fee * (app("OrderService")->getOrderQuantity($system->owner_id));
+                    break;
+                case "年":
+                    $money = $system->usage_fee/12;
+                    break;
+                default:
+                    $money = $system->usage_fee;
+            }
         }
         if ($system->taxRate)$taxFee = $money * ($system->taxRate->value/100);
         else{
@@ -120,6 +126,6 @@ class CreateOwnerBillReport extends Command
             if ($system->owner && $system->owner->taxRate)$taxFee = $money * ($system->owner->taxRate->value/100);
             else $taxFee = null;
         }
-        return $money;
+        return array($money,$taxFee);
     }
 }

+ 25 - 2
app/Http/Controllers/CustomerController.php

@@ -3,7 +3,9 @@
 namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
+use App\Jobs\OrderCreateInstantBill;
 use App\Jobs\ResetInstantBill;
+use App\Order;
 use App\Owner;
 use App\OwnerAreaReport;
 use App\OwnerBillReport;
@@ -14,6 +16,7 @@ use App\Services\OwnerAreaReportService;
 use App\Services\OwnerBillReportService;
 use App\Services\OwnerReportService;
 use App\Services\OwnerService;
+use App\Store;
 use Exception;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Http\Request;
@@ -538,6 +541,7 @@ class CustomerController extends Controller
 
     public function resetInstantBill()
     {
+        ini_set('max_execution_time', 2500);
         $startData = request("startDate");
         $endDate = request("endDate");
         $owner = request("owner");
@@ -546,11 +550,30 @@ class CustomerController extends Controller
         if ($endDate)$details->where("worked_at","<=",$endDate." 23:59:59");
         if (count($owner)>0)$details->whereIn("owner_id",$owner);
         $details->get()->each(function ($detail){
-            $this->dispatch(new ResetInstantBill($detail));
+            dispatch(new ResetInstantBill($detail));
         });
+        $this->restoreResetInstantBillOrder($startData,$endDate);
+        $this->restoreResetInstantBillStore($startData,$endDate);
         $this->success();
     }
-
+    private function restoreResetInstantBillOrder($startData,$endDate)
+    {
+        $orders = Order::query()->where("wms_status","订单完成")->whereBetween("updated_at",["{$startData} 00:00:00","{$endDate} 23:59:59"])
+            ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","orders")
+                ->whereBetween("worked_at",["{$startData} 00:00:00","{$endDate} 23:59:59"]))->get();
+        foreach ($orders->chunk(50) as $or){
+            dispatch(new OrderCreateInstantBill($or));
+        }
+    }
+    private function restoreResetInstantBillStore($startData,$endDate)
+    {
+        $stores = Store::query()->where("status","已入库")->whereBetween("updated_at",["{$startData} 00:00:00","{$endDate} 23:59:59"])
+            ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","stores")
+                ->whereBetween("worked_at",["{$startData} 00:00:00","{$endDate} 23:59:59"]))->get();
+        foreach ($stores->chunk(50) as $st){
+            dispatch(new OrderCreateInstantBill($st));
+        }
+    }
     public function resetBillConfirmation()
     {
         $month = request("month");

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

@@ -177,40 +177,14 @@ class TestController extends Controller
 
     public function test()
     {
+        $order = Order::query()->where("code","SO210509003964")->first();
+        $ser = new OrderService();
+        $ser->createInstantBill($order);
+        dd();
         $store = Store::query()->find(164944);
         $ser = new StoreService();
         $ser->createInstantBill($store);
     }
-    public function restoreResetInstantBill()
-    {
-        ini_set('max_execution_time', 2500);
-        $date = \request("date");
-        foreach (OwnerFeeDetail::query()->whereBetween("worked_at",["{$date} 00:00:00","{$date} 23:59:59"])->cursor() as $detail){
-            dispatch(new ResetInstantBill($detail));
-        }
-    }
-    public function restoreResetInstantBillOrder()
-    {
-        ini_set('max_execution_time', 2500);
-        $date = \request("date");
-        $orders = Order::query()->where("wms_status","订单完成")->whereBetween("updated_at",["{$date} 00:00:00","{$date} 23:59:59"])
-            ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","orders")
-                ->whereBetween("worked_at",["{$date} 00:00:00","{$date} 23:59:59"]))->get();
-        foreach ($orders->chunk(50) as $or){
-            dispatch(new OrderCreateInstantBill($or));
-        }
-    }
-    public function restoreResetInstantBillStore()
-    {
-        ini_set('max_execution_time', 2500);
-        $date = \request("date");
-        $stores = Store::query()->where("status","已入库")->whereBetween("updated_at",["{$date} 00:00:00","{$date} 23:59:59"])
-            ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","stores")
-                ->whereBetween("worked_at",["{$date} 00:00:00","{$date} 23:59:59"]))->get();
-        foreach ($stores->chunk(50) as $st){
-            dispatch(new OrderCreateInstantBill($st));
-        }
-    }
     public function supplementMarchOwnerReport()
     {
         $ows = OwnerAreaReport::query()->select("owner_id")->where("counting_month",'like',"2021-03%")->get();

+ 2 - 0
app/OwnerBillReport.php

@@ -20,6 +20,8 @@ class OwnerBillReport extends Model
        "difference",     //差额
        "confirmed",      //确认状态
        "other_fee",      //其他费用
+       "storage_tax_fee",//仓储税费
+       "other_tax_fee",  //其他税费
    ];
    protected $appends=[
         "initial_fee"

+ 5 - 3
app/Services/OwnerPriceExpressService.php

@@ -292,9 +292,11 @@ sql
 
         $initPrice = $model->details[0]->initial_weight_price[$to1][$to2];
         $additionalPrice = $model->details[0]->additional_weight_price[$to1][$to2];
-        if ($weight <= $model->initial_weight)return $initPrice;
-        $weight -= $model->initial_weight;
-        $money = (ceil($weight/$model->additional_weight)*$additionalPrice)+$initPrice;
+        if ($weight <= $model->initial_weight)$money = $initPrice;
+        else{
+            $weight -= $model->initial_weight;
+            $money = (ceil($weight/$model->additional_weight)*$additionalPrice)+$initPrice;
+        }
         if ($model->tax_rate_id && $model->taxRate){
             $taxFee = $money*($model->taxRate->value/100);
         }else{

+ 13 - 2
app/Services/OwnerStoragePriceModelService.php

@@ -3,6 +3,7 @@
 namespace App\Services;
 
 use App\Order;
+use App\Owner;
 use App\OwnerReport;
 use App\OwnerStoragePriceModel;
 use App\Services\common\QueryService;
@@ -111,7 +112,7 @@ class OwnerStoragePriceModelService
     public function calculationAmount(OwnerStoragePriceModel $model, $area, $owner_id = null, $month = null)
     {
         /** @var \stdClass $model */
-        if (!$model || !$area || $model->operation) return 0;
+        if (!$model || !$area || $model->operation) return array(0,null);
         if ($area < $model->minimum_area) $area = $model->minimum_area;
         switch ($model->discount_type){
             case "按单减免":
@@ -154,6 +155,16 @@ class OwnerStoragePriceModelService
                 if ($total>=$model->amount_interval[$i])$model->price = $index;
             }
         }
-        return $area>0 ? $area*$model->price[$index] : 0;
+        $money = $area>0 ? $area*$model->price[$index] : 0;
+        if ($model->taxRate)$taxFee = $money * ($model->taxRate->value/100);
+        else{
+            /** @var Owner|\stdClass $owner */
+            $owner = new Owner();
+            $owner->id = $owner_id;
+            $owner->load("taxRate");
+            if ($owner->taxRate)$taxFee = $money * ($owner->taxRate->value/100);
+            else $taxFee = null;
+        }
+        return array($money,$taxFee);
     }
 }

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

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeOwnerBillReportAddColumnTax extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table("owner_bill_reports",function (Blueprint $table){
+           $table->decimal("storage_tax_fee",9,3)->nullable()->comment("仓储税费");
+           $table->decimal("other_tax_fee",9,3)->nullable()->comment("其他税费");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table("owner_bill_reports",function (Blueprint $table){
+            $table->dropColumn("storage_tax_fee");
+            $table->dropColumn("other_tax_fee");
+        });
+    }
+}