示例#1
0
 function getMycartInnerhtml()
 {
     $ses = new session();
     $back = '';
     if (isset($_SESSION['shop']) and count($_SESSION['shop']) != 0) {
         $price = 0;
         foreach ($_SESSION['shop'] as $s) {
             $back .= "\n\t\t\t\t\t<span class='prod'>\n\t\t\t\t\t<span class='img'><img src='{$s['pro_img']}' alt='IMG'></span>\n\t\t\t\t\t<span class='name'>{$s['pro_name']}</span>\n\t\t\t\t\t<span class='price'>单价:" . number_format($s['pro_nowprice'], 0, '.', '') . "</span>\n\t\t\t\t\t<span class='num'>数目:{$s['num']}</span>\n\t\t\t\t\t<span class='delete' onclick='clearProduct(this,{id:{$s['pro_id']}})'>删除</span>\n\t\t\t\t\t</span>\n\t\t\t\t";
             $price += $s['pro_nowprice'] * $s['num'];
         }
         $back .= "\n\t\t\t\t<input type='hidden' id='duoshaoge' value='" . $ses->getSessionNum() . "'>\n\t\t\t\t<span class='prod'><span class='final_price'>总计:¥{$price}</span><a href='mycart.php'><span id='buy_now'>立即购买</span></a></span>\n\t\t\t";
     } else {
         $back .= "<div style='width:240px;line-height:60px;text-align:center;'>您的购物车还没有商品哦~</div>";
     }
     return $back;
 }
示例#2
0
     $ses->start();
     echo $page->getMycartInnerhtml();
     break;
 case 10:
     //clear prod
     $ses = new session();
     $ses->start();
     unset($_SESSION['shop'][$_POST['proId']]);
     echo "{\"back\":[{\"isok\":\"1\",\"info\":\"\"}]}";
     break;
 case 11:
     $ses = new session();
     $ses->start();
     $sql = new mysql();
     $dbc = $sql->connect();
     $num = $ses->getSessionNum();
     $store = array();
     foreach ($_SESSION['shop'] as $v) {
         $store[] = $v['pro_id'] . '=' . $v['num'];
     }
     $order_biaoji = time() . rand(1000, 9999);
     $order_str = implode(',', $store);
     $order_username = safe($_POST['person']);
     $order_phone = safe($_POST['phone']);
     $order_address = safe($_POST['address']);
     $query = sprintf("INSERT INTO orders (order_biaoji,order_str,order_username,order_phone,order_address) VALUES('%s','%s','%s','%s','%s')", $order_biaoji, $order_str, $order_username, $order_phone, $order_address);
     $_SESSION['order_biaoji'] = $order_biaoji;
     setcookie('order_biaoji', $order_biaoji, time() + 3600);
     $_SESSION['shop'] = array();
     mysql_query('set names utf8');
     if (mysql_query($query, $dbc)) {