ANG YU 4 anni fa
parent
commit
a5b46e14c6
36 ha cambiato i file con 1112 aggiunte e 249 eliminazioni
  1. 10 10
      app/Http/Controllers/OwnerFeeTotalController.php
  2. 85 0
      app/Http/Controllers/OwnerWayBillFeeDetailController.php
  3. 24 7
      app/Http/Controllers/SettlementBillLogisticFeeController.php
  4. 11 11
      app/Http/Controllers/TestController.php
  5. 2 0
      app/Interfaces/SettlementBillDetailInterface.php
  6. 1 0
      app/Owner.php
  7. 0 30
      app/OwnerBillTotal.php
  8. 42 0
      app/OwnerFeeTotal.php
  9. 13 2
      app/OwnerLogisticFeeDetail.php
  10. 15 1
      app/OwnerLogisticFeeReport.php
  11. 40 0
      app/OwnerWayBillFeeDetail.php
  12. 4 6
      app/Providers/AppServiceProvider.php
  13. 0 109
      app/Services/OwnerBillTotalService.php
  14. 217 0
      app/Services/OwnerFeeTotalService.php
  15. 27 1
      app/Services/OwnerLogisticFeeReportService.php
  16. 6 0
      app/Services/OwnerProcessSettlementBillService.php
  17. 13 26
      app/Services/OwnerStoreOutFeeDetailService.php
  18. 13 0
      app/Services/OwnerWayBillFeeDetailService.php
  19. 49 6
      app/Services/OwnerWaybillSettlementBillService.php
  20. 9 1
      app/Services/SettlementBillsAreaFeeService.php
  21. 5 2
      app/Waybill.php
  22. 12 0
      database/factories/OwnerFeeTotalFactory.php
  23. 1 0
      database/factories/OwnerLogisticFeeDetailFactory.php
  24. 1 0
      database/factories/OwnerLogisticFeeReportFactory.php
  25. 22 0
      database/factories/OwnerWayBillFeeDetailFactory.php
  26. 58 0
      database/factories/WaybillFactory.php
  27. 0 36
      database/migrations/2021_06_30_113024_create_owner_bill_totals_table.php
  28. 46 0
      database/migrations/2021_07_06_101511_create_owner_fee_totals_table.php
  29. 32 0
      database/migrations/2021_07_06_132504_add_tax_fee_to_owner_logistic_fee_details.php
  30. 32 0
      database/migrations/2021_07_06_133059_add_tax_fee_to_owner_logistic_fee_reports.php
  31. 41 0
      database/migrations/2021_07_06_160116_create_owner_way_bill_fee_details_table.php
  32. 1 1
      database/seeds/OwnerFeeTotalSeeder.php
  33. 16 0
      database/seeds/OwnerWayBillFeeDetailSeeder.php
  34. 40 0
      database/seeds/SettlementBillLogisticFeeSeeder.php
  35. 3 0
      database/seeds/SettlementBillSeeder.php
  36. 221 0
      resources/views/finance/settlementBills/logisticFee/index.blade.php

+ 10 - 10
app/Http/Controllers/OwnerBillTotalController.php → app/Http/Controllers/OwnerFeeTotalController.php

@@ -2,10 +2,10 @@
 
 namespace App\Http\Controllers;
 
-use App\OwnerBillTotal;
+use App\OwnerFeeTotal;
 use Illuminate\Http\Request;
 
-class OwnerBillTotalController extends Controller
+class OwnerFeeTotalController extends Controller
 {
     /**
      * Display a listing of the resource.
@@ -41,10 +41,10 @@ class OwnerBillTotalController extends Controller
     /**
      * Display the specified resource.
      *
-     * @param  \App\OwnerBillTotal  $ownerBillTotal
+     * @param  \App\OwnerFeeTotal  $ownerFeeTotal
      * @return \Illuminate\Http\Response
      */
-    public function show(OwnerBillTotal $ownerBillTotal)
+    public function show(OwnerFeeTotal $ownerFeeTotal)
     {
         //
     }
@@ -52,10 +52,10 @@ class OwnerBillTotalController extends Controller
     /**
      * Show the form for editing the specified resource.
      *
-     * @param  \App\OwnerBillTotal  $ownerBillTotal
+     * @param  \App\OwnerFeeTotal  $ownerFeeTotal
      * @return \Illuminate\Http\Response
      */
-    public function edit(OwnerBillTotal $ownerBillTotal)
+    public function edit(OwnerFeeTotal $ownerFeeTotal)
     {
         //
     }
@@ -64,10 +64,10 @@ class OwnerBillTotalController extends Controller
      * Update the specified resource in storage.
      *
      * @param  \Illuminate\Http\Request  $request
-     * @param  \App\OwnerBillTotal  $ownerBillTotal
+     * @param  \App\OwnerFeeTotal  $ownerFeeTotal
      * @return \Illuminate\Http\Response
      */
-    public function update(Request $request, OwnerBillTotal $ownerBillTotal)
+    public function update(Request $request, OwnerFeeTotal $ownerFeeTotal)
     {
         //
     }
@@ -75,10 +75,10 @@ class OwnerBillTotalController extends Controller
     /**
      * Remove the specified resource from storage.
      *
-     * @param  \App\OwnerBillTotal  $ownerBillTotal
+     * @param  \App\OwnerFeeTotal  $ownerFeeTotal
      * @return \Illuminate\Http\Response
      */
-    public function destroy(OwnerBillTotal $ownerBillTotal)
+    public function destroy(OwnerFeeTotal $ownerFeeTotal)
     {
         //
     }

+ 85 - 0
app/Http/Controllers/OwnerWayBillFeeDetailController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\OwnerWayBillFeeDetail;
+use Illuminate\Http\Request;
+
+class OwnerWayBillFeeDetailController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\OwnerWayBillFeeDetail  $ownerWayBillFeeDetail
+     * @return \Illuminate\Http\Response
+     */
+    public function show(OwnerWayBillFeeDetail $ownerWayBillFeeDetail)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\OwnerWayBillFeeDetail  $ownerWayBillFeeDetail
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(OwnerWayBillFeeDetail $ownerWayBillFeeDetail)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\OwnerWayBillFeeDetail  $ownerWayBillFeeDetail
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, OwnerWayBillFeeDetail $ownerWayBillFeeDetail)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\OwnerWayBillFeeDetail  $ownerWayBillFeeDetail
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(OwnerWayBillFeeDetail $ownerWayBillFeeDetail)
+    {
+        //
+    }
+}

+ 24 - 7
app/Http/Controllers/SettlementBillLogisticFeeController.php

@@ -3,10 +3,12 @@
 namespace App\Http\Controllers;
 
 use App\Interfaces\SettlementBillControllerInterface;
+use App\Owner;
 use App\Services\OwnerBillReportArchiveService;
 use App\Services\OwnerWaybillSettlementBillService;
 use App\Traits\SettlementBillTrait;
 use Illuminate\Http\Request;
