|
|
@ -10,9 +10,12 @@ use App\Models\AgentSetting; |
|
|
use App\Models\Category; |
|
|
use App\Models\Category; |
|
|
use Dcat\Admin\Admin; |
|
|
use Dcat\Admin\Admin; |
|
|
use Dcat\Admin\Form; |
|
|
use Dcat\Admin\Form; |
|
|
|
|
|
use Dcat\Admin\Form\NestedForm; |
|
|
use Dcat\Admin\Grid; |
|
|
use Dcat\Admin\Grid; |
|
|
use Dcat\Admin\Show; |
|
|
use Dcat\Admin\Show; |
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
|
|
use Dcat\Admin\Widgets\Card; |
|
|
|
|
|
use Dcat\Admin\Widgets\Table; |
|
|
use Illuminate\Support\Facades\DB; |
|
|
use Illuminate\Support\Facades\DB; |
|
|
use Illuminate\Support\Facades\Log; |
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
|
|
|
@ -27,7 +30,15 @@ class ProductController extends AdminController |
|
|
protected function grid() |
|
|
protected function grid() |
|
|
{ |
|
|
{ |
|
|
return Grid::make(new Product(['category:id,name']), function (Grid $grid) { |
|
|
return Grid::make(new Product(['category:id,name']), function (Grid $grid) { |
|
|
$grid->model()->where('supplier_id', Admin::user()->id); |
|
|
|
|
|
|
|
|
$type = request()->input('type'); |
|
|
|
|
|
|
|
|
|
|
|
if (isset($type) && isset(admin_trans('product.options.public_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 . '"); });'); |
|
|
|
|
|
} else { |
|
|
|
|
|
$grid->model()->where('supplier_id', Admin::user()->id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$grid->column('id')->sortable(); |
|
|
$grid->column('id')->sortable(); |
|
|
$grid->column('category.name', '产品分类'); |
|
|
$grid->column('category.name', '产品分类'); |
|
|
@ -43,8 +54,9 @@ class ProductController extends AdminController |
|
|
$grid->column('updated_at'); |
|
|
$grid->column('updated_at'); |
|
|
|
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
$filter->equal('id'); |
|
|
|
|
|
|
|
|
$filter->panel(); |
|
|
|
|
|
|
|
|
|
|
|
$filter->equal('id')->width(2); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -72,6 +84,22 @@ class ProductController extends AdminController |
|
|
$show->field('know')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
|
|
$show->field('know')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
|
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
|
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
|
|
$show->field('verify_mobile','核销员手机'); |
|
|
$show->field('verify_mobile','核销员手机'); |
|
|
|
|
|
$show->field('extends', '附加信息') |
|
|
|
|
|
->unescape() |
|
|
|
|
|
->as(function ($v) { |
|
|
|
|
|
$html = ''; |
|
|
|
|
|
$arr = [ |
|
|
|
|
|
'project' => '服务项目', |
|
|
|
|
|
'date' => '时间', |
|
|
|
|
|
'tags' => '包含项目', |
|
|
|
|
|
'open_time' => '开放时间', |
|
|
|
|
|
'package' => '包含套餐', |
|
|
|
|
|
]; |
|
|
|
|
|
foreach ($v as $k => $item) { |
|
|
|
|
|
$html .= new Card(Table::make([$arr[$k] ?? '项目'], $item)); |
|
|
|
|
|
} |
|
|
|
|
|
return $html; |
|
|
|
|
|
}); |
|
|
$show->field('created_at'); |
|
|
$show->field('created_at'); |
|
|
$show->field('updated_at'); |
|
|
$show->field('updated_at'); |
|
|
}); |
|
|
}); |
|
|
@ -84,13 +112,27 @@ class ProductController extends AdminController |
|
|
*/ |
|
|
*/ |
|
|
protected function form() |
|
|
protected function form() |
|
|
{ |
|
|
{ |
|
|
|
|
|
Admin::user()->public_type = json_decode(Admin::user()->public_type, true); |
|
|
return Form::make(new Product(), function (Form $form) { |
|
|
return Form::make(new Product(), function (Form $form) { |
|
|
//不允许编辑非自己数据
|
|
|
//不允许编辑非自己数据
|
|
|
if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { |
|
|
if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { |
|
|
return $form->response()->error('数据不存在'); |
|
|
return $form->response()->error('数据不存在'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$type = request()->input('type'); |
|
|
|
|
|
if ($form->isCreating()) { |
|
|
|
|
|
if ($type == null) { |
|
|
|
|
|
Admin::exit('请选择要发布的产品类型'); |
|
|
|
|
|
} |
|
|
|
|
|
if (!Admin::user()->public_type || !in_array($type, Admin::user()->public_type)) { |
|
|
|
|
|
Admin::exit('对不起,你没有此类产品的发布权限'); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
$type = $form->model()->type; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$form->display('id'); |
|
|
$form->display('id'); |
|
|
|
|
|
$form->hidden('type')->value($type); |
|
|
|
|
|
|
|
|
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); |
|
|
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); |
|
|
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); |
|
|
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); |
|
|
@ -102,6 +144,43 @@ class ProductController extends AdminController |
|
|
$form->editor('know'); |
|
|
$form->editor('know'); |
|
|
$form->editor('content')->required(); |
|
|
$form->editor('content')->required(); |
|
|
$form->text('verify_mobile','核销员手机'); |
|
|
$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) { //酒店
|
|
|
|
|
|
$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元'); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if ($form->isEditing()) { |
|
|
if ($form->isEditing()) { |
|
|
$form->confirm('提示', '修改标题、价格、产品图片、旅游须知、产品详情需要重新审核,同时<span class="btn-danger">下架所有</span>关联的代理商产品,是否继续?'); |
|
|
$form->confirm('提示', '修改标题、价格、产品图片、旅游须知、产品详情需要重新审核,同时<span class="btn-danger">下架所有</span>关联的代理商产品,是否继续?'); |
|
|
} |
|
|
} |
|
|
@ -111,6 +190,11 @@ class ProductController extends AdminController |
|
|
return $form->response()->error('数据不存在'); |
|
|
return $form->response()->error('数据不存在'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$type = $form->isCreating() ? $form->type : $form->model()->type; |
|
|
|
|
|
if (!Admin::user()->public_type || !in_array($type, Admin::user()->public_type)) { |
|
|
|
|
|
return $form->response()->error('对不起,你没有此类产品的发布、编辑权限'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//不允许编辑的字段,忽略字段不起作用?
|
|
|
//不允许编辑的字段,忽略字段不起作用?
|
|
|
$form->ignore(['id', 'supplier_id', 'sale', 'status', 'created_at', 'updated_at', 'deleted_at']); |
|
|
$form->ignore(['id', 'supplier_id', 'sale', 'status', 'created_at', 'updated_at', 'deleted_at']); |
|
|
|
|
|
|
|
|
@ -122,9 +206,9 @@ class ProductController extends AdminController |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//特殊字段处理
|
|
|
//特殊字段处理
|
|
|
$form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值
|
|
|
|
|
|
$form->supplier_id = Admin::user()->id; |
|
|
|
|
|
if ($form->isCreating()) { |
|
|
if ($form->isCreating()) { |
|
|
|
|
|
$form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值
|
|
|
|
|
|
$form->supplier_id = Admin::user()->id; |
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
} |
|
|
} |
|
|
})->saved(function (Form $form, $result) { |
|
|
})->saved(function (Form $form, $result) { |
|
|
|