HomeController.php 3.9 KB
<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\User\User;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Intervention\Image\ImageManagerStatic as Image;


class HomeController extends Controller
{
    public function index(Content $content)
    {

        return redirect(admin_url('chat-records'));

//        redirect('ChatRecordsController')
//
////        return $content->withInfo('Title', 'messages..');
//
////        return $content->withSuccess('Title', 'messages..');
//        return $content
//            ->row(function (Row $row) {
//                $row->column(12, function (Column $column) {
//                    $column->append(view('admin::home.index'));
//                });
//            });

        return $content
            ->title('Dashboard')
            ->description('Description...')
            ->row(Dashboard::title())
            ->row(function (Row $row) {

//                $row->column(4, function (Column $column) {
//                    $column->append(Dashboard::environment());
//                });
//
//                $row->column(4, function (Column $column) {
//                    $column->append(Dashboard::extensions());
//                });

                $row->column(12, function (Column $column) {
                    $column->append(Dashboard::dependencies());
                });
            });
    }

    public function image()
    {
        ini_set("memory_limit", "-1");

        // 获取商品
        Goods::all()->each(function ($goods) {
            $cover_image = substr_file_path($goods->cover_image);
            $cover_image_thumb = substr_file_path($goods->cover_image_thumb);
            if ($cover_image && (!$cover_image_thumb || ($cover_image_thumb === $cover_image))) {
                $image = 'storage/'.$cover_image;
                $img = Image::make($image);

                $filename = $img->filename;
                $basename = $img->basename;
                $pre = str_replace($basename, '', $cover_image);
                $thumburl = 'storage/' . $pre .$filename .'_thumb.'.$img->extension;
                $width_o = $img->width();
                $height_o = $img->height();
                $width = $width_o;
                $height = $height_o;
                if ($width_o > 320) {
                    $width = 320;
                    $rate =  $width_o / 320;
                    $height = $height_o / $rate;
                }
                $img->resize($width, $height);
                $img->save($thumburl);

                $cover_image_thum = $pre .$filename .'_thumb.'.$img->extension;
                $goods->cover_image_thumb = $cover_image_thum;
                $goods->save();
            }
        });

        // 获取商品
        GoodsCategory::all()->each(function ($model) {
            $icon = substr_file_path($model->icon);
            $icon_thumb = substr_file_path($model->icon_thumb);
            if ($icon && ($icon_thumb == $icon)) {
                $image = 'storage/'.$icon;
                dump($image);
                $img = Image::make($image);

                $filename = $img->filename;
                $basename = $img->basename;
                $pre = str_replace($basename, '', $icon);
                $thumburl = 'storage/' . $pre .$filename .'_thumb.'.$img->extension;
                $width_o = $img->width();
                $height_o = $img->height();
                $width = $width_o;
                $height = $height_o;
                if ($width_o > 100) {
                    $width = 100;
                    $rate =  $width_o / 100;
                    $height = $height_o / $rate;
                }
                $img->resize($width, $height);
                $img->save($thumburl);
                $model->icon_thumb = $pre .$filename .'_thumb.'.$img->extension;
                $model->save();
            }
        });
    }
}