+use Oursdreams\Export\Export;
 
 class SettlementBillLogisticFeeController extends Controller implements SettlementBillControllerInterface
 {
@@ -29,21 +31,36 @@ class SettlementBillLogisticFeeController extends Controller implements Settleme
     public function __construct()
     {
         $this->service = app('OwnerWaybillSettlementBillService');
-        $this->service = app('OwnerBillReportArchiveService');
+        $this->archiveService = app('OwnerBillReportArchiveService');
     }
 
     public function index(Request $request)
     {
-        // TODO: Implement index() method.
+        $paginateParams = $request->input();
+        list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
+        $details = $this->service->get([
+            'counting_month' => $counting_month,
+            'owner_id' => $owner_id,
+            'type' => $this->service::TYPE,
+        ]);
+        $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
+        $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
+        $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
+        $request = $this->buildRequest($request, $counting_month);
+        return view('finance.settlementBills.logisticFee.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
     }
 
-    public function confirmBill(Request $request): \Illuminate\Http\RedirectResponse
-    {
-        // TODO: Implement confirmBill() method.
-    }
 
     public function export(Request $request)
     {
-        // TODO: Implement export() method.
+        list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
+        $query = $this->service->getSql($owner_id,$counting_month);
+        if (!$request->exists('checkAllSign')) {
+            $query->whereIn('id', explode(',', $request['data']));
+        }
+        $details = $query->get();
+        $json = $this->service->buildExport($details);
+        $row = ['承运商', '订单号', '收件人姓名', '收件人电话', '重量/体积', '计数单位', '计数区间', '省份', '市', '单价', '送货费', '提货费', '燃油附加费', '信息费', '其它费用', '备注', '起始计费', '起始计数', '运费合计'];
+        return Export::make($row, $json, "物流费");
     }
 }

+ 11 - 11
app/Http/Controllers/TestController.php

@@ -81,10 +81,12 @@ use App\Services\OrderPackageService;
 use App\Services\OrderService;
 use App\Services\OrderTrackingService;
 use App\Services\OwnerBillTotalService;
+use App\Services\OwnerFeeTotalService;
 use App\Services\OwnerLogisticFeeDetailService;
 use App\Services\OwnerLogisticFeeReportService;
 use App\Services\OwnerStoreFeeReportService;
 use App\Services\OwnerStoreOutFeeReportService;
+use App\Services\OwnerWaybillSettlementBillService;
 use App\Services\RejectedBillService;
 use App\Services\StorageService;
 use App\Services\StoreItemService;
@@ -1325,23 +1327,21 @@ TEXT;
         }
         return $owner_price_operation_fees;
     }
-
-    public function test_store_out_record()
+    public function test_bill_total_record()
     {
-        /**@var $service OwnerStoreOutFeeReportService */
-        $service = app('OwnerStoreOutFeeReportService');
-        $service->recordReport();
+        /**@var $service OwnerFeeTotalService */
+        $service = app('OwnerFeeTotalService');
+        $service->record();
     }
 
-    public function test_store_out_get()
+    public function OwnerWaybillSettlementBillServiceGet()
     {
-        /**@var $service OwnerStoreOutFeeReportService */
-        $service = app('OwnerStoreOutFeeReportService');
+        /**@var $service OwnerWaybillSettlementBillService */
+        $service = app('OwnerWaybillSettlementBillService');
         $result = $service->get([
-            'owner_id' => 3,
+            'owner_id' => 8,
             'counting_month' => now()->subMonth()->startOfMonth()->toDateString(),
-            'type' => $service::TYPE,
         ]);
-        return $result;
+        dd($result->items()[0]->toArray());
     }
 }

+ 2 - 0
app/Interfaces/SettlementBillDetailInterface.php

@@ -27,4 +27,6 @@ interface SettlementBillDetailInterface
      * @return mixed
      */
     public function add(array $model);
+
+    public function getTotalFee($owner_id, $counting_month);
 }

+ 1 - 0
app/Owner.php

@@ -4,6 +4,7 @@ namespace App;
 
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
 use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Support\Facades\Auth;
 

+ 0 - 30
app/OwnerBillTotal.php

@@ -1,30 +0,0 @@
-<?php
-
-namespace App;
-
-use Carbon\Carbon;
-use Illuminate\Database\Eloquent\Model;
-
-use App\Traits\ModelLogChanging;
-use Illuminate\Database\Eloquent\Relations\BelongsTo;
-
-class OwnerBillTotal extends Model
-{
-    use ModelLogChanging;
-
-    public $fillable = ['owner_id', 'discount_fee', 'discount_remark', 'counting_month', 'information'];
-
-    public $casts = [
-        'information' => 'array',
-    ];
-
-    public function owner(): BelongsTo
-    {
-        return $this->belongsTo(Owner::class);
-    }
-
-    public function setCountingMonth($value): string
-    {
-        return Carbon::parse($value)->startOfMonth()->toDateString();
-    }
-}

+ 42 - 0
app/OwnerFeeTotal.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class OwnerFeeTotal extends Model
+{
+    use ModelLogChanging;
+
+    public $fillable = [
+        'owner_id',//货主
+        'counting_month',//结算月
+        'discount_fee',//优惠费
+        'discount_remark',//优惠备注
+        'information',//仓储,入库出库费
+        'fee',//总费用
+        'logistic_fee',//物流费
+        'logistic_tax_fee',//物流税费
+        'express_fee',//快递费
+        'express_tax_fee',//快递税费
+        'process_fee',//加工费
+        'process_tax_fee',//加工税费
+        'system_fee',//系统使用费
+        'system_tax_fee',//系统使用税费
+        'sundry_information',//杂项费
+        'tax_rate'//税率
+    ];
+
+    public $casts = [
+        'information'=>'array',
+        'sundry_information'=>'array',
+    ];
+
+    public function owner(): BelongsTo
+    {
+        return $this->belongsTo(Owner::class);
+    }
+}

+ 13 - 2
app/OwnerLogisticFeeDetail.php

