|
|
|
@ -67,4 +67,26 @@ class Goods extends Model |
|
|
|
return $value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* add:2022-04-11,获取产品毛重,主要用于计算顺丰运费 |
|
|
|
*/ |
|
|
|
public function getWeightAttribute($value): int |
|
|
|
{ |
|
|
|
if (empty($value) && !empty($this->attributes['goods_unit'])) { |
|
|
|
$goods_unit = $this->attributes['goods_unit']; |
|
|
|
switch (true) { |
|
|
|
case preg_match('/(\d{2,})\D*±(\d{2,})/', $goods_unit, $matches): |
|
|
|
array_shift($matches); |
|
|
|
$value = (int)max($matches); |
|
|
|
break; |
|
|
|
case preg_match_all('/(\d{2,})[g|克]/', $goods_unit, $matches): |
|
|
|
$value = (int)max($matches[1]); |
|
|
|
break; |
|
|
|
default: |
|
|
|
$value = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
return $value ?: 0; |
|
|
|
} |
|
|
|
} |