|
@@ -240,16 +240,25 @@ class Info
|
|
|
}
|
|
|
|
|
|
# 获取支付所需要的信息
|
|
|
- public function getPayInfo($id, $sku)
|
|
|
+ public function getPayInfo($id, $sku, $num = 1, $user = array())
|
|
|
{
|
|
|
$info = Dever::db($this->table_info)->getOne($id);
|
|
|
|
|
|
- if ($info && $sku > 0) {
|
|
|
- $where['info_id'] = $info['id'];
|
|
|
- $where['id'] = $sku;
|
|
|
- $sku = Dever::db('goods/info_sku')->one($where);
|
|
|
- if ($sku) {
|
|
|
- $info['price'] = $sku['price'];
|
|
|
+ if ($info) {
|
|
|
+ $info['freight_id'] = 0;
|
|
|
+ $info['freight_price'] = 0;
|
|
|
+ if ($sku > 0) {
|
|
|
+ $where['info_id'] = $info['id'];
|
|
|
+ $where['id'] = $sku;
|
|
|
+ $sku = Dever::db('goods/info_sku')->one($where);
|
|
|
+ if ($sku) {
|
|
|
+ $info['price'] = $sku['price'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $freight = $this->freight($info, $info['price'], $user, $num);
|
|
|
+ if ($freight) {
|
|
|
+ $info['freight_id'] = $freight['id'];
|
|
|
+ $info['freight_price'] = $freight['price'];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -257,12 +266,12 @@ class Info
|
|
|
}
|
|
|
|
|
|
# 获取基本信息
|
|
|
- public function getInfo($id, $attr = true, $order = 'view_reorder')
|
|
|
+ public function getInfo($id, $attr = true, $order = 'view_reorder', $user = array())
|
|
|
{
|
|
|
$info = Dever::db($this->table_info)->getOne($id);
|
|
|
|
|
|
if ($info && $attr) {
|
|
|
- $info = $this->info($info, $order);
|
|
|
+ $info = $this->info($info, $order, false, $user);
|
|
|
}
|
|
|
|
|
|
if ($info['pic']) {
|
|
@@ -273,14 +282,8 @@ class Info
|
|
|
}
|
|
|
|
|
|
# 获取基本信息
|
|
|
- public function info($info, $key = 'list_reorder', $is_sell = false)
|
|
|
+ public function info($info, $key = 'list_reorder', $is_sell = false, $user = array())
|
|
|
{
|
|
|
- $info['freight'] = 0;
|
|
|
- if ($info['type'] == 1) {
|
|
|
- # 获取运费
|
|
|
- $info['freight'] = $this->freight($info);
|
|
|
- }
|
|
|
-
|
|
|
if ($info['price_type'] == 2) {
|
|
|
|
|
|
$attr = $this->setAttr($info['category'], $key);
|
|
@@ -341,28 +344,57 @@ class Info
|
|
|
|
|
|
$info = $this->getInfoLink($info);
|
|
|
|
|
|
+ $info['freight'] = 0;
|
|
|
+ if ($info['type'] == 1) {
|
|
|
+ # 获取运费
|
|
|
+ $info['freight'] = $this->freight($info, $info['price']['min']['price'], $user);
|
|
|
+ }
|
|
|
+
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
- private function freight($info)
|
|
|
+ # 运费计算,暂时用省份代表地区
|
|
|
+ private function freight($info, $goods_price, $user = array(), $num = 1)
|
|
|
{
|
|
|
- # 之后要加入当前用户的地理位置
|
|
|
$array = explode(',', $info['category']);
|
|
|
$cate = $freight = array();
|
|
|
$total = count($array);
|
|
|
$total -= 1;
|
|
|
+ if ($info && $info['goods_area']) {
|
|
|
+ $where['goods_area'] = $info['goods_area'];
|
|
|
+ }
|
|
|
+ # 用户所在地理位置
|
|
|
+ if ($user && $user['area_id']) {
|
|
|
+ $area = explode(',', $user['area_id']);
|
|
|
+ $where['area'] = $area[0];
|
|
|
+ }
|
|
|
foreach ($array as $k => $v) {
|
|
|
$cate[$k] = $v;
|
|
|
if ($k < $total) {
|
|
|
$cate[] = '-1';
|
|
|
}
|
|
|
$where['category'] = $cate;
|
|
|
+
|
|
|
$data = Dever::db('goods/freight')->one($where);
|
|
|
if ($data) {
|
|
|
$freight = $data;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ($freight) {
|
|
|
+ $price = $freight['first_price'];
|
|
|
+ if ($num > $freight['first_num']) {
|
|
|
+ $num = $num - $freight['first_num'];
|
|
|
+ $price = $freight['first_price'] + ($freight['next_price']*$num);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($freight['type'] == 2) {
|
|
|
+ $freight['price'] = $goods_price*($price/100);
|
|
|
+ } else {
|
|
|
+ $freight['price'] = $price;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return $freight;
|
|
|
}
|
|
|
|