13 changed files with 257 additions and 28 deletions
-
4app/Admin/Controllers/v3/CategoryController.php
-
4app/Admin/Controllers/v3/CouponController.php
-
4app/Admin/Controllers/v3/GoodsActivityController.php
-
97app/Admin/Controllers/v3/GoodsCategoryController.php
-
42app/Admin/Controllers/v3/GoodsController.php
-
4app/Admin/Controllers/v3/StoreController.php
-
16app/Admin/Repositories/v3/GoodsCategory.php
-
4app/Admin/routes.php
-
4app/Models/v3/Category.php
-
51app/Models/v3/GoodsCategory.php
-
36database/migrations/2020_09_08_145454_create_lanzu_goods_category_table.php
-
16resources/lang/zh-CN/goods-category.php
-
3resources/lang/zh-CN/goods.php
@ -0,0 +1,97 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers\v3; |
||||
|
|
||||
|
use App\Admin\Repositories\v3\GoodsCategory; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use App\Models\v3\Category as CategoryModel; |
||||
|
use Symfony\Component\HttpFoundation\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use App\Models\v3\GoodsCategory as GoodsCategoryModel; |
||||
|
class GoodsCategoryController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new GoodsCategory(), function (Grid $grid) { |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('category_id')->display(function($categoryId){ |
||||
|
$item = CategoryModel::getInfo($categoryId,'title'); |
||||
|
return empty($item) ? '' : $item->title; |
||||
|
}); |
||||
|
$grid->column('title'); |
||||
|
$grid->column('cover_img')->image('',50); |
||||
|
$grid->column('sort'); |
||||
|
|
||||
|
$grid->model()->orderBy('id','desc'); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
|
||||
|
}); |
||||
|
$grid->disableBatchDelete(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new GoodsCategory(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('category_id')->as(function($categoryId){ |
||||
|
$item = CategoryModel::getInfo($categoryId,'title'); |
||||
|
return empty($item) ? '' : $item->title; |
||||
|
}); |
||||
|
$show->field('title'); |
||||
|
$show->field('cover_img')->image('',50); |
||||
|
$show->field('sort'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new GoodsCategory(), function (Form $form) { |
||||
|
$form->hidden('id'); |
||||
|
$category = CategoryModel::getArray([['parent_id','>',0]]); |
||||
|
$form->select('category_id')->width(4)->required()->options($category); |
||||
|
$form->text('title')->width(4)->required(); |
||||
|
$form->image('cover_img')->width(2); |
||||
|
$form->number('sort'); |
||||
|
|
||||
|
$form->disableResetButton(); |
||||
|
$form->disableViewCheck(); |
||||
|
$form->disableEditingCheck(); |
||||
|
$form->disableCreatingCheck(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取商品类目列表 |
||||
|
*/ |
||||
|
public function getList(Request $request) |
||||
|
{ |
||||
|
$categoryId = $request->get('q'); |
||||
|
$list = GoodsCategoryModel::where('category_id',$categoryId)->get(['id',DB::raw('title as text')]); |
||||
|
return $list; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories\v3; |
||||
|
|
||||
|
use App\Models\v3\GoodsCategory as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class GoodsCategory extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models\v3; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class GoodsCategory extends Model |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
use SoftDeletes; |
||||
|
|
||||
|
protected $table = 'lanzu_goods_category'; |
||||
|
protected $dateFormat = 'U'; |
||||
|
/* 查询记录数 limit */ |
||||
|
protected $perPage = 10; |
||||
|
|
||||
|
/** |
||||
|
* 获取单个信息 |
||||
|
* @param int $id |
||||
|
* @param string $field |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function getInfo($id,$field = '*') |
||||
|
{ |
||||
|
return self::select($field)->find($id); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取二级分类数组 |
||||
|
* id为键,title为值 |
||||
|
* @return array |
||||
|
*/ |
||||
|
public static function getArray($where = [],$options = []) |
||||
|
{ |
||||
|
$model = self::where('status',1) |
||||
|
->whereNull('deleted_at'); |
||||
|
|
||||
|
if(count($where) > 0){ |
||||
|
$model->where($where); |
||||
|
} |
||||
|
$list = $model->pluck('title','id')->toArray(); |
||||
|
if(!empty($options)){ |
||||
|
return array_merge($options,$list); |
||||
|
}else{ |
||||
|
return $list; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
use Illuminate\Database\Schema\Blueprint; |
||||
|
use Illuminate\Database\Migrations\Migration; |
||||
|
|
||||
|
class CreateLanzuGoodsCategoryTable extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* Run the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function up() |
||||
|
{ |
||||
|
Schema::create('lanzu_goods_category', function (Blueprint $table) { |
||||
|
$table->increments('id'); |
||||
|
$table->integer('category_id')->default('0')->nullable()->comment('分类'); |
||||
|
$table->string('title')->default('')->comment('分类名称'); |
||||
|
$table->string('cover_img')->nullable()->comment('封面图'); |
||||
|
$table->integer('sort')->default('0')->nullable()->comment('排序'); |
||||
|
$table->timestamps(); |
||||
|
$table->softDeletes(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Reverse the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
Schema::dropIfExists('lanzu_goods_category'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'GoodsCategory' => '商品类目', |
||||
|
'goodsCategory' => '商品类目', |
||||
|
'goods_category' => '商品类目', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'category_id' => '分类', |
||||
|
'title' => '名称', |
||||
|
'cover_img' => '封面图', |
||||
|
'sort' => '排序', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue