6
0
Fork 0

调整售后单标签

release
vine_liutk 2021-12-28 11:29:05 +08:00
parent dca972a2f9
commit 7b94a0bcf3
12 changed files with 111 additions and 9 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace App\Admin\Actions\Grid;
use App\Admin\Forms\Tags\AfterSaleTag as AfterSaleTagForm;
use App\Models\AfterSale;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Widgets\Modal;
class AfterSaleSetTag extends RowAction
{
/**
* @return string
*/
protected $title = '<i class="feather icon-tag grid-action-icon"></i>';
public function title()
{
if ($this->title) {
return $this->title.'&nbsp;标签';
}
return '标签';
}
public function render()
{
$form = AfterSaleTagForm::make()->payload(['id'=>$this->getKey(), 'type'=>AfterSale::class]);
return Modal::make()
->lg()
->title($this->title())
->body($form)
->button($this->title());
}
}

View File

@ -2,6 +2,7 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\AfterSaleSetTag;
use App\Admin\Actions\Show\AfterSaleFinance; use App\Admin\Actions\Show\AfterSaleFinance;
use App\Admin\Actions\Show\AfterSaleFinanceShipping; use App\Admin\Actions\Show\AfterSaleFinanceShipping;
use App\Admin\Actions\Show\AfterSaleShipping; use App\Admin\Actions\Show\AfterSaleShipping;
@ -11,6 +12,8 @@ use App\Admin\Actions\Show\AfterSaleVerify;
use App\Admin\Repositories\AfterSale; use App\Admin\Repositories\AfterSale;
use App\Models\AfterSale as AfterSaleModel; use App\Models\AfterSale as AfterSaleModel;
use App\Models\AfterSaleLog; use App\Models\AfterSaleLog;
use App\Models\Tag;
use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController; use Dcat\Admin\Http\Controllers\AdminController;
@ -26,12 +29,19 @@ class AfterSaleController extends AdminController
*/ */
protected function grid() protected function grid()
{ {
$builder = AfterSale::with(['user', 'order', 'orderProduct']); $builder = AfterSale::with(['user', 'order', 'orderProduct', 'tags']);
return Grid::make($builder, function (Grid $grid) { return Grid::make($builder, function (Grid $grid) {
$grid->column('id')->sortable(); $grid->column('sn');
$grid->column('tags', '标签')->display(function ($tags) {
$array = [];
foreach ($this->tags as $key => $tag) {
$array[] = $tag->name;
}
return $array;
})->label();
$grid->column('user.phone'); $grid->column('user.phone');
$grid->column('order.sn'); $grid->column('order.sn');
$grid->column('sn');
$grid->column('orderProduct.name'); $grid->column('orderProduct.name');
$grid->column('num'); $grid->column('num');
$grid->column('amount')->display(function ($value) { $grid->column('amount')->display(function ($value) {
@ -64,12 +74,16 @@ class AfterSaleController extends AdminController
]); ]);
// $grid->column('remarks'); // $grid->column('remarks');
// $grid->column('tracking_number'); // $grid->column('tracking_number');
$grid->column('created_at'); $grid->column('created_at');
$grid->column('updated_at')->sortable(); $grid->column('updated_at')->sortable();
$grid->model()->orderBy('created_at', 'desc'); $grid->model()->orderBy('created_at', 'desc');
$grid->actions(function (Grid\Displayers\Actions $actions) { $grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableView(false); $actions->disableView(false);
if (Admin::user()->can('dcat.admin.after_sales.tags')) {
$actions->append(new AfterSaleSetTag());
}
}); });
$grid->filter(function (Grid\Filter $filter) { $grid->filter(function (Grid\Filter $filter) {
@ -86,6 +100,11 @@ class AfterSaleController extends AdminController
$filter->equal('user.phone')->width(3); $filter->equal('user.phone')->width(3);
$filter->equal('order.sn')->width(3); $filter->equal('order.sn')->width(3);
$filter->equal('sn')->width(3); $filter->equal('sn')->width(3);
$filter->where('tags', function ($query) {
$query->whereHas('tags', function ($q) {
$q->whereIn('tags.id', $this->input);
});
}, '标签')->multipleSelect(Tag::AfterSaleTag()->pluck('name', 'id'))->width(3);
}); });
}); });
} }
@ -101,13 +120,16 @@ class AfterSaleController extends AdminController
{ {
return function (Row $row) use ($id) { return function (Row $row) use ($id) {
$row->column(4, function ($column) use ($id) { $row->column(4, function ($column) use ($id) {
$builder = AfterSale::with(['user', 'order', 'orderProduct']); $builder = AfterSale::with(['user', 'order', 'orderProduct', 'tags']);
$column->row(Show::make($id, $builder, function (Show $show) { $column->row(Show::make($id, $builder, function (Show $show) {
$show->field('id'); $show->field('id');
$show->field('sn'); $show->field('sn');
$show->field('order.sn'); $show->field('order.sn');
$show->field('user.phone'); $show->field('user.phone');
$show->field('order_product.name'); $show->field('order_product.name');
$show->field('tags')->as(function () {
return $this->tags->pluck('name');
})->label();
$show->field('num'); $show->field('num');
if (in_array($show->model()->type, [AfterSaleModel::TYPE_REFUND_AND_RETURN, AfterSaleModel::TYPE_REFUND])) { if (in_array($show->model()->type, [AfterSaleModel::TYPE_REFUND_AND_RETURN, AfterSaleModel::TYPE_REFUND])) {
$show->field('amount')->as(function ($amount) { $show->field('amount')->as(function ($amount) {

View File

@ -129,7 +129,7 @@ class OrderController extends AdminController
{ {
return function (Row $row) use ($id) { return function (Row $row) use ($id) {
$row->column(5, function ($column) use ($id) { $row->column(5, function ($column) use ($id) {
$builder = Order::with(['user', 'userCoupon']); $builder = Order::with(['user', 'userCoupon', 'tags']);
$column->row(Show::make($id, $builder, function (Show $show) { $column->row(Show::make($id, $builder, function (Show $show) {
// $show->field('id'); // $show->field('id');
$show->field('sn'); $show->field('sn');
@ -166,7 +166,9 @@ class OrderController extends AdminController
'无'=>'#b3b9bf', '无'=>'#b3b9bf',
]); ]);
$show->field('pay_at'); $show->field('pay_at');
$show->field('tags')->as(function () {
return $this->tags->pluck('name');
})->label();
$show->divider(); $show->divider();
$show->field('consignee_name'); $show->field('consignee_name');
$show->field('consignee_telephone'); $show->field('consignee_telephone');

View File

@ -27,7 +27,7 @@ class TagController extends AdminController
$grid->column('type')->using([ $grid->column('type')->using([
TagModel::TYPE_ORDER =>'订单', TagModel::TYPE_ORDER =>'订单',
TagModel::TYPE_PACKAGE=>'货运', TagModel::TYPE_PACKAGE=>'货运',
// TagModel::TYPE_AFTER_SALE=>'售后', TagModel::TYPE_AFTER_SALE=>'售后',
])->label(); ])->label();
$grid->column('name'); $grid->column('name');
$grid->column('created_at')->sortable(); $grid->column('created_at')->sortable();
@ -55,7 +55,7 @@ class TagController extends AdminController
$filter->equal('type')->select([ $filter->equal('type')->select([
TagModel::TYPE_ORDER =>'订单', TagModel::TYPE_ORDER =>'订单',
TagModel::TYPE_PACKAGE =>'货运', TagModel::TYPE_PACKAGE =>'货运',
// 3=>'售后', TagModel::TYPE_AFTER_SALE =>'售后',
])->width(3); ])->width(3);
}); });
}); });
@ -92,7 +92,7 @@ class TagController extends AdminController
$form->radio('type')->options([ $form->radio('type')->options([
TagModel::TYPE_ORDER =>'订单', TagModel::TYPE_ORDER =>'订单',
TagModel::TYPE_PACKAGE=>'货运', TagModel::TYPE_PACKAGE=>'货运',
// 3=>'售后', TagModel::TYPE_AFTER_SALE =>'售后',
])->default($type)->required(); ])->default($type)->required();
$form->text('name')->required(); $form->text('name')->required();

View File

@ -0,0 +1,15 @@
<?php
namespace App\Admin\Forms\Tags;
use Dcat\Admin\Traits\LazyWidget;
class AfterSaleTag extends Tag
{
use LazyWidget;
protected function authorize($user): bool
{
return $user->can('dcat.admin.after_sales.tags');
}
}

View File

@ -44,6 +44,7 @@ class Tag extends Form implements LazyRenderable
$type = $this->payload['type']; $type = $this->payload['type'];
$tags = Taggable::where('taggable_id', $id)->where('taggable_type', $type)->get(); $tags = Taggable::where('taggable_id', $id)->where('taggable_type', $type)->get();
$scopeTag = lcfirst(class_basename($type)).'Tag'; $scopeTag = lcfirst(class_basename($type)).'Tag';
$this->multipleSelect('tags') $this->multipleSelect('tags')
->options(TagModel::$scopeTag()->pluck('name', 'id')) ->options(TagModel::$scopeTag()->pluck('name', 'id'))
->customFormat(function () use ($tags) { ->customFormat(function () use ($tags) {

View File

@ -86,6 +86,11 @@ class AfterSale extends Model
return $this->hasMany(AfterSaleLog::class, 'after_sale_id'); return $this->hasMany(AfterSaleLog::class, 'after_sale_id');
} }
public function tags()
{
return $this->belongsToMany(Tag::class, 'taggables', 'taggable_id', 'tag_id')->wherePivot('taggable_type', self::class)->withTimestamps();
}
/** /**
* 确认此售后单是否是换货 * 确认此售后单是否是换货
* *

View File

@ -43,4 +43,9 @@ class Tag extends Model
{ {
return $this->where('type', self::TYPE_PACKAGE); return $this->where('type', self::TYPE_PACKAGE);
} }
public function scopeAfterSaleTag()
{
return $this->where('type', self::TYPE_AFTER_SALE);
}
} }

View File

@ -50,6 +50,16 @@ class AdAddressSeeder extends Seeder
'dimensions'=> '375*200', 'dimensions'=> '375*200',
'is_show' => true, 'is_show' => true,
], ],
'share_register_banner' => [
'name' => '分享注册位',
'dimensions'=> '',
'is_show' => true,
],
'share_download_banner' => [
'name' => '分享下载位',
'dimensions'=> '',
'is_show' => true,
],
] as $key => $values) { ] as $key => $values) {
AdAddress::firstOrCreate(['key' => $key], $values); AdAddress::firstOrCreate(['key' => $key], $values);
} }

View File

@ -210,6 +210,11 @@ class AdminMenuSeeder extends Seeder
'icon' => '', 'icon' => '',
'uri' => 'after-sales', 'uri' => 'after-sales',
], ],
[
'title' =>'售后标签',
'icon' => '',
'uri' => 'tags?type=3',
],
], ],
], ],
[ [

View File

@ -178,6 +178,7 @@ class AdminPermissionSeeder extends Seeder
'verify'=>['name' =>'审核'], 'verify'=>['name' =>'审核'],
'shipping'=>['name' =>'确认收货'], 'shipping'=>['name' =>'确认收货'],
'finance'=>['name' =>'确认打款'], 'finance'=>['name' =>'确认打款'],
'tags'=>['name' =>'标签设置'],
], ],
], ],
'messages'=>[ 'messages'=>[

View File

@ -35,6 +35,7 @@ return [
'remarks3' => '备注', 'remarks3' => '备注',
'tracking_number' => '运单号', 'tracking_number' => '运单号',
'created_at'=>'申请时间', 'created_at'=>'申请时间',
'tags' => '标签',
], ],
'options' => [ 'options' => [
], ],