You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.5 KiB
67 lines
2.5 KiB
<?php
|
|
|
|
namespace app\common;
|
|
|
|
use think\facade\Db;
|
|
|
|
class Goods
|
|
{
|
|
public static function get_goods_properties($id)
|
|
{
|
|
/* 對屬性進行重新排序和分組 */
|
|
$grp = Db::name('goods_type')
|
|
->alias('gt')
|
|
->join('goods g', 'gt.cat_id=g.goods_type')
|
|
->where('g.goods_id', $id)
|
|
->value('attr_group');
|
|
|
|
if (!empty($grp)) {
|
|
$groups = explode("\n", strtr($grp, "\r", ''));
|
|
}
|
|
|
|
$res = Db::name('goods_attr')
|
|
->field('a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type,g.goods_attr_id, g.attr_value, g.attr_price, g.attr_sort_order,g.thumb_url,g.img_url, g.img_original, hex_color')
|
|
->alias('g')
|
|
->join('attribute a', 'a.attr_id=g.attr_id')
|
|
->where('g.goods_id', $id)
|
|
->order('a.sort_order, a.attr_id, g.attr_sort_order, g.attr_price, g.goods_attr_id')
|
|
->select();
|
|
|
|
$arr['pro'] = []; // 屬性
|
|
$arr['spe'] = []; // 規格
|
|
$arr['lnk'] = []; // 關聯的屬性
|
|
|
|
foreach ($res as $row) {
|
|
$row['attr_value'] = str_replace("\n", '<br />', $row['attr_value']);
|
|
|
|
if ($row['attr_type'] == 0) {
|
|
$group = (isset($groups[$row['attr_group']])) ? $groups[$row['attr_group']] : $GLOBALS['_LANG']['goods_attr'];
|
|
|
|
$arr['pro'][$group][$row['attr_id']]['name'] = $row['attr_name'];
|
|
$arr['pro'][$group][$row['attr_id']]['value'] = $row['attr_value'];
|
|
} else {
|
|
$arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];
|
|
$arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];
|
|
$arr['spe'][$row['attr_id']]['values'][] = array(
|
|
'label' => $row['attr_value'],
|
|
'price' => $row['attr_price'],
|
|
'thumb_url' => $row['thumb_url'],
|
|
'img_url' => $row['img_url'],
|
|
'img_original' => $row['img_original'],
|
|
'hex_color' => $row['hex_color'],
|
|
'format_price' => price_format(abs($row['attr_price']), false),
|
|
'id' => $row['goods_attr_id']
|
|
);
|
|
}
|
|
|
|
if ($row['is_linked'] == 1) {
|
|
/* 如果該屬性需要關聯,先保存下來 */
|
|
$arr['lnk'][$row['attr_id']]['name'] = $row['attr_name'];
|
|
$arr['lnk'][$row['attr_id']]['value'] = $row['attr_value'];
|
|
}
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
}
|