9 changed files with 222 additions and 53 deletions
-
133app/AdminAgent/Controllers/SpecialController.php
-
3app/AdminAgent/Renderable/SelectAgentProduct.php
-
16app/AdminAgent/Repositories/Special.php
-
1app/AdminAgent/routes.php
-
12app/Http/Controllers/Api/IndexController.php
-
6app/Http/Controllers/Api/SpecialController.php
-
20app/Models/Special.php
-
68dcat_admin_ide_helper.php
-
16resources/lang/zh_CN/special.php
@ -0,0 +1,133 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Controllers; |
||||
|
|
||||
|
use App\AdminAgent\Renderable\SelectAgentProduct; |
||||
|
use App\AdminAgent\Repositories\Special; |
||||
|
use App\Models\AgentProduct; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Illuminate\Support\Facades\Storage; |
||||
|
|
||||
|
class SpecialController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Special(), function (Grid $grid) { |
||||
|
$grid->disableFilterButton(); |
||||
|
|
||||
|
$grid->model()->where('agent_id', Admin::user()->id); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('picture_ad')->image('', 60, 60); |
||||
|
$grid->column('agent_product_id', '专题产品') |
||||
|
->display('查看') |
||||
|
->modal(function ($modal) use ($grid) { |
||||
|
$data = AgentProduct::with('product:id,title,pictures') |
||||
|
->whereIn('id', $this->agent_product_id) |
||||
|
->get(['id', 'product_id', 'sale', 'stock']); |
||||
|
$result = []; |
||||
|
$prefix = Storage::disk('public')->url(''); |
||||
|
foreach ($data as $k => $v) { |
||||
|
$result[] = [ |
||||
|
$v->id, |
||||
|
$v->product->title, |
||||
|
'<img data-action="preview-img" src="'.$prefix.$v->product->picture.'" style="max-width:60px;max-height:60px;cursor:pointer" class="img img-thumbnail">', |
||||
|
$v->sale, |
||||
|
$v->stock, |
||||
|
]; |
||||
|
} |
||||
|
return Table::make(['产品ID', '标题', '图片', '销量', '库存'], $result); |
||||
|
}); |
||||
|
$grid->column('sort'); |
||||
|
$grid->column('created_at'); |
||||
|
$grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->panel(); |
||||
|
|
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Special(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('picture_ad')->image('', 80, 80); |
||||
|
$show->field('picture')->image('', 80, 80); |
||||
|
$show->field('agent_product_id', '产品') |
||||
|
->unescape() |
||||
|
->as(function ($v) { |
||||
|
$data = AgentProduct::with('product:id,title') |
||||
|
->whereIn('id', $v) |
||||
|
->orderBy('id')->get(['id', 'product_id']); |
||||
|
return join("<br>", $data->map(fn($v) => $v->product->title)->toArray()); |
||||
|
}); |
||||
|
$show->field('sort'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Special(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->image('picture_ad') |
||||
|
->required()->removable(false)->uniqueName() |
||||
|
->help('图片大小:750*230'); |
||||
|
$form->multipleImage('picture') |
||||
|
->required()->removable(false)->uniqueName() |
||||
|
->help('图片大小:750*490'); |
||||
|
$form->multipleSelectTable('agent_product_id') |
||||
|
->title('选择在售产品')->required() |
||||
|
->dialogWidth('80%;min-width:825px;') |
||||
|
->from(SelectAgentProduct::make()) |
||||
|
->options(function ($v) { |
||||
|
if (!$v) return []; |
||||
|
$agent_product = AgentProduct::with('product:id,title') |
||||
|
->select(['id', 'product_id']) |
||||
|
->whereIn('id', $v) |
||||
|
->orderBy('id')->get(); |
||||
|
$result = []; |
||||
|
foreach ($agent_product as $v) { |
||||
|
$result[$v->id] = $v->product->title ?? ''; |
||||
|
} |
||||
|
return $result; |
||||
|
}) |
||||
|
->pluck('product.title') |
||||
|
->value(join(',', $form->model()->agent_product_id ?? [])); |
||||
|
$form->text('sort')->default(255); |
||||
|
})->saving(function (Form $form) { |
||||
|
//处理特殊字段
|
||||
|
$form->hidden(['agent_id', 'created_at', 'updated_at']); |
||||
|
$form->agent_id = Admin::user()->id; |
||||
|
|
||||
|
//不允许编辑的字段
|
||||
|
$form->ignore(['id', 'agent_id', 'created_at', 'updated_at']); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Repositories; |
||||
|
|
||||
|
use App\Models\Special as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class Special extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'Special' => '专题', |
||||
|
'special' => '专题', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'agent_id' => '代理商ID', |
||||
|
'picture' => '专题页轮播图', |
||||
|
'picture_ad' => '首页广告图', |
||||
|
'agent_product_id' => '产品ID', |
||||
|
'sort' => '排序', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue