|
|
|
@ -5,6 +5,7 @@ namespace App\AdminSupplier\Controllers; |
|
|
|
use App\AdminSupplier\Repositories\IndustryProduct; |
|
|
|
use App\Common\ProductStatus; |
|
|
|
use App\Models\Category; |
|
|
|
use App\Models\DiyForm; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Form\NestedForm; |
|
|
|
@ -105,22 +106,44 @@ class IndustryProductController extends AdminController |
|
|
|
{ |
|
|
|
Admin::user()->publish_type = json_decode(Admin::user()->publish_type, true); |
|
|
|
|
|
|
|
return Form::make(new IndustryProduct(), function (Form $form) { |
|
|
|
return Form::make(new IndustryProduct(['spec']), function (Form $form) { |
|
|
|
$form->disableDeleteButton(); |
|
|
|
|
|
|
|
$form->display('id'); |
|
|
|
|
|
|
|
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); |
|
|
|
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); |
|
|
|
$form->text('title')->required(); |
|
|
|
$form->currency('price')->required(); |
|
|
|
$form->currency('original_price')->required(); |
|
|
|
$form->number('stock')->required(); |
|
|
|
$form->number('min_sale')->min(1)->required(); |
|
|
|
//信息收集表单
|
|
|
|
$options = DiyForm::where('supplier_id', Admin::user()->id)->pluck('name', 'id'); |
|
|
|
if ($options->isEmpty()) { |
|
|
|
$form->select('diy_form_id', '信息收集表单') |
|
|
|
->help('提示:信息收集表单为空,请前往“<a href="' . admin_url('diy_form') . '">信息收集表单</a>”处新增') |
|
|
|
->options($options)->required(); |
|
|
|
} else { |
|
|
|
$form->select('diy_form_id', '信息收集表单')->options($options)->required(); |
|
|
|
} |
|
|
|
|
|
|
|
$form->text('title')->required(); |
|
|
|
$form->number('min_sale')->default(1)->min(1)->required(); |
|
|
|
$form->hasMany('spec', function (NestedForm $form) { |
|
|
|
$form->hidden('id'); |
|
|
|
$form->text('name', '规格')->required()->readonly(); |
|
|
|
$form->date('date', '日期')->required(); |
|
|
|
$form->text('stock')->required(); |
|
|
|
$form->text('original_price')->required(); |
|
|
|
$form->text('price')->required(); |
|
|
|
Admin::style('.field_date{width:100px!important;} |
|
|
|
.has-many-spec .col-md-12{padding:0;} |
|
|
|
.has-many-spec .add.btn{display:none;} |
|
|
|
.has-many-spec .input-group-prepend{display:none;} |
|
|
|
.has-many-spec .form-group{margin-bottom:0;} |
|
|
|
.has-many-spec .input-group>.form-control:not(:first-child){border-radius:.25rem;}'); |
|
|
|
Admin::script(file_get_contents(resource_path('js/supplier-batch-add-spec.js'))); |
|
|
|
})->useTable()->required(); |
|
|
|
if ($form->isEditing() && in_array($form->model()->status, [ProductStatus::SOLD_OUT, ProductStatus::ON_SALE])) { |
|
|
|
$form->radio('status')->options([1 => '上架', -2 => '下架'])->default(1); |
|
|
|
} |
|
|
|
$form->multipleImage('pictures')->required(); |
|
|
|
$form->multipleImage('pictures')->required()->removable(false)->uniqueName(); |
|
|
|
$form->editor('know'); |
|
|
|
$form->editor('content')->required(); |
|
|
|
$form->mobile('verify_mobile')->required(); |
|
|
|
@ -228,10 +251,20 @@ class IndustryProductController extends AdminController |
|
|
|
$form->deleteInput('type'); |
|
|
|
} |
|
|
|
|
|
|
|
//规格处理
|
|
|
|
if (!$form->spec || !$spec = array_filter($form->spec, fn($v) => !$v['_remove_'])) { |
|
|
|
return $form->response()->error('请输入产品规格'); |
|
|
|
} |
|
|
|
|
|
|
|
//处理库存、市场价、销售价
|
|
|
|
$form->hidden(['stock', 'original_price', 'price']); |
|
|
|
$form->stock = array_sum(array_column($spec, 'stock')); |
|
|
|
$form->original_price = min(array_column($spec, 'original_price')); |
|
|
|
$form->price = min(array_column($spec, 'price')); |
|
|
|
|
|
|
|
//用户可编辑的状态
|
|
|
|
$user_status = [ProductStatus::SOLD_OUT, ProductStatus::ON_SALE]; |
|
|
|
|
|
|
|
//目前逻辑不考虑总后台修改单人头交易费的情况
|
|
|
|
if ($form->isCreating()) { |
|
|
|
$form->hidden(['status', 'supplier_id']); |
|
|
|
$form->supplier_id = Admin::user()->id; |
|
|
|
|