Jelajahi Sumber

合并增加类型:全部

Zhouzhendong 5 tahun lalu
induk
melakukan
d9422a1efa

+ 8 - 1
app/Http/Controllers/TestController.php

@@ -94,12 +94,19 @@ class TestController extends Controller
             app(BatchUpdateService::class)->batchUpdate('inventory_accounts',$updateParams);
         }
     }
-    public function test4(){
+    public function mergeCarrier(){
         $carriers = Carrier::query()->get();
         $logistics = [];
         $map = [];
         foreach ($carriers as $carrier){
             $map[$carrier->name] = $carrier->id;
+            $lo = Logistic::query()->where("name",$carrier->name)->first();
+            if ($lo){
+                if ($lo->type == '快递'){
+                    $lo->update(["type"=>"全部"]);$lo->save();
+                }
+                continue;
+            };
             $logistics[] = [
                 "name" => $carrier->name,
                 'mobile' => $carrier->mobile,

+ 2 - 2
app/Http/Controllers/UserController.php

@@ -49,7 +49,7 @@ class UserController extends Controller
     {
         if(!Gate::allows('用户-录入')){ return redirect(url('/'));  }
         $roles=Role::all();
-        $logistics=app('LogisticService')->getSelection(["id","name"],"logistic");
+        $logistics=app('LogisticService')->getSelection(["id","name"],"物流");
         $userWorkgroups=UserWorkgroup::query()->get();
         return view('maintenance.user.create',['rolesAll'=>$roles,'logistics'=>$logistics,'userWorkgroups'=>$userWorkgroups]);
     }
@@ -80,7 +80,7 @@ class UserController extends Controller
         if(!Gate::allows('用户-编辑')){ return redirect(url('/'));  }
         $rolesAll=Role::all();
         $roles=$user->roles()->get();
-        $logistics=app('LogisticService')->getSelection(["id","name"],"logistic");
+        $logistics=app('LogisticService')->getSelection(["id","name"],"物流");
         $logisticUser=$user->logistics()->get();
         $userWorkgroups=UserWorkgroup::query()->get();
         $userWorkgroup=$user->userWorkgroups()->first();

+ 2 - 2
app/Http/Controllers/WaybillController.php

@@ -55,7 +55,7 @@ class WaybillController extends Controller
         $waybills=app('waybillService')->paginate($request->input());
         return view('waybill.index', [
             'waybills' => $waybills,
-            'logistics' => $logisticService->getSelection(["id","name"],"logistic"),
+            'logistics' => $logisticService->getSelection(["id","name"],"物流"),
             'owners' => $ownerService->getSelection(),
             'paginateParams'=>$paginateParams,
             'uriType'=>$request->uriType??'']);
@@ -95,7 +95,7 @@ class WaybillController extends Controller
         $cities=$cityService->getSelection();
         $units=$unitService->getSelection();
         $carTypes=$carTypeService->getSelection();
-        return view('waybill/edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"logistic"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
+        return view('waybill/edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
     }
 
     public function update(Request $request, $id,WaybillPriceModelService $waybillPriceModelService,

+ 3 - 3
app/Http/Controllers/WaybillPriceModelsController.php

@@ -21,7 +21,7 @@ class WaybillPriceModelsController extends Controller
     public function index(Request $request)
     {
         if(!Gate::allows('计费模型-查询')){ return redirect(url('/'));  }
-        $logistics=app('LogisticService')->getSelection(["id","name"],"logistic");
+        $logistics=app('LogisticService')->getSelection(["id","name"],"物流");
         $provinces=Province::query()->get();
         $data=$request->input();
         $waybillPriceModels= WaybillPriceModel::query()->orderBy('id', 'DESC');
@@ -44,7 +44,7 @@ class WaybillPriceModelsController extends Controller
     public function create()
     {
         if(!Gate::allows('计费模型-录入')){ return redirect(url('/'));  }
-        $logistics=app('LogisticService')->getSelection(["id","name"],"logistic");
+        $logistics=app('LogisticService')->getSelection(["id","name"],"物流");
         $provinces=Province::get();
         $units=Unit::get();
         return view('maintenance.priceModel.waybillPriceModel.create',['logistics'=>$logistics,'provinces'=>$provinces,'units'=>$units]);
@@ -101,7 +101,7 @@ class WaybillPriceModelsController extends Controller
     {
         if(!Gate::allows('计费模型-编辑')){ return redirect(url('/'));  }
         $waybillPriceModel=WaybillPriceModel::find($id);
-        $logistics=app('LogisticService')->getSelection(["id","name"],"logistic");
+        $logistics=app('LogisticService')->getSelection(["id","name"],"物流");
         $provinces=Province::get();
         $cities=City::where('province_id',$waybillPriceModel->province_id)->get();
         $units=Unit::get();

+ 6 - 2
app/Services/LogisticService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 use App\Logistic;
 use App\OracleBasCustomer;
 use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Str;
 
@@ -15,10 +16,13 @@ Class LogisticService
     function __construct(){
         $this->cacheService=app('CacheService');
     }
-    public function getSelection($column = ['id','name'], $type = 'express'){
+    public function getSelection($column = ['id','name'], $type = '快递'){
         return $this->cacheService->getOrExecute('LogisticAll_idName'.Str::studly($type),function()use($column,$type){
             $query = Logistic::query()->select($column);
-            if ($type)$query->where("type",$type);
+            if ($type)$query->where(function ($query)use($type){
+                /** @var Builder $query */
+                $query->where("type",$type)->orWhere("type","全部");
+            });
             return $query->get();
         },config('cache.expirations.persistent'));
     }

+ 38 - 0
database/migrations/2020_11_27_110032_change_column_type_table_logistics.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeColumnTypeTableLogistics extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('logistics', function (Blueprint $table) {
+            $table->dropColumn("type");
+        });
+        Schema::table('logistics', function (Blueprint $table) {
+            $table->enum("type",["物流","快递","全部"])->default("快递")->index()->comment("类型");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('logistics', function (Blueprint $table) {
+            $table->dropColumn("type");
+        });
+        Schema::table('logistics', function (Blueprint $table) {
+            $table->enum("type",["logistic","express"])->default("express")->comment("类型");
+        });
+    }
+}

+ 1 - 0
resources/views/maintenance/logistic/create.blade.php

@@ -20,6 +20,7 @@
                             <select id="type" name="type" class="form-control @error('type') is-invalid @enderror" value="{{ old('type') }}" required>
                                 <option value="快递">快递</option>
                                 <option value="物流">物流</option>
+                                <option value="全部">全部</option>
                             </select>
                             @error('type')
                             <span class="invalid-feedback" role="alert">