Selaa lähdekoodia

Merge branch 'master' of ssh://was.baoshi56.com:10022/var/git/bswas

LD 5 vuotta sitten
vanhempi
commit
cd7b737df0
32 muutettua tiedostoa jossa 875 lisäystä ja 48 poistoa
  1. 11 1
      app/Customer.php
  2. 27 0
      app/CustomerLog.php
  3. 11 0
      app/CustomerLogStatus.php
  4. 13 5
      app/Http/Controllers/CustomerBaseController.php
  5. 60 0
      app/Http/Controllers/CustomerLogStatusesController.php
  6. 69 0
      app/Http/Controllers/CustomerLogsController.php
  7. 27 0
      app/Policies/CustomerLogPolice.php
  8. 23 0
      app/Policies/CustomerLogStatusesPolice.php
  9. 8 0
      app/Providers/AuthServiceProvider.php
  10. 3 3
      app/Services/CustomerService.php
  11. 23 0
      database/factories/CustomerLogFactory.php
  12. 12 0
      database/factories/CustomerLogStatusFactory.php
  13. 25 0
      database/migrations/2020_12_14_101617_create_customerlogs_table.php
  14. 23 0
      database/migrations/2020_12_14_103401_create_customerlogstatuses_table.php
  15. 38 0
      database/migrations/2020_12_15_095959_add_customer_phone_address.php
  16. 20 0
      database/seeds/CustomerLogStatusesTableSeeder.php
  17. 20 0
      database/seeds/CustomerLogsTableSeeder.php
  18. 10 0
      resources/views/common/error.blade.php
  19. 28 3
      resources/views/customer/customer/create.blade.php
  20. 22 16
      resources/views/customer/customer/index.blade.php
  21. 19 0
      resources/views/customer/customer/menu.blade.php
  22. 52 0
      resources/views/customer/customer_log_statuses/create_and_edit.blade.php
  23. 64 0
      resources/views/customer/customer_log_statuses/index.blade.php
  24. 41 0
      resources/views/customer/customer_log_statuses/show.blade.php
  25. 68 0
      resources/views/customer/customer_logs/create_and_edit.blade.php
  26. 69 0
      resources/views/customer/customer_logs/index.blade.php
  27. 59 0
      resources/views/customer/customer_logs/show.blade.php
  28. 3 0
      resources/views/customer/menu.blade.php
  29. 0 15
      resources/views/maintenance/customer/menu.blade.php
  30. 0 4
      resources/views/maintenance/menu.blade.php
  31. 6 1
      routes/web.php
  32. 21 0
      tests/Unit/CustomerLogTest.php

+ 11 - 1
app/Customer.php

@@ -3,12 +3,22 @@
 namespace App;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\HasMany;
 
 class Customer extends Model
 {
     protected $fillable = [
         "code",         //客户代码
         "name",         //客户名称
-        "company_name"  //公司名称
+        "company_name",  //公司名称
+        "invoice_address",  //公司名称
+        "contact_man",  //公司名称
+        "phone",  //公司名称
+        "comment",  //公司名称
     ];
+
+    public function customerLogs(): HasMany
+    {
+        return $this->hasMany(CustomerLog::class,'customer_id','id');
+    }
 }

+ 27 - 0
app/CustomerLog.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class CustomerLog extends Model
+{
+    protected $fillable = ['customer_id', 'customer_log_status_id', 'user_id', 'description'];
+    protected $guarded = ['id'];
+
+    public function customerLogStatus(): BelongsTo
+    {
+        return $this->belongsTo(CustomerLogStatus::class);
+    }
+
+    public function user(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+
+    public function customer(): BelongsTo
+    {
+        return $this->belongsTo(Customer::class);
+    }
+}

+ 11 - 0
app/CustomerLogStatus.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerLogStatus extends Model
+{
+    protected $fillable = ['name', 'description'];
+    protected $guarded = ['id'];
+}

+ 13 - 5
app/Http/Controllers/CustomerBaseController.php

@@ -19,7 +19,7 @@ class CustomerBaseController extends Controller
     {
         if(!Gate::allows('客户-查询')){ return redirect('denied');  }
         $customers = app('CustomerService')->paginate();
-        return response()->view('maintenance.customer.index',compact("customers"));
+        return response()->view('customer.customer.index',compact("customers"));
     }
 
     /**
@@ -30,7 +30,7 @@ class CustomerBaseController extends Controller
     public function create()
     {
         if(!Gate::allows('客户-录入')){ return redirect('denied');  }
-        return response()->view('maintenance.customer.create');
+        return response()->view('customer.customer.create');
     }
 
     /**
@@ -47,9 +47,13 @@ class CustomerBaseController extends Controller
             "code"=>$request->input("code"),
             "name"=>$request->input("name"),
             "company_name"=>$request->input("company_name"),
+            "invoice_address"=>$request->input("invoice_address"),
+            "contact_man"=>$request->input("contact_man"),
+            "phone"=>$request->input("phone"),
+            "comment"=>$request->input("comment"),
         ]);
         LogService::log(__METHOD__,"录入客户",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
-        return response()->redirectTo("maintenance/customer")->with("successTip","成功创建客户“".$request->input("name")."”");
+        return response()->redirectTo("customer/customer")->with("successTip","成功创建客户“".$request->input("name")."”");
     }
 
     /**
@@ -62,7 +66,7 @@ class CustomerBaseController extends Controller
     {
         if(!Gate::allows('客户-编辑')){ return redirect('denied');  }
         $customer = app('CustomerService')->find($id);
-        return response()->view('maintenance.customer.create',compact("customer"));
+        return response()->view('customer.customer.create',compact("customer"));
     }
 
     /**
@@ -80,10 +84,14 @@ class CustomerBaseController extends Controller
             "code"=>$request->input("code"),
             "name"=>$request->input("name"),
             "company_name"=>$request->input("company_name"),
+            "invoice_address"=>$request->input("invoice_address"),
+            "contact_man"=>$request->input("contact_man"),
+            "phone"=>$request->input("phone"),
+            "comment"=>$request->input("comment"),
         ]);
         if ($result == 1){
             LogService::log(__METHOD__,"修改客户",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
-            return response()->redirectTo("maintenance/customer")->with("successTip","成功修改客户“".$request->input("name")."”的信息");
+            return response()->redirectTo("customer/customer")->with("successTip","成功修改客户“".$request->input("name")."”的信息");
         }
         return response()->view("exception.default",["code"=>"509"]);
     }

+ 60 - 0
app/Http/Controllers/CustomerLogStatusesController.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\CustomerLogStatus;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+
+
+class CustomerLogStatusesController extends Controller
+{
+    public function __construct()
+    {
+        $this->middleware('auth');
+    }
+
+    public function index()
+    {
+        $customer_log_statuses = CustomerLogStatus::paginate();
+        return view('customer.customer_log_statuses.index', compact('customer_log_statuses'));
+    }
+
+    public function show(CustomerLogStatus $customer_log_status)
+    {
+        return view('customer.customer_log_statuses.show', compact('customer_log_status'));
+    }
+
+    public function create(CustomerLogStatus $customer_log_status)
+    {
+        return view('customer.customer_log_statuses.create_and_edit', compact('customer_log_status'));
+    }
+
+    public function store(Request $request): RedirectResponse
+    {
+        $customer_log_status = CustomerLogStatus::create($request->all());
+        return redirect()->route('customer_log_statuses.show', $customer_log_status->id)->with('message', 'Created successfully.');
+    }
+
+    public function edit(CustomerLogStatus $customer_log_status)
+    {
+        $this->authorize('update', $customer_log_status);
+        return view('customer.customer_log_statuses.create_and_edit', compact('customer_log_status'));
+    }
+
+    public function update(Request $request, CustomerLogStatus $customer_log_status)
+    {
+        $this->authorize('update', $customer_log_status);
+        $customer_log_status->update($request->all());
+
+        return redirect()->route('customer_log_statuses.show', $customer_log_status->id)->with('message', 'Updated successfully.');
+    }
+
+    public function destroy(CustomerLogStatus $customer_log_status)
+    {
+        $this->authorize('destroy', $customer_log_status);
+        $customer_log_status->delete();
+
+        return redirect()->route('customer_log_statuses.index')->with('message', 'Deleted successfully.');
+    }
+}

+ 69 - 0
app/Http/Controllers/CustomerLogsController.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Customer;
+use App\CustomerLog;
+use App\CustomerLogStatus;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+
+class CustomerLogsController extends Controller
+{
+    public function __construct()
+    {
+        $this->middleware('auth');
+    }
+
+    public function index(Request $request)
+    {
+        $customer_logs = CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->where('id',$request->id) ->orderByDesc('updated_at')->paginate();
+        return view('customer.customer_logs.index', compact('customer_logs'));
+    }
+
+    public function show($customer_log_id)
+    {
+        $customer_log =CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->where('id',$customer_log_id)->first();
+        return view('customer.customer_logs.show', compact('customer_log'));
+    }
+
+    public function create(CustomerLog $customer_log)
+    {
+        $customers = Customer::all();
+        $customerLogStatuses = CustomerLogStatus::all();
+        return view('customer.customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
+    }
+
+    public function store(Request $request): RedirectResponse
+    {
+        $data = [];
+        $data = $request->all();
+        $data['user_id'] = auth()->id();
+        $customer_log = CustomerLog::create($data);
+        return redirect()->route('customer_logs.show', $customer_log->id)->with('message', 'Created successfully.');
+    }
+
+    public function edit(CustomerLog $customer_log)
+    {
+        $this->authorize('update', $customer_log);
+        $customers = Customer::all();
+        $customerLogStatuses = CustomerLogStatus::all();
+        return view('customer.customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
+    }
+
+    public function update(Request $request, CustomerLog $customer_log)
+    {
+        $this->authorize('update', $customer_log);
+        $customer_log->update($request->all());
+
+        return redirect()->route('customer_logs.show', $customer_log->id)->with('message', 'Updated successfully.');
+    }
+
+    public function destroy(CustomerLog $customer_log)
+    {
+        $this->authorize('destroy', $customer_log);
+        $customer_log->delete();
+
+        return redirect()->route('customer_logs.index')->with('message', 'Deleted successfully.');
+    }
+}

+ 27 - 0
app/Policies/CustomerLogPolice.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Policies;
+
+use App\CustomerLog;
+use App\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class CustomerLogPolice
+{
+    use HandlesAuthorization;
+
+    protected $cache_key = 'customerLog_update_auth_';
+
+    public function update(User $user, CustomerLog $customerLog): bool
+    {
+        $lastOne = cache()->remember($this->cache_key . $user->id, 1, function () use ($user) {
+            return CustomerLog::query()->where('user_id', $user->id)->orderByDesc('updated_at')->first();
+        });
+        return (int)$user->id === (int)$customerLog->user_id && $customerLog->id == $lastOne->id;
+    }
+
+    public function destroy(User $user, CustomerLog $customerLog)
+    {
+        return (int)$user->id === (int)$customerLog->user_id;
+    }
+}

+ 23 - 0
app/Policies/CustomerLogStatusesPolice.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Policies;
+
+use App\CustomerLogStatus;
+use App\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class CustomerLogStatusesPolice
+{
+    use HandlesAuthorization;
+
+    public function update(User $user, CustomerLogStatus $customerLogStatus): bool
+    {
+
+        return true;
+    }
+
+    public function destroy(User $user, CustomerLogStatus $customerLogStatus): bool
+    {
+        return true;
+    }
+}

+ 8 - 0
app/Providers/AuthServiceProvider.php

@@ -3,6 +3,10 @@
 namespace App\Providers;
 
 use App\Authority;
+use App\CustomerLog;
+use App\CustomerLogStatus;
+use App\Policies\CustomerLogPolice;
+use App\Policies\CustomerLogStatusesPolice;
 use App\Services\AuthorityService;
 use App\Services\CacheService;
 use App\Services\UserService;
@@ -22,6 +26,10 @@ class AuthServiceProvider extends ServiceProvider
      */
     protected $policies = [
         // 'App\Model' => 'App\Policies\ModelPolicy',
+        CustomerLog::class => CustomerLogPolice::class,
+
+        CustomerLogStatus::class => CustomerLogStatusesPolice::class,
+
     ];
 
     /**

+ 3 - 3
app/Services/CustomerService.php

@@ -1,6 +1,6 @@
-<?php 
+<?php
 
-namespace App\Services; 
+namespace App\Services;
 
 use App\Customer;
 
@@ -39,4 +39,4 @@ Class CustomerService
     {
         return Customer::destroy($id);
     }
-}
+}

+ 23 - 0
database/factories/CustomerLogFactory.php

@@ -0,0 +1,23 @@
+<?php
+/** @var Factory $factory */
+
+use App\Customer;
+use App\CustomerLogStatus;
+use App\User;
+use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
+
+$factory->define(App\CustomerLog::class, function (Faker $faker) {
+    return [
+        'customer_id' => function () {
+            return factory(Customer::class)->create()->id;
+        },
+        'customer_log_status_id' =>  function () {
+            return factory(CustomerLogStatus::class)->create()->id;
+        },
+        'user_id' => function () {
+            return factory(User::class)->create()->id;
+        },
+        'description' => $faker->text,
+    ];
+});

+ 12 - 0
database/factories/CustomerLogStatusFactory.php

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

+ 25 - 0
database/migrations/2020_12_14_101617_create_customerlogs_table.php

@@ -0,0 +1,25 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCustomerLogsTable extends Migration
+{
+    public function up()
+    {
+        Schema::create('customer_logs', function (Blueprint $table) {
+            $table->increments('id');
+            $table->bigInteger('customer_id')->unsigned()->index();
+            $table->integer('customer_log_status_id')->unsigned()->index();
+            $table->bigInteger('user_id')->unsigned()->index();
+            $table->text('description');
+            $table->timestamps();
+        });
+    }
+
+    public function down()
+    {
+        Schema::drop('customer_logs');
+    }
+}

+ 23 - 0
database/migrations/2020_12_14_103401_create_customerlogstatuses_table.php

@@ -0,0 +1,23 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCustomerLogStatusesTable extends Migration
+{
+	public function up()
+	{
+		Schema::create('customer_log_statuses', function(Blueprint $table) {
+            $table->increments('id');
+            $table->string('name')->index();
+            $table->text('description');
+            $table->timestamps();
+        });
+	}
+
+	public function down()
+	{
+		Schema::drop('customer_log_statuses');
+	}
+}

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

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddCustomerPhoneAddress extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('customers', function (Blueprint $table) {
+            $table->string('invoice_address')->nullable()->comment('发票地址');
+            $table->string('contact_man')->index()->nullable()->comment('联系人');
+            $table->integer('phone')->index()->nullable()->comment('联系电话');
+            $table->string('comment')->nullable()->comment('公司备注');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('customers',function (Blueprint $table){
+            $table->dropColumn('invoice_address');
+            $table->dropColumn('contact_man');
+            $table->dropColumn('phone');
+            $table->dropColumn('comment');
+        });
+    }
+}

+ 20 - 0
database/seeds/CustomerLogStatusesTableSeeder.php

@@ -0,0 +1,20 @@
+<?php
+
+use App\CustomerLogStatus;
+use Illuminate\Database\Seeder;
+
+class CustomerLogStatusesTableSeeder extends Seeder
+{
+    public function run()
+    {
+        $customer_log_statuses = factory(CustomerLogStatus::class)->times(50)->make()->each(function ($customer_log_status, $index) {
+            if ($index == 0) {
+                // $customer_log_status->field = 'value';
+            }
+        });
+
+        CustomerLogStatus::insert($customer_log_statuses->toArray());
+    }
+
+}
+

+ 20 - 0
database/seeds/CustomerLogsTableSeeder.php

@@ -0,0 +1,20 @@
+<?php
+
+use App\CustomerLog;
+use Illuminate\Database\Seeder;
+
+class CustomerLogsTableSeeder extends Seeder
+{
+    public function run()
+    {
+        $customer_logs = factory(CustomerLog::class)->times(50)->make()->each(function ($customer_log, $index) {
+            if ($index == 0) {
+                // $customer_log->field = 'value';
+            }
+        });
+
+        CustomerLog::insert($customer_logs->toArray());
+    }
+
+}
+

+ 10 - 0
resources/views/common/error.blade.php

@@ -0,0 +1,10 @@
+@if (count($errors) > 0)
+  <div class="alert alert-danger">
+    <div class="mt-2"><b>有错误发生:</b></div>
+    <ul class="mt-2 mb-2">
+      @foreach ($errors->all() as $error)
+      <li><i class="glyphicon glyphicon-remove"></i> {{ $error }}</li>
+      @endforeach
+    </ul>
+  </div>
+@endif

+ 28 - 3
resources/views/maintenance/customer/create.blade.php → resources/views/customer/customer/create.blade.php

@@ -3,8 +3,8 @@
 
 @section('content')
     <div id="nav2">
-        @component('maintenance.menu')@endcomponent
-        @component('maintenance.customer.menu')
+        @component('customer.menu')@endcomponent
+        @component('customer.customer.menu')
                 @if(isset($customer))@can('客户-编辑')
                 <li class="nav-item">
                     <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('edit',4)}">编辑</a>
@@ -13,7 +13,7 @@
     </div>
     <div class="container-fluid card">
         <div class="card-body offset-3 mt-2">
-            <form method="post" action="{{isset($customer) ? url('maintenance/customer').'/'.$customer->id : url('maintenance/customer')}}">
+            <form method="post" action="{{isset($customer) ? url('customer/customer').'/'.$customer->id : url('customer/customer')}}">
                 @csrf
                 @if(isset($customer)) @method('PUT') @endif
                 <div class="row">
@@ -37,6 +37,31 @@
                     <input class="form-control col-6" id="company_name" name="company_name"
                     value="{{old("company_name") ?? (isset($customer) ? $customer->company_name : '')}}">
                 </div>
+
+                <div class="row mt-3">
+                    <label class="col-2" for="invoice_address">发票地址</label>
+                    <input class="form-control col-6" id="invoice_address" name="invoice_address"
+                           value="{{old("invoice_address") ?? (isset($customer) ? $customer->invoice_address : '')}}">
+                </div>
+
+                <div class="row mt-3">
+                    <label class="col-2" for="contact_man">联系人</label>
+                    <input class="form-control col-6" id="contact_man" name="contact_man"
+                           value="{{old("contact_man") ?? (isset($customer) ? $customer->contact_man : '')}}">
+                </div>
+
+                <div class="row mt-3">
+                    <label class="col-2" for="phone">联系电话</label>
+                    <input class="form-control col-6" id="phone" name="phone"
+                           value="{{old("phone") ?? (isset($customer) ? $customer->phone : '')}}">
+                </div>
+
+                <div class="row mt-3">
+                    <label class="col-2" for="comment">公司备注</label>
+                    <input class="form-control col-6" id="comment" name="comment"
+                           value="{{old("comment") ?? (isset($customer) ? $customer->comment : '')}}">
+                </div>
+
                 <div class="row mt-3 offset-1">
                     <button class="btn btn-success col-7">提交</button>
                 </div>

