文件地址:app/services/product/sku/StoreProductAttrValueServices.php
方法名:getattr
替换此方法:
public function getattr($attr, $id, $type)
{
$value = attr_format($attr)[1];
$valueNew = [];
$count = 0;
if ($type == 2) {
/** @var StoreBargainServices $storeBargainServices */
$storeBargainServices = app()->make(StoreBargainServices::class);
$min_price = $storeBargainServices->value(['id' => $id], 'min_price');
} else {
$min_price = 0;
}
$sukValueArr = $this->getSkuArray(['product_id' => $id, 'type' => $type], 'bar_code,code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota,quota_show,settle_price,integral', 'suk');
foreach ($value as $key => $item) {
$detail = $item['detail'];
// sort($item['detail'], SORT_STRING);
$suk = implode(',', $item['detail']);
$sukValue = $sukValueArr[$suk] ?? [];
if ($sukValue) {
foreach (array_values($detail) as $k => $v) {
$valueNew[$count]['value' . ($k + 1)] = $v;
}
$valueNew[$count]['detail'] = json_encode($detail);
$valueNew[$count]['pic'] = $sukValue['pic'] ?? '';
$valueNew[$count]['price'] = $sukValue['price'] ? floatval($sukValue['price']) : 0;
$valueNew[$count]['integral'] = $sukValue['integral'] ?: 0;
$valueNew[$count]['settle_price'] = $sukValue['cost'] ? floatval($sukValue['settle_price']) : 0;
$valueNew[$count]['cost'] = $sukValue['cost'] ? floatval($sukValue['cost']) : 0;
$valueNew[$count]['ot_price'] = isset($sukValue['ot_price']) ? floatval($sukValue['ot_price']) : 0;
$valueNew[$count]['stock'] = $sukValue['stock'] ? intval($sukValue['stock']) : 0;
$valueNew[$count]['quota'] = isset($sukValue['quota_show']) && $sukValue['quota_show'] ? intval($sukValue['quota_show']) : 0;
$valueNew[$count]['code'] = $sukValue['code'] ?? '';
$valueNew[$count]['bar_code'] = $sukValue['bar_code'] ?? '';
$valueNew[$count]['weight'] = $sukValue['weight'] ? floatval($sukValue['weight']) : 0;
$valueNew[$count]['volume'] = $sukValue['volume'] ? floatval($sukValue['volume']) : 0;
$valueNew[$count]['brokerage'] = $sukValue['brokerage'] ? floatval($sukValue['brokerage']) : 0;
$valueNew[$count]['brokerage_two'] = $sukValue['brokerage_two'] ? floatval($sukValue['brokerage_two']) : 0;
switch ($type) {
case 1://秒杀
$valueNew[$count]['_checked'] = true;
break;
case 2://砍价
$valueNew[$count]['min_price'] = $min_price ? floatval($min_price) : 0;
$valueNew[$count]['opt'] = true;
break;
case 3://拼团
$valueNew[$count]['_checked'] = true;
break;
case 4://积分
$valueNew[$count]['integral'] = isset($sukValue['integral']) ? floatval($sukValue['integral']) : 0;
$valueNew[$count]['_checked'] = true;
break;
default:
$valueNew[$count]['_checked'] = false;
$valueNew[$count]['opt'] = false;
break;
}
$count++;
}
}
return $valueNew;
}