@@ -12,7 +12,18 @@ class OwnerLogisticFeeDetail extends Model
 {
     use ModelLogChanging;
 
-    public $fillable = ['owner_fee_detail_id', 'logistic_bill', 'initial_weight', 'initial_weight_price', 'additional_weight', 'additional_price','logistic_id','owner_id','additional_weigh_weight'];
+    public $fillable = [
+        'owner_fee_detail_id', //
+        'logistic_bill',//快递单号
+        'initial_weight',//首重
+        'initial_weight_price',//首重价格
+        'additional_weight',//续重
+        'additional_price',//续重价格
+        'logistic_id',//承运商
+        'owner_id',//货主
+        'additional_weigh_weight',//续重重量
+        'tax_fee'//税费
+    ];
 
     public function ownerFeeDetail(): BelongsTo
     {
@@ -22,7 +33,7 @@ class OwnerLogisticFeeDetail extends Model
 
     public function ownerFeeDetailLogistic(): BelongsTo
     {
-        return $this->belongsTo(OwnerFeeDetailLogistic::class,'logistic_bill', 'logistic_bill');
+        return $this->belongsTo(OwnerFeeDetailLogistic::class, 'logistic_bill', 'logistic_bill');
     }
 
     public function logistic(): BelongsTo

+ 15 - 1
app/OwnerLogisticFeeReport.php

@@ -11,7 +11,21 @@ class OwnerLogisticFeeReport extends Model
 {
     use ModelLogChanging;
 
-    public $fillable = ['owner_logistic_sum_fee_report_id', 'logistic_id', 'province', 'counted_date', 'initial_weight', 'initial_weight_price', 'initial_amount', 'additional_weight', 'additional_price', 'additional_amount', 'fee','owner_id'];
+    public $fillable = [
+        'owner_logistic_sum_fee_report_id',//
+        'logistic_id',//承运商
+        'province', //省份
+        'counted_date',//统计月份
+        'initial_weight',//首重
+        'initial_weight_price',//首重价格
+        'initial_amount', //数量
+        'additional_weight', //续重
+        'additional_price', //续重价格
+        'additional_amount',//续重数量
+        'fee',//费用
+        'tax_fee',//税费
+        'owner_id'//货主
+    ];
     public $timestamps = false;
 
     public function logistic(): BelongsTo

+ 40 - 0
app/OwnerWayBillFeeDetail.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+
+class OwnerWayBillFeeDetail extends Model
+{
+    use ModelLogChanging;
+
+    public $fillable = [
+        'owner_fee_detail_id',
+        'waybill_id',
+        'util_id',
+        'step',//计数区间
+        'fuel_fee',//燃油附加费
+        'service_fee',//信息费
+        'originate_fee',//起始计费
+        'originate_count',//起始计数
+        'price',//单价
+        'delivery_fee'//送货费
+    ];
+
+    public function ownerFeeDetail()
+    {
+        return $this->belongsTo(OwnerFeeDetail::class);
+    }
+
+    public function waybill()
+    {
+        return $this->belongsTo(Waybill::class);
+    }
+
+    public function unit()
+    {
+        return $this->belongsTo(Unit::class);
+    }
+}

+ 4 - 6
app/Providers/AppServiceProvider.php

@@ -4,10 +4,6 @@ namespace App\Providers;
 
 use App\Authority;
 use App\Http\Controllers\Controller;
-use App\Jobs\LogisticSFSync;
-use App\Jobs\LogisticYDSync;
-use App\Jobs\LogisticYTOSync;
-use App\Jobs\LogisticZopSync;
 use App\Menu;
 use App\Observers\AuthorityObserver;
 use App\Observers\MenuObserver;
@@ -157,7 +153,8 @@ use App\Services\OwnerProcurementSettlementBillService;
 use App\Services\OwnerWaybillSettlementBillService;
 use App\Services\OwnerProcessSettlementBillService;
 use App\Services\OwnerDischargeTaskSettlementBillService;
-use App\Services\OwnerBillTotalService;
+use App\Services\OwnerFeeTotalService;
+use App\Services\OwnerWayBillFeeDetailService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -296,9 +293,9 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('OwnerAreaReportService', OwnerAreaReportService::class);
         app()->singleton('OwnerBillReportArchiveService',OwnerBillReportArchiveService::class);
         app()->singleton('OwnerBillReportService', OwnerBillReportService::class);
-        app()->singleton('OwnerBillTotalService',OwnerBillTotalService::class);
         app()->singleton('OwnerDischargeTaskSettlementBillService',OwnerDischargeTaskSettlementBillService::class);
         app()->singleton('OwnerFeeDetailService', OwnerFeeDetailService::class);
+        app()->singleton('OwnerFeeTotalService',OwnerFeeTotalService::class);
         app()->singleton('OwnerLogisticFeeDetailService',OwnerLogisticFeeDetailService::class);
         app()->singleton('OwnerLogisticFeeReportService',OwnerLogisticFeeReportService::class);
         app()->singleton('OwnerMaterialService', OwnerMaterialService::class);
@@ -318,6 +315,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('OwnerStoreOutFeeDetailService',OwnerStoreOutFeeDetailService::class);
         app()->singleton('OwnerStoreOutFeeReportService',OwnerStoreOutFeeReportService::class);
         app()->singleton('OwnerSundryFeeDetailService',OwnerSundryFeeDetailService::class);
+        app()->singleton('OwnerWayBillFeeDetailService',OwnerWayBillFeeDetailService::class);
         app()->singleton('OwnerWaybillSettlementBillService',OwnerWaybillSettlementBillService::class);
         app()->singleton('PackageService', PackageService::class);
         app()->singleton('PackageStatisticsService', PackageStatisticsService::class);

+ 0 - 109
app/Services/OwnerBillTotalService.php

@@ -1,109 +0,0 @@
-<?php
-
-namespace App\Services;
-
-use App\Traits\ServiceAppAop;
-use App\OwnerBillTotal;
-
-class OwnerBillTotalService
-{
-    use ServiceAppAop;
-
-    protected $modelClass = OwnerBillTotal::class;
-    /**
-     * 生成统计数据
-     * @param string|null $counting_month string 统计月份默认为上一个月
-     */
-    public function record(string $counting_month = null)
-    {
-        if (is_null($counting_month)) {
-            $counting_month = now()->subMonth()->startOfMonth()->toDateString();
-        }
-        /**
-         * 1. 查询需要统计的货主
-         * 2. 遍历货主
-         * 3. 计算单个货主的费用
-         * 4. 从相关表中获取总计信息,填入information
-         * 5. 保存单个货主的信息
-         */
-        //查询需要统计的货主
-        //没有删除的货主,货主删除时间晚于上个月1号的
-        $owners = \App\Owner::query()
-            ->where('deleted_at', '>=', now()->subMonth()->startOfMonth())
-            ->orWhereNull('deleted_at')->get();
-
-        foreach ($owners as $owner) {
-            $information = [];
-            //仓储费
-            $storageFee = $this->getStorageFeeForTotal($counting_month, $owner->id);
-            //入库费
-            $storeFee = $this->getStoreFeeForTotal($counting_month, $owner->id);
-
-            $information[] = [
-                'storageFee' => $storageFee,
-            ];
-            dd($information);
-        }
-
-    }
-
-    /**
-     * 重新统计
-     * @param $owner_id
-     * @param $counting_month
-     */
-    public function restartRecord($owner_id, $counting_month)
-    {
-        OwnerBillTotal::query()
-            ->where('owner_id', $owner_id)
-            ->where('counting_month', $counting_month)
-            ->updateOrInsert();
-    }
-
-
-    public function getRecord(): array
-    {
-        $result = [];
-
-        return $result;
-    }
-
-    /**
-     * 仓储费
-     * @param string|null $counting_month
-     * @param $owner_id
-     * @return array
-     */
-    private function getStorageFeeForTotal(?string $counting_month, $owner_id): array
-    {
-        /** @var  $service  SettlementBillsAreaFeeService */
-        $service = app('SettlementBillsAreaFeeService');
-        list($areaReports, $billReport) = $service->get([
-            'counting_month' => $counting_month,
-            'owner_id' => $owner_id,
-            'type' => $service::TYPE,
-        ]);
-        $storageFee = [
-            'data' => [],
-            'fee' => $billReport->storage_fee,
-        ];
-        foreach ($areaReports as $areaReport) {
-            //起租面积:1.2元/m^3/天
-            $remark = '起租面积:'
-                . $areaReport->ownerStoragePriceModel->minimum_area . ','
-                . $areaReport->ownerStoragePriceModel->price . '/'
-                . $areaReport->ownerStoragePriceModel->unit->name .
-                '/' . $areaReport->ownerStoragePriceModel->timeUnit->name;
-            $storageFee['data'][] = [
-                'name' => $areaReport->ownerStoragePriceModel->name,
-                'remark' => $remark,
-            ];
-        }
-        return $storageFee;
-    }
-
-    private function getStoreFeeForTotal(?string $counting_month, $id)
-    {
-//        $service = app('')
-    }
-}

+ 217 - 0
app/Services/OwnerFeeTotalService.php

@@ -0,0 +1,217 @@
+<?php
+
+namespace App\Services;
+
+use App\Owner;
+use App\OwnerPriceOperation;
+use App\OwnerPriceOperationItem;
+use App\Traits\ServiceAppAop;
+use App\OwnerFeeTotal;
+use Illuminate\Database\Eloquent\Builder;
+
+class OwnerFeeTotalService
+{
+    use ServiceAppAop;
+
+    protected $modelClass = OwnerFeeTotal::class;
+
+    /**
+     * 生成统计数据
+     * @param string|null $counting_month string 统计月份默认为上一个月
+     */
+    public function record(string $counting_month = null)
+    {
+        if (is_null($counting_month)) {
+            $counting_month = now()->subMonth()->startOfMonth()->toDateString();
+        }
+        /**
+         * 仓储。入库,出库
+         * 1. 查到所有货主
+         * 2. 遍历货主
+         * 3. 获得货主下的计费模型,将计费模型里面的数据转换成“描述”
+         * 4. 查询相关表,获得指定计费模型下的费用总和(含税费)
+         *
+         * 配送,加工,系统使用,杂项
+         * 1. 查询对应表的总和即可,不需关联计费模型
+         *
+         * 理赔
+         * 1. 暂不明确
+         *
+         * 优惠
+         * 1. 一个字段,在结算管理-账单却认下添加一个优惠输入的字段
+         *
+         * 税率
+         * 1. 计算得出:总税费/总金额
+         */
+        //仓储:ownerStoragePriceModels。入库,出库:ownerPriceOperations
+        $owners = Owner::query()
+            ->with([
+                "ownerStoragePriceModels.unit:id,name",
+                "ownerStoragePriceModels.timeUnit:id,name",
+                "ownerPriceOperations" => function ($query) {
+                    /** @var Builder $query */
+                    $query->with(["items" => function ($query) {
+                        /** @var Builder $query */
+                        $query->orderByRaw("CASE strategy  WHEN '起步' THEN 1 WHEN '默认' THEN 2 WHEN '特征' THEN 3 END");
+                    }]);
+                }])
+            ->where('deleted_at', '>=', now()->subMonth()->startOfMonth())
+            ->orWhereNull('deleted_at')->get();
+        foreach ($owners as $owner) {
+            $features = app("FeatureService")->getMapArray();
+            OwnerPriceOperation::$features = $features;
+            OwnerPriceOperationItem::$features = $features;
+            foreach ($owner->ownerPriceOperations as &$operation) {
+                $operation["featureFormat"] = $operation->featureFormat;
+                $operation["isRejected"] = $operation->type_mark === 0 ? true : false;
+                foreach ($operation->items as &$item) {
+                    $item["featureFormat"] = $item->featureFormat;
+                    if ($item["strategy"] == "起步") $item["type"] = $item["amount"] ? 0 : 1;
+                }
+            }
+            $information = [
+                //仓储
+                'storageFee' => [],
+                //入库
+                'storeFee' => [],
+                //出库
+                'storeOutFee' => [],
+            ];
+            //仓储
+            foreach ($owner->ownerStoragePriceModels as $ownerStoragePriceModel) {
+                /**@var $areaFeeService SettlementBillsAreaFeeService */
+                $areaFeeService = app('SettlementBillsAreaFeeService');
+                $remark = "起租面积:{$ownerStoragePriceModel->minimum_area},{$ownerStoragePriceModel->price[0]}元/{$ownerStoragePriceModel->unit->name}/{$ownerStoragePriceModel->timeUnit->name}";
+                $information['storageFee'][] = [
+                    'name' => $ownerStoragePriceModel->name,
+                    'remark' => $remark,
+                    'id' => $ownerStoragePriceModel->id,
+                    'fee' => $areaFeeService->getTotalFee($owner->id, $counting_month)->storage_fee ?? 0,
+                    'tax_fee' => $areaFeeService->getTotalFee($owner->id, $counting_month)->storage_tax_fee ?? 0
+                ];
+            }
+
+            $ownerPriceOperationsGrouped = $owner->ownerPriceOperations->groupBy('operation_type');
+            /**@var $storeOutFeeDetailsService OwnerStoreOutFeeDetailService */
+            $storeOutFeeDetailsService = app('OwnerStoreOutFeeDetailService');
+            $workFeeTotalGrouped = $storeOutFeeDetailsService->getTotalFee($owner->id, $counting_month)->groupBy('owner_price_operation_id');
+            //入库
+            foreach ($ownerPriceOperationsGrouped['入库'] ?? [] as $ownerPriceOperationsGroupedItem) {
+                $information['storeFee'][] = [
+                    'name' => $ownerPriceOperationsGroupedItem->name,
+                    'remark' => $this->buildPriceRemarks($ownerPriceOperationsGroupedItem),
+                    'id' => $ownerPriceOperationsGroupedItem->id,
+                    'fee' => $workFeeTotalGrouped[$ownerPriceOperationsGroupedItem->id][0]->work_fee ?? 0,
+                    'tax_fee' => $workFeeTotalGrouped[$ownerPriceOperationsGroupedItem->id][0]->work_tax_fee ?? 0,
+                ];
+            }
+
+            //出库
+            foreach ($ownerPriceOperationsGrouped['出库'] ?? [] as $ownerPriceOperationsGroupedItem) {
+                $information['storeOutFee'][] = [
+                    'name' => $ownerPriceOperationsGroupedItem->name,
+                    'remark' => $this->buildPriceRemarks($ownerPriceOperationsGroupedItem),
+                    'id' => $ownerPriceOperationsGroupedItem->id,
+                    'fee' => $workFeeTotalGrouped[$ownerPriceOperationsGroupedItem->id][0]->work_fee ?? 0,
+                    'tax_fee' => $workFeeTotalGrouped[$ownerPriceOperationsGroupedItem->id][0]->work_tax_fee ?? 0,
+                ];
+            }
+            $ownerFeeTotal = [];
+            $ownerFeeTotal['information'] = $information;
+            //快递费
+            /**@var $expressFeeService OwnerLogisticFeeReportService */
+            $expressFeeService = app('OwnerLogisticFeeReportService');
+            $expressFeeTotal = $expressFeeService->getTotalFee($owner->id, $counting_month);
+
+            $ownerFeeTotal ['logistic_fee'] = $expressFeeTotal->fee;
+            $ownerFeeTotal ['logistic_tax_fee'] = $expressFeeTotal->tax_fee;
+
+            //物流作业费
+        }
+    }
+
+    /**
+     * 出库入库描述
+     * @param $ownerPriceOperation
+     * @return array
+     */
+    public function buildPriceRemarks($ownerPriceOperation): array
+    {
+        //起步: 3 件 / 2.7000元  (满减单价: 0-19999 单(2.7元) , 20000-49999 单(2.5元) , 50000-99999 单(2元) , 100000+ 单(1.6元) )
+        //默认续费: 1 件 / 0.5000元  (满减单价: 0-19999 单(0.5元) , 20000-49999 单(0.4元) , 50000-99999 单(0.3元) , 100000+ 单(0.2元) )
+        $discount_counts = explode(',', $ownerPriceOperation->discount_count);
+        $priceRemarks = [];
+        foreach ($ownerPriceOperation->items as $operationItem) {
+            $discount_prices = explode(',', $operationItem->discount_price);
+            $strategy = $operationItem->strategy == '起步' ? '起步' : '默认续费';
+            $priceRemark = "{$strategy}: {$operationItem->amount} {$operationItem->unit->name}/{$operationItem->unit_price}元";
+            if (!empty($discount_prices)) {
+                $priceRemark .= "(满减单价:";
+                for ($i = 0; $i < count($discount_counts) - 1; $i++) {
+                    $next_discount_count = $discount_counts[$i + 1] ?? '+';
+                    $discount_count = $discount_counts[$i] ?? '';
+                    $discount_price = $discount_prices[$i] ?? '';
+                    $priceRemark .= "{$discount_count}-{$next_discount_count} {$operationItem->unit->name} {$discount_price}元,";
+                }
+                $priceRemark .= ")";
+            }
+            $priceRemarks[] = $priceRemark;
+        }
+        return $priceRemarks;
+    }
+
+    /**
+     * 重新统计
+     * @param $owner_id
+     * @param $counting_month
+     */
+    public function restartRecord($owner_id, $counting_month)
+    {
+//        OwnerBillTotal::query()
+//            ->where('owner_id', $owner_id)
+//            ->where('counting_month', $counting_month)
+//            ->updateOrInsert();
+    }
+
+
+    public function getRecord(): array
+    {
+        $result = [];
+
+        return $result;
+    }
+
+    /**
+     * 仓储费
+     * @param string|null $counting_month
+     * @param $owner_id
+     * @return array
+     */
+    private function getStorageFeeForTotal(?string $counting_month, $owner_id): array
+    {
+        /** @var  $service  SettlementBillsAreaFeeService */
+        $service = app('SettlementBillsAreaFeeService');
+        list($areaReports, $billReport) = $service->get([
+            'counting_month' => $counting_month,
+            'owner_id' => $owner_id,
+            'type' => $service::TYPE,
+        ]);
+        $storageFee = [
+            'data' => [],
+            'fee' => $billReport->storage_fee,
+        ];
+        foreach ($areaReports as $areaReport) {
+            //起租面积:1.2元/m^3/天
+            $remark = '起租面积:'
+                . $areaReport->ownerStoragePriceModel->minimum_area . ','
+                . $areaReport->ownerStoragePriceModel->price . '/'
+                . $areaReport->ownerStoragePriceModel->unit->name .
+                '/' . $areaReport->ownerStoragePriceModel->timeUnit->name;
+            $storageFee['data'][] = [
+                'name' => $areaReport->ownerStoragePriceModel->name,
+                'remark' => $remark,
+            ];
+        }
+        return $storageFee;
+    }
+}

+ 27 - 1
app/Services/OwnerLogisticFeeReportService.php

@@ -40,7 +40,19 @@ class OwnerLogisticFeeReportService
 
 
         $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()
-            ->selectRaw("logistic_id,province,DATE_FORMAT(created_at,'%Y-%m') as counted_date,initial_weight,initial_weight_price,count(1) as initial_amount,additional_price,additional_weight,sum(additional_weigh_weight) as additional_amount,created_at,owner_id")
+            ->selectRaw("logistic_id,
+            province,
+            DATE_FORMAT(created_at,
+            '%Y-%m') as counted_date,
+            initial_weight,
+            initial_weight_price,
+            count(1) as initial_amount,
+            additional_price,
+            additional_weight,
+            sum(additional_weigh_weight) as additional_amount,
+            sum(tax_fee) as tax_fee,
+            created_at,
+            owner_id")
             ->whereBetween('created_at', [$start, $end])
             ->groupBy('initial_weight', 'initial_weight_price', 'additional_price', 'additional_weight', 'logistic_id', 'province', 'counted_date', 'owner_id')
             ->get();
@@ -58,6 +70,7 @@ class OwnerLogisticFeeReportService
                 'additional_price' => $ownerLogisticFeeDetail->additional_price,
                 'additional_amount' => $ownerLogisticFeeDetail->additional_amount,
                 'fee' => ($ownerLogisticFeeDetail['initial_weight_price'] * $ownerLogisticFeeDetail['initial_amount']) + ($ownerLogisticFeeDetail['additional_amount'] * $ownerLogisticFeeDetail['additional_price']),
+                'tax_fee' => $ownerLogisticFeeDetail->tax_fee,
                 'owner_id' => $ownerLogisticFeeDetail->owner_id,
             ];
         }
@@ -140,4 +153,17 @@ class OwnerLogisticFeeReportService
             ->orderByDesc('logistic_id')
             ->orderByDesc('province');
     }
+
+    /**
+     *获取总金额和税费
+     */
+    public function getTotalFee($owner_id, $counting_month)
+    {
+        return OwnerLogisticFeeReport::query()
+            ->selectRaw("sum(fee) as fee,
+            sum(tax_fee) as tax_fee")
+            ->where('owner_id', $owner_id)
+            ->where('counted_date', $counting_month)
+            ->first();
+    }
 }

+ 6 - 0
app/Services/OwnerProcessSettlementBillService.php

@@ -58,4 +58,10 @@ class OwnerProcessSettlementBillService implements SettlementBillDetailInterface
     {
         // TODO: Implement add() method.
     }
+
+    public function getTotalFee($owner_id, $counting_month)
+    {
+        // TODO: Implement getTotalFee() method.
+    }
+
 }

