ANG YU 5 лет назад
Родитель
Сommit
23319a29a5

+ 10 - 0
app/CustomerLog.php

@@ -14,4 +14,14 @@ class CustomerLog extends Model
     {
         return $this->belongsTo(CustomerLogStatus::class);
     }
+
+    public function user(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+
+    public function customer(): BelongsTo
+    {
+        return $this->belongsTo(Customer::class);
+    }
 }

+ 5 - 2
app/Http/Controllers/CustomerLogStatusesController.php

@@ -3,6 +3,9 @@
 namespace App\Http\Controllers;
 
 use App\CustomerLogStatus;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+
 
 class CustomerLogStatusesController extends Controller
 {
@@ -27,7 +30,7 @@ class CustomerLogStatusesController extends Controller
         return view('customer_log_statuses.create_and_edit', compact('customer_log_status'));
     }
 
-    public function store($request)
+    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.');
@@ -39,7 +42,7 @@ class CustomerLogStatusesController extends Controller
         return view('customer_log_statuses.create_and_edit', compact('customer_log_status'));
     }
 
-    public function update($request, CustomerLogStatus $customer_log_status)
+    public function update(Request $request, CustomerLogStatus $customer_log_status)
     {
         $this->authorize('update', $customer_log_status);
         $customer_log_status->update($request->all());

+ 18 - 7
app/Http/Controllers/CustomerLogsController.php

@@ -2,7 +2,10 @@
 
 namespace App\Http\Controllers;
 
+use App\Customer;
 use App\CustomerLog;
+use App\CustomerLogStatus;
+use Illuminate\Http\RedirectResponse;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Controller;
 
@@ -15,33 +18,41 @@ class CustomerLogsController extends Controller
 
     public function index()
     {
-        $customer_logs = CustomerLog::paginate();
+        $customer_logs = CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->orderByDesc('updated_at')->paginate();
         return view('customer_logs.index', compact('customer_logs'));
     }
 
-    public function show(CustomerLog $customer_log)
+    public function show($customer_log_id)
     {
+        $customer_log =CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->where('id',$customer_log_id)->first();
         return view('customer_logs.show', compact('customer_log'));
     }
 
     public function create(CustomerLog $customer_log)
     {
-        return view('customer_logs.create_and_edit', compact('customer_log'));
+        $customers = Customer::all();
+        $customerLogStatuses = CustomerLogStatus::all();
+        return view('customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
     }
 
-    public function store($request)
+    public function store(Request $request): RedirectResponse
     {
-        $customer_log = CustomerLog::create($request->all());
+        $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);
-        return view('customer_logs.create_and_edit', compact('customer_log'));
+        $customers = Customer::all();
+        $customerLogStatuses = CustomerLogStatus::all();
+        return view('customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
     }
 
-    public function update($request, CustomerLog $customer_log)
+    public function update(Request $request, CustomerLog $customer_log)
     {
         $this->authorize('update', $customer_log);
         $customer_log->update($request->all());

+ 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,
+
     ];
 
     /**

+ 9 - 9
resources/views/customer_log_statuses/create_and_edit.blade.php

@@ -8,11 +8,11 @@
 
       <div class="card-header">
         <h1>
-          CustomerLogStatus /
+            客户日志状态-
           @if($customer_log_status->id)
-            Edit #{{ $customer_log_status->id }}
+            编辑 #{{ $customer_log_status->id }}
           @else
-            Create
+              新建
           @endif
         </h1>
       </div>
@@ -29,19 +29,19 @@
 
           <input type="hidden" name="_token" value="{{ csrf_token() }}">
 
-          
+
                 <div class="form-group">
-                	<label for="name-field">Name</label>
+                	<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>
                 <div class="form-group">
-                	<label for="description-field">Description</label>
+                	<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">Save</button>
-            <a class="btn btn-link float-xs-right" href="{{ route('customer_log_statuses.index') }}"> <- Back</a>
+            <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>

+ 7 - 14
resources/views/customer_log_statuses/index.blade.php

@@ -6,8 +6,8 @@
     <div class="card ">
       <div class="card-header">
         <h1>
-          CustomerLogStatus
-          <a class="btn btn-success float-xs-right" href="{{ route('customer_log_statuses.create') }}">Create</a>
+          客户日志状态
+          <a class="btn btn-success float-xs-right" href="{{ route('customer_log_statuses.create') }}">新建</a>
         </h1>
       </div>
 
@@ -17,8 +17,8 @@
             <thead>
               <tr>
                 <th class="text-xs-center">#</th>
-                <th>Name</th> <th>Description</th>
-                <th class="text-xs-right">OPTIONS</th>
+                <th>名称</th> <th>详情</th>
+                <th class="text-xs-right">操作</th>
               </tr>
             </thead>
 
@@ -31,19 +31,12 @@
 
                 <td class="text-xs-right">
                   <a class="btn btn-sm btn-primary" href="{{ route('customer_log_statuses.show', $customer_log_status->id) }}">
-                    V
+                    
                   </a>
 
                   <a class="btn btn-sm btn-warning" href="{{ route('customer_log_statuses.edit', $customer_log_status->id) }}">
-                    E
+                    
                   </a>
-
-                  <form action="{{ route('customer_log_statuses.destroy', $customer_log_status->id) }}" method="POST" style="display: inline;" onsubmit="return confirm('Delete? Are you sure?');">
-                    {{csrf_field()}}
-                    <input type="hidden" name="_method" value="DELETE">
-
-                    <button type="submit" class="btn btn-sm btn-danger">D </button>
-                  </form>
                 </td>
               </tr>
               @endforeach
@@ -51,7 +44,7 @@
           </table>
           {!! $customer_log_statuses->render() !!}
         @else
-          <h3 class="text-xs-center alert alert-info">Empty!</h3>
+          <h3 class="text-xs-center alert alert-info">暂时还没有内容 ~ ~</h3>
         @endif
       </div>
     </div>

+ 31 - 29
resources/views/customer_log_statuses/show.blade.php

@@ -2,38 +2,40 @@
 
 @section('content')
 
-<div class="container">
-  <div class="col-md-10 offset-md-1">
-    <div class="card ">
-      <div class="card-header">
-        <h1>CustomerLogStatus / Show #{{ $customer_log_status->id }}</h1>
-      </div>
+    <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') }}"><- Back</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) }}">
-                Edit
-              </a>
+                <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>
-        <br>
-
-        <label>Name</label>
-<p>
-	{{ $customer_log_status->name }}
-</p> <label>Description</label>
-<p>
-	{{ $customer_log_status->description }}
-</p>
-      </div>
     </div>
-  </div>
-</div>
 
 @endsection

+ 24 - 16
resources/views/customer_logs/create_and_edit.blade.php

@@ -8,11 +8,11 @@
 
       <div class="card-header">
         <h1>
-          CustomerLog /
+          客户日志 -
           @if($customer_log->id)
             Edit #{{ $customer_log->id }}
           @else
-            Create
+            创建
           @endif
         </h1>
       </div>
@@ -29,27 +29,35 @@
 
           <input type="hidden" name="_token" value="{{ csrf_token() }}">
 
-          
-                <div class="form-group">
-                    <label for="customer_id-field">Customer_id</label>
-                    <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">Customer_log_status_id</label>
-                    <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> 
+                    <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="user_id-field">User_id</label>
-                    <input class="form-control" type="text" name="user_id" id="user_id-field" value="{{ old('user_id', $customer_log->user_id ) }}" />
-                </div> 
+                    <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">Description</label>
+                	<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">Save</button>
-            <a class="btn btn-link float-xs-right" href="{{ route('customer_logs.index') }}"> <- Back</a>
+            <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>

+ 61 - 53
resources/views/customer_logs/index.blade.php

@@ -1,61 +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>
-          CustomerLog
-          <a class="btn btn-success float-xs-right" href="{{ route('customer_logs.create') }}">Create</a>
-        </h1>
-      </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_logs.create') }}">新建</a>
+                    </h1>
+                </div>
 
-      <div class="card-body">
-        @if($customer_logs->count())
-          <table class="table table-sm table-striped">
-            <thead>
-              <tr>
-                <th class="text-xs-center">#</th>
-                <th>Customer_id</th> <th>Customer_log_status_id</th> <th>User_id</th> <th>Description</th>
-                <th class="text-xs-right">OPTIONS</th>
-              </tr>
-            </thead>
+                <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 class="text-xs-center"><strong>{{$customer_log->id}}</strong></td>
+                            <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>{{$customer_log->customer_id}}</td> <td>{{$customer_log->customer_log_status_id}}</td> <td>{{$customer_log->user_id}}</td> <td>{{$customer_log->description}}</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">
 
-                <td class="text-xs-right">
-                  <a class="btn btn-sm btn-primary" href="{{ route('customer_logs.show', $customer_log->id) }}">
-                    V
-                  </a>
-
-                  <a class="btn btn-sm btn-warning" href="{{ route('customer_logs.edit', $customer_log->id) }}">
-                    E
-                  </a>
-
-                  <form action="{{ route('customer_logs.destroy', $customer_log->id) }}" method="POST" style="display: inline;" onsubmit="return confirm('Delete? Are you sure?');">
-                    {{csrf_field()}}
-                    <input type="hidden" name="_method" value="DELETE">
-
-                    <button type="submit" class="btn btn-sm btn-danger">D </button>
-                  </form>
-                </td>
-              </tr>
-              @endforeach
-            </tbody>
-          </table>
-          {!! $customer_logs->render() !!}
-        @else
-          <h3 class="text-xs-center alert alert-info">Empty!</h3>
-        @endif
-      </div>
+                                            <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>
-  </div>
-</div>
-
-@endsection
+@stop

+ 47 - 35
resources/views/customer_logs/show.blade.php

@@ -2,44 +2,56 @@
 
 @section('content')
 
-<div class="container">
-  <div class="col-md-10 offset-md-1">
-    <div class="card ">
-      <div class="card-header">
-        <h1>CustomerLog / Show #{{ $customer_log->id }}</h1>
-      </div>
+    <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') }}"><- Back</a>
-            </div>
-            <div class="col-md-6">
-              <a class="btn btn-sm btn-warning float-right mt-1" href="{{ route('customer_logs.edit', $customer_log->id) }}">
-                Edit
-              </a>
+                <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>
+                            <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>
+                        </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>
-        <br>
-
-        <label>Customer_id</label>
-<p>
-	{{ $customer_log->customer_id }}
-</p> <label>Customer_log_status_id</label>
-<p>
-	{{ $customer_log->customer_log_status_id }}
-</p> <label>User_id</label>
-<p>
-	{{ $customer_log->user_id }}
-</p> <label>Description</label>
-<p>
-	{{ $customer_log->description }}
-</p>
-      </div>
     </div>
-  </div>
-</div>
 
 @endsection