find($where); } elseif ($spec_type == 3) { $sku = Dever::db('sku', $app)->find($where, array('order' => 'price asc,id desc')); } if (isset($sku) && $sku && $sku['key']) { $result['price'] = $sku['price']; $result['id'] = $sku['id']; if (isset($sku['num'])) { $result['num'] = $sku['num']; } $result['key'] = str_replace(',', '_', $sku['key']); $result['name'] = $this->getName($sku['key'], $app); } else { Dever::error('价格传入错误'); } return $result; } # 多规格获取多个价格 public function getList($where, $sku_id, $app) { $result = array(); $sku = Dever::db('sku', $app)->select($where, array('order' => 'price asc,id desc')); if ($sku) { $result['sku'] = array(); $result['spec'] = Dever::load('spec', 'api')->getList($where, $app); foreach ($sku as $k => $v) { $t = array(); $k = str_replace(',', '_', $v['key']); $t['id'] = $v['id']; $t['pic'] = $v['pic']; $t['price'] = $v['price']; if (isset($v['num'])) { $t['num'] = $v['num']; } $result['price'][$k] = $t; if ($sku_id && $sku_id == $v['id']) { $t['name'] = $this->getName($v['key'], $app); $result['sku'] = $t; } } } return $result; } # 获取某个sku的名称 public function getName($key, $app) { if (!$key || $key == '-1') { return '无规格'; } else { $name = array(); $where['id'] = array('in', $key); $data = Dever::db('spec_value', $app)->select($where); if ($data) { foreach ($data as $k => $v) { $info = Dever::db('spec', $app)->find($v['spec_id']); $name[] = $info['name'] . ':' . $v['value']; } } return implode(',', $name); } } }