| xqd
@@ -2,8 +2,12 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
+use App\Models\BaseAttachmentModel;
|
|
|
+use App\Models\ClassModel;
|
|
|
use App\Models\Setting;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
+use Intervention\Image\Facades\Image;
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
{
|
| xqd
@@ -25,9 +29,9 @@ class SettingController extends Controller
|
|
|
|
|
|
public function share()
|
|
|
{
|
|
|
- $share_image = $this->model->firstOrCreate(['key' => 'share_image'], ['key_show' => '图片']);
|
|
|
- $share_text = $this->model->firstOrCreate(['key' => 'share_text'], ['key_show' => '文本标签']);
|
|
|
- $share_text_pos = $this->model->firstOrCreate(['key' => 'share_text_pos'], ['key_show' => '文本位置']);
|
|
|
+ $share_image = $this->model->firstOrCreate(['key' => 'share_image'], ['value' => '图片']);
|
|
|
+ $share_text = $this->model->firstOrCreate(['key' => 'share_text'], ['value' => '文本标签']);
|
|
|
+ $share_text_pos = $this->model->firstOrCreate(['key' => 'share_text_pos'], ['value' => '文本位置']);
|
|
|
|
|
|
list($pre_uri, $model, $model_name) = array($this->pre_uri, $this->model, $this->model_name);
|
|
|
|
| xqd
@@ -76,4 +80,46 @@ class SettingController extends Controller
|
|
|
}
|
|
|
return $this->showMessage('操作成功');
|
|
|
}
|
|
|
+
|
|
|
+ public function generateSharePhoto(Request $request)
|
|
|
+ {
|
|
|
+ $share_image = $this->where('key', 'share_image')->first();
|
|
|
+ if(empty($share_image) || empty($share_image->value) || !Storage::disk('upload')->exists($share_image->value)) {
|
|
|
+ return $this->showWarning('分享图片错误或未设置');
|
|
|
+ }
|
|
|
+ $share_text = $this->where('key', 'share_text')->first();
|
|
|
+ if(empty($share_text) || empty($share_text->value)) {
|
|
|
+ return $this->showWarning('分享文字错误或未设置');
|
|
|
+ }
|
|
|
+ $share_text_pos = $this->where('key', 'share_text_pos')->first();
|
|
|
+ if(empty($share_text_pos) || empty($share_text_pos->value) || count($pos = explode(',', $share_text_pos->value)) < 2) {
|
|
|
+ return $this->showWarning('分享文字位置错误或未设置');
|
|
|
+ }
|
|
|
+
|
|
|
+ $text = str_replace_array('{days}', [15], $share_text_pos->value);
|
|
|
+
|
|
|
+ $image = Image::make($share_image->value)->text($text, $pos[0], $pos[1]);
|
|
|
+
|
|
|
+ $size = $image->filesize();
|
|
|
+
|
|
|
+ $name = uniqid();
|
|
|
+ $path = 'tmp/share/' . date("Ymd") . '/' . $name . '.png';
|
|
|
+ $full_path = '/' . $path;
|
|
|
+ if(!\File::isDirectory($path)) {
|
|
|
+ \File::makeDirectory($path, 493, true);
|
|
|
+ }
|
|
|
+ $image->save($path);
|
|
|
+
|
|
|
+ BaseAttachmentModel::create([
|
|
|
+ 'path' => $full_path,
|
|
|
+ 'name' => $name,
|
|
|
+ 'type' => 'png',
|
|
|
+ 'class' => '分享图片',
|
|
|
+ 'size' => $size,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ ClassModel::firstOrCreate(['class' => '分享图片']);
|
|
|
+
|
|
|
+ return redirect($path);
|
|
|
+ }
|
|
|
}
|