ANG YU 4 жил өмнө
parent
commit
2f6747b93b

+ 31 - 70
app/Http/Controllers/OwnerLogisticFeeDetailController.php

@@ -6,6 +6,7 @@ use App\Owner;
 use App\OwnerLogisticFeeDetail;
 use App\Services\OwnerLogisticFeeDetailService;
 use Illuminate\Http\Request;
+use Oursdreams\Export\Export;
 
 class OwnerLogisticFeeDetailController extends Controller
 {
@@ -19,6 +20,35 @@ class OwnerLogisticFeeDetailController extends Controller
     public function index(Request $request)
     {
         $paginateParams = $request->input();
+        list($permittingOwnerIds, $owner_id, $start, $end) = $this->getRequestParams($request);
+        $details = $this->service->getDetails($owner_id, $start, $end, $paginateParams);
+        $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
+        $owner = Owner::query()->selectRaw("name")->find($owner_id);
+        return view('finance.settlementBills.logisticFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner'));
+    }
+
+    public function export(Request $request)
+    {
+        list($permittingOwnerIds, $owner_id, $start, $end) = $this->getRequestParams($request);
+        $query = $this->service->getSql($owner_id, $start, $end);
+        if (!$request->exists('checkAllSign')) {
+            $query->whereIn('id', explode(',', $request['data']));
+        }
+        $details = $this->service->buildDetails($query->get());
+        $json = [];
+        foreach ($details as $detail) {
+            $json[] = array_values($detail);
+        }
+        $row = ['主键', '快递公司', '省份', '快递单号', '重量', '首重价格', '续重价格', '快递费',];
+        return Export::make($row, $json, "快递费用详情");
+    }
+
+    /**
+     * @param Request $request
+     * @return array
+     */
+    private function getRequestParams(Request $request): array
+    {
         $this->service = app('OwnerLogisticFeeDetailService');
         $this->userService = app('UserService');
         $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
@@ -39,75 +69,6 @@ class OwnerLogisticFeeDetailController extends Controller
         } else {
             $end = $request->end;
         }
-        $details = $this->service->getDetails($owner_id, $start, $end, $paginateParams);
-        $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
-        $owner = Owner::query()->selectRaw("name")->find($owner_id);
-        return view('finance.settlementBills.logisticFee.detail.index', compact('details', 'paginateParams', 'owners','owner'));
-    }
-
-    /**
-     * 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\OwnerLogisticFeeDetail $ownerLogisticFeeDetail
-     * @return \Illuminate\Http\Response
-     */
-    public function show(OwnerLogisticFeeDetail $ownerLogisticFeeDetail)
-    {
-        //
-    }
-
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param \App\OwnerLogisticFeeDetail $ownerLogisticFeeDetail
-     * @return \Illuminate\Http\Response
-     */
-    public function edit(OwnerLogisticFeeDetail $ownerLogisticFeeDetail)
-    {
-        //
-    }
-
-    /**
-     * Update the specified resource in storage.
-     *
-     * @param \Illuminate\Http\Request $request
-     * @param \App\OwnerLogisticFeeDetail $ownerLogisticFeeDetail
-     * @return \Illuminate\Http\Response
-     */
-    public function update(Request $request, OwnerLogisticFeeDetail $ownerLogisticFeeDetail)
-    {
-        //
-    }
-
-    /**
-     * Remove the specified resource from storage.
-     *
-     * @param \App\OwnerLogisticFeeDetail $ownerLogisticFeeDetail
-     * @return \Illuminate\Http\Response
-     */
-    public function destroy(OwnerLogisticFeeDetail $ownerLogisticFeeDetail)
-    {
-        //
+        return array($permittingOwnerIds, $owner_id, $start, $end);
     }
 }

+ 51 - 72
app/Http/Controllers/OwnerLogisticFeeReportController.php

@@ -4,9 +4,11 @@ namespace App\Http\Controllers;
 
 use App\Owner;
 use App\OwnerLogisticFeeReport;
