9 changed files with 258 additions and 82 deletions
-
80app/Admin/Controllers/TypeCorrelation.php
-
117app/Admin/Controllers/TypeCorrelationController.php
-
34app/Admin/Extensions/TypeCorrelationBind.php
-
16app/Admin/Repositories/TypeCorrelation.php
-
2app/Admin/routes.php
-
12app/Models/LanzuStore.php
-
30app/Models/TypeCorrelation.php
-
32database/migrations/2020_08_31_180258_create_lanzu_type_correlation_table.php
-
17resources/lang/zh-CN/type-correlation.php
@ -1,80 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers; |
|||
|
|||
use App\Admin\Repositories\StoreType; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Controllers\AdminController; |
|||
use App\Models\StoreType as StoreTypeModel; |
|||
|
|||
class TypeCorrelationController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new StoreType(), function (Grid $grid) { |
|||
$grid->id->sortable(); |
|||
$grid->cover_img->image('',50); |
|||
$grid->type_name; |
|||
$grid->sort->sortable(); |
|||
// 排序
|
|||
$grid->model()->orderBy('id', 'desc'); |
|||
|
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->like('type_name'); |
|||
}); |
|||
|
|||
// 每页10条
|
|||
$grid->paginate(10); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
// $s = StoreTypeModel::find(23);
|
|||
// dd($s->cover_img_url);
|
|||
return Show::make($id, new StoreType(), function (Show $show) { |
|||
$show->type_name->width(4); |
|||
$show->cover_img_url->image()->width(1); |
|||
$show->sort->width(1); |
|||
$show->created_at_text->width(2); |
|||
$show->updated_at_text->width(2); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new StoreType(), function (Form $form) { |
|||
$form->hidden('id'); |
|||
$form->text('type_name')->required()->maxLength(20,'最多只能输入20个中文字'); |
|||
|
|||
/* uniqueName图片名称唯一,否则可能图片上传失败 */ |
|||
$form->image('cover_img')->required()->uniqueName(); |
|||
|
|||
$form->number('sort')->width(100); |
|||
|
|||
$form->disableResetButton(); |
|||
$form->disableViewCheck(); |
|||
$form->disableEditingCheck(); |
|||
$form->disableCreatingCheck(); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,117 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers; |
|||
|
|||
use App\Admin\Repositories\TypeCorrelation; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Controllers\AdminController; |
|||
use App\Models\LanzuStore as StoreModel; |
|||
use App\Models\LanzuGoods as goods; |
|||
|
|||
class TypeCorrelationController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new TypeCorrelation(), function (Grid $grid) { |
|||
$grid->id->sortable(); |
|||
$grid->store_type_name; |
|||
$grid->goods_type_id; |
|||
|
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->equal('id'); |
|||
}); |
|||
|
|||
$grid->disableCreateButton(); |
|||
$grid->disableViewButton(); |
|||
$grid->disableEditButton(); |
|||
$grid->disableDeleteButton(); |
|||
$grid->disableBatchDelete(); |
|||
$grid->actions(function (Grid\Displayers\Actions $actions) { |
|||
// new TypeCorrelationBind()
|
|||
$id = $actions->getKey(); |
|||
$actions->append('<a href="/admin/typeCorrelation/'.$id.'/edit">绑定</a>'); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
return Show::make($id, new TypeCorrelation(), function (Show $show) { |
|||
$show->id; |
|||
$show->store_type_id; |
|||
$show->goods_type_id; |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new TypeCorrelation(), function (Form $form) { |
|||
$form->hidden('id'); |
|||
|
|||
if ($form->isEditing()) { |
|||
|
|||
} |
|||
$storeName = $this->createNames(); |
|||
$form->listbox('goods_ids', '商品分类')->options($storeName); |
|||
|
|||
$form->disableHeader(); |
|||
$form->disableResetButton(); |
|||
$form->disableViewCheck(); |
|||
$form->disableEditingCheck(); |
|||
$form->disableCreatingCheck(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 搜索获取店铺名称 |
|||
*/ |
|||
protected function searchStoreName() |
|||
{ |
|||
if (isset($this->storeName)) { |
|||
return $this->storeName; |
|||
} |
|||
$this->storeName = []; |
|||
$store = StoreModel::select('id','name')->where('name','like','')->get(); |
|||
|
|||
|
|||
return $this->storeName; |
|||
} |
|||
/** |
|||
* 生成随机数据 |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function createNames() |
|||
{ |
|||
if (isset($this->names)) { |
|||
return $this->names; |
|||
} |
|||
// $faker = Factory::create();
|
|||
$faker = ['胜多负少','sdsf','风格恢复']; |
|||
$this->names = []; |
|||
foreach ($faker as $key => $value) { |
|||
$name = $value; |
|||
$this->names[$name] = $name; |
|||
} |
|||
return $this->names; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?php |
|||
namespace App\Admin\Extensions; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
|
|||
class TypeCorrelationBind extends RowAction |
|||
{ |
|||
public function title() |
|||
{ |
|||
return '绑定'; |
|||
} |
|||
|
|||
/** |
|||
* 添加JS |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function script() |
|||
{ |
|||
return <<<JS |
|||
$('.type-bind-row').on('click', function () { |
|||
// Your code.
|
|||
window.location.href ='/admin/coupon/TieForm'; |
|||
}); |
|||
JS; |
|||
} |
|||
|
|||
public function html() |
|||
{ |
|||
$this->setHtmlAttribute(['class' => 'coupon-edit-row']); |
|||
return parent::html(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Repositories; |
|||
|
|||
use App\Models\TypeCorrelation as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class TypeCorrelation extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
use App\Models\LanzuStore; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class TypeCorrelation extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
protected $table = 'lanzu_type_correlation'; |
|||
public $timestamps = false; |
|||
|
|||
protected $appends = [ |
|||
'store_type_name' |
|||
]; |
|||
|
|||
public function getStoreTypeNameAttribute() |
|||
{ |
|||
$store = $this->getStoreInfo($this->store_type_id,'name'); |
|||
|
|||
return $store ? $store->name : ''; |
|||
} |
|||
|
|||
public function getStoreInfo($id,$field = '*') |
|||
{ |
|||
return LanzuStore::select($field)->find($id); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Support\Facades\Schema; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Database\Migrations\Migration; |
|||
|
|||
class CreateLanzuTypeCorrelationTable extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function up() |
|||
{ |
|||
Schema::create('lanzu_type_correlation', function (Blueprint $table) { |
|||
$table->increments('id'); |
|||
$table->integer('store_type_id')->default('0')->nullable()->comment('一级分类(店铺分类)'); |
|||
$table->integer('goods_type_id')->default('0')->nullable()->comment('二级分类(商品分类)'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function down() |
|||
{ |
|||
Schema::dropIfExists('lanzu_type_correlation'); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'TypeCorrelation' => '分类绑定', |
|||
'typeCorrelation' => '分类绑定', |
|||
'Edit' => '绑定', |
|||
'edit' => '绑定' |
|||
], |
|||
'fields' => [ |
|||
'store_type_id' => '一级分类(店铺)', |
|||
'store_type_name' => '一级分类(店铺)', |
|||
'goods_type_id' => '二级分类(商品)', |
|||
'goods_type_name' => '二级分类(商品)', |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue