瀏覽代碼

美化 商品管理页面

兔姬桑 3 年之前
父節點
當前提交
d09bb5fcae
共有 3 個文件被更改,包括 24 次插入9 次删除
  1. 10 3
      app/Http/Controllers/Admin/ShopController.php
  2. 6 0
      app/Models/Goods.php
  3. 8 6
      resources/views/admin/shop/index.blade.php

+ 10 - 3
app/Http/Controllers/Admin/ShopController.php

@@ -32,7 +32,14 @@ class ShopController extends Controller
             });
         }
 
-        return view('admin.shop.index', ['goodsList' => $query->orderByDesc('status')->paginate(10)->appends($request->except('page'))]);
+        $goodsList = $query->orderByDesc('status')->paginate(10)->appends($request->except('page'));
+
+        foreach ($goodsList->load('orders') as $goods) {
+            $goods->use_count = $goods->orders->whereIn('status', [2, 3])->where('is_expire', 0)->count();
+            $goods->total_count = $goods->orders->whereIn('status', [2, 3])->count();
+        }
+
+        return view('admin.shop.index', ['goodsList' => $goodsList]);
     }
 
     // 添加商品页面
@@ -89,8 +96,8 @@ class ShopController extends Controller
     public function edit(Goods $good)
     {
         return view('admin.shop.info', [
-            'good'   => $good,
-            'levels' => Level::orderBy('level')->get(),
+            'good'       => $good,
+            'levels'     => Level::orderBy('level')->get(),
             'categories' => GoodsCategory::all(),
         ]);
     }

+ 6 - 0
app/Models/Goods.php

@@ -3,6 +3,7 @@
 namespace App\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Database\Eloquent\SoftDeletes;
 
 /**
@@ -16,6 +17,11 @@ class Goods extends Model
     protected $dates = ['deleted_at'];
     protected $guarded = [];
 
+    public function orders(): HasMany
+    {
+        return $this->hasMany(Order::class);
+    }
+
     public function scopeType($query, $type)
     {
         return $query->whereType($type)->whereStatus(1)->orderByDesc('sort');

+ 8 - 6
resources/views/admin/shop/index.blade.php

@@ -44,6 +44,7 @@
                         <th> 内含流量</th>
                         <th> 售价</th>
                         <th> 排序</th>
+                        <th> 使用 / 销售</th>
                         <th> 热销</th>
                         <th> 限购数</th>
                         <th> {{trans('common.status')}}</th>
@@ -64,25 +65,26 @@
                                     充值
                                 @endif
                             </td>
-                            <td>
+                            <td style="background-color: {{$goods->color ?? 'white'}}" @if($goods->color)class="text-white"@endif>
                                 @if($goods->logo)
                                     <a href="{{asset($goods->logo)}}" target="_blank">
                                         <img src="{{asset($goods->logo)}}" class="h-50" alt="logo"/>
                                     </a>
+                                @elseif($goods->color)
+                                    无 LOGO
                                 @endif
                             </td>
                             <td> {{$goods->traffic_label}} </td>
-                            <td> {{$goods->price}}元</td>
+                            <td> {{$goods->price}} 元</td>
                             <td> {{$goods->sort}} </td>
+                            <td><code>{{$goods->use_count}} / {{$goods->total_count}}</code></td>
                             <td>
                                 @if($goods->is_hot)
-                                    <span class="badge badge-lg badge-danger">是</span>
-                                @else
-                                    <span class="badge badge-lg badge-default">否</span>
+                                    🔥
                                 @endif
                             </td>
                             <td>
-                                {{$goods->limit_num}}
+                                {{$goods->limit_num ?: '无限制'}}
                             </td>
                             <td>
                                 @if($goods->status)