+use App\Services\common\ExportService;
 use App\Services\OwnerLogisticFeeReportService;
 use App\Services\UserService;
 use Illuminate\Http\Request;
+use Oursdreams\Export\Export;
 
 class OwnerLogisticFeeReportController extends Controller
 {
@@ -15,95 +17,72 @@ class OwnerLogisticFeeReportController extends Controller
     /* @var UserService $userService */
     private $userService;
 
+    /**
+     * OwnerLogisticFeeReportController constructor.
+     */
+    public function __construct()
+    {
+        $this->middleware('auth');
+    }
+
+
     /**
      * Display a listing of the resource.
      */
     public function index(Request $request)
     {
         $paginateParams = $request->input();
-        $this->service = app('OwnerLogisticFeeReportService');
-        $this->userService = app('UserService');
-        $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
-        if (is_null($request->year) || is_null($request->month)) {
-            $date = now()->subMonth()->startOfMonth()->toDateString();
-        } else {
-            $date = $request->year . '-' . $request->month . '-' . '01';
-        }
-        if (is_null($request->owner_id)) {
-            $owner_id = $permittingOwnerIds[0];
-        }else{
-            $owner_id = $request->owner_id;
-        }
+        list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
         $reports = $this->service->getRecordPagination($owner_id, $date, $paginateParams);
         $recordTotal = $this->service->getRecordTotal($owner_id, $date);
         $owner = Owner::query()->selectRaw("name")->find($owner_id);
         $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
-        return view('finance.settlementBills.logisticFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners','owner'));
-    }
-
-    /**
-     * Show the form for creating a new resource.
-     *
-     * @return \Illuminate\Http\Response
-     */
-    public function create()
-    {
-        //
+        return view('finance.settlementBills.logisticFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners', 'owner'));
     }
 
-    /**
-     * Store a newly created resource in storage.
-     *
-     * @param \Illuminate\Http\Request $request
-     * @return \Illuminate\Http\Response
-     */
-    public function store(Request $request)
+    public function export(Request $request)
     {
-        //
-    }
-
-    /**
-     * Display the specified resource.
-     *
-     * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
-     * @return \Illuminate\Http\Response
-     */
-    public function show(OwnerLogisticFeeReport $ownerLogisticFeeReport)
-    {
-        //
-    }
-
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
-     * @return \Illuminate\Http\Response
-     */
-    public function edit(OwnerLogisticFeeReport $ownerLogisticFeeReport)
-    {
-        //
-    }
-
-    /**
-     * Update the specified resource in storage.
-     *
-     * @param \Illuminate\Http\Request $request
-     * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
-     * @return \Illuminate\Http\Response
-     */
-    public function update(Request $request, OwnerLogisticFeeReport $ownerLogisticFeeReport)
-    {
-        //
+        list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
+        $query = $this->service->getSql($owner_id, $date);
+        if (!$request->exists('checkAllSign')) {
+            $query->whereIn('id', explode(',', $request['data']));
+        }
+        $reports = $query->get();
+        $json = [];
+        foreach ($reports as $report) {
+            $json[] = [
+                $report->logistic->name ?? '',
+                $report->province,
+                $report->initial_weight,
+                $report->initial_amount,
+                $report->additional_weight,
+                $report->additional_amount,
+                $report->fee,
+            ];
+        }
+        $row = ['快递公司', '地区', '首重', '订单数', '续重', '续重合计', '(省份)合计'];
+        return Export::make($row, $json, "快递费用合计");
     }
 
     /**
-     * Remove the specified resource from storage.
-     *
-     * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
-     * @return \Illuminate\Http\Response
+     * @param Request $request
+     * @return array
      */
-    public function destroy(OwnerLogisticFeeReport $ownerLogisticFeeReport)
+    private function getRequestParams(Request $request): array
     {
-        //
+        $this->service = app('OwnerLogisticFeeReportService');
+        $this->userService = app('UserService');
+        $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
+        if (is_null($request->year) || is_null($request->month)) {
+            $date = now()->subMonth()->startOfMonth()->toDateString();
+        } else {
+            $date = $request->year . '-' . $request->month . '-' . '01';
+        }
+        if (is_null($request->owner_id)) {
+            $owner_id = $permittingOwnerIds[0];
+        } else {
+            $owner_id = $request->owner_id;
+        }
+        return array($permittingOwnerIds, $date, $owner_id);
     }
 }

