|
|
|
@ -6,7 +6,6 @@ use App\AdminSupplier\Repositories\Product; |
|
|
|
use App\Common\ProductStatus; |
|
|
|
use App\Models\AgentProduct; |
|
|
|
use App\Models\AgentProductItem; |
|
|
|
use App\Models\AgentSetting; |
|
|
|
use App\Models\Category; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
@ -18,7 +17,6 @@ use Dcat\Admin\Widgets\Alert; |
|
|
|
use Dcat\Admin\Widgets\Card; |
|
|
|
use Dcat\Admin\Widgets\Table; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
|
|
class ProductController extends AdminController |
|
|
|
{ |
|
|
|
@ -31,21 +29,10 @@ class ProductController extends AdminController |
|
|
|
protected function grid() |
|
|
|
{ |
|
|
|
return Grid::make(new Product(['category:id,name']), function (Grid $grid) { |
|
|
|
$type = request()->input('type'); |
|
|
|
|
|
|
|
if (isset($type) && isset(admin_trans('product.options.publish_type')[$type])) { |
|
|
|
$grid->model()->where(['supplier_id' => Admin::user()->id, 'type' => $type]); |
|
|
|
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); |
|
|
|
} |
|
|
|
$grid->model()->where('supplier_id', Admin::user()->id); |
|
|
|
|
|
|
|
$grid->column('id')->sortable(); |
|
|
|
$grid->column('type')->using(admin_trans('product.options.publish_type')); |
|
|
|
$grid->column('category.name', '产品分类'); |
|
|
|
$grid->column('title'); |
|
|
|
$grid->column('picture')->image('', 60, 60); |
|
|
|
@ -62,6 +49,7 @@ class ProductController extends AdminController |
|
|
|
$filter->panel(); |
|
|
|
|
|
|
|
$filter->equal('id')->width(2); |
|
|
|
$filter->equal('type')->select(admin_trans('product.options.publish_type'))->width(2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -76,13 +64,6 @@ 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'); |
|
|
|
@ -126,22 +107,12 @@ 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'); |
|
|
|
|
|
|
|
$form->display('id'); |
|
|
|
$form->hidden('type')->value($type); |
|
|
|
|
|
|
|
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); |
|
|
|
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); |
|
|
|
@ -155,64 +126,64 @@ class ProductController extends AdminController |
|
|
|
$form->text('verify_mobile','核销员手机'); |
|
|
|
|
|
|
|
//扩展字段
|
|
|
|
if ($type == 0) { //旅游线路
|
|
|
|
$form->table('extends.project', '包含项目', function (NestedForm $table) { |
|
|
|
$table->text('name', '项目名称'); |
|
|
|
$table->text('num', '数量'); |
|
|
|
$table->text('price', '费用'); |
|
|
|
}); |
|
|
|
$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小时热水、干洗服务等'); |
|
|
|
}); |
|
|
|
} else if ($type == 2) { //景区
|
|
|
|
$form->table('extends.open_time', '开放时间', function (NestedForm $table) { |
|
|
|
$table->text('week', '星期')->placeholder('如:周一至周五'); |
|
|
|
$table->text('section', '时段')->placeholder('如:上午/下午'); |
|
|
|
$table->text('time', '时间')->placeholder('如:08:00~18:00'); |
|
|
|
}); |
|
|
|
$form->table('extends.project', '包含项目', function (NestedForm $table) { |
|
|
|
$table->text('name', '项目名称'); |
|
|
|
$table->text('num', '数量'); |
|
|
|
$table->text('price', '费用'); |
|
|
|
}); |
|
|
|
} else if ($type == 3) { //餐厅
|
|
|
|
$form->table('extends.open_time', '开放时间', function (NestedForm $table) { |
|
|
|
$table->text('week', '星期')->placeholder('如:周一至周五'); |
|
|
|
$table->text('section', '时段')->placeholder('如:上午/下午'); |
|
|
|
$table->text('time', '时间')->placeholder('如:08:00~18:00'); |
|
|
|
}); |
|
|
|
$form->table('extends.package', '包含套餐', function (NestedForm $table) { |
|
|
|
$table->text('name', '名称')->placeholder('如:清蒸鱿鱼'); |
|
|
|
$table->text('num', '数量')->placeholder('如:1条'); |
|
|
|
$table->text('price', '价格')->placeholder('如:99元'); |
|
|
|
$publish_type = array_intersect_key( |
|
|
|
admin_trans('product.options.publish_type'), |
|
|
|
array_flip(Admin::user()->publish_type) |
|
|
|
); |
|
|
|
$form->radio('type', '产品类型') |
|
|
|
->options($publish_type) |
|
|
|
->default(current(Admin::user()->publish_type)) |
|
|
|
->when(0, function (Form $form) { //旅游线路
|
|
|
|
$form->table('extends.field_0.project', '包含项目', function (NestedForm $table) { |
|
|
|
$table->text('name', '项目名称'); |
|
|
|
$table->text('num', '数量'); |
|
|
|
$table->text('price', '费用'); |
|
|
|
}); |
|
|
|
$form->dateRange('extends.field_0.date.start', 'extends.field_0.date.end', '行程时间'); |
|
|
|
})->when(1, function (Form $form) { //酒店
|
|
|
|
$default = [ |
|
|
|
['tag' => '行李寄存'], ['tag' => '24小时前台'], ['tag' => '前台保险柜'], ['tag' => '唤醒服务'], |
|
|
|
['tag' => '早餐'], ['tag' => '送餐服务'], ['tag' => '电梯'], ['tag' => '空调'], |
|
|
|
['tag' => '新风系统'], ['tag' => '24小时热水'], ['tag' => '吹风机'], ['tag' => '加湿器'], |
|
|
|
['tag' => '自动售货机'], ['tag' => '健身房'], ['tag' => '桌球室'], ['tag' => '洗衣服务'] |
|
|
|
]; |
|
|
|
$form->table('extends.field_1.tags', '酒店设施', function (NestedForm $table) { |
|
|
|
$table->text('tag', '包含项目')->placeholder('如:24小时热水、干洗服务等'); |
|
|
|
})->value($default); |
|
|
|
})->when(2, function (Form $form) { //景区
|
|
|
|
$form->table('extends.field_2.open_time', '开放时间', function (NestedForm $table) { |
|
|
|
$table->text('week', '星期')->placeholder('如:周一至周五'); |
|
|
|
$table->text('section', '时段')->placeholder('如:上午/下午'); |
|
|
|
$table->text('time', '时间')->placeholder('如:08:00~18:00'); |
|
|
|
}); |
|
|
|
$form->table('extends.field_2.project', '包含项目', function (NestedForm $table) { |
|
|
|
$table->text('name', '项目名称'); |
|
|
|
$table->text('num', '数量'); |
|
|
|
$table->text('price', '费用'); |
|
|
|
}); |
|
|
|
})->when(3, function (Form $form) { //餐厅
|
|
|
|
$form->table('extends.field_3.open_time', '开放时间', function (NestedForm $table) { |
|
|
|
$table->text('week', '星期')->placeholder('如:周一至周五'); |
|
|
|
$table->text('section', '时段')->placeholder('如:上午/下午'); |
|
|
|
$table->text('time', '时间')->placeholder('如:08:00~18:00'); |
|
|
|
}); |
|
|
|
$form->table('extends.field_3.package', '包含套餐', function (NestedForm $table) { |
|
|
|
$table->text('name', '名称')->placeholder('如:清蒸鱿鱼'); |
|
|
|
$table->text('num', '数量')->placeholder('如:1条'); |
|
|
|
$table->text('price', '价格')->placeholder('如:99元'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if ($form->isEditing()) { |
|
|
|
$form->confirm('提示', '修改标题、价格、产品图片、旅游须知、产品详情需要重新审核,同时<span class="btn-danger">下架所有</span>关联的代理商产品,是否继续?'); |
|
|
|
} |
|
|
|
})->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) { |
|
|
|
return $form->response()->error('数据不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
$type = $form->isCreating() ? $form->type : $form->model()->type; |
|
|
|
if (!Admin::user()->publish_type || !in_array($type, Admin::user()->publish_type)) { |
|
|
|
if (!Admin::user()->publish_type || !in_array($form->type, Admin::user()->publish_type)) { |
|
|
|
return $form->response()->error('对不起,你没有此类产品的发布、编辑权限'); |
|
|
|
} |
|
|
|
|
|
|
|
|