+ 13 - 26
app/Services/OwnerStoreOutFeeDetailService.php

@@ -71,31 +71,18 @@ class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
         // TODO: Implement add() method.
     }
 
+    public function getTotalFee($owner_id, $counting_month)
+    {
+       list($start, $end) = $this->getStartAndEnd($counting_month);
+        return \App\OwnerFeeDetail::query()
+            ->selectRaw("owner_price_operation_id,
+            sum(work_fee) as work_fee,
+            sum(work_tax_fee) as work_tax_fee
+             ")
+            ->where('owner_id', $owner_id)
+            ->whereBetween('created_at', [$start, $end])
+            ->groupBy('owner_id', 'owner_price_operation_id')
+            ->get();
+    }
 
-//    public function buildPriceRemarks(&$storeOutFeeDetails)
-//    {
-//        foreach ($storeOutFeeDetails as &$ownerStoreOutFeeDetail) {
-//            //起步: 3 件 / 2.7000元  (满减单价: 0-19999 单(2.7元) , 20000-49999 单(2.5元) , 50000-99999 单(2元) , 100000+ 单(1.6元) )
-//            //默认续费: 1 件 / 0.5000元  (满减单价: 0-19999 单(0.5元) , 20000-49999 单(0.4元) , 50000-99999 单(0.3元) , 100000+ 单(0.2元) )
-//            $discount_counts = explode(',', $ownerStoreOutFeeDetail->ownerPriceOperation->discount_count);
-//            $priceRemarks = [];
-//            foreach ($ownerStoreOutFeeDetail->ownerPriceOperation->items as $operationItem) {
-//                $discount_prices = explode(',', $operationItem->discount_price);
-//                $strategy = $operationItem->strategy == '起步' ? '起步' : '默认续费';
-//                $priceRemark = "{$strategy}: {$operationItem->amount} {$operationItem->unit->name}/{$operationItem->unit_price}元";
-//                if (!empty($discount_prices)) {
-//                    $priceRemark .= "(满减单价:";
-//                    for ($i = 0; $i < count($discount_counts) - 1; $i++) {
-//                        $next_discount_count = $discount_counts[$i + 1] ?? '+';
-//                        $discount_count = $discount_counts[$i] ?? '';
-//                        $discount_price = $discount_prices[$i] ?? '';
-//                        $priceRemark .= "{$discount_count}-{$next_discount_count} {$operationItem->unit->name} {$discount_price}元,";
-//                    }
-//                    $priceRemark .= ")";
-//                }
-//                $priceRemarks[] = $priceRemark;
-//            }
-//            $ownerStoreOutFeeDetail['price_remarks'] = $priceRemarks;
-//        }
-//    }
 }

+ 13 - 0
app/Services/OwnerWayBillFeeDetailService.php

@@ -0,0 +1,13 @@
+<?php 
+
+namespace App\Services;
+
+use App\Traits\ServiceAppAop;
+use App\OwnerWayBillFeeDetail;
+
+class OwnerWayBillFeeDetailService
+{
+    use ServiceAppAop;
+    protected $modelClass=OwnerWayBillFeeDetail::class;
+
+}

+ 49 - 6
app/Services/OwnerWaybillSettlementBillService.php

@@ -2,28 +2,42 @@
 
 namespace App\Services;
 
+use App\OwnerFeeDetail;
+use App\OwnerPriceLogisticDetail;
 use App\Traits\ServiceAppAop;
+use App\Waybill;
+use Illuminate\Database\Eloquent\Builder;
 
 class OwnerWaybillSettlementBillService implements \App\Interfaces\SettlementBillDetailInterface
 {
     use ServiceAppAop;
     use \App\Traits\SettlementBillServiceTrait;
 
+    const TYPE = '物流费';
+
 
     public function get(array $kvPairs)
     {
-
+        return $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
     }
 
 
-    public function getSql($owner_id, $counting_month): \Illuminate\Database\Eloquent\Builder
+    /**
+     * @param $owner_id
+     * @param $counting_month
+     * @return Builder
+     */
+    public function getSql($owner_id, $counting_month): Builder
     {
         list($start, $end) = $this->getStartAndEnd($counting_month);
-        \App\Waybill::query()
-            ->select('id', 'created_at', 'wms_bill_number', 'recipient', 'recipient_mobile', 'warehouse_weight', 'warehouse_weight_unit_id', 'destination_city_id')
-            ->with(['logistic:id,name', 'warehouseWeightUnit:id,name', 'destinationCity.parent'])
+        $ownerFeeDetailIdsQuery = OwnerFeeDetail::query()
+            ->select('id')
+            ->with('ownerPriceLogistic')
             ->where('owner_id', $owner_id)
+            ->where('outer_table_name', 'waybills')
             ->whereBetween('created_at', [$start, $end]);
+        return Waybill::query()->whereIn('id', $ownerFeeDetailIdsQuery)
+            ->with(['ownerWayBillFeeDetail.ownerFeeDetail', 'logistic', 'warehouseWeightUnit', 'originationCity', 'destinationCity']);
     }
 
     public function switchType($type)
@@ -33,11 +47,40 @@ class OwnerWaybillSettlementBillService implements \App\Interfaces\SettlementBil
 
     public function buildExport($details): array
     {
-        // TODO: Implement buildExport() method.
+        $results = [];
+        foreach ($details as $detail) {
+            $results[] = [
+                $detail->logistic->name ?? '',
+                $detail->order_id ?? '',
+                $detail->recipient ?? '',
+                $detail->recipient_mobile ?? '',
+                $detail->warehouse_weight ?? '',
+                $detail->warehouseWeightUnit->name ?? '',
+                $detail->ownerWayBillFeeDetail->step ?? '',
+                $detail->ownerWayBillFeeDetail->ownerFeeDetail->province ?? '',
+                $detail->destination_city->name ?? '',
+                $detail->ownerWayBillFeeDetail->price ?? '',
+                $detail->ownerWayBillFeeDetail->delivery_fee ?? '',
+                $detail->pick_up_fee ?? '',
+                $detail->ownerWayBillFeeDetail->fuel_fee ?? '',
+                $detail->ownerWayBillFeeDetail->service_fee ?? '',
+                $detail->other_fee ?? '',
+                $detail->dispatch_remark ?? '',
+                $detail->ownerWayBillFeeDetail->originate_fee ?? '',
+                $detail->ownerWayBillFeeDetail->originate_count ?? '',
+                $detail->fee ?? '',
+            ];
+        }
+        return $results;
     }
 
     public function add(array $model)
     {
         // TODO: Implement add() method.
     }
+
+    public function getTotalFee($owner_id, $counting_month)
+    {
+        // TODO: Implement getTotalFee() method.
+    }
 }

