From 3ecbfe947248037354c2f93ce1f95500558b3069 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 8 Sep 2021 10:43:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E5=B9=B2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ProductController.php | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/app/AdminSupplier/Controllers/ProductController.php b/app/AdminSupplier/Controllers/ProductController.php index 549b0f8..0a54671 100644 --- a/app/AdminSupplier/Controllers/ProductController.php +++ b/app/AdminSupplier/Controllers/ProductController.php @@ -14,6 +14,7 @@ use Dcat\Admin\Form\NestedForm; use Dcat\Admin\Grid; use Dcat\Admin\Show; use Dcat\Admin\Http\Controllers\AdminController; +use Dcat\Admin\Widgets\Alert; use Dcat\Admin\Widgets\Card; use Dcat\Admin\Widgets\Table; use Illuminate\Support\Facades\DB; @@ -34,8 +35,12 @@ class ProductController extends AdminController if (isset($type) && isset(admin_trans('product.options.publish_type')[$type])) { $grid->model()->where(['supplier_id' => Admin::user()->id, 'type' => $type]); - $create_url = $grid->resource() . '/create?type=' . $type; - Admin::script('$(function(){ $(".pull-right a").attr("href", "' . $create_url . '"); });'); + Admin::script('$(function(){ + $(".pull-right a").each(function() { + var href = $(this).attr("href"); + $(this).attr("href", href + "?type='.$type.'") + }); + });'); } else { $grid->model()->where('supplier_id', Admin::user()->id); } @@ -71,6 +76,13 @@ class ProductController extends AdminController protected function detail($id) { return Show::make($id, new Product(), function (Show $show) { + Admin::script('$(function(){ + $(".pull-right a").each(function() { + var href = $(this).attr("href"); + $(this).attr("href", href + "?type='.request()->input('type').'") + }); + });'); + $show->field('id'); $show->field('supplier_id'); $show->field('category_id'); @@ -114,22 +126,19 @@ class ProductController extends AdminController { Admin::user()->publish_type = json_decode(Admin::user()->publish_type, true); return Form::make(new Product(), function (Form $form) { + Admin::script('$(function(){ + $(".pull-right a").each(function() { + var href = $(this).attr("href"); + $(this).attr("href", href + "?type='.request()->input('type').'") + }); + });'); + //不允许编辑非自己数据 if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { return $form->response()->error('数据不存在'); } $type = request()->input('type'); - if ($form->isCreating()) { - if ($type == null) { - Admin::exit('请选择要发布的产品类型'); - } - if (!Admin::user()->publish_type || !in_array($type, Admin::user()->publish_type)) { - Admin::exit('对不起,你没有此类产品的发布权限'); - } - } else { - $type = $form->model()->type; - } $form->display('id'); $form->hidden('type')->value($type); @@ -140,7 +149,7 @@ class ProductController extends AdminController $form->text('price')->required(); $form->text('original_price')->required(); $form->multipleImage('pictures')->required()->removable(false)->retainable()->uniqueName(); - $form->text('stock')->default(9999)->required(); + $form->text('stock')->default(99999)->required(); $form->editor('know'); $form->editor('content')->required(); $form->text('verify_mobile','核销员手机'); @@ -154,6 +163,8 @@ class ProductController extends AdminController }); $form->dateRange('extends.date.start', 'extends.date.end', '行程时间'); } else if ($type == 1) { //酒店 + $default = ['行李寄存', '24小时前台', '前台保险柜', '唤醒服务', '早餐', '送餐服务', '电梯', '空调', + '新风系统', '24小时热水', '吹风机', '加湿器', '自动售货机', '健身房', '桌球室', '洗衣服务']; $form->table('extends.tags', '酒店设施', function (NestedForm $table) { $table->text('tag', '包含项目')->placeholder('如:24小时热水、干洗服务等'); }); @@ -184,6 +195,16 @@ class ProductController extends AdminController if ($form->isEditing()) { $form->confirm('提示', '修改标题、价格、产品图片、旅游须知、产品详情需要重新审核,同时下架所有关联的代理商产品,是否继续?'); } + })->creating(function (Form $form) { + $type = request()->input('type'); + if ($form->isCreating()) { + if ($type == null) { + Admin::exit('请选择要发布的产品类型'); + } + if (!Admin::user()->publish_type || !in_array($type, Admin::user()->publish_type)) { + Admin::exit(Alert::make('对不起,你没有此类产品的发布权限', '权限不足')->danger()); + } + } })->saving(function (Form $form) { //不允许编辑非自己数据 if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) {