HomeController.php
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?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();
}
});
}
}