getOne($id); $info = $this->get($info); print_r($info);die; return $info; } private function get($info) { # 基本信息 $info['udate'] = date('Y-m-d H:i', $info['udate']); $info['cdate'] = date('Y-m-d H:i', $info['cdate']); # 获取分类 $info['category_info'] = Dever::load('product/lib/category')->getInfo($info['category']); # 获取属性 $attr = Dever::db('product/info_attr')->select(array('info_id' => $info['id'])); if ($attr) { foreach ($attr as $k => $v) { $attr_info = Dever::load('product/lib/attr')->getInfo($v['attr_id'], $v['attr_value']); if ($attr_info) { $info['attr'][] = $attr_info; } } } # 获取规格 $info['spec'] = Dever::load('product/lib/spec')->getData($info['id'], 'getData'); # 获取价格 $info['sku'] = Dever::load('product/lib/sku')->getData($info['id']); # 获取组合商品 if ($info['type'] > 10) { $info['goods'] = Dever::json_decode($info['goods']); } else { unset($info['goods']); } # 获取单位信息 if ($info['unit'] > 0) { $info['unit'] = Dever::db('product/unit')->find($info['unit']); } return $info; } # 获取商品及其属性列表 public function getSetList($table, $other_where, $cate_id = false, $col = 'goods_id', $set = array()) { $price = Dever::input('price', 0); $buy_price = Dever::input('buy_price', 0); $total = Dever::input('total', 1); if ($cate_id) { $where['top_category_id'] = $cate_id; } $where['status'] = 1; $data = Dever::db('product/info')->getData($where); $result = array(); if ($data) { $i = 0; foreach ($data as $k => $v) { $sku = Dever::db('product/info_sku')->select(array('info_id' => $v['id'])); if ($sku) { $other_where[$col] = $v['id']; $other_where['sku_id'] = -1; $other = Dever::db($table)->find($other_where); if ($set) { $result[$i]['set'] = $set; } $result[$i]['id'] = $v['id']; $result[$i]['name'] = $v['name']; $result[$i]['type'] = $v['type']; $result[$i]['stock'] = $v['stock']; $result[$i]['commission'] = $v['commission']; $result[$i]['old_price'] = 0; $result[$i]['old_buy_price'] = 0; $result[$i]['price'] = $price; $result[$i]['buy_price'] = $buy_price; $result[$i]['select'] = 2; $result[$i]['del'] = 1; $result[$i]['total'] = 0; if ($other) { if (isset($other['commission']) && $other['commission']) { $result[$i]['commission'] = $other['commission']; } if (isset($other['price']) && $other['price']) { $result[$i]['price'] = $other['price']; } if (isset($other['buy_price']) && $other['buy_price']) { $result[$i]['buy_price'] = $other['buy_price']; } if (isset($other['min']) && $other['min']) { $result[$i]['min'] = $other['min']; } if (isset($other['in_num'])) { if (isset($other['out_num'])) { $result[$i]['total'] = $other['in_num'] - $other['out_num']; } else { $result[$i]['total'] = $other['in_num']; } } elseif (isset($other['num'])) { $result[$i]['total'] = $other['num']; } $result[$i]['select'] = $other['state']; } $result[$i]['total'] = $result[$i]['total'] * $total; $result[$i]['children'] = array(); $num = count($sku); if ($sku[0]['key'] == -1) { $result[$i]['old_price'] = $sku[0]['price']; $result[$i]['old_buy_price'] = $sku[0]['buy_price']; if (!$price && $result[$i]['price'] <= 0) { $result[$i]['price'] = $sku[0]['price']; } if (!$buy_price && $result[$i]['buy_price'] <= 0) { $result[$i]['buy_price'] = $sku[0]['buy_price']; } //$result[$i]['id'] .= '-' . $sku[0]['id']; $result[$i]['end'] = true; } else { foreach ($sku as $k1 => $v1) { $v1['sku_name'] = ''; if ($v1['key']) { $key = str_replace('-', ',', $v1['key']); $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key)); $v1['sku_name'] = $spec['name']; } $name = $v['name']; if ($v1['sku_name']) { $name .= '-' . $v1['sku_name']; } $children = array ( 'id' => $v['id'] . '-' . $v1['id'], 'name' => $name, 'stock' => $v['stock'], 'commission' => $v['commission'], 'old_price' => $v1['price'] ? $v1['price'] : 0, 'old_buy_price' => $v1['buy_price'] ? $v1['buy_price'] : 0, 'price' => $price ? $price : $v1['price'], 'buy_price' => $buy_price ? $buy_price : $v1['buy_price'], 'type' => $v['type'], 'del' => 1, 'end' => true, 'total' => 0, ); $other_where['sku_id'] = $v1['id']; $other_sku = Dever::db($table)->find($other_where); $children['select'] = 2; $children['total'] = 0; if ($set) { $children['set'] = $set; } if ($other_sku) { if (isset($other_sku['commission']) && $other_sku['commission']) { $children['commission'] = $other_sku['commission']; } if (isset($other_sku['price']) && $other_sku['price']) { $children['price'] = $other_sku['price']; } if (isset($other_sku['buy_price']) && $other_sku['buy_price']) { $children['buy_price'] = $other_sku['buy_price']; } if (isset($other_sku['min']) && $other_sku['min']) { $children['min'] = $other_sku['min']; } if (isset($other_sku['in_num'])) { if (isset($other_sku['out_num'])) { $children['total'] = $other_sku['in_num'] - $other_sku['out_num']; } else { $children['total'] = $other_sku['in_num']; } } elseif (isset($other_sku['num'])) { $children['total'] = $other_sku['num']; } $children['select'] = $other_sku['state']; } $children['total'] = $children['total']*$total; $result[$i]['children'][] = $children; } } $i++; } } } return $result; } # 获取支付所需要的信息 public function getPayInfo($id, $sku = 0, $type = 1, $value = '') { $info = is_array($id) ? $id : Dever::db($this->table_info)->one($id); if ($info) { if ($type == 2) { $info['price'] = $info['f_price']; unset($info['s_price']); } else { unset($info['f_price']); } $info['sku_name'] = ''; $sku = $sku > 0 ? $sku : $info['sku_id']; if ($sku > 0) { $where['info_id'] = $info['id']; $where['id'] = $sku; $sku = Dever::db('goods/info_sku')->find($where); if ($sku) { if ($sku['type'] == 3) { $price = $sku['price']; $s_price = $sku['s_price']; $f_price = $sku['f_price']; $c_price = $sku['c_price']; $sku['price'] = 0; $sku['s_price'] = 0; $sku['f_price'] = 0; $sku['c_price'] = 0; # 计算价格 $key = explode('_', $sku['key']); $attr = Dever::db('attr/info')->find($key[0]); if ($attr) { if ($value >= $attr['sell_value']) { $sku['price'] = $price; $sku['s_price'] = $s_price; $sku['f_price'] = $f_price; $sku['c_price'] = $c_price; } } } $info['sku_id'] = $sku['id']; if ($type == 2) { $info['price'] = $sku['f_price']; } else { $info['price'] = $sku['price']; $info['s_price'] = $sku['s_price']; $info['c_price'] = $sku['c_price']; } $info['min'] = $sku['min']; //$info['attr_json'] = $sku['attr']; $info['attr'] = Dever::json_decode($sku['attr']); if ($info['attr']) { $info['attr'] = Dever::load('attr/api')->getInfoByJson($info['attr']); $info['sku_name'] = $info['attr']['string']; } } } $this->getGroup($info); if (floor($info['min']) == $info['min']) { $info['min'] = intval($info['min']); } /* $info['freight_id'] = 0; $info['freight_price'] = 0; $freight = $this->freight($info, $info['price'], $user, $num); if ($freight) { $info['freight_id'] = $freight['id']; $info['freight_price'] = $freight['price']; } */ # 佣金计算 //$info['reward'] = $this->reward($info, $info['price']*$num); } if (isset($info['price'])) { $info['price'] = trim($info['price']); } if (isset($info['s_price'])) { $info['s_price'] = trim($info['s_price']); } if (isset($info['c_price'])) { $info['c_price'] = trim($info['c_price']); } if (isset($info['f_price'])) { $info['f_price'] = trim($info['f_price']); } return $info; } }