+ 46 - 14
app/Services/OwnerLogisticFeeDetailService.php

@@ -27,45 +27,77 @@ class OwnerLogisticFeeDetailService
      * @param string $owner_id
      * @param string $start
      * @param string $end
+     * @param $paginateParams
      * @return LengthAwarePaginator
      */
     public function getDetails(string $owner_id, string $start, string $end, $paginateParams): LengthAwarePaginator
     {
-        $logistic_ids = Logistic::query()->selectRaw('id')->where('type', '快递');
-        $ownerFeeDetailQuery = OwnerFeeDetail::query()->selectRaw('id')
+        $ownerLogisticFeeDetails = $this->getSql($owner_id, $start, $end)
+            ->paginate($paginateParams['paginate'] ?? 50);
+        $items = $this->buildDetails($ownerLogisticFeeDetails);
+        return new LengthAwarePaginator(
+            $items,
+            $ownerLogisticFeeDetails->total(),
+            $ownerLogisticFeeDetails->perPage(),
+            $ownerLogisticFeeDetails->currentPage(),
+            ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"]
+        );
+    }
+
+    /**
+     * @param Builder $logistic_ids
+     * @param string $owner_id
+     * @param string $start
+     * @param string $end
+     * @return Builder
+     */
+    private function getOwnerFeeDetailQuery(Builder $logistic_ids, string $owner_id, string $start, string $end): Builder
+    {
+        return OwnerFeeDetail::query()->selectRaw('id')
             ->where('type', '发货')
             ->where('outer_table_name', 'orders')
             ->whereIn('logistic_id', $logistic_ids)
             ->where('owner_id', $owner_id)
             ->where('worked_at', '>=', Carbon::parse($start)->startOfDay())
             ->where('worked_at', '<=', Carbon::parse($end)->endOfDay());
+    }
 
-        $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()->with([
+    /**
+     * @param string $owner_id
+     * @param string $start
+     * @param string $end
+     * @return Builder
+     */
+    public function getSql(string $owner_id, string $start, string $end): Builder
+    {
+        return OwnerLogisticFeeDetail::query()->with([
             'ownerFeeDetail:id,province,weight,logistic_fee',
             'ownerFeeDetailLogistic:id,weight,logistic_fee,logistic_bill',
             'logistic:id,name'
         ])
-            ->whereIn('owner_fee_detail_id', $ownerFeeDetailQuery)
-            ->orderBy('logistic_id')
-            ->paginate($paginateParams['paginate'] ?? 50);
+            ->whereIn('owner_fee_detail_id', $this->getOwnerFeeDetailQuery(Logistic::query()->selectRaw('id')->where('type', '快递'), $owner_id, $start, $end))
+            ->orderBy('logistic_id');
+    }
+
+    /**
+     * @param  $ownerLogisticFeeDetails
+     * @return array
+     */
+    public function buildDetails($ownerLogisticFeeDetails): array
+    {
         $items = [];
         foreach ($ownerLogisticFeeDetails as $ownerLogisticFeeDetail) {
             $items[] = [
+                'id' => $ownerLogisticFeeDetail->id,
                 'logistic_name' => $ownerLogisticFeeDetail->logistic->name ?? '',//快递公司
                 'province' => $ownerLogisticFeeDetail->province,//省份
                 'logistic_bill' => $ownerLogisticFeeDetail->logistic_bill ?? '',//快递单号
                 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight ?? $ownerLogisticFeeDetail->ownerFeeDetail->weight ?? '0.00',//重量
-                'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
                 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
                 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格
+                'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
             ];
         }
-        return new LengthAwarePaginator(
-            $items,
-            $ownerLogisticFeeDetails->total(),
-            $ownerLogisticFeeDetails->perPage(),
-            $ownerLogisticFeeDetails->currentPage(),
-            ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"]
-        );
+        return $items;
     }
 }

+ 18 - 6
app/Services/OwnerLogisticFeeReportService.php

@@ -7,6 +7,8 @@ use App\Traits\ServiceAppAop;
 use App\OwnerLogisticFeeReport;
 use Carbon\Carbon;
 use Illuminate\Contracts\Pagination\LengthAwarePaginator;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
 
 class OwnerLogisticFeeReportService
 {
@@ -68,12 +70,7 @@ class OwnerLogisticFeeReportService
      */
     public function getRecordPagination($owner_id, string $date,$paginateParams): LengthAwarePaginator
     {
-        return OwnerLogisticFeeReport::query()
-            ->with('logistic:id,name')
-            ->where('owner_id', $owner_id)
-            ->where('counted_date', $date)
-            ->orderByDesc('logistic_id')
-            ->orderByDesc('province')
+        return $this->getSql($owner_id, $date)
             ->paginate($paginateParams['paginate']??50);
     }
 
@@ -98,4 +95,19 @@ class OwnerLogisticFeeReportService
             'order_count' => $order_count,
         ];
     }