+ 9 - 1
app/Services/SettlementBillsAreaFeeService.php

@@ -30,7 +30,7 @@ class SettlementBillsAreaFeeService implements \App\Interfaces\SettlementBillDet
             $billReport = collect($archived->information['billReport']);
         } else {
             $areaReports = OwnerAreaReport::query()
-                ->with(['ownerStoragePriceModel'=>function ($query){
+                ->with(['ownerStoragePriceModel' => function ($query) {
                     $query->selectRaw("id,using_type,price,unit_id,unit_id,time_unit_id,name,minimum_area")
                         ->with(['unit:id,name', 'timeUnit:id,name']);
                 }])
@@ -53,6 +53,14 @@ class SettlementBillsAreaFeeService implements \App\Interfaces\SettlementBillDet
         // TODO: Implement getSql() method.
     }
 
+    public function getTotalFee($owner_id, $counting_month)
+    {
+        return OwnerBillReport::query()
+            ->where('owner_id', $owner_id)
+            ->where('counting_month', $counting_month)
+            ->first();
+    }
+
     public function switchType($type)
     {
         // TODO: Implement switchType() method.

+ 5 - 2
app/Waybill.php

@@ -2,12 +2,11 @@
 
 namespace App;
 
-use App\Services\UserService;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 use App\Traits\ModelTimeFormat;
+use Illuminate\Database\Eloquent\Relations\HasOne;
 use Illuminate\Database\Eloquent\SoftDeletes;
-use Illuminate\Support\Facades\Auth;
 
 use App\Traits\ModelLogChanging;
 
@@ -152,5 +151,9 @@ column
         });
     }
 
+    public function ownerWayBillFeeDetail(): HasOne
+    {
+        return $this->hasOne(OwnerWayBillFeeDetail::class);
+    }
 
 }

+ 12 - 0
database/factories/OwnerFeeTotalFactory.php

@@ -0,0 +1,12 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerFeeTotal;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerFeeTotal::class, function (Faker $faker) {
+    return [
+        //
+    ];
+});

+ 1 - 0
database/factories/OwnerLogisticFeeDetailFactory.php

@@ -19,6 +19,7 @@ $factory->define(OwnerLogisticFeeDetail::class, function (Faker $faker) {
         'province' => $faker->randomElement($province),
         'owner_id' => random_int(1, 100),
         'additional_weigh_weight' => random_int(1, 100),
+        'tax_fee' => random_int(1, 100),
         'created_at' => now()->subMonth()->startOfMonth()->addDays(random_int(1, 28))->toDateTimeString(),
         'updated_at' => now()->subMonth()->startOfMonth()->addDays(random_int(1, 28))->toDateTimeString(),
     ];

+ 1 - 0
database/factories/OwnerLogisticFeeReportFactory.php

@@ -20,6 +20,7 @@ $factory->define(OwnerLogisticFeeReport::class, function (Faker $faker) {
         'additional_price' => random_int(1, 100),
         'additional_amount' => random_int(1, 100),
         'fee' => random_int(1, 100),
+        'tax_fee' => random_int(1, 100),
         'owner_id' => random_int(1, 100),
     ];
 });

+ 22 - 0
database/factories/OwnerWayBillFeeDetailFactory.php

@@ -0,0 +1,22 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerWayBillFeeDetail;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerWayBillFeeDetail::class, function (Faker $faker) {
+    $step = ['0-10000', '10000-50000', '50000-100000'];
+    return [
+        'owner_fee_detail_id' => rand(1, 100),
+        'waybill_id' => rand(1, 100),
+        'util_id' => rand(1, 7),
+        'step' => $faker->randomElement($step),//计数区间
+        'fuel_fee' => rand(1, 100),//燃油附加费
+        'service_fee' => rand(1, 100),//信息费
+        'originate_fee' => rand(1, 100),//起始计费
+        'originate_count' => rand(1, 100), //起始计数
+        'price' => rand(1, 100),//起始计数
+        'delivery_fee' => rand(1, 100),//送货费
+    ];
+});

+ 58 - 0
database/factories/WaybillFactory.php

@@ -0,0 +1,58 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use Faker\Generator as Faker;
+
+$factory->define(\App\Waybill::class, function (Faker $faker) {
+    $created_at = $faker->dateTimeThisMonth(now()->subMonth());
+    $updated_at = $faker->dateTimeThisMonth($created_at);
+    $types = ['直发车', '专线'];
+    $status = ['未审核', '已审核', '待重审', '待终审', '已完结', '无模型',];
+    return [
+        'created_at'=>$created_at,
+        'updated_at'=>$updated_at,
+        'type'=>$faker->randomElement($types),
+        'waybill_number'=>$faker->uuid,
+        'source_bill'=>$faker->uuid,
+        'owner_id'=>random_int(1,100),
+        'wms_bill_number'=>$faker->uuid,
+        'origination'=>$faker->city,
+        'destination'=>$faker->city,
+        'recipient'=>$faker->name,
+        'recipient_mobile'=>$faker->phoneNumber,
+        'charge'=>random_int(1,100),
+        'collect_fee'=>random_int(1,100),
+        'ordering_remark'=>$faker->sentence,
+        'logistic_id'=>random_int(1,100),
+        'carrier_bill'=>$faker->uuid,
+        'origination_city_id'=>random_int(1,10),
+        'destination_city_id'=>random_int(1,10),
+        'warehouse_weight'=>random_int(1,10),
+        'warehouse_weight_unit_id'=>random_int(1,10),
+        'carrier_weight'=>random_int(1,10),
+        'carrier_weight_unit_id'=>random_int(1,10),
+        'carType_id'=>random_int(1,10),
+        'fee'=>random_int(1,10),
+        'pick_up_fee'=>random_int(1,10),
+        'other_fee'=>random_int(1,10),
+        'dispatch_remark'=>$faker->sentence,
+        'waybill_price_model_id'=>random_int(1,10),
+        'warehouse_weight_other'=>random_int(1,10),
+        'warehouse_weight_unit_id_other'=>random_int(1,10),
+        'carrier_weight_other'=>random_int(1,10),
+        'carrier_weight_unit_id_other'=>random_int(1,10),
+        'car_owner_info'=>$faker->sentence,
+        'status'=>$faker->randomElement($status),
+        'mileage'=>random_int(1,10),
+        'amount'=>random_int(1,10),
+        'inquire_tel'=>$faker->phoneNumber,
+        'amount_unit_id'=>random_int(1,7),
+        'other_charge'=>random_int(1,100),
+        'other_charge_remark'=>$faker->sentence,
+        'deliver_at'=>now(),
+        'district_id'=>random_int(1,10),
+        'order_id'=>random_int(2511,100000),
+        'is_to_pay'=>random_int(0,1),
+    ];
+});

