13 changed files with 694 additions and 212 deletions
-
6app/Admin/Controllers/v3/CategoryController.php
-
195app/Admin/Controllers/v3/GoodsActivityController.php
-
4app/Admin/Controllers/v3/GoodsController.php
-
5app/Admin/Forms/CategoryTieForm.php
-
16app/Admin/Repositories/v3/GoodsActivity.php
-
1app/Admin/routes.php
-
90app/Models/v3/GoodsActivity.php
-
18app/Models/v3/GoodsActivityBanners.php
-
2database/migrations/2020_09_01_095556_create_lanzu_goods_table.php
-
58database/migrations/2020_09_05_151852_create_lanzu_goods_activity_table.php
-
460dcat_admin_ide_helper.php
-
44resources/lang/zh-CN/goods-activity.php
-
5resources/lang/zh-CN/goods.php
@ -0,0 +1,195 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers\v3; |
||||
|
|
||||
|
use App\Admin\Repositories\v3\GoodsActivity; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
use App\Models\v3\Category as CategoryModel; |
||||
|
use App\Models\v3\GoodsActivity as GoodsActivityModel; |
||||
|
use Dcat\Admin\Form\NestedForm; |
||||
|
|
||||
|
class GoodsActivityController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new GoodsActivity(), function (Grid $grid) { |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('cover_img')->image('',50); |
||||
|
$grid->column('name'); |
||||
|
$grid->column('price'); |
||||
|
$grid->column('type_text'); |
||||
|
|
||||
|
$grid->column('market_id')->display(function($marketId){ |
||||
|
$item = MarketModel::getMarketInfo($marketId,'name'); |
||||
|
return empty($item) ? '' : $item->name; |
||||
|
}); |
||||
|
$grid->column('store_id')->display(function($storeId){ |
||||
|
$item = StoreModel::getStoreInfo($storeId,'name'); |
||||
|
return empty($item) ? '' : $item->name; |
||||
|
}); |
||||
|
$grid->column('category_id')->display(function($categoryId){ |
||||
|
$item = CategoryModel::getCategoryInfo($categoryId,'title'); |
||||
|
return empty($item) ? '' : $item->title; |
||||
|
}); |
||||
|
|
||||
|
$grid->column('expire_time_text'); |
||||
|
$grid->column('sort'); |
||||
|
$grid->column('on_sale')->switch(); |
||||
|
$grid->model()->orderby('id','desc'); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
|
||||
|
}); |
||||
|
// 每页10条
|
||||
|
$grid->paginate(10); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new GoodsActivity(), function (Show $show) { |
||||
|
$show->row(function (Show\Row $show) { |
||||
|
$show->width(6)->field('id'); |
||||
|
$show->width(6)->field('name'); |
||||
|
$show->width(6)->field('cover_img')->image(); |
||||
|
$show->width(6)->field('goods_unit'); |
||||
|
$show->width(6)->field('price'); |
||||
|
$show->width(6)->field('original_price'); |
||||
|
$show->width(6)->field('vip_price'); |
||||
|
$show->width(6)->field('start_num'); |
||||
|
$show->width(6)->field('restrict_num'); |
||||
|
$show->width(6)->field('is_infinite'); |
||||
|
$show->width(6)->field('inventory'); |
||||
|
$show->width(6)->field('type_text'); |
||||
|
$show->width(6)->field('goods_id'); |
||||
|
$show->width(6)->field('market_id'); |
||||
|
$show->width(6)->field('store_id'); |
||||
|
$show->width(6)->field('category_id'); |
||||
|
$show->width(6)->field('on_sale'); |
||||
|
$show->width(6)->field('sort'); |
||||
|
}); |
||||
|
$show->row(function (Show\Row $show) { |
||||
|
$show->width(6)->field('content'); |
||||
|
$show->width(6)->field('expire_time_text'); |
||||
|
$show->width(6)->field('time_limit_days'); |
||||
|
$show->width(6)->field('time_limit_num'); |
||||
|
$show->width(6)->field('can_use_coupon_text'); |
||||
|
$show->width(6)->field('tags')->as(function ($value){ |
||||
|
return $value; |
||||
|
}); |
||||
|
|
||||
|
$show->width(6)->field('spec')->as(function ($value){ |
||||
|
$text = ''; |
||||
|
foreach ($value as $v){ |
||||
|
$text .= '【'.$v['spec_key'] .':'.$v['spec_value'].'】 '; |
||||
|
} |
||||
|
return $text; |
||||
|
}); |
||||
|
// $show->width(6)->field('details_imgs');
|
||||
|
$show->width(6)->field('remark'); |
||||
|
|
||||
|
$show->width(6)->field('created_at'); |
||||
|
$show->width(6)->field('updated_at'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
$builder = GoodsActivityModel::with(['ImageBanners','VideoBanners']); |
||||
|
return Form::make($builder, function (Form $form) { |
||||
|
$form->hidden('id'); |
||||
|
|
||||
|
// 二级分类
|
||||
|
$categoryList = CategoryModel::getCategoryArray([['parent_id','>',0]]); |
||||
|
// 店铺
|
||||
|
$storeList = StoreModel::getStoreArray(); |
||||
|
//市场
|
||||
|
$marketList = MarketModel::getMarket(); |
||||
|
|
||||
|
$form->column(6, function (Form $form) use($marketList,$storeList,$categoryList ){ |
||||
|
$form->text('goods_id'); |
||||
|
$form->select('market_id')->required()->options($marketList); |
||||
|
$form->select('category_id')->required()->options($categoryList); |
||||
|
$form->select('store_id')->required()->options($storeList); |
||||
|
$form->text('name')->required()->maxLength(20); |
||||
|
$form->image('cover_img')->required(); |
||||
|
$form->select('type')->options(GoodsActivityModel::$_type)->default('flash_sale'); |
||||
|
$form->datetime('expire_time')->value($form->model()->expire_time_text); |
||||
|
$form->number('time_limit_days'); |
||||
|
|
||||
|
}); |
||||
|
$form->column(6, function (Form $form) { |
||||
|
$form->currency('price')->required()->floatTwo()->symbol('¥'); |
||||
|
$form->currency('original_price')->required()->floatTwo()->symbol('¥'); |
||||
|
$form->currency('vip_price')->required()->floatTwo()->symbol('¥'); |
||||
|
$form->text('goods_unit')->help('如:斤,个,盒,500克,1000克,1500克等'); |
||||
|
$form->radio('is_infinite')->options(['关闭','开启'])->default(1); |
||||
|
$form->number('inventory')->required()->attribute('min', 1)->default(1); |
||||
|
$form->number('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购'); |
||||
|
$form->number('start_num')->attribute('min', 1)->default(1); |
||||
|
$form->number('time_limit_num'); |
||||
|
$form->switch('can_use_coupon'); |
||||
|
}); |
||||
|
$form->column(12, function (Form $form) { |
||||
|
$form->hasMany('image_banners', function (Form\NestedForm $form) { |
||||
|
$form->image('path')->width(2); |
||||
|
$form->number('sort')->width(2)->default(0); |
||||
|
$form->hidden('type')->value(1)->default(1); |
||||
|
})->required(); |
||||
|
$form->divider(); |
||||
|
$form->hasMany('video_banners', function (Form\NestedForm $form) { |
||||
|
$form->file('path')->width(2); |
||||
|
$form->number('sort')->width(2)->default(0); |
||||
|
$form->hidden('type')->value(2)->default(2); |
||||
|
}); |
||||
|
$form->divider(); |
||||
|
|
||||
|
$form->multipleImage('details_imgs')->help('按图片顺序上传'); |
||||
|
$form->text('content')->maxLength(50); |
||||
|
$form->text('remark')->maxLength(50); |
||||
|
|
||||
|
$form->tags('tags','标签')->options(['新品','热销','新鲜']); |
||||
|
$form->table('spec', function (NestedForm $table) { |
||||
|
$table->text('spec_key')->help('如:净含量:500克,保质期:120天,包装:12个/盒等'); |
||||
|
$table->text('spec_value'); |
||||
|
}); |
||||
|
$form->switch('on_sale') |
||||
|
->customFormat(function ($v) { |
||||
|
return $v == '上架' ? 1 : 0; |
||||
|
}) |
||||
|
->saving(function ($v) { |
||||
|
return $v; |
||||
|
}); |
||||
|
|
||||
|
$form->disableResetButton(); |
||||
|
$form->disableViewCheck(); |
||||
|
$form->disableEditingCheck(); |
||||
|
$form->disableCreatingCheck(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories\v3; |
||||
|
|
||||
|
use App\Models\v3\GoodsActivity as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class GoodsActivity extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models\v3; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class GoodsActivity extends Model |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
use SoftDeletes; |
||||
|
|
||||
|
protected $table = 'lanzu_goods_activity'; |
||||
|
protected $dateFormat = 'U'; |
||||
|
protected $appends = [ |
||||
|
'cover_img_url', |
||||
|
'on_sale_text', |
||||
|
'is_infinite_text', |
||||
|
'can_use_coupon_text', |
||||
|
'expire_time_text' |
||||
|
]; |
||||
|
|
||||
|
protected $casts = [ |
||||
|
'details_imgs'=>'array', |
||||
|
'tags'=>'array', |
||||
|
'spec'=>'array', |
||||
|
]; |
||||
|
|
||||
|
public static $_type = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品']; |
||||
|
public static $_onSale = ['否','是']; |
||||
|
public static $_isInfinite = ['关闭','开启']; |
||||
|
public static $_canUseCoupon = ['否','是']; |
||||
|
|
||||
|
public function getCoverImgUrlAttribute($value) |
||||
|
{ |
||||
|
$value = $value ? $value : $this->cover_img; |
||||
|
return $this->imageUrl($value); |
||||
|
} |
||||
|
public function getTypeTextAttribute($value) |
||||
|
{ |
||||
|
$value = $value ? $value : $this->type; |
||||
|
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; |
||||
|
} |
||||
|
public function getOnSaleTextAttribute($value) |
||||
|
{ |
||||
|
$value = $value ? $value : $this->on_sale; |
||||
|
return isset(self::$_onSale[$value]) ? self::$_onSale[$value] : ''; |
||||
|
} |
||||
|
public function getIsInfiniteTextAttribute($value) |
||||
|
{ |
||||
|
$value = $value ? $value : $this->is_infinite; |
||||
|
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; |
||||
|
} |
||||
|
public function getCanUseCouponTextAttribute($value) |
||||
|
{ |
||||
|
$value = $value ? $value : $this->can_use_coupon; |
||||
|
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; |
||||
|
} |
||||
|
public function getExpireTimeTextAttribute() |
||||
|
{ |
||||
|
$value = $this->expire_time; |
||||
|
return empty($value) ? '' : date('Y-m-d H:i:s',$value); |
||||
|
} |
||||
|
public function ImageBanners(){ |
||||
|
return $this->hasMany('\App\Models\v3\GoodsActivityBanners','goods_id','id')->where('type',1); |
||||
|
} |
||||
|
|
||||
|
public function VideoBanners(){ |
||||
|
return $this->hasMany('\App\Models\v3\GoodsActivityBanners','goods_id','id')->where('type',2); |
||||
|
} |
||||
|
|
||||
|
public function setExpireTimeAttribute($value){ |
||||
|
$this->attributes['expire_time'] = strtotime($value); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理旧图片 |
||||
|
* @param $value |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function imageUrl($value) |
||||
|
{ |
||||
|
if(strripos($value,"http") === false){ |
||||
|
return env('OSS_IMG_HOST').'/'.$value; |
||||
|
}else{ |
||||
|
return $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models\v3; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class GoodsActivityBanners extends Model |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
use SoftDeletes; |
||||
|
|
||||
|
protected $table = 'lanzu_goods_activity_banners'; |
||||
|
protected $dateFormat = 'U'; |
||||
|
protected $fillable = ['path', 'id', 'goods_id','type','url']; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
use Illuminate\Database\Schema\Blueprint; |
||||
|
use Illuminate\Database\Migrations\Migration; |
||||
|
|
||||
|
class CreateLanzuGoodsActivityTable extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* Run the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function up() |
||||
|
{ |
||||
|
Schema::create('lanzu_goods_activity', function (Blueprint $table) { |
||||
|
$table->increments('id'); |
||||
|
$table->enum('type')->default('flash_sale')->nullable()->comment('活动类型'); |
||||
|
$table->bigInteger('goods_id')->nullable()->comment('原始商品'); |
||||
|
$table->integer('market_id')->comment('市场'); |
||||
|
$table->bigInteger('store_id')->default('0')->comment('商家'); |
||||
|
$table->integer('category_id')->default('0')->comment('分类'); |
||||
|
$table->tinyInteger('on_sale')->default('1')->comment('是否上架'); |
||||
|
$table->integer('sort')->default('0')->comment('排序'); |
||||
|
$table->decimal('price')->comment('售价'); |
||||
|
$table->decimal('original_price')->comment('原价'); |
||||
|
$table->decimal('vip_price')->comment('会员价'); |
||||
|
$table->integer('start_num')->default('1')->comment('起售份数'); |
||||
|
$table->integer('restrict_num')->default('0')->comment('限购份数'); |
||||
|
$table->tinyInteger('is_infinite')->default('1')->comment('是否开启无限库存'); |
||||
|
$table->integer('inventory')->default('0')->comment('库存'); |
||||
|
$table->string('name')->default('')->comment('商品名称'); |
||||
|
$table->string('cover_img')->nullable()->comment('封面图'); |
||||
|
$table->string('goods_unit')->nullable()->comment('商品单位'); |
||||
|
$table->json('tags')->nullable()->comment('标签'); |
||||
|
$table->json('details_imgs')->nullable()->comment('商品详情图片'); |
||||
|
$table->json('spec')->nullable()->comment('规格'); |
||||
|
$table->string('content')->nullable()->comment('简介'); |
||||
|
$table->string('remark')->nullable()->comment('备注'); |
||||
|
$table->integer('expire_time')->default('0')->nullable()->comment('活动结束时间时间戳'); |
||||
|
$table->integer('time_limit_days')->default('1')->nullable()->comment('限制的天数'); |
||||
|
$table->integer('time_limit_num')->default('1')->nullable()->comment('某天数下购买的数量'); |
||||
|
$table->tinyInteger('can_use_coupon')->default('0')->nullable()->comment('是否可以使用优惠券'); |
||||
|
$table->timestamps(); |
||||
|
$table->softDeletes(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Reverse the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
Schema::dropIfExists('lanzu_goods_activity'); |
||||
|
} |
||||
|
} |
||||
460
dcat_admin_ide_helper.php
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'GoodsActivity' => '活动商品', |
||||
|
'goodsActivity' => '活动商品', |
||||
|
'goods_activity' => '活动商品', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'type' => '活动类型', |
||||
|
'type_text' => '活动类型', |
||||
|
'goods_id' => '原始商品', |
||||
|
'market_id' => '市场', |
||||
|
'store_id' => '商家', |
||||
|
'category_id' => '分类', |
||||
|
'on_sale' => '是否上架', |
||||
|
'sort' => '排序', |
||||
|
'price' => '售价', |
||||
|
'original_price' => '原价', |
||||
|
'vip_price' => '会员价', |
||||
|
'start_num' => '起售份数', |
||||
|
'restrict_num' => '限购份数', |
||||
|
'is_infinite' => '是否开启无限库存', |
||||
|
'inventory' => '库存', |
||||
|
'name' => '商品名称', |
||||
|
'cover_img' => '封面图', |
||||
|
'goods_unit' => '商品单位', |
||||
|
'tags' => '标签', |
||||
|
'details_imgs' => '商品详情图片', |
||||
|
'spec' => '规格', |
||||
|
'content' => '简介', |
||||
|
'remark' => '备注', |
||||
|
'expire_time' => '活动结束时间', |
||||
|
'time_limit_days' => '限制的天数', |
||||
|
'time_limit_num' => '限制购买数量', |
||||
|
'can_use_coupon' => '可同时使用优惠券', |
||||
|
'can_use_coupon_text' => '可同时使用优惠券', |
||||
|
'image_banners' => '轮播图片', |
||||
|
'video_banners' => '轮播视频', |
||||
|
'spec_key' =>'规格名称', |
||||
|
'spec_value' => '规格参数', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue