|
|
|
@ -106,6 +106,35 @@ class AgentProductController extends Controller |
|
|
|
$agent_product->product = null; |
|
|
|
} |
|
|
|
|
|
|
|
//处理规格
|
|
|
|
if (!$agent_product->spec->isEmpty()) { |
|
|
|
$specs = $agent_product->spec->toArray(); |
|
|
|
|
|
|
|
//二维数组转一维
|
|
|
|
$specs = array_map(function ($v) { |
|
|
|
if (is_array($v['product_spec'])) { |
|
|
|
unset($v['product_spec']['id']); |
|
|
|
$v = array_merge($v, $v['product_spec']); |
|
|
|
} |
|
|
|
unset($v['agent_product_id'], $v['product_spec_id'], $v['product_spec']); |
|
|
|
return $v; |
|
|
|
}, $specs); |
|
|
|
|
|
|
|
//去年name和date为空的数组
|
|
|
|
$specs = array_filter($specs, fn($v) => isset($v['name'], $v['date'])); |
|
|
|
|
|
|
|
$names = array_column($specs, 'name'); |
|
|
|
$names = array_values(array_unique($names)); |
|
|
|
|
|
|
|
$result = []; |
|
|
|
foreach ($names as $name) { |
|
|
|
$list = array_filter($specs, fn($v) => $v['name'] == $name); |
|
|
|
$result[] = ['name' => $name, 'list' => array_column($list, null, 'date')]; |
|
|
|
} |
|
|
|
unset($agent_product->spec); |
|
|
|
$agent_product->spec = $result; |
|
|
|
} |
|
|
|
|
|
|
|
unset($agent_product->agent_id, $agent_product->status, $agent_product->deleted_at); |
|
|
|
return $this->success($agent_product); |
|
|
|
} |
|
|
|
|