|
|
|
@ -6,8 +6,10 @@ use App\AdminSupplier\Repositories\Product; |
|
|
|
use App\Common\ProductStatus; |
|
|
|
use App\Models\AgentProduct; |
|
|
|
use App\Models\AgentProductItem; |
|
|
|
use App\Models\AgentProductSpec; |
|
|
|
use App\Models\Category; |
|
|
|
use App\Models\DiyForm; |
|
|
|
use App\Models\ProductSpec; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Form\NestedForm; |
|
|
|
@ -328,7 +330,33 @@ class ProductController extends AdminController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
//TODO 还需要规格同步到代理商
|
|
|
|
$delete_specs = array_filter($form->spec, fn($v) => $v['_remove_'] !== null); //删除的规格
|
|
|
|
|
|
|
|
//同步删除代理商规格
|
|
|
|
AgentProductSpec::whereIn('product_spec_id', array_keys($delete_specs))->delete(); |
|
|
|
|
|
|
|
//最新销售价同步到代理商规格
|
|
|
|
$product_id = $form->getKey(); |
|
|
|
|
|
|
|
$agent_product_ids = AgentProduct::where('product_id', $product_id)->pluck('id')->toArray(); //获取当前供应商产品的所有供应商产品ID
|
|
|
|
$product_specs = ProductSpec::where('product_id', $product_id)->get(); |
|
|
|
$product_spec_old_ids = $form->model()->spec->pluck('id')->toArray(); //旧的规格ID(不包括新增的)
|
|
|
|
|
|
|
|
if ($agent_product_ids && $product_spec_old_ids) { |
|
|
|
//将代理商规格价格小于供应商销售价的,设置代理商规格的价格设置为供应商的售价
|
|
|
|
foreach ($product_specs->whereIn('id', $product_spec_old_ids) as $v) { |
|
|
|
AgentProductSpec::whereIn('agent_product_id', $agent_product_ids) |
|
|
|
->where([['product_spec_id', '=', $v->id], ['price', '<', $v->price]]) |
|
|
|
->update(['price' => $v->price]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*if ($product_spec_old_ids) { |
|
|
|
$product_spec_new_ids = $product_specs->whereNotIn('id', $product_spec_old_ids)->get()->toArray(); //新增的规格
|
|
|
|
if ($product_spec_new_ids) { |
|
|
|
//暂时不处理新增的规格
|
|
|
|
} |
|
|
|
}*/ |
|
|
|
} |
|
|
|
})->deleting(function (Form $form) { |
|
|
|
//不允许删除非自己的数据
|
|
|
|
|