function AddDd($add)
{
    global $empire, $user_tablename, $user_money, $user_userid, $user_userfen, $user_rnd, $public_r, $dbtbpre;
    //验证权限
    ShopCheckAddDdGroup();
    //购物车无内容
    if (!getcvar('mybuycar')) {
        printerror("EmptyBuycar", "history.go(-1)", 1);
    }
    $add[ddno] = RepPostVar($add[ddno]);
    $add[truename] = RepPostStr($add[truename]);
    $add[oicq] = RepPostStr($add[oicq]);
    $add[msn] = RepPostStr($add[msn]);
    $add[call] = RepPostStr($add[call]);
    $add[phone] = RepPostStr($add[phone]);
    $add[email] = RepPostStr($add[email]);
    $add[address] = RepPostStr($add[address]);
    $add[zip] = RepPostStr($add[zip]);
    $add[bz] = RepPostStr($add[bz]);
    $add[g_truename] = RepPostStr($add[g_truename]);
    $add[g_oicq] = RepPostStr($add[g_oicq]);
    $add[g_msn] = RepPostStr($add[g_msn]);
    $add[g_call] = RepPostStr($add[g_call]);
    $add[g_phone] = RepPostStr($add[g_phone]);
    $add[g_email] = RepPostStr($add[g_email]);
    $add[g_address] = RepPostStr($add[g_address]);
    $add[g_zip] = RepPostStr($add[g_zip]);
    $add[fptt] = RepPostStr($add[fptt]);
    $add[fp] = (int) $add[fp];
    $add[psid] = (int) $add[psid];
    $add[payfsid] = (int) $add[payfsid];
    if (!$add[truename] || !$add[call] || !$add[email] || !$add[address] || !$add[g_truename] || !$add[g_call] || !$add[g_address] || !$add[g_email] || !$add[psid] || !$add[payfsid]) {
        printerror("MustEnterSelect", "history.go(-1)", 1);
    }
    $mess = "AddDdSuccess";
    $haveprice = 0;
    $payby = 0;
    //返回购物车存放格式
    $buyr = ReturnBuycardd();
    $alltotal = $buyr[2];
    $alltotalfen = $buyr[1];
    $buycar = $buyr[3];
    //发票
    $fptotal = 0;
    if ($add[fp]) {
        $fptotal = $alltotal * ($public_r[fpnum] / 100);
    }
    //配送方式
    $pr = $empire->fetch1("select pid,pname,price from {$dbtbpre}enewsshopps where pid='{$add['psid']}'");
    if (empty($pr[pid])) {
        printerror("NotPsid", "history.go(-1)", 1);
    }
    //支付方式
    $payr = $empire->fetch1("select payid,payname,payurl,userpay,userfen from {$dbtbpre}enewsshoppayfs where payid='{$add['payfsid']}'");
    if (empty($payr[payid])) {
        printerror("NotPayfsid", "history.go(-1)", 1);
    }
    //取得用户信息
    $userid = (int) getcvar('mluserid');
    $username = RepPostVar(getcvar('mlusername'));
    if ($userid) {
        $rnd = RepPostVar(getcvar('mlrnd'));
        $user = $empire->fetch1("select " . $user_userid . "," . $user_money . "," . $user_userfen . " from " . $user_tablename . " where " . $user_userid . "='{$userid}' and " . $user_rnd . "='{$rnd}' limit 1");
        if (!$user[$user_userid]) {
            printerror("MustSingleUser", "history.go(-1)", 1);
        }
    }
    $location = "../ShopSys/buycar/";
    //直接扣点
    if ($payr[userfen]) {
        if ($buyr[0]) {
            printerror("NotProductForBuyfen", "history.go(-1)", 1);
        } else {
            if ($userid) {
                $buyallfen = $alltotalfen + $pr[price];
                if ($buyallfen > $user[$user_userfen]) {
                    printerror("NotEnoughFenBuy", "history.go(-1)", 1);
                }
                //扣除点数
                $usql = $empire->query("update " . $user_tablename . " set " . $user_userfen . "=" . $user_userfen . "-" . $buyallfen . " where " . $user_userid . "='{$userid}'");
                if ($usql) {
                    $mess = "AddDdSuccessa";
                    $payby = 1;
                    $haveprice = 1;
                }
            } else {
                printerror("NotLoginTobuy", "history.go(-1)", 1);
            }
        }
    } elseif ($payr[userpay]) {
        if ($userid) {
            $buyallmoney = $alltotal + $pr[price] + $fptotal;
            if ($buyallmoney > $user[$user_money]) {
                printerror("NotEnoughMoneyBuy", "history.go(-1)", 1);
            }
            //扣除金额
            $usql = $empire->query("update " . $user_tablename . " set " . $user_money . "=" . $user_money . "-" . $buyallmoney . " where " . $user_userid . "='{$userid}'");
            if ($usql) {
                $mess = "AddDdSuccessa";
                $payby = 2;
                $haveprice = 1;
            }
        } else {
            printerror("NotLoginTobuy", "history.go(-1)", 1);
        }
    } elseif ($payr[payurl]) {
        $mess = "AddDdAndToPaySuccess";
        $location = $payr[payurl];
    } else {
    }
    $ddtime = date("Y-m-d H:i:s");
    $pr[price] = (double) $pr[price];
    $alltotal = (double) $alltotal;
    $alltotalfen = (double) $alltotalfen;
    $fptotal = (double) $fptotal;
    $sql = $empire->query("insert into {$dbtbpre}enewsshopdd(ddno,ddtime,userid,username,outproduct,haveprice,checked,truename,oicq,msn,email,`call`,phone,address,zip,bz,g_truename,g_oicq,g_msn,g_email,g_call,g_phone,g_address,g_zip,buycar,psid,psname,pstotal,alltotal,payfsid,payfsname,payby,alltotalfen,fp,fptt,fptotal) values('{$add['ddno']}','{$ddtime}',{$userid},'{$username}',0,'{$haveprice}',0,'{$add['truename']}','{$add['oicq']}','{$add['msn']}','{$add['email']}','{$add['call']}','{$add['phone']}','{$add['address']}','{$add['zip']}','{$add['bz']}','{$add['g_truename']}','{$add['g_oicq']}','{$add['g_msn']}','{$add['g_email']}','{$add['g_call']}','{$add['g_phone']}','{$add['g_address']}','{$add['g_zip']}','" . addslashes($buycar) . "','{$add['psid']}','{$pr['pname']}',{$pr['price']},{$alltotal},'{$add['payfsid']}','{$payr['payname']}','{$payby}',{$alltotalfen},{$add['fp']},'{$add['fptt']}',{$fptotal});");
    if ($sql) {
        $ddid = $empire->lastid();
        $set = esetcookie("paymoneyddid", $ddid, 0);
        SetBuycar("");
        printerror($mess, $location, 1);
    } else {
        printerror("DbError", "history.go(-1)", 1);
    }
}
Exemple #2
0
function AddDd($add)
{
    global $empire, $public_r, $dbtbpre;
    $shoppr = ShopSys_ReturnSet();
    //验证权限
    ShopCheckAddDdGroup($shoppr);
    //购物车无内容
    if (!getcvar('mybuycar')) {
        printerror("EmptyBuycar", "history.go(-1)", 1);
    }
    $add[ddno] = RepPostVar($add[ddno]);
    $add[truename] = RepPostStr($add[truename]);
    $add[oicq] = RepPostStr($add[oicq]);
    $add[msn] = RepPostStr($add[msn]);
    $add[mycall] = RepPostStr($add[mycall]);
    $add[phone] = RepPostStr($add[phone]);
    $add[email] = RepPostStr($add[email]);
    $add[address] = RepPostStr($add[address]);
    $add[zip] = RepPostStr($add[zip]);
    $add[signbuild] = RepPostStr($add[signbuild]);
    $add[besttime] = RepPostStr($add[besttime]);
    $add[bz] = RepPostStr($add[bz]);
    $add[fptt] = RepPostStr($add[fptt]);
    $add[fpname] = RepPostStr($add[fpname]);
    $add[fp] = (int) $add[fp];
    $add[psid] = (int) $add[psid];
    $add[payfsid] = (int) $add[payfsid];
    $add['precode'] = RepPostVar($add['precode']);
    //基本必填
    if (!$add['ddno']) {
        printerror("EmptyBuycar", "history.go(-1)", 1);
    }
    //必填项
    ShopSys_CheckDdMust($add, $shoppr);
    $mess = "AddDdSuccess";
    $haveprice = 0;
    $payby = 0;
    //返回购物车存放格式
    $buyr = ReturnBuycardd($shoppr);
    $alltotal = $buyr[2];
    $alltotalfen = $buyr[1];
    $buycar = $buyr[3];
    $classids = $buyr['classids'];
    //配送方式
    $pr = array();
    if ($shoppr['shoppsmust']) {
        $pr = $empire->fetch1("select pid,pname,price from {$dbtbpre}enewsshopps where pid='{$add['psid']}' and isclose=0");
        if (empty($pr['pid'])) {
            printerror("NotPsid", "history.go(-1)", 1);
        }
    }
    //支付方式
    $payr = array();
    if ($shoppr['shoppayfsmust']) {
        $payr = $empire->fetch1("select payid,payname,payurl,userpay,userfen from {$dbtbpre}enewsshoppayfs where payid='{$add['payfsid']}' and isclose=0");
        if (empty($payr['payid'])) {
            printerror("NotPayfsid", "history.go(-1)", 1);
        }
    }
    //取得用户信息
    $user = array();
    $userid = (int) getcvar('mluserid');
    $username = RepPostVar(getcvar('mlusername'));
    if ($userid) {
        $rnd = RepPostVar(getcvar('mlrnd'));
        $user = $empire->fetch1("select " . eReturnSelectMemberF('userid,money,userfen,groupid') . " from " . eReturnMemberTable() . " where " . egetmf('userid') . "='{$userid}' and " . egetmf('rnd') . "='{$rnd}' limit 1");
        if (!$user['userid']) {
            printerror("MustSingleUser", "history.go(-1)", 1);
        }
    }
    //优惠
    $prer = array();
    $pretotal = 0;
    if ($add['precode']) {
        $prer = ShopSys_GetPre($add['precode'], $alltotal, $user, $classids);
        $pretotal = ShopSys_PreMoney($prer, $alltotal);
    }
    //运费
    $truetotalmoney = $alltotal - $pretotal;
    if ($pr['pid']) {
        $pr['price'] = ShopSys_PrePsTotal($pr['pid'], $pr['price'], $truetotalmoney, $shoppr);
    }
    //发票
    $fptotal = 0;
    if ($add[fp]) {
        $fptotal = ($alltotal - $pretotal) * ($shoppr['fpnum'] / 100);
    }
    //支付金额
    $buyallfen = $alltotalfen + $pr['price'];
    $buyallmoney = $alltotal + $pr['price'] + $fptotal - $pretotal;
    if ($buyallmoney < 0) {
        $buyallmoney = 0;
    }
    $location = "buycar/";
    if ($payr[userfen]) {
        if ($buyr[0]) {
            printerror("NotProductForBuyfen", "history.go(-1)", 1);
        } else {
            if ($userid) {
                $buyallfen = $alltotalfen + $pr[price];
                if ($buyallfen > $user['userfen']) {
                    printerror("NotEnoughFenBuy", "history.go(-1)", 1);
                }
                //扣除点数
                $usql = $empire->query("update " . eReturnMemberTable() . " set " . egetmf('userfen') . "=" . egetmf('userfen') . "-" . $buyallfen . " where " . egetmf('userid') . "='{$userid}'");
                if ($usql) {
                    $mess = "AddDdSuccessa";
                    $payby = 1;
                    $haveprice = 1;
                }
            } else {
                printerror("NotLoginTobuy", "history.go(-1)", 1);
            }
        }
    } elseif ($payr[userpay]) {
        if ($userid) {
            $buyallmoney = $alltotal + $pr[price] + $fptotal - $pretotal;
            if ($buyallmoney < 0) {
                $buyallmoney = 0;
            }
            if ($buyallmoney > $user['money']) {
                printerror("NotEnoughMoneyBuy", "history.go(-1)", 1);
            }
            //扣除金额
            $usql = $empire->query("update " . eReturnMemberTable() . " set " . egetmf('money') . "=" . egetmf('money') . "-" . $buyallmoney . " where " . egetmf('userid') . "='{$userid}'");
            if ($usql) {
                $mess = "AddDdSuccessa";
                $payby = 2;
                $haveprice = 1;
            }
        } else {
            printerror("NotLoginTobuy", "history.go(-1)", 1);
        }
    } elseif ($payr[payurl]) {
        $mess = "AddDdAndToPaySuccess";
        $location = $payr[payurl];
    } else {
    }
    $ddtime = date("Y-m-d H:i:s");
    $ddtruetime = time();
    $ip = egetip();
    $pr[price] = (double) $pr[price];
    $alltotal = (double) $alltotal;
    $alltotalfen = (double) $alltotalfen;
    $fptotal = (double) $fptotal;
    $pretotal = (double) $pretotal;
    $sql = $empire->query("insert into {$dbtbpre}enewsshopdd(ddno,ddtime,userid,username,outproduct,haveprice,checked,truename,oicq,msn,email,`mycall`,phone,address,zip,psid,psname,pstotal,alltotal,payfsid,payfsname,payby,alltotalfen,fp,fptt,fptotal,fpname,userip,signbuild,besttime,pretotal,ddtruetime) values('{$add['ddno']}','{$ddtime}',{$userid},'{$username}',0,'{$haveprice}',0,'{$add['truename']}','{$add['oicq']}','{$add['msn']}','{$add['email']}','{$add['mycall']}','{$add['phone']}','{$add['address']}','{$add['zip']}','{$add['psid']}','{$pr['pname']}',{$pr['price']},{$alltotal},'{$add['payfsid']}','{$payr['payname']}','{$payby}',{$alltotalfen},{$add['fp']},'{$add['fptt']}',{$fptotal},'{$add['fpname']}','{$ip}','{$add['signbuild']}','{$add['besttime']}','{$pretotal}','{$ddtruetime}');");
    $ddid = $empire->lastid();
    $sqladd = $empire->query("insert into {$dbtbpre}enewsshopdd_add(ddid,buycar,bz,retext) values('{$ddid}','" . addslashes($buycar) . "','{$add['bz']}','');");
    //减库存
    if ($shoppr['cutnumtype'] == 0) {
        Shopsys_CutMaxnum($ddid, $buycar, 0, $shoppr, 0);
    } else {
        if ($haveprice == 1) {
            Shopsys_CutMaxnum($ddid, $buycar, 0, $shoppr, 0);
        }
    }
    //优惠码
    if ($prer['id']) {
        $prer['id'] = (int) $prer['id'];
        if ($prer['reuse'] == 0) {
            $empire->query("delete from {$dbtbpre}enewsshop_precode where id='" . $prer['id'] . "'");
        } elseif ($prer['reuse'] && $prer['usenum']) {
            if ($prer['usenum'] <= $prer['haveusenum'] + 1) {
                $empire->query("delete from {$dbtbpre}enewsshop_precode where id='" . $prer['id'] . "'");
            } else {
                $empire->query("update {$dbtbpre}enewsshop_precode set haveusenum=haveusenum+1 where id='" . $prer['id'] . "'");
            }
        }
    }
    if ($sql) {
        $set = esetcookie("paymoneyddid", $ddid, 0);
        SetBuycar("");
        printerror($mess, $location, 1);
    } else {
        printerror("DbError", "history.go(-1)", 1);
    }
}