添加后台赠品管理
parent
c89644a051
commit
63b58ccd93
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\SkuGift as SkuGiftForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class SkuGift extends RowAction
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-package grid-action-icon"></i>';
|
||||
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title.' '.__('admin_message.actions.grid.sku_gift');
|
||||
}
|
||||
|
||||
return __('admin_message.actions.grid.sku_gift');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.product_skus.gift');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = SkuGiftForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\ProductGift;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
|
||||
class ProductGiftController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(new ProductGift(), function (Grid $grid) {
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('sku_id');
|
||||
$grid->column('gift_sku_id');
|
||||
$grid->column('num');
|
||||
$grid->column('sent');
|
||||
$grid->column('created_at');
|
||||
$grid->column('updated_at')->sortable();
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->equal('id');
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return Show::make($id, new ProductGift(), function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('sku_id');
|
||||
$show->field('gift_sku_id');
|
||||
$show->field('num');
|
||||
$show->field('sent');
|
||||
$show->field('created_at');
|
||||
$show->field('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new ProductGift(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('sku_id');
|
||||
$form->text('gift_sku_id');
|
||||
$form->text('num');
|
||||
$form->text('sent');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Models\ProductGift;
|
||||
use App\Models\ProductSku;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Form\NestedForm;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class SkuGift extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$giftSkuIds = [];
|
||||
$giftSku = [];
|
||||
$delGiftIds = [];
|
||||
foreach ($input['gifts'] as $gift) {
|
||||
if ($gift['_remove_'] == 1) {
|
||||
$delGiftIds[] = $gift['id'];
|
||||
} else {
|
||||
$giftSku[] = new ProductGift($gift);
|
||||
}
|
||||
}
|
||||
$skuId = $input['sku_id'];
|
||||
$sku = ProductSku::findOrFail($skuId);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$sku->gifts()->saveMany($giftSku);
|
||||
|
||||
ProductGift::whereIn('id', $delGiftIds)->delete();
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
$sku = ProductSku::with('gifts')->findOrFail($id);
|
||||
|
||||
$this->hasMany('gifts', function (NestedForm $form) {
|
||||
$form->select('gift_sku_id')->options(function ($id) {
|
||||
$sku = ProductSku::find($id);
|
||||
if ($sku) {
|
||||
return [$sku->id => $sku->name];
|
||||
}
|
||||
})->ajax(admin_route('api.product_skus'))->required();
|
||||
$form->number('num')->default(1);
|
||||
$form->number('limit')->default(0);
|
||||
})->customFormat(function () use ($sku) {
|
||||
return $sku->gifts;
|
||||
});
|
||||
$this->hidden('sku_id')->value($id);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Admin\Renderable;
|
|||
use App\Admin\Actions\Grid\ReleaseCancel;
|
||||
use App\Admin\Actions\Grid\ReleaseDown;
|
||||
use App\Admin\Actions\Grid\ReleaseUp;
|
||||
use App\Admin\Actions\Grid\SkuGift;
|
||||
use App\Admin\Actions\Grid\SkuSyncSpu;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\AddSku;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseCancel;
|
||||
|
|
@ -86,6 +87,7 @@ class ProductSkuTable extends Grid
|
|||
$actions->append(new ReleaseDown());
|
||||
}
|
||||
}
|
||||
$actions->append(new SkuGift());
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\ProductGift as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class ProductGift extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductGift extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'sku_id',
|
||||
'gift_sku_id',
|
||||
'num',
|
||||
'sent',
|
||||
];
|
||||
}
|
||||
|
|
@ -116,4 +116,14 @@ class ProductSku extends Model
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 此商品的赠品
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function gifts()
|
||||
{
|
||||
return $this->hasMany(ProductGift::class, 'sku_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProductGiftsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('product_gifts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('sku_id')->comment('主SKU商品ID');
|
||||
$table->unsignedBigInteger('gift_sku_id')->comment('赠品SKU商品ID');
|
||||
$table->unsignedInteger('num')->default(0)->comment('赠送数量');
|
||||
$table->unsignedInteger('limit')->default(0)->comment('上限数量');
|
||||
$table->unsignedInteger('sent')->default(0)->comment('已送数量');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('product_gifts');
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,14 @@ namespace Dcat\Admin {
|
|||
* @property Grid\Column|Collection is_show
|
||||
* @property Grid\Column|Collection created_at
|
||||
* @property Grid\Column|Collection updated_at
|
||||
* @property Grid\Column|Collection user_id
|
||||
* @property Grid\Column|Collection consignee
|
||||
* @property Grid\Column|Collection telephone
|
||||
* @property Grid\Column|Collection province
|
||||
* @property Grid\Column|Collection city
|
||||
* @property Grid\Column|Collection district
|
||||
* @property Grid\Column|Collection address
|
||||
* @property Grid\Column|Collection is_default
|
||||
* @property Grid\Column|Collection type
|
||||
* @property Grid\Column|Collection version
|
||||
* @property Grid\Column|Collection detail
|
||||
|
|
@ -33,7 +41,6 @@ namespace Dcat\Admin {
|
|||
* @property Grid\Column|Collection http_method
|
||||
* @property Grid\Column|Collection http_path
|
||||
* @property Grid\Column|Collection role_id
|
||||
* @property Grid\Column|Collection user_id
|
||||
* @property Grid\Column|Collection value
|
||||
* @property Grid\Column|Collection username
|
||||
* @property Grid\Column|Collection password
|
||||
|
|
@ -64,10 +71,13 @@ namespace Dcat\Admin {
|
|||
* @property Grid\Column|Collection abilities
|
||||
* @property Grid\Column|Collection last_used_at
|
||||
* @property Grid\Column|Collection remarks
|
||||
* @property Grid\Column|Collection sku_id
|
||||
* @property Grid\Column|Collection gift_sku_id
|
||||
* @property Grid\Column|Collection num
|
||||
* @property Grid\Column|Collection sent
|
||||
* @property Grid\Column|Collection attrs
|
||||
* @property Grid\Column|Collection specs
|
||||
* @property Grid\Column|Collection part_id
|
||||
* @property Grid\Column|Collection sku_id
|
||||
* @property Grid\Column|Collection spu_id
|
||||
* @property Grid\Column|Collection status
|
||||
* @property Grid\Column|Collection images
|
||||
|
|
@ -111,6 +121,14 @@ namespace Dcat\Admin {
|
|||
* @method Grid\Column|Collection is_show(string $label = null)
|
||||
* @method Grid\Column|Collection created_at(string $label = null)
|
||||
* @method Grid\Column|Collection updated_at(string $label = null)
|
||||
* @method Grid\Column|Collection user_id(string $label = null)
|
||||
* @method Grid\Column|Collection consignee(string $label = null)
|
||||
* @method Grid\Column|Collection telephone(string $label = null)
|
||||
* @method Grid\Column|Collection province(string $label = null)
|
||||
* @method Grid\Column|Collection city(string $label = null)
|
||||
* @method Grid\Column|Collection district(string $label = null)
|
||||
* @method Grid\Column|Collection address(string $label = null)
|
||||
* @method Grid\Column|Collection is_default(string $label = null)
|
||||
* @method Grid\Column|Collection type(string $label = null)
|
||||
* @method Grid\Column|Collection version(string $label = null)
|
||||
* @method Grid\Column|Collection detail(string $label = null)
|
||||
|
|
@ -126,7 +144,6 @@ namespace Dcat\Admin {
|
|||
* @method Grid\Column|Collection http_method(string $label = null)
|
||||
* @method Grid\Column|Collection http_path(string $label = null)
|
||||
* @method Grid\Column|Collection role_id(string $label = null)
|
||||
* @method Grid\Column|Collection user_id(string $label = null)
|
||||
* @method Grid\Column|Collection value(string $label = null)
|
||||
* @method Grid\Column|Collection username(string $label = null)
|
||||
* @method Grid\Column|Collection password(string $label = null)
|
||||
|
|
@ -157,10 +174,13 @@ namespace Dcat\Admin {
|
|||
* @method Grid\Column|Collection abilities(string $label = null)
|
||||
* @method Grid\Column|Collection last_used_at(string $label = null)
|
||||
* @method Grid\Column|Collection remarks(string $label = null)
|
||||
* @method Grid\Column|Collection sku_id(string $label = null)
|
||||
* @method Grid\Column|Collection gift_sku_id(string $label = null)
|
||||
* @method Grid\Column|Collection num(string $label = null)
|
||||
* @method Grid\Column|Collection sent(string $label = null)
|
||||
* @method Grid\Column|Collection attrs(string $label = null)
|
||||
* @method Grid\Column|Collection specs(string $label = null)
|
||||
* @method Grid\Column|Collection part_id(string $label = null)
|
||||
* @method Grid\Column|Collection sku_id(string $label = null)
|
||||
* @method Grid\Column|Collection spu_id(string $label = null)
|
||||
* @method Grid\Column|Collection status(string $label = null)
|
||||
* @method Grid\Column|Collection images(string $label = null)
|
||||
|
|
@ -209,6 +229,14 @@ namespace Dcat\Admin {
|
|||
* @property Show\Field|Collection is_show
|
||||
* @property Show\Field|Collection created_at
|
||||
* @property Show\Field|Collection updated_at
|
||||
* @property Show\Field|Collection user_id
|
||||
* @property Show\Field|Collection consignee
|
||||
* @property Show\Field|Collection telephone
|
||||
* @property Show\Field|Collection province
|
||||
* @property Show\Field|Collection city
|
||||
* @property Show\Field|Collection district
|
||||
* @property Show\Field|Collection address
|
||||
* @property Show\Field|Collection is_default
|
||||
* @property Show\Field|Collection type
|
||||
* @property Show\Field|Collection version
|
||||
* @property Show\Field|Collection detail
|
||||
|
|
@ -224,7 +252,6 @@ namespace Dcat\Admin {
|
|||
* @property Show\Field|Collection http_method
|
||||
* @property Show\Field|Collection http_path
|
||||
* @property Show\Field|Collection role_id
|
||||
* @property Show\Field|Collection user_id
|
||||
* @property Show\Field|Collection value
|
||||
* @property Show\Field|Collection username
|
||||
* @property Show\Field|Collection password
|
||||
|
|
@ -255,10 +282,13 @@ namespace Dcat\Admin {
|
|||
* @property Show\Field|Collection abilities
|
||||
* @property Show\Field|Collection last_used_at
|
||||
* @property Show\Field|Collection remarks
|
||||
* @property Show\Field|Collection sku_id
|
||||
* @property Show\Field|Collection gift_sku_id
|
||||
* @property Show\Field|Collection num
|
||||
* @property Show\Field|Collection sent
|
||||
* @property Show\Field|Collection attrs
|
||||
* @property Show\Field|Collection specs
|
||||
* @property Show\Field|Collection part_id
|
||||
* @property Show\Field|Collection sku_id
|
||||
* @property Show\Field|Collection spu_id
|
||||
* @property Show\Field|Collection status
|
||||
* @property Show\Field|Collection images
|
||||
|
|
@ -302,6 +332,14 @@ namespace Dcat\Admin {
|
|||
* @method Show\Field|Collection is_show(string $label = null)
|
||||
* @method Show\Field|Collection created_at(string $label = null)
|
||||
* @method Show\Field|Collection updated_at(string $label = null)
|
||||
* @method Show\Field|Collection user_id(string $label = null)
|
||||
* @method Show\Field|Collection consignee(string $label = null)
|
||||
* @method Show\Field|Collection telephone(string $label = null)
|
||||
* @method Show\Field|Collection province(string $label = null)
|
||||
* @method Show\Field|Collection city(string $label = null)
|
||||
* @method Show\Field|Collection district(string $label = null)
|
||||
* @method Show\Field|Collection address(string $label = null)
|
||||
* @method Show\Field|Collection is_default(string $label = null)
|
||||
* @method Show\Field|Collection type(string $label = null)
|
||||
* @method Show\Field|Collection version(string $label = null)
|
||||
* @method Show\Field|Collection detail(string $label = null)
|
||||
|
|
@ -317,7 +355,6 @@ namespace Dcat\Admin {
|
|||
* @method Show\Field|Collection http_method(string $label = null)
|
||||
* @method Show\Field|Collection http_path(string $label = null)
|
||||
* @method Show\Field|Collection role_id(string $label = null)
|
||||
* @method Show\Field|Collection user_id(string $label = null)
|
||||
* @method Show\Field|Collection value(string $label = null)
|
||||
* @method Show\Field|Collection username(string $label = null)
|
||||
* @method Show\Field|Collection password(string $label = null)
|
||||
|
|
@ -348,10 +385,13 @@ namespace Dcat\Admin {
|
|||
* @method Show\Field|Collection abilities(string $label = null)
|
||||
* @method Show\Field|Collection last_used_at(string $label = null)
|
||||
* @method Show\Field|Collection remarks(string $label = null)
|
||||
* @method Show\Field|Collection sku_id(string $label = null)
|
||||
* @method Show\Field|Collection gift_sku_id(string $label = null)
|
||||
* @method Show\Field|Collection num(string $label = null)
|
||||
* @method Show\Field|Collection sent(string $label = null)
|
||||
* @method Show\Field|Collection attrs(string $label = null)
|
||||
* @method Show\Field|Collection specs(string $label = null)
|
||||
* @method Show\Field|Collection part_id(string $label = null)
|
||||
* @method Show\Field|Collection sku_id(string $label = null)
|
||||
* @method Show\Field|Collection spu_id(string $label = null)
|
||||
* @method Show\Field|Collection status(string $label = null)
|
||||
* @method Show\Field|Collection images(string $label = null)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ return [
|
|||
'sku_verify'=>'商品审核',
|
||||
'disable_user'=>'禁用用户',
|
||||
'enable_user'=>'启用用户',
|
||||
'sku_gift'=>'赠品管理',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
return [
|
||||
'labels' => [
|
||||
'ProductGift' => 'ProductGift',
|
||||
'product-gift' => 'ProductGift',
|
||||
],
|
||||
'fields' => [
|
||||
'sku_id' => 'SKU商品',
|
||||
'gift_sku_id' => '赠品',
|
||||
'num' => '赠送数量',
|
||||
'sent' => '已送数量',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
|
|
@ -34,6 +34,10 @@ return [
|
|||
'verify_state'=>'状态',
|
||||
'release_at' => '上架时间',
|
||||
'attr_group'=>'商品分组',
|
||||
'gifts'=>'赠品',
|
||||
'gift_sku_id'=>'赠品名称',
|
||||
'num'=>'赠送数量',
|
||||
'limit'=>'限量',
|
||||
],
|
||||
'options' => [
|
||||
'deny' => '删除失败',
|
||||
|
|
|
|||
Loading…
Reference in New Issue