+ 22 - 16
resources/views/maintenance/customer/index.blade.php → resources/views/customer/customer/index.blade.php

@@ -3,8 +3,8 @@
 
 @section('content')
     <div id="nav2">
-        @component('maintenance.menu')@endcomponent
-        @component('maintenance.customer.menu')@endcomponent
+        @component('customer.menu')@endcomponent
+        @component('customer.customer.menu')@endcomponent
     </div>
     <div class="container-fluid card" id="container">
         <div class="card-body mt-2">
@@ -17,6 +17,12 @@
                     <th>代码</th>
                     <th>名称</th>
                     <th>客户全称</th>
+                    <th>发票地址</th>
+                    <th>联系人</th>
+                    <th>联系电话</th>
+                    <th>公司备注</th>
+                    <th>日志</th>
+                    <th>合同</th>
                     <th>创建时间</th>
                     <th>操作</th>
                 </tr>
@@ -25,9 +31,15 @@
                     <td>@{{ customer.code }}</td>
                     <td>@{{ customer.name }}</td>
                     <td>@{{ customer.company_name }}</td>
+                    <td>@{{ customer.invoice_address }}</td>
+                    <td>@{{ customer.contact_man }}</td>
+                    <td>@{{ customer.phone }}</td>
+                    <td>@{{ customer.comment }}</td>
+                    <td><a href="#" @click="gotoLogs(customer.id)">链接</a></td>
+                    <td>#</td>
                     <td>@{{ customer.created_at }}</td>
                     <td>