+ 0 - 36
database/migrations/2021_06_30_113024_create_owner_bill_totals_table.php

@@ -1,36 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-class CreateOwnerBillTotalsTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('owner_bill_totals', function (Blueprint $table) {
-            $table->id();
-            $table->integer('owner_id')->comment('货主');
-            $table->decimal('discount_fee')->comment('优惠金额');
-            $table->string('discount_remark')->comment('优惠说明');
-            $table->date('counting_month')->comment('统计月份');
-            $table->longText('information')->comment('统计信息');
-            $table->timestamps();
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::dropIfExists('owner_bill_totals');
-    }
-}

+ 46 - 0
database/migrations/2021_07_06_101511_create_owner_fee_totals_table.php

@@ -0,0 +1,46 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateOwnerFeeTotalsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('owner_fee_totals', function (Blueprint $table) {
+            $table->id();
+            $table->integer('owner_id')->comment('货主');
+            $table->date('counting_month')->comment('结算月');
+            $table->decimal('discount_fee')->comment('优惠费');
+            $table->string('discount_remark')->comment('优惠备注');
+            $table->longText('information')->comment('入库出库费');
+            $table->decimal('fee')->comment('总费用');
+            $table->decimal('logistic_fee')->comment('物流费');
+            $table->decimal('logistic_tax_fee')->comment('物流税费');
+            $table->decimal('express_fee')->comment('快递费');
+            $table->decimal('express_tax_fee')->comment('快递税费');
+            $table->decimal('process_fee')->comment('加工费');
+            $table->decimal('process_tax_fee')->comment('加工税费');
+            $table->decimal('system_fee')->comment('系统使用费');
+            $table->decimal('system_tax_fee')->comment('系统使用税费');
+            $table->decimal('tax_rate')->comment('税率');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('owner_fee_totals');
+    }
+}

+ 32 - 0
database/migrations/2021_07_06_132504_add_tax_fee_to_owner_logistic_fee_details.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddTaxFeeToOwnerLogisticFeeDetails extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_logistic_fee_details', function (Blueprint $table) {
+            $table->decimal('tax_fee')->comment('税费');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_logistic_fee_details', function (Blueprint $table) {
+            $table->dropColumn('tax_fee');
+        });
+    }
+}

+ 32 - 0
database/migrations/2021_07_06_133059_add_tax_fee_to_owner_logistic_fee_reports.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddTaxFeeToOwnerLogisticFeeReports extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_logistic_fee_reports', function (Blueprint $table) {
+            $table->decimal('tax_fee')->comment('税费');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_logistic_fee_reports', function (Blueprint $table) {
+            $table->dropColumn('tax_fee');
+        });
+    }
+}

+ 41 - 0
database/migrations/2021_07_06_160116_create_owner_way_bill_fee_details_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateOwnerWayBillFeeDetailsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('owner_way_bill_fee_details', function (Blueprint $table) {
+            $table->id();
+            $table->integer('owner_fee_detail_id')->comment('');
+            $table->integer('waybill_id')->comment('');
+            $table->integer('util_id')->comment('');
+            $table->string('step')->comment('计数区间');
+            $table->decimal('fuel_fee')->comment('燃油附加费');
+            $table->decimal('service_fee')->comment('信息费');
+            $table->decimal('originate_fee')->comment('起始计费');
+            $table->decimal('price')->comment('单价');
+            $table->decimal('delivery_fee')->comment('送货费');
+            $table->integer('originate_count')->comment('起始计数');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('owner_way_bill_fee_details');
+    }
+}

+ 1 - 1
database/seeds/OwnerBillTotalSeeder.php → database/seeds/OwnerFeeTotalSeeder.php

@@ -2,7 +2,7 @@
 
 use Illuminate\Database\Seeder;
 
-class OwnerBillTotalSeeder extends Seeder
+class OwnerFeeTotalSeeder extends Seeder
 {
     /**
      * Run the database seeds.

+ 16 - 0
database/seeds/OwnerWayBillFeeDetailSeeder.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class OwnerWayBillFeeDetailSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        //
+    }
+}

+ 40 - 0
database/seeds/SettlementBillLogisticFeeSeeder.php

@@ -0,0 +1,40 @@
+<?php
+
+use App\Owner;
+use App\OwnerFeeDetail;
+use App\OwnerWayBillFeeDetail;
+use App\Waybill;
+use Illuminate\Database\Seeder;
+
+class SettlementBillLogisticFeeSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $owners = Owner::query()->limit(10)->get();
+
+        Waybill::query()->truncate();
+        OwnerFeeDetail::query()->truncate();
+        OwnerWayBillFeeDetail::query()->truncate();
+        foreach ($owners as $owner) {
+            /**@var $owner Owner */
+            $waybills = factory(Waybill::class)->times(100)->create(['owner_id' => $owner->id]);
+            foreach ($waybills as $waybill) {
+                $ownerFeeDetail = factory(OwnerFeeDetail::class)->create([
+                    'owner_id' => $owner->id,
+                    'outer_table_name' => 'waybills',
+                    'outer_id' => $waybill->id,
+                    'created_at' => now()->subMonth(),
+                ]);
+                factory(OwnerWayBillFeeDetail::class)->create([
+                    'owner_fee_detail_id' => $ownerFeeDetail->id,
+                    'waybill_id' => $waybill->id,
+                ]);
+            }
+        }
+    }
+}

+ 3 - 0
database/seeds/SettlementBillSeeder.php

@@ -48,6 +48,9 @@ class SettlementBillSeeder extends Seeder
 
             //加工费
             SettlementBillProcessFeeTableSeeder::class,
+
+            //物流费
+            SettlementBillLogisticFeeSeeder::class,
         ]);
 
     }

+ 221 - 0
resources/views/finance/settlementBills/logisticFee/index.blade.php