+
+    /**
+     * @param $owner_id
+     * @param string $date
+     * @return Builder
+     */
+    public function getSql($owner_id, string $date): Builder
+    {
+        return OwnerLogisticFeeReport::query()
+            ->with('logistic:id,name')
+            ->where('owner_id', $owner_id)
+            ->where('counted_date', $date)
+            ->orderByDesc('logistic_id')
+            ->orderByDesc('province');
+    }
 }

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 66 - 484
composer.lock


+ 26 - 6
resources/views/finance/settlementBills/logisticFee/detail/index.blade.php

@@ -1,13 +1,23 @@
 @extends('layouts.app')
 
 @section('content')
-    @component("finance.settlementBills.logisticFee.menu")@endcomponent
     @include('shared._messages')
     @include('shared._error')
     <div id="list" class="d-none">
         <div class="container-fluid">
             <div id="form_div"></div>
-            <div class="form-inline" id="btn"></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">
                 <span class="fa fa-user fa-4x offset-md-3" style="color: #4c2584;opacity: 0.3"></span>
                 <span class="ml-4 mt-2">
@@ -22,7 +32,7 @@
                     <td><input class="checkItem" type="checkbox" :value="detail.id"></td>
                     <td>@{{ i+1 }}</td>
                     <td v-if="i==0 || detail.logistic_name!== details[i-1].logistic_name"
-                        :rowspan="calRowspan(detail.logistic_name)" class="text-center pt-4">@{{ detail.logistic_name }}
+                        :rowspan="calRowspan(detail.logistic_name)" class="text-center pt-4 bg-light">@{{ detail.logistic_name }}
                     </td>
                     <td>@{{ detail.province }}</td>
                     <td>@{{ detail.logistic_bill }}</td>
@@ -49,6 +59,7 @@
                 details: [
                         @foreach($details as $detail)
                     {
+                        id: " {!! $detail['id'] !!}",
                         logistic_name: " {!! $detail['logistic_name'] !!}",
                         province: " {!! $detail['province'] !!}",
                         logistic_bill: "{!! $detail['logistic_bill'] !!}",
@@ -127,6 +138,7 @@
                 _this.form = new query({
                     el: '#form_div',
                     condition: data,
+                    appendDom : "btn",
                 });
                 _this.form.init();
                 let column = [
@@ -150,9 +162,17 @@
             },
             methods: {
                 calRowspan(logistic_name) {
-                    return this.details.filter(item => item.logistic_name == logistic_name).length;
-
-                }
+                    return this.details.filter(item => item.logistic_name === logistic_name).length;
+                },
+                detailExport(sign) {
+                    let url = '{{url('finance/settlementBills/logisticFee/detail/export')}}';
+                    let token = '{{ csrf_token() }}';
+                    if (sign) {
+                        excelExport(true, checkData, url, this.total, token);
+                    } else {
+                        excelExport(false, checkData, url, null, token);
+                    }
+                },
             },
             filters: {},
         });