-                        @can("客户-编辑")<a :href="'{{url('maintenance/customer')}}/'+customer.id+'/edit'"><button class="btn btn-sm btn-outline-info">改</button></a>@endcan
+                        @can("客户-编辑")<a :href="'{{url('customer/customer')}}/'+customer.id+'/edit'"><button class="btn btn-sm btn-outline-info">改</button></a>@endcan
                         @can("客户-删除")<button class="btn btn-sm btn-outline-danger" @click="destroy(customer.id,i,customer.name)">删</button>@endcan
                     </td>
                 </tr>
@@ -41,22 +53,12 @@
         new Vue({
             el:"#container",
             data:{
-                customers : [
-                    @foreach($customers as $customer)
-                    {
-                        id:"{{$customer->id}}",
-                        code:"{{$customer->code}}",
-                        name:"{{$customer->name}}",
-                        company_name:"{{$customer->company_name}}",
-                        created_at:"{{$customer->created_at}}",
-                    },
-                    @endforeach
-                ],
+                customers :  {!!  $customers->toJson() !!}['data']
             },
             methods:{
                 destroy(id,index,name){
                     window.tempTip.confirm("确定要删除"+name+"吗?",()=>{
-                        window.axios.delete("{{url('maintenance/customer')}}/"+id)
+                        window.axios.delete("{{url('customer/customer')}}/"+id)
                             .then(res=>{
                                 if (res.data.success){
                                     this.$delete(this.customers,index);
@@ -71,8 +73,12 @@
                             window.tempTip.show("网络错误:"+err);
                         })
                     })
+                },
+                gotoLogs(id){
+                    let url = '{{ url("customer/customer/customer_logs") }}'+'?id='+id;
+                    window.open(url);
                 }
             },
         });
     </script>
-@stop
+@stop

+ 19 - 0
resources/views/customer/customer/menu.blade.php

@@ -0,0 +1,19 @@
+<div class="container-fluid nav3">
+    <div class="card menu-third" >
+        <ul class="nav nav-pills">
+            @can('客户-查询')
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('customer/customer')}}" :class="{active:isActive('',3)}">查询</a>
+            </li> @endcan
+            @can('客户-录入')
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('customer/customer/create')}}" :class="{active:isActive('create',3)}">录入</a>
+            </li> @endcan
+
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('customer\customer/customer_log_statuses')}}" :class="{active:isActive('customer_log_statuses',3)}">客户状态</a>
+            </li>
+            {{$slot}}
+        </ul>
+    </div>
+</div>

+ 52 - 0
resources/views/customer/customer_log_statuses/create_and_edit.blade.php

@@ -0,0 +1,52 @@
+@extends('layouts.app')
+
+@section('content')
+
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+
+      <div class="card-header">
+        <h1>
+            客户日志状态-
+          @if($customer_log_status->id)
+            编辑 #{{ $customer_log_status->id }}
+          @else
+              新建
+          @endif
+        </h1>
+      </div>
+
+      <div class="card-body">
+        @if($customer_log_status->id)
+          <form action="{{ route('customer_log_statuses.update', $customer_log_status->id) }}" method="POST" accept-charset="UTF-8">
+          <input type="hidden" name="_method" value="PUT">
+        @else
+          <form action="{{ route('customer_log_statuses.store') }}" method="POST" accept-charset="UTF-8">
+        @endif
+
+          @include('common.error')
+
+          <input type="hidden" name="_token" value="{{ csrf_token() }}">
+
+
+                <div class="form-group">
+                	<label for="name-field">名称</label>
+                	<input class="form-control" type="text" name="name" id="name-field" value="{{ old('name', $customer_log_status->name ) }}" />
+                </div>
+                <div class="form-group">
+                	<label for="description-field">详情</label>
+                	<textarea name="description" id="description-field" class="form-control" rows="3">{{ old('description', $customer_log_status->description ) }}</textarea>
+                </div>
+
+          <div class="well well-sm">
+            <button type="submit" class="btn btn-primary">保存</button>
+            <a class="btn btn-link float-xs-right" href="{{ route('customer_log_statuses.index') }}"> <- 返回</a>
+          </div>
+        </form>
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 64 - 0
resources/views/customer/customer_log_statuses/index.blade.php

@@ -0,0 +1,64 @@
+@extends('layouts.app')
+
+@section('content')
+
+    <div id="nav2">
+        @component('customer.menu')@endcomponent
+        @component('customer.customer.menu')@endcomponent
+    </div>
+    <div class="container">
+        <div class="col-md-10 offset-md-1">
+            <div class="card ">
+                <div class="card-header">
+                    <h1>
+                        客户日志状态
+                        <a class="btn btn-success float-xs-right"
+                           href="{{ route('customer_log_statuses.create') }}">新建</a>
+                    </h1>
+                </div>
+
+                <div class="card-body">
+                    @if($customer_log_statuses->count())
+                        <table class="table table-sm table-striped">
+                            <thead>
+                            <tr>
+                                <th class="text-xs-center">#</th>
+                                <th>名称</th>
+                                <th>详情</th>
+                                <th class="text-xs-right">操作</th>
+                            </tr>
+                            </thead>
+
+                            <tbody>
+                            @foreach($customer_log_statuses as $customer_log_status)
+                                <tr>
+                                    <td class="text-xs-center"><strong>{{$customer_log_status->id}}</strong></td>
+
+                                    <td>{{$customer_log_status->name}}</td>
+                                    <td>{{$customer_log_status->description}}</td>
+
+                                    <td class="text-xs-right">
+                                        <a class="btn btn-sm btn-primary"
+                                           href="{{ route('customer_log_statuses.show', $customer_log_status->id) }}">
+                                            查
+                                        </a>
+
+                                        <a class="btn btn-sm btn-warning"
+                                           href="{{ route('customer_log_statuses.edit', $customer_log_status->id) }}">
+                                            改
+                                        </a>
+                                    </td>
+                                </tr>
+                            @endforeach
+                            </tbody>
+                        </table>
+                        {!! $customer_log_statuses->render() !!}
+                    @else
+                        <h3 class="text-xs-center alert alert-info">暂时还没有内容 ~ ~</h3>
+                    @endif
+                </div>
+            </div>
+        </div>
+    </div>
+
+@endsection

+ 41 - 0
resources/views/customer/customer_log_statuses/show.blade.php

@@ -0,0 +1,41 @@
+@extends('layouts.app')
+
+@section('content')
+
+    <div class="container">
+        <div class="col-md-10 offset-md-1">
+            <div class="card ">
+                <div class="card-header">
+                    <h1>客户日志状态#{{ $customer_log_status->id }}</h1>
+                </div>
+
+                <div class="card-body">
+                    <div class="card-block bg-light">
+                        <div class="row">
+                            <div class="col-md-6">
+                                <a class="btn btn-link" href="{{ route('customer_log_statuses.index') }}"><- 返回</a>
+                            </div>
+                            <div class="col-md-6">
+                                <a class="btn btn-sm btn-warning float-right mt-1"
+                                   href="{{ route('customer_log_statuses.edit', $customer_log_status->id) }}">
+                                    编辑
+                                </a>
+                            </div>
+                        </div>
+                    </div>
+                    <br>
+
+                    <label><b>名称</b></label>
+                    <p>
+                        {{ $customer_log_status->name }}
+                    </p>
+                    <label><b>详情</b></label>
+                    <p>
+                        {{ $customer_log_status->description }}
+                    </p>
+                </div>
+            </div>
+        </div>
+    </div>
+
+@endsection

+ 68 - 0
resources/views/customer/customer_logs/create_and_edit.blade.php

@@ -0,0 +1,68 @@
+@extends('layouts.app')
+
+@section('content')
+
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+
+      <div class="card-header">
+        <h1>
+          客户日志 -
+          @if($customer_log->id)
+            Edit #{{ $customer_log->id }}
+          @else
+            创建
+          @endif
+        </h1>
+      </div>
+
+      <div class="card-body">
+        @if($customer_log->id)
+          <form action="{{ route('customer_logs.update', $customer_log->id) }}" method="POST" accept-charset="UTF-8">
+          <input type="hidden" name="_method" value="PUT">
+        @else
+          <form action="{{ route('customer_logs.store') }}" method="POST" accept-charset="UTF-8">
+        @endif
+
+          @include('common.error')
+
+          <input type="hidden" name="_token" value="{{ csrf_token() }}">
+
+
+                <div class="form-group">
+                    <label for="customer_id-field">客户名称</label>
+                    <select name="customer_id" class="form-control" required>
+                        <option value="" hidden disabled {{ $customer_log->customer_id ? '':'selected' }}>请选择客户名称</option>
+                        @foreach($customers as $customer)
+                            <option value="{{ $customer->id }}">{{ $customer->name }}</option>
+                        @endforeach
+                    </select>
+{{--                    <input class="form-control" type="text" name="customer_id" id="customer_id-field" value="{{ old('customer_id', $customer_log->customer_id ) }}" />--}}
+                </div>
+                <div class="form-group">
+                    <label for="customer_log_status_id-field">状态</label>
+                    <select name="customer_log_status_id" class="form-control" required>
+                        <option value="" hidden disabled {{ $customer_log->customer_log_status_id ? '':'selected' }}>请选择状态</option>
+                        @foreach($customerLogStatuses as $customerLogStatus)
+                            <option value="{{ $customerLogStatus->id }}">{{ $customerLogStatus->name }}</option>
+                        @endforeach
+                    </select>
+{{--                    <input class="form-control" type="text" name="customer_log_status_id" id="customer_log_status_id-field" value="{{ old('customer_log_status_id', $customer_log->customer_log_status_id ) }}" />--}}
+                </div>
+                <div class="form-group">
+                	<label for="description-field">描述</label>
+                	<textarea name="description" id="description-field" class="form-control" rows="3">{{ old('description', $customer_log->description ) }}</textarea>
+                </div>
+
+          <div class="well well-sm">
+            <button type="submit" class="btn btn-primary">保存</button>
+            <a class="btn btn-link float-xs-right" href="{{ route('customer_logs.index') }}"> <- 返回</a>
+          </div>
+        </form>
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 69 - 0
resources/views/customer/customer_logs/index.blade.php

@@ -0,0 +1,69 @@
+@extends('layouts.app')
+
+@section('content')
+    <div class="container">
+        <div class="col-md-10 offset-md-1">
+            <div class="card ">
+                <div class="card-header">
+                    <h1>
+                        客户日志
+                        <a class="btn btn-success float-xs-right" href="{{ route('customer_logs.create') }}">新建</a>
+                    </h1>
+                </div>
+
+                <div class="card-body">
+                    @if($customer_logs->count())
+                        <table class="table table-sm table-striped">
+                            <thead>
+                            <tr>
+                                <th>客户名称</th>
+                                <th>状态</th>
+                                <th>创建用户</th>
+                                <th>详情</th>
+                                <th>编辑时间</th>
+                                <th class="text-xs-right">操作</th>
+                            </tr>
+                            </thead>
+
+                            <tbody>
+                            @foreach($customer_logs as $customer_log)
+                                <tr>
+                                    <td>{{$customer_log->customer->name}}</td>
+                                    <td>{{$customer_log->customerLogStatus->name}}</td>
+                                    <td>{{$customer_log->user->name}}</td>
+                                    <td>{{$customer_log->description}}</td>
+                                    <td>{{$customer_log->updated_at->diffForHumans()}}</td>
+
+                                    <td class="text-xs-right">
+                                        <a class="btn btn-sm btn-primary"
+                                           href="{{ route('customer_logs.show', $customer_log->id) }}">
+                                            查
+                                        </a>
+                                        @can('update',$customer_log)
+                                            <a class="btn btn-sm btn-warning"
+                                               href="{{ route('customer_logs.edit', $customer_log->id) }}">
+                                                改
+                                            </a>
+                                        @endcan
+                                        <form action="{{ route('customer_logs.destroy', $customer_log->id) }}"
+                                              method="POST" style="display: inline;"
+                                              onsubmit="return confirm('删除!无法恢复!您确定么?');">
+                                            {{csrf_field()}}
+                                            <input type="hidden" name="_method" value="DELETE">
+
+                                            <button type="submit" class="btn btn-sm btn-danger">删</button>
+                                        </form>
+                                    </td>
+                                </tr>
+                            @endforeach
+                            </tbody>
+                        </table>
+                        {!! $customer_logs->render() !!}
+                    @else
+                        <h3 class="text-xs-center alert alert-info">Empty!</h3>
+                    @endif
+                </div>
+            </div>
+        </div>
+    </div>
+@stop

+ 59 - 0
resources/views/customer/customer_logs/show.blade.php

@@ -0,0 +1,59 @@
+@extends('layouts.app')
+
+@section('content')
+
+    <div class="container">
+        <div class="col-md-10 offset-md-1">
+            <div class="card ">
+                <div class="card-header">
+                    <h1>客户日志</h1>
+                </div>
+
+                <div class="card-body">
+                    <div class="card-block bg-light">
+                        <div class="row">
+                            <div class="col-md-6">
+                                <a class="btn btn-link" href="{{ route('customer_logs.index') }}"><- 返回</a>
+                            </div>
+                            @can('update',$customer_log)
+                            <div class="col-md-6">
+                                <a class="btn btn-sm btn-warning float-right mt-1"
+                                   href="{{ route('customer_logs.edit', $customer_log->id) }}">
+                                    编辑
+                                </a>
+                            </div>
+                            @endcan
+                        </div>
+                    </div>
+                    <br>
+
+                    <p id="customer"><b>客户信息</b></p>
+                    <table class="table table-sm table-striped" aria-describedby="customer">
+                        <tr>
+                            <th>客户名称</th>
+                            <th>公司名称</th>
+                        </tr>
+                        <tr>
+                            <th>{{ $customer_log->customer->name }}</th>
+                            <th>{{ $customer_log->customer->company_name }}</th>
+                        </tr>
+                    </table>
+
+                    <label><b>状态</b></label>
+                    <p>
+                        {{ $customer_log->customerLogStatus->name }}
+                    </p>
+                    <label><b>创建用户</b></label>
+                    <p>
+                        {{ $customer_log->user->name }}
+                    </p>
+                    <label><b>详情</b></label>
+                    <p>
+                        {{ $customer_log->description }}
+                    </p>
+                </div>
+            </div>
+        </div>
+    </div>
+
+@endsection

+ 3 - 0
resources/views/customer/menu.blade.php

@@ -9,6 +9,9 @@
             <li class="nav-item">
                 <a class="nav-link" href="{{url('customer/finance/instantBill')}}" :class="{active:isActive('finance',2)}">财务</a>
             </li>
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('customer/customer')}}" :class="{active:isActive('customer',2)}">客户</a>
+            </li>
             <li class="nav-item">
                 <a class="nav-link" href="{{url('customer/relating')}}" :class="{active:isActive('relating',2)}">相关设置</a>
             </li>

+ 0 - 15
resources/views/maintenance/customer/menu.blade.php

@@ -1,15 +0,0 @@
-<div class="container-fluid nav3">
-    <div class="card menu-third" >
-        <ul class="nav nav-pills">
-            @can('客户-查询')
-            <li class="nav-item">
-                <a class="nav-link" href="{{url('maintenance/customer')}}" :class="{active:isActive('',3)}">查询</a>
-            </li> @endcan
-            @can('客户-录入')
-            <li class="nav-item">
-                <a class="nav-link" href="{{url('maintenance/customer/create')}}" :class="{active:isActive('create',3)}">录入</a>
-            </li> @endcan
-            {{$slot}}
-        </ul>
-    </div>
-</div>

+ 0 - 4
resources/views/maintenance/menu.blade.php

@@ -26,10 +26,6 @@
                 <li class="nav-item">
                     <a class="nav-link text-muted" href="{{url('maintenance/warehouse')}}" :class="{active:isActive('warehouse',2)}">仓库</a>
                 </li> @endcan
-            @can('客户')
-                <li class="nav-item">
-                    <a class="nav-link text-dark" href="{{url('maintenance/customer')}}" :class="{active:isActive('customer',2)}">客户</a>
-                </li> @endcan
             @can('货主')
                 <li class="nav-item">
                     <a class="nav-link text-dark" href="{{url('maintenance/owner')}}" :class="{active:isActive('owner',2)}">货主</a>

+ 6 - 1
routes/web.php

@@ -184,7 +184,6 @@ Route::group(['prefix'=>'maintenance'],function(){
     Route::resource('tutorial', 'TutorialController');
     Route::resource('userLabor','UserLaborController');
     Route::resource('paperBox', 'PaperBoxController');
-    Route::resource('customer', 'CustomerBaseController');
     Route::resource('userOwnerGroup', 'UserOwnerGroupController');
     Route::resource('processMethod', 'ProcessMethodController');
     Route::resource('feature', 'FeatureController');
@@ -597,6 +596,12 @@ Route::group(['prefix'=>'customer'],function(){
         Route::post('billConfirm','CustomerController@billConfirm');
     });
     Route::get('relating',function (){return view('customer.relating');});
+    Route::group(['prefix' => 'customer'], function () {
+        Route::resource('customer_log_statuses', 'CustomerLogStatusesController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
+        Route::resource('customer_logs', 'CustomerLogsController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
+    });
+    Route::resource('customer', 'CustomerBaseController');
+
 });
 
 /** 站管理 */

+ 21 - 0
tests/Unit/CustomerLogTest.php

@@ -0,0 +1,21 @@
+<?php
+
+
+use App\CustomerLog;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class CustomerLogTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /**
+     * @test
+     */
+    public function customerLog_belongsTo_customerLogStatus()
+    {
+        $customerLog =  factory(CustomerLog::class)->create();
+        $this->assertInstanceOf(BelongsTo::class, $customerLog->customerLogStatus());
+    }
+}