14 changed files with 3 additions and 624 deletions
-
96app/Admin/Controllers/GoodsTypeController.php
-
89app/Admin/Controllers/StoreTypeController.php
-
117app/Admin/Controllers/TypeCorrelationController.php
-
16app/Admin/Repositories/GoodsType.php
-
16app/Admin/Repositories/StoreType.php
-
8app/Admin/Repositories/StoreUserReport.php
-
16app/Admin/Repositories/TypeCorrelation.php
-
87app/Models/GoodsType.php
-
93app/Models/StoreType.php
-
25app/Models/TypeCorrelation.php
-
15app/Models/storeUserReport.php
-
17resources/lang/zh-CN/goods-type.php
-
15resources/lang/zh-CN/store-type.php
-
17resources/lang/zh-CN/type-correlation.php
@ -1,96 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Admin\Controllers; |
|
||||
|
|
||||
use App\Admin\Repositories\GoodsType; |
|
||||
use Dcat\Admin\Form; |
|
||||
use Dcat\Admin\Grid; |
|
||||
use Dcat\Admin\Show; |
|
||||
use Dcat\Admin\Controllers\AdminController; |
|
||||
use App\Models\StoreType as StoreTypeModel; |
|
||||
use App\Models\GoodsType as GoodsTypeModel; |
|
||||
|
|
||||
class GoodsTypeController extends AdminController |
|
||||
{ |
|
||||
/** |
|
||||
* Make a grid builder. |
|
||||
* |
|
||||
* @return Grid |
|
||||
*/ |
|
||||
protected function grid() |
|
||||
{ |
|
||||
return Grid::make(new GoodsType(), function (Grid $grid) { |
|
||||
$grid->id->sortable(); |
|
||||
$grid->cover_img->image('',50); |
|
||||
$grid->type_name; |
|
||||
$grid->store_type_id->display(function ($storeTypeId){ |
|
||||
$storeType = StoreTypeModel::getStoreTypeInfo($storeTypeId,'type_name'); |
|
||||
return empty($storeType) ? '' : $storeType->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) |
|
||||
{ |
|
||||
return Show::make($id, new GoodsType(), function (Show $show) { |
|
||||
$show->type_name->width(4); |
|
||||
$show->cover_img->image()->width(2); |
|
||||
$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() |
|
||||
{ |
|
||||
$builder = GoodsTypeModel::with('correlation'); |
|
||||
|
|
||||
return Form::make($builder, function (Form $form) { |
|
||||
$form->hidden('id'); |
|
||||
// 查询一级分类(店铺分类)
|
|
||||
$storeTypeList = StoreTypeModel::getStoreTypeArray(); |
|
||||
|
|
||||
// $form->select('store_type_id')->options($storeTypeList);
|
|
||||
$form->hasMany('correlation',function (Form\NestedForm $form) use($storeTypeList){ |
|
||||
$form->select('store_type_id')->options($storeTypeList); |
|
||||
$form->hidden('goods_type_id')->value($form->getKey()); |
|
||||
}); |
|
||||
|
|
||||
$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(); |
|
||||
|
|
||||
|
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,89 +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\GoodsType as GoodsTypeModel; |
|
||||
use App\Models\StoreType as StoreTypeModel; |
|
||||
|
|
||||
class StoreTypeController 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) |
|
||||
{ |
|
||||
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() |
|
||||
{ |
|
||||
$builder = StoreTypeModel::with('correlation'); |
|
||||
|
|
||||
return Form::make(new StoreType(), function (Form $form) { |
|
||||
$form->hidden('id'); |
|
||||
// 二级分类
|
|
||||
$goodsTypeList = GoodsTypeModel::getGoodsTypeArray(); |
|
||||
|
|
||||
$form->text('type_name')->required()->maxLength(20,'最多只能输入20个中文字'); |
|
||||
|
|
||||
/* uniqueName图片名称唯一,否则可能图片上传失败 */ |
|
||||
$form->image('cover_img')->required()->uniqueName(); |
|
||||
|
|
||||
//选择二级分类
|
|
||||
$form->hasMany('correlation',function (Form\NestedForm $form) { |
|
||||
$form->multipleSelect(); |
|
||||
}); |
|
||||
|
|
||||
$form->number('sort')->width(100); |
|
||||
|
|
||||
$form->disableResetButton(); |
|
||||
$form->disableViewCheck(); |
|
||||
$form->disableEditingCheck(); |
|
||||
$form->disableCreatingCheck(); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,117 +0,0 @@ |
|||||
<?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; |
|
||||
} |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Admin\Repositories; |
|
||||
|
|
||||
use App\Models\GoodsType as Model; |
|
||||
use Dcat\Admin\Repositories\EloquentRepository; |
|
||||
|
|
||||
class GoodsType extends EloquentRepository |
|
||||
{ |
|
||||
/** |
|
||||
* Model. |
|
||||
* |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $eloquentClass = Model::class; |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Admin\Repositories; |
|
||||
|
|
||||
use App\Models\StoreType as Model; |
|
||||
use Dcat\Admin\Repositories\EloquentRepository; |
|
||||
|
|
||||
class StoreType extends EloquentRepository |
|
||||
{ |
|
||||
/** |
|
||||
* Model. |
|
||||
* |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $eloquentClass = Model::class; |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
<?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; |
|
||||
} |
|
||||
@ -1,87 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Models; |
|
||||
|
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|
||||
use Illuminate\Database\Eloquent\SoftDeletes; |
|
||||
use Illuminate\Database\Eloquent\Model; |
|
||||
|
|
||||
class GoodsType extends Model |
|
||||
{ |
|
||||
use HasDateTimeFormatter; |
|
||||
use SoftDeletes; |
|
||||
|
|
||||
protected $table = 'lanzu_goods_type'; |
|
||||
protected $dateFormat = 'U'; |
|
||||
|
|
||||
protected $appends = [ |
|
||||
'cover_img_url', |
|
||||
'created_at_text', |
|
||||
'updated_at_text' |
|
||||
]; |
|
||||
|
|
||||
/** |
|
||||
* 关联关系 |
|
||||
*/ |
|
||||
public function correlation() |
|
||||
{ |
|
||||
return $this->hasMany(TypeCorrelation::class,'goods_type_id','id'); |
|
||||
} |
|
||||
|
|
||||
public function getCreatedAtTextAttribute($value) |
|
||||
{ |
|
||||
$value = $value ? $value : $this->created_at; |
|
||||
return $value; |
|
||||
// return date('Y-m-d H:i:s',$value);
|
|
||||
} |
|
||||
public function getUpdatedAtTextAttribute($value) |
|
||||
{ |
|
||||
$value = $value ? $value : $this->updated_at; |
|
||||
return $value; |
|
||||
// return date('Y-m-d H:i:s',$value);
|
|
||||
} |
|
||||
|
|
||||
public function getCoverImgUrlAttribute($value) |
|
||||
{ |
|
||||
$value = $value ? $value : $this->cover_img; |
|
||||
return $this->imageUrl($value); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取单个商品信息 |
|
||||
* @param int $id |
|
||||
* @param string $field |
|
||||
* @return string |
|
||||
*/ |
|
||||
public static function getGoodsInfo($id,$field = '*') |
|
||||
{ |
|
||||
return self::select($field)->find($id); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取二级分类数组 |
|
||||
* id为键,name为值 |
|
||||
* @return array |
|
||||
*/ |
|
||||
public static function getGoodsTypeArray() |
|
||||
{ |
|
||||
$list = self::select('id','type_name') |
|
||||
->where('status',1) |
|
||||
->whereNull('deleted_at') |
|
||||
->get(); |
|
||||
$array = []; |
|
||||
if(count($list) > 0){ |
|
||||
foreach ($list as $value) { |
|
||||
$array[$value->id] = $value->type_name; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $array; |
|
||||
} |
|
||||
|
|
||||
// 处理图片
|
|
||||
public function imageUrl($value) |
|
||||
{ |
|
||||
return env('OSS_IMG_HOST').'/'.$value; |
|
||||
} |
|
||||
} |
|
||||
@ -1,93 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Models; |
|
||||
|
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|
||||
use Illuminate\Database\Eloquent\SoftDeletes; |
|
||||
use Illuminate\Database\Eloquent\Model; |
|
||||
use phpDocumentor\Reflection\Project; |
|
||||
use App\Models\TypeCorrelation; |
|
||||
|
|
||||
class StoreType extends Model |
|
||||
{ |
|
||||
use HasDateTimeFormatter; |
|
||||
use SoftDeletes; |
|
||||
|
|
||||
protected $table = 'lanzu_store_type'; |
|
||||
protected $dateFormat = 'U'; |
|
||||
|
|
||||
protected $appends = [ |
|
||||
'cover_img_url', |
|
||||
'created_at_text', |
|
||||
'updated_at_text' |
|
||||
]; |
|
||||
|
|
||||
/** |
|
||||
* 关联关系 |
|
||||
*/ |
|
||||
public function correlation() |
|
||||
{ |
|
||||
return $this->hasMany(TypeCorrelation::class,'store_type_id','id'); |
|
||||
} |
|
||||
|
|
||||
public function getCreatedAtTextAttribute($value) |
|
||||
{ |
|
||||
$value = $value ? $value : $this->created_at; |
|
||||
return $value; |
|
||||
// return date('Y-m-d H:i:s',$value);
|
|
||||
} |
|
||||
public function getUpdatedAtTextAttribute($value) |
|
||||
{ |
|
||||
$value = $value ? $value : $this->updated_at; |
|
||||
return $value; |
|
||||
// return date('Y-m-d H:i:s',$value);
|
|
||||
} |
|
||||
|
|
||||
public function getCoverImgUrlAttribute($value) |
|
||||
{ |
|
||||
$value = $value ? $value : $this->cover_img; |
|
||||
return $this->imageUrl($value); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取单个一级分类信息 |
|
||||
* @param int $id |
|
||||
* @param string $field |
|
||||
* @return object |
|
||||
*/ |
|
||||
public static function getStoreTypeInfo($id,$field = '*') |
|
||||
{ |
|
||||
return self::select($field)->find($id); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取一级分类数组 |
|
||||
* id为键,name为值 |
|
||||
* @return array |
|
||||
*/ |
|
||||
public static function getStoreTypeArray() |
|
||||
{ |
|
||||
$list = self::select('id','type_name') |
|
||||
->where('status',1) |
|
||||
->whereNull('deleted_at') |
|
||||
->get(); |
|
||||
$array = []; |
|
||||
if(count($list) > 0){ |
|
||||
foreach ($list as $value) { |
|
||||
$array[$value->id] = $value->type_name; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $array; |
|
||||
} |
|
||||
|
|
||||
// 处理图片
|
|
||||
public function imageUrl($value) |
|
||||
{ |
|
||||
if(strripos($value,"http") === false){ |
|
||||
return env('OSS_IMG_HOST').'/'.$value; |
|
||||
}else{ |
|
||||
return $value; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,25 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Models; |
|
||||
|
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|
||||
use App\Models\Store as StoreModel; |
|
||||
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 = StoreModel::getStoreInfo($this->store_type_id,'name'); |
|
||||
return $store ? $store->name : ''; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Models; |
|
||||
|
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|
||||
|
|
||||
use Illuminate\Database\Eloquent\Model; |
|
||||
|
|
||||
class storeUserReport extends Model |
|
||||
{ |
|
||||
use HasDateTimeFormatter; |
|
||||
protected $table = 'ims_cjdc_store'; |
|
||||
public $timestamps = false; |
|
||||
|
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
<?php |
|
||||
return [ |
|
||||
'labels' => [ |
|
||||
'GoodsType' => '二级分类(商品)', |
|
||||
'goodsType' => '二级分类(商品)', |
|
||||
], |
|
||||
'fields' => [ |
|
||||
'type_name' => '分类名称', |
|
||||
'cover_img' => '封面图', |
|
||||
'cover_img_url' => '封面图', |
|
||||
'sort' => '排序', |
|
||||
'store_type_id' => '上级分类', |
|
||||
'correlation' =>'上级分类' |
|
||||
], |
|
||||
'options' => [ |
|
||||
], |
|
||||
]; |
|
||||
@ -1,15 +0,0 @@ |
|||||
<?php |
|
||||
return [ |
|
||||
'labels' => [ |
|
||||
'StoreType' => '一级分类(店铺)', |
|
||||
'storeType' => '一级分类(店铺)', |
|
||||
], |
|
||||
'fields' => [ |
|
||||
'type_name' => '分类名称', |
|
||||
'cover_img' => '封面图', |
|
||||
'cover_img_url' => '封面图', |
|
||||
'sort' => '排序' |
|
||||
], |
|
||||
'options' => [ |
|
||||
], |
|
||||
]; |
|
||||
@ -1,17 +0,0 @@ |
|||||
<?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