李帅

1.重构模板和临境上传功能

......@@ -9,3 +9,11 @@
- composer install
- php artisan admin:publish
- php artisan admin:install
## todo
- 合成优化
- 登录、注册(仅邮箱)
- 支付(Paypal)
......
<?php
namespace App\Admin\Controllers;
use App\Admin\Renderable\PoemTable;
use App\Admin\Renderable\TemplateTable;
use App\Jobs\MakeVideo;
use App\Models\AdminMakeVideo;
use App\Models\Order;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
class AdminMakeVideoController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new AdminMakeVideo(), function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('poem_id');
$grid->column('type');
$grid->column('video_url');
$grid->column('images_url');
$grid->column('bg_music');
$grid->column('bgm_url');
$grid->column('feel');
$grid->column('temp_id');
$grid->column('thumbnail');
$grid->column('thumbnail_url');
$grid->column('created_at');
$grid->column('updated_at')->sortable();
$grid->filter(function (Grid\Filter $filter) {
$filter->equal('id');
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new AdminMakeVideo(), function (Show $show) {
$show->field('id');
$show->field('poem_id');
$show->field('type');
$show->field('video_url');
$show->field('images_url');
$show->field('bg_music');
$show->field('bgm_url');
$show->field('feel');
$show->field('temp_id');
$show->field('thumbnail');
$show->field('thumbnail_url');
$show->field('created_at');
$show->field('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new AdminMakeVideo(), function (Form $form) {
$form->display('id');
$form->selectTable('poem_id','选择一言')
->title('一言诗词库')
->from(PoemTable::make());
$form->radio('type')
->options([1=>'视频', 2=>'图文音频'])
->when(1,function (Form $form){
$form->file('video_url','上传视频')
->accept('mp4')
->autoUpload()
->uniqueName()
->maxSize('102400')
->addElementClass('video_url');
})
->when(2,function (Form $form){
$form->multipleImage('images_url','上传图片')
->limit(5)
->uniqueName()
->addElementClass('images_url');
})
->default(1);
$form->radio('bg_music','背景音')
->options(['无', '有'])
->when(1,function (Form $form){
$form->file('bgm_url','上传背景音')
->accept('mp3,aac,wav')
->autoUpload()
->uniqueName()
->addElementClass('bg_music');
})
->default(0);
$form->textarea('feel','有感');
$form->selectTable('temp_id','选择模板')
->title('模板选择')
->from(TemplateTable::make());
$form->radio('thumbnail','封面')
->options([1=>'手动上传', 2=>'自动截屏'])
->when(1,function (Form $form){
$form->multipleImage('thumbnail_url','上传图片')
->limit(5)
->uniqueName();
// ->addElementClass('bg_img_url');
})
->when(2,function (Form $form){
$form->html('');
})
->default(1);
$form->display('created_at');
$form->display('updated_at');
});
}
public function store()
{
$all = request()->all();
if (isset($all['upload_column'])) return $this->form()->store();
try{
$video = AdminMakeVideo::query()->create($all);
// 添加至队列
MakeVideo::dispatch($video);
}catch (\Exception $exception){
return $this->form()->response()->error($exception->getMessage());
}
return $this->form()->response()->refresh()->success(trans('admin.save_succeeded'));
}
}
......@@ -5,7 +5,7 @@ namespace App\Admin\Controllers;
use App\Admin\Renderable\PoemTable;
use App\Admin\Renderable\TemplateTable;
use App\Admin\Repositories\VideoShow;
use App\Models\OnePoem;
use App\Models\AdminMakeVideo;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
......@@ -63,30 +63,28 @@ class VideoShowController extends AdminController
*/
protected function form()
{
return Form::make(new VideoShow(), function (Form $form) {
return Form::make(new AdminMakeVideo(), function (Form $form) {
$form->display('id');
$form->selectTable('poem_id','选择一言')
->title('一言诗词库')
->from(PoemTable::make());
// $form->radio('type')->addElementClass('type')
// ->options([1=>'图文音频',2=>'视频'])->default(1);
$form->radio('type')
->options([1=>'视频', 2=>'图文音频'])
->when(1,function (Form $form){
$form->file('bg_url','上传视频')
$form->file('video_url','上传视频')
->accept('mp4')
->autoUpload()
->uniqueName()
->addElementClass('bg_video_url');
->maxSize('102400')
->addElementClass('video_url');
})
->when(2,function (Form $form){
$form->multipleImage('bg_url','上传图片')
$form->multipleImage('images_url','上传图片')
->limit(5)
->uniqueName()
->addElementClass('bg_img_url');
->addElementClass('images_url');
})
->default(1);
$form->radio('bg_music','背景音')
......@@ -96,23 +94,23 @@ class VideoShowController extends AdminController
->accept('mp3,aac,wav')
->autoUpload()
->uniqueName()
->addElementClass('bgm_url');
->addElementClass('bg_music');
})
->default(0);
$form->textarea('feel','有感');
$form->selectTable('poem_id','选择模板')
$form->selectTable('temp_id','选择模板')
->title('模板选择')
->from(TemplateTable::make());
$form->radio('thumbnail','封面')
->options([1=>'手动上传', 2=>'选择截屏'])
->options([1=>'手动上传', 2=>'自动截屏'])
->when(1,function (Form $form){
$form->multipleImage('bg_url','上传图片')
$form->multipleImage('thumbnail_url','上传图片')
->limit(5)
->uniqueName()
->addElementClass('bg_img_url');
->uniqueName();
// ->addElementClass('bg_img_url');
})
->when(2,function (Form $form){
$form->html('');
......@@ -123,4 +121,22 @@ class VideoShowController extends AdminController
$form->display('updated_at');
});
}
public function store()
{
$all = request()->all();
if (isset($all['upload_column'])) return $this->form()->store();
try{
$video = AdminMakeVideo::query()->create($all);
// todo 添加至队列
}catch (\Exception $exception){
return $this->form()->response()->error($exception->getMessage());
}
return $this->form()->response()->refresh()->success(trans('admin.save_succeeded'));
}
}
......
......@@ -171,33 +171,23 @@ class VideoTempController extends AdminController
$form->checkbox('components','组件')
->when('every_poem', function (Form\BlockForm $form) {
$form->select('pos_every_poem', '每日位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->select('pos_every_poem', '每日位置')->options(VideoTemp::POSITION_OPTIONS);
$form->divider();
})
->when('one_poem', function (Form\BlockForm $form) {
$form->select('pos_one_poem', '一言位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->select('pos_one_poem', '一言位置')->options(VideoTemp::POSITION_OPTIONS);
$form->divider();
})
->when('weather', function (Form\BlockForm $form) {
$form->select('pos_weather', '天气位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->select('pos_weather', '天气位置')->options(VideoTemp::POSITION_OPTIONS);
$form->divider();
})
->when('date', function (Form\BlockForm $form) {
$form->select('pos_date', '日期位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->select('pos_date', '日期位置')->options(VideoTemp::POSITION_OPTIONS);
$form->divider();
})
->when('feel', function (Form\BlockForm $form) {
$form->select('pos_feel', '有感位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->select('pos_feel', '有感位置')->options(VideoTemp::POSITION_OPTIONS);
$form->divider();
})
->default(['one_poem','weather','date'])
......@@ -228,7 +218,7 @@ class VideoTempController extends AdminController
public function store()
{
$all = \request()->all();
dd($all);
try{
DB::transaction(function ()use ($all){
$vide_temp = VideoTemp::query()->create([
......
<?php
namespace App\Admin\Repositories;
use App\Models\AdminMakeVideo as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class AdminMakeVideo extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}
......@@ -27,7 +27,7 @@ Route::group([
/** 临境*/
$router->group(['prefix'=>'/linjing'],function (Router $router){
$router->resource('/template', 'VideoTempController');
$router->resource('/official', 'VideoShowController');
$router->resource('/official', 'AdminMakeVideoController');
});
/** 订单*/
......
This diff is collapsed. Click to expand it.
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
class AdminMakeVideo extends Model
{
use HasDateTimeFormatter;
protected $table = 'admin_make_video';
protected $guarded = [''];
}
......@@ -51,6 +51,7 @@ class Order extends Model
public function timeoutCanceled()
{
$this->status = self::TIMEOUT_CANCEL;
$this->save();
}
}
\ No newline at end of file
......
......@@ -9,6 +9,13 @@ use Illuminate\Database\Eloquent\Model;
class VideoTemp extends Model
{
use HasDateTimeFormatter;
const POSITION_OPTIONS = [
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
'midLeft'=>'中左','midMiddle'=>'中中','midRight'=>'中右',
'botLeft'=>'下左','botMiddle'=>'下中','botRight'=>'下右',
];
protected $table = 'video_temp';
protected $guarded = [''];
......
......@@ -221,7 +221,7 @@ return [
'Queue' => Illuminate\Support\Facades\Queue::class,
'RateLimiter' => Illuminate\Support\Facades\RateLimiter::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
// 'Redis' => Illuminate\Support\Facades\Redis::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAdminMakeVideoTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_make_video', function (Blueprint $table) {
$table->increments('id');
$table->string('poem_id')->default('')->comment('一言id');
$table->unsignedTinyInteger('type')->comment('类型');
$table->string('video_url')->nullable()->comment('视频地址');
$table->string('images_url')->nullable()->comment('图片地址');
$table->unsignedTinyInteger('bg_music')->comment('是否背景音');
$table->string('bgm_url')->nullable()->comment('背景音地址');
$table->string('feel')->default('')->comment('有感');
$table->string('temp_id')->default('')->comment('模板id');
$table->unsignedTinyInteger('thumbnail')->comment('封面图');
$table->string('thumbnail_url')->nullable()->comment('封面图地址');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admin_make_video');
}
}