Ejemplo n.º 1
0
function get_min_price($goods_id, $number, $rec_id)
{
    $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('cart') . " WHERE goods_id = '{$goods_id}' AND  rec_id = '{$rec_id}'";
    $res = $GLOBALS['db']->getRow($sql);
    $attr_id = $res['goods_attr_id'];
    //取得属性价格  开始
    if (empty($attr_id)) {
        $atr_price = 0;
    } else {
        $goods_att = explode(',', $attr_id);
        foreach ($goods_att as $value) {
            if (!empty($value)) {
                $sql = "SELECT `attr_price` FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id='{$goods_id}' AND `goods_attr_id`='{$value}'";
                $atr_price += $GLOBALS['db']->getOne($sql);
            }
        }
    }
    $sql = "SELECT volume_price FROM " . $GLOBALS['ecs']->table('volume_price') . "WHERE goods_id = '{$goods_id}' AND volume_number <= '{$number}'";
    $volume = $GLOBALS['db']->getOne($sql);
    //优惠价格
    //属性价格   结束
    $user_id = $res['user_id'];
    if ($user_id == 0) {
        if (!empty($atr_price)) {
            $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
            $res = $GLOBALS['db']->getROW($sql);
            if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
                if (empty($volume)) {
                    if ($res['shop_price'] > $res['promote_price']) {
                        $min_price = $res['promote_price'] + $atr_price;
                        return $min_price;
                    } else {
                        $min_price = $res['shop_price'] + $atr_price;
                        return $min_price;
                    }
                } else {
                    $min = min($volume, $res['shop_price'], $res['promote_price']);
                    //返回优惠  促销 本店 最小的价格
                    $min_price = $min + $atr_price;
                    return $min_price;
                }
            } else {
                if (empty($volume)) {
                    $min_price = $res['shop_price'] + $atr_price;
                    //return $min_price;
                } else {
                    $min = min($volume, $res['shop_price']);
                    //返回优惠  促销 本店 最小的价格
                    $min_price = $min + $atr_price;
                }
                return $min_price;
            }
        } else {
            $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
            $res = $GLOBALS['db']->getROW($sql);
            if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
                if (empty($volume)) {
                    if ($res['shop_price'] > $res['promote_price']) {
                        $min_price = $res['promote_price'];
                    } else {
                        $min_price = $res['shop_price'];
                    }
                    return $min_price;
                } else {
                    $min = min($volume, $res['shop_price'], $res['promote_price']);
                    //返回优惠  促销 本店 最小的价格
                    $min_price = $min;
                    return $min_price;
                }
            } else {
                if (empty($volume)) {
                    $min_price = $res['shop_price'];
                    return $min_price;
                } else {
                    $min = min($volume, $res['shop_price']);
                    //返回优惠  促销 本店 最小的价格
                    $min_price = $min;
                    return $min_price;
                }
            }
        }
    } else {
        $row = $GLOBALS['db']->getOne("SELECT rank_points FROM " . $GLOBALS['ecs']->table('users') . " WHERE `user_id`='{$user_id}'");
        $sql = "SELECT rank_id FROM " . $GLOBALS['ecs']->table('user_rank') . " WHERE max_points > '{$row}' ORDER BY max_points ASC LIMIT 1";
        $rank_id = $GLOBALS['db']->getOne($sql);
        //取得会员等级
        if (empty($rank_id)) {
            if (!empty($atr_price) && $atr_price != 0) {
                $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
                $res = $GLOBALS['db']->getROW($sql);
                if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
                    if (empty($volume)) {
                        if ($res['shop_price'] > $res['promote_price']) {
                            $min_price = $res['promote_price'] + $atr_price;
                        } else {
                            $min_price = $res['shop_price'] + $atr_price;
                        }
                        return $min_price;
                    } else {
                        $min = min($volume, $res['shop_price'], $res['promote_price']);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min + $atr_price;
                        return $min_price;
                    }
                } else {
                    if (empty($volume)) {
                        $min_price = $res['shop_price'] + $atr_price;
                        return $min_price;
                    } else {
                        $min = min($volume, $res['shop_price']);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min + $atr_price;
                        return $min_price;
                    }
                }
            } else {
                $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
                $res = $GLOBALS['db']->getROW($sql);
                if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
                    if (empty($volume)) {
                        if ($res['shop_price'] > $res['promote_price']) {
                            $min_price = $res['promote_price'];
                        } else {
                            $min_price = $res['shop_price'];
                        }
                        return $min_price;
                    } else {
                        $min = min($volume, $res['shop_price'], $res['promote_price']);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min;
                        return $min_price;
                    }
                } else {
                    if (empty($volume)) {
                        $min_price = $res['shop_price'];
                        return $min_price;
                    } else {
                        $min = min($volume, $res['shop_price']);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min;
                        return $min_price;
                    }
                }
            }
        } else {
            if (!empty($atr_price) && $atr_price != 0) {
                $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
                $res = $GLOBALS['db']->getROW($sql);
                $rank_price = rank_price($rank_id, $res['shop_price']);
                if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
                    if (empty($volume)) {
                        if ($res['shop_price'] > $res['promote_price']) {
                            if ($res['promote_price'] > $rank_price) {
                                $min_price = $rank_price + $atr_price;
                            } else {
                                $min_price = $res['promote_price'] + $atr_price;
                            }
                            return $min_price;
                        } else {
                            if ($res['shop_price'] > $rank_price) {
                                $min_price = $rank_price + $atr_price;
                            } else {
                                $min_price = $res['shop_price'] + $atr_price;
                            }
                            return $min_price;
                        }
                    } else {
                        $min = min($volume, $res['shop_price'], $res['promote_price'], $rank_price);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min + $atr_price;
                        return $min_price;
                    }
                } else {
                    if (empty($volume)) {
                        if ($res['shop_price'] > $rank_price) {
                            $min_price = $rank_price + $atr_price;
                        } else {
                            $min_price = $res['shop_price'] + $atr_price;
                        }
                        return $min_price;
                    } else {
                        $min = min($volume, $res['shop_price']);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min + $atr_price;
                        return $min_price;
                    }
                }
            } else {
                $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
                $res = $GLOBALS['db']->getROW($sql);
                $rank_price = rank_price($rank_id, $res['shop_price']);
                if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
                    if (empty($volume)) {
                        if ($res['shop_price'] > $res['promote_price']) {
                            if ($res['promote_price'] > $rank_price) {
                                $min_price = $rank_price;
                            } else {
                                $min_price = $res['promote_price'];
                            }
                            return $min_price;
                        } else {
                            if ($res['shop_price'] > $rank_price) {
                                $min_price = $rank_price;
                            } else {
                                $min_price = $res['shop_price'];
                            }
                            return $min_price;
                        }
                    } else {
                        $min = min($volume, $res['shop_price'], $res['promote_price'], $rank_price);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min;
                        return $min_price;
                    }
                } else {
                    if ($volume == '' && empty($volume)) {
                        if ($res['shop_price'] > $rank_price) {
                            $min_price = $rank_price;
                        } else {
                            $min_price = $res['shop_price'];
                        }
                        return $min_price;
                    } else {
                        $min = min($volume, $res['shop_price'], $rank_price);
                        //返回优惠  促销 本店 最小的价格
                        $min_price = $min;
                        return $min_price;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
             } else {
                 $total = ($res['shop_price'] + $atr_price) * $val;
                 //商品的总价
             }
             die(json_encode($total));
         } else {
             $min = min($volume, $res['shop_price']);
             //返回优惠  促销 本店 最小的价格
             $total = ($min + $atr_price) * $val;
             die(json_encode($total));
         }
     }
 } else {
     $sql = " SELECT * FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'";
     $res = $GLOBALS['db']->getROW($sql);
     $rank_price = rank_price($rank_id, $res['shop_price']);
     if ($res['is_promote'] == 1 && $res['promote_start_date'] < gmtime() && $res['promote_end_date'] > gmtime()) {
         if (empty($volume)) {
             if ($res['shop_price'] > $res['promote_price']) {
                 if ($res['promote_price'] > $rank_price) {
                     $total = $rank_price * $val;
                 } else {
                     $total = $res['promote_price'] * $val;
                     //商品的总价
                 }
                 die(json_encode($total));
             } else {
                 if ($res['shop_price'] > $rank_price) {
                     $total = $rank_price * $val;
                 } else {
                     $total = $res['shop_price'] * $val;