@@ -0,0 +1,221 @@
+@extends('layouts.app')
+@section('title','物流费')
+@section('content')
+    @include('shared._messages')
+    @include('shared._error')
+    <div id="list" class="d-none">
+        <div class="container-fluid">
+            <div id="form_div"></div>
+            <div class="ml-3 form-inline" id="btn">
+                    <span class="dropdown">
+                        <button type="button"
+                                class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget"
+                                data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果,将其全部记录(每一页)导出">导出Excel
+                        </button>
+                        <div class="dropdown-menu">
+                            <a class="dropdown-item" @click="detailExport(false)" href="javascript:">导出勾选内容</a>
+                            <a class="dropdown-item" @click="detailExport(true)" href="javascript:">导出所有页</a>
+                        </div>
+                    </span>
+            </div>
+            <div class="row">
+                <div class="col-3">
+                    <div class="row pt-2">
+                        <span class="fa fa-user fa-4x offset-md-3" style="color: #4c2584;opacity: 0.3"></span>
+                        <span class="ml-4 mt-2"><h5 class="font-weight-bold">{{ $owner->name }}</h5><p
+                                class="text-muted">货主</p></span>
+                    </div>
+                </div>
+                <div v-if="(isArchived===1)" class="col-3">
+                    <div class="row pt-2">
+                        <span class="fa fa-check-circle  fa-4x offset-md-3" aria-hidden="true"
+                              style="color: #4c2584;opacity: 0.3"></span>
+                        <span class="ml-4 mt-2"><h5 class="font-weight-bold">已确认</h5></span>
+                    </div>
+                </div>
+                <div v-else class="col-3">
+                    <div class="row pt-2">
+                        <form action="{{ 'logisticFee/confirmBill' }}" method="post" style="display: inline-block;"
+                              onsubmit="return confirm('您确定要确认金额吗?');">
+                            {{ csrf_field() }}
+                            <input type="hidden" name="owner_id" value="{{ $request['owner_id']??'' }}">
+                            <input type="hidden" name="year" value="{{ $request['year']??'' }}">
+                            <input type="hidden" name="month" value="{{ $request['month']??'' }}">
+                            <span class="ml-4 mt-2">
+                              <button type="submit" class="btn btn-success btn-lg">
+                                <i class="far fa-trash-alt"></i> 确认金额
+                            </button>
+                            </span>
+
+                        </form>
+                    </div>
+                </div>
+            </div>
+            <table class="table table-striped table-sm text-nowrap table-hover table-bordered" id="table">
+                <tr v-for="(detail,i) in details"
+                    @click="selectTr===i+1?selectTr=0:selectTr=i+1"
+                    :class="selectTr===i+1?'focusing' : ''">
+                    <td><input class="checkItem" type="checkbox" :value="detail.id"></td>
+                    <td>@{{ i+1 }}</td>
+                    <td>@{{ detail.logistic?detail.logistic.name:'' }}</td>
+                    <td>@{{ detail.order_id }}</td>
+                    <td>@{{ detail.recipient }}</td>
+                    <td>@{{ detail.recipient_mobile }}</td>
+                    <td>@{{ detail.warehouse_weight }}</td>
+                    <td>@{{ detail.warehouse_weight_unit.name }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.step }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.owner_fee_detail.province }}</td>
+                    <td>@{{ detail.destination_city.name }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.price }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.delivery_fee }}</td>
+                    <td>@{{ detail.pick_up_fee }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.fuel_fee }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.service_fee }}</td>
+                    <td>@{{ detail.other_fee }}</td>
+                    <td>@{{ detail.dispatch_remark }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.originate_fee }}</td>
+                    <td>@{{ detail.owner_way_bill_fee_detail.originate_count }}</td>
+                    <td>@{{ detail.fee }}</td>
+                </tr>
+            </table>
+            <div class="text-info h5 btn btn">{{$details->count()}}/{{$details->total()}}</div>
+            {{$details->appends($paginateParams)->links()}}
+        </div>
+        <textarea hidden id="clipboardDiv" style="opacity:0"></textarea>
+    </div>
+@endsection
+@section('lastScript')
+    <script type="text/javascript" src="{{mix('js/queryForm/export.js')}}"></script>
+    <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
+    <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
+    <script>
+        let vue = new Vue({
+            el: "#list",
+            data: {
+                owner: {!! $owner !!},
+                details: [@foreach($details as $detail){!! $detail !!}, @endforeach],
+                owners: [@foreach($owners as $owner){name: '{{ $owner->id }}', value: '{{ $owner->name}}'},@endforeach],
+                isArchived: {!! $isArchived !!},
+                request: {!! $request !!},
+                selectTr: 0,
+            },
+            created() {
+            },
+            mounted() {
+                $('#list').removeClass('d-none');
+                let _this = this;
+                $(".up").slideUp();
+                let data = [
+                    [
+                        {
+                            name: 'owner_id',
+                            type: 'select',
+                            tip: ['多货主权限选择查看指定货主,默认为权限下的第一个货主'],
+                            placeholder: ['货主'],
+                            data: _this.owners,
+                        },
+                        {
+                            name: 'year',
+                            type: 'select',
+                            tip: ['默认为时间上一个月所属年份'],
+                            placeholder: ['年'],
+                            data: [
+                                {name: 2021, value: 2021},
+                                {name: 2022, value: 2022},
+                                {name: 2023, value: 2023},
+                                {name: 2024, value: 2024},
+                                {name: 2025, value: 2025},
+                                {name: 2026, value: 2026},
+                                {name: 2027, value: 2027},
+                                {name: 2028, value: 2028},
+                                {name: 2029, value: 2029},
+                                {name: 2030, value: 2030},
+                                {name: 2031, value: 2031},
+                                {name: 2032, value: 2032},
+                                {name: 2033, value: 2033},
+                                {name: 2034, value: 2034},
+                                {name: 2035, value: 2035},
+                                {name: 2036, value: 2036},
+
+                            ],
+                        },
+                        {
+                            name: 'month',
+                            type: 'select',
+                            tip: ['默认为上一月'],
+                            placeholder: ['月'],
+                            data: [
+                                {name: 1, value: 1},
+                                {name: 2, value: 2},
+                                {name: 3, value: 3},
+                                {name: 4, value: 4},
+                                {name: 5, value: 5},
+                                {name: 6, value: 6},
+                                {name: 7, value: 7},
+                                {name: 8, value: 8},
+                                {name: 9, value: 9},
+                                {name: 10, value: 10},
+                                {name: 11, value: 11},
+                                {name: 12, value: 12},
+                            ],
+                        },
+                    ]
+                ];
+                _this.form = new query({
+                    el: '#form_div',
+                    condition: data,
+                    appendDom: "btn",
+                });
+                _this.form.init();
+                //计数单位	计数区间	省份	市	单价	送货费	提货费	燃油附加费	信息费	其它费用	备注	起始计费	起始计数	运费合计
+
+                let column = [
+                    {name: 'index', value: '序号', neglect: true},
+                    {name: 'logistic', value: '承运商'},
+                    {name: 'order_no', value: '订单号'},
+                    {name: 'receiver_name', value: '收件人姓名'},
+                    {name: 'receiver_phone', value: '收件人电话'},
+                    {name: 'weight', value: '重量/体积'},
+                    {name: 'sept_unit', value: '计数单位'},
+                    {name: 'price', value: '计数区间'},
+                    {name: 'fee', value: '省份'},
+                    {name: 'fee', value: '市'},
+                    {name: 'fee', value: '单价'},
+                    {name: 'fee', value: '送货费'},
+                    {name: 'fee', value: '提货费'},
+                    {name: 'fee', value: '燃油附加费'},
+                    {name: 'fee', value: '信息费'},
+                    {name: 'fee', value: '其它费用'},
+                    {name: 'fee', value: '备注'},
+                    {name: 'fee', value: '起始计费'},
+                    {name: 'fee', value: '起始计数'},
+                    {name: 'fee', value: '运费合计'},
+                ];
+                new Header({
+                    el: "table",
+                    name: "detail",
+                    column: column,
+                    data: this.details,
+                    restorationColumn: 'addtime',
+                    fixedTop: ($('#form_div').height()) + ($('#btn').height()) + 1,
+                }).init();
+            },
+            methods: {
+                detailExport(sign) {
+                    let url = '{{url('finance/settlementBills/logisticFee/export')}}';
+                    let token = '{{ csrf_token() }}';
+                    if (sign) {
+                        excelExport(true, checkData, url, this.total, token);
+                    } else {
+                        excelExport(false, checkData, url, null, token, {
+                            owner_id: this.owner.id,
+                            year: this.request.year,
+                            month: this.request.month,
+                        });
+                    }
+                },
+            },
+            filters: {},
+        });
+    </script>
+@endsection