+ 36 - 16
resources/views/finance/settlementBills/logisticFee/report/index.blade.php

@@ -1,13 +1,23 @@
 @extends('layouts.app')
 
 @section('content')
-    @component("finance.settlementBills.logisticFee.menu")@endcomponent
     @include('shared._messages')
     @include('shared._error')
     <div id="list" class="d-none">
         <div class="container-fluid">
             <div id="form_div"></div>
-            <div class="form-inline" id="btn"></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="reportExport(false)" href="javascript:">导出勾选内容</a>
+                            <a class="dropdown-item" @click="reportExport(true)" href="javascript:">导出所有页</a>
+                        </div>
+                    </span>
+            </div>
             <div class="row">
                 <div class="col-4">
                     <div class="row pt-2">
@@ -44,7 +54,7 @@
                     <td><input class="checkItem" type="checkbox" :value="report.id"></td>
                     <td>@{{ i+1 }}</td>
                     <td v-if="i==0 || report.logistic.name!== reports[i-1].logistic.name"
-                        :rowspan="calRowspan(report.logistic.name)" class="text-center pt-4">@{{ report.logistic.name }}
+                        :rowspan="calRowspan(report.logistic.name)" class="text-center pt-4 bg-light">@{{ report.logistic.name }}
                     </td>
                     <td>@{{ report.province }}</td>
                     <td>@{{ report.initial_weight }}</td>
@@ -122,18 +132,18 @@
                             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},
+                                {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},
                             ],
                         },
                     ]
@@ -141,6 +151,7 @@
                 _this.form = new query({
                     el: '#form_div',
                     condition: data,
+                    appendDom: 'btn'
                 });
                 _this.form.init();
                 let column = [
@@ -165,7 +176,16 @@
             methods: {
                 calRowspan(logistic_name) {
                     return this.reports.filter(item => item.logistic.name === logistic_name).length;
-                }
+                },
+                reportExport(sign) {
+                    let url = '{{url('finance/settlementBills/logisticFee/report/export')}}';
+                    let token = '{{ csrf_token() }}';
+                    if (sign) {
+                        excelExport(true, checkData, url, this.total, token);
+                    } else {
+                        excelExport(false, checkData, url, null, token);
+                    }
+                },
             },
             filters: {},
         });

+ 2 - 1
routes/web.php

@@ -782,6 +782,8 @@ Route::group(['prefix'=>'finance'],function(){
     Route::group(['prefix'=>'settlementBills'],function(){
 //        Route::resource('ownerSundryFeeDetails', 'OwnerSundryFeeDetailsController', ['only' => ['index', 'create', 'store', 'update', 'edit','destroy']]);
         Route::group(['prefix' => 'logisticFee'], function () {
+            Route::any('detail/export', 'OwnerLogisticFeeDetailController@export');
+            Route::any('report/export', 'OwnerLogisticFeeReportController@export');
             Route::resource('detail', 'OwnerLogisticFeeDetailController', ['only' => ['index']]);
             Route::resource('report', 'OwnerLogisticFeeReportController', ['only' => ['index']]);
         });
@@ -908,4 +910,3 @@ Route::group(['prefix'=>'procurement'],function () {
 Route::group(['prefix'=>'demand'],function (){
     Route::get('/','DemandController@index');
 });
-

+ 5 - 0
yarn.lock

@@ -3514,6 +3514,11 @@ http-proxy@^1.17.0:
     follow-redirects "^1.0.0"
     requires-port "^1.0.0"
 
+http-vue-loader@^1.4.2:
+  version "1.4.2"
+  resolved "https://registry.npm.taobao.org/http-vue-loader/download/http-vue-loader-1.4.2.tgz#98e8c3304f5c1351858eaca60c5d80bf6a244196"
+  integrity sha1-mOjDME9cE1GFjqymDF2Av2okQZY=
+
 https-browserify@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно