Exemplo n.º 1
0
 public function change_quantity()
 {
     import('Think.ORG.Cart');
     // 导入购物车类
     $cart = new Cart();
     $itemId = $this->_post('itemId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $item = M('item')->field('goods_stock')->find($itemId);
     if ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '该商品的库存不足');
     } else {
         $cart->modNum($itemId, $quantity);
         $data = array('status' => 1, 'item' => $cart->getItem($itemId), 'sumPrice' => $cart->getPrice());
     }
     echo json_encode($data);
 }
Exemplo n.º 2
0
 public function pay()
 {
     if (IS_POST && count($_SESSION['cart']) > 0) {
         $_SESSION['end'] = 0;
         import('Think.ORG.Cart');
         // 导入分页类
         $cart = new Cart();
         $user_address = M('user_address');
         $item_order = M('item_order');
         $order_detail = M('order_detail');
         $item_goods = M('item');
         $this->visitor->info['id'];
         //用户ID
         $this->visitor->info['username'];
         //用户账号
         //生成订单号
         $dingdanhao = date("Y-m-dH-i-s");
         $dingdanhao = str_replace("-", "", $dingdanhao);
         $dingdanhao .= rand(1000, 2000);
         $time = time();
         //订单添加时间
         $address_options = $this->_post('address_options', 'intval');
         //地址  0:刚填的地址 大于0历史的地址
         $shipping_id = $this->_post('shipping_id', 'intval');
         //配送方式
         $postscript = $this->_post('postscript', 'trim');
         //卖家留言
         if (!empty($postscript)) {
             $data['note'] = $postscript;
         }
         if (empty($shipping_id)) {
             $data['freetype'] = 0;
             $data['order_sumPrice'] = $cart->getPrice();
         } else {
             $data['freetype'] = $shipping_id;
             $data['freeprice'] = $this->getFree($shipping_id);
             //取到运费
             $data['order_sumPrice'] = $cart->getPrice() + $this->getFree($shipping_id);
             //echo $cart->getPrice()+$this->getFree($shipping_id);exit;
         }
         $data['orderId'] = $dingdanhao;
         //订单号
         $data['add_time'] = $time;
         //添加时间
         $data['goods_sumPrice'] = $cart->getPrice();
         //商品总额
         $data['color'] = $cart->getColor();
         //商品颜色
         //$data['userId']=$this->visitor->info['id'];//用户ID
         //$data['userName']=$this->visitor->info['username'];//用户名
         $data['userId'] = '123';
         //用户ID
         $data['userName'] = '******';
         //用户名
         if ($address_options == 0) {
             $consignee = $this->_post('consignee', 'trim');
             //真实姓名
             $sheng = $this->_post('sheng', 'trim');
             //省
             $shi = $this->_post('shi', 'trim');
             //市
             $qu = $this->_post('qu', 'trim');
             //区
             $address = $this->_post('address', 'trim');
             //详细地址
             $phone_mob = $this->_post('phone_mob', 'trim');
             //电话号码
             $save_address = $this->_post('save_address', 'trim');
             //是否保存地址
             $data['address_name'] = $consignee;
             //收货人姓名
             $data['mobile'] = $phone_mob;
             //电话号码
             $data['address'] = $sheng . $shi . $qu . $address;
             //地址
             if ($save_address) {
                 $add_address['uid'] = $this->visitor->info['id'];
                 $add_address['consignee'] = $consignee;
                 $add_address['address'] = $address;
                 $add_address['mobile'] = $phone_mob;
                 $add_address['sheng'] = $sheng;
                 $add_address['shi'] = $shi;
                 $add_address['qu'] = $qu;
                 $user_address->data($add_address)->add();
             }
         } else {
             $userId = $this->visitor->info['id'];
             $address = $user_address->where("uid='{$userId}'")->find($address_options);
             //取到地址
             $data['address_name'] = $address['consignee'];
             //收货人姓名
             $data['mobile'] = $address['mobile'];
             //电话号码
             $data['address'] = $address['sheng'] . $address['shi'] . $address['qu'] . $address['address'];
             //地址
         }
         if ($orderid = $item_order->data($data)->add()) {
             $orders['orderId'] = $dingdanhao;
             foreach ($_SESSION['cart'] as $item) {
                 $item_goods->where('id=' . $item['id'])->setDec('goods_stock', $item['num']);
                 $orders['itemId'] = $item['id'];
                 //商品ID
                 $orders['title'] = $item['name'];
                 //商品名称
                 $orders['img'] = $item['img'];
                 //商品图片
                 $orders['price'] = $item['price'];
                 //商品价格
                 $orders['quantity'] = $item['num'];
                 //购买数量
                 $orders['color'] = $item['color'];
                 //购买数量
                 $order_detail->data($orders)->add();
             }
             $cart->clear();
             //清空购物车
             $payment_id = $_POST['payment_id'];
             $item_order = M('item_order')->where(" orderId='{$dingdanhao}'")->find();
             !$item_order && $this->_404();
             $title = '新订单' . $data['goods_sumPrice'] . '元';
             $content = '您收到订单' . $dingdanhao . ',商品' . $orders['quantity'] . '件,总价格' . $data['goods_sumPrice'] . '元。购买者姓名:' . $consignee . '。收货人地址:' . $data['address'];
             $tips_data = M('setting')->where(" name='tips'")->find();
             $emails = unserialize($tips_data['data']);
             if ($payment_id == 2) {
                 $data['status'] = 2;
                 $data['supportmetho'] = 2;
                 $data['support_time'] = time();
                 if (M('item_order')->where("orderId='{$dingdanhao}'")->data($data)->save()) {
                     $_SESSION['end'] = 1;
                     if ($emails && !empty($emails)) {
                         $mailer = mailer::get_instance();
                         $mailer->send($emails, $title, $content);
                     }
                     $this->redirect('Shopcart/index');
                 } else {
                     $this->error('操作失败!');
                 }
             } elseif ($payment_id == 1) {
                 $data['supportmetho'] = 1;
                 $userId = $this->visitor->info['id'];
                 if (M('item_order')->where("and orderId='{$dingdanhao}'")->data($data)->save()) {
                     $alipay = M('alipay')->find();
                     echo "<script>location.href='api/wapalipay/alipayapi.php?WIDseller_email=" . $alipay['alipayname'] . "&WIDout_trade_no=" . $dingdanhao . "&WIDsubject=" . $dingdanhao . "&WIDtotal_fee=" . $item_order['order_sumPrice'] . "'</script>";
                 } else {
                     $this->error('操作失败!');
                 }
             } else {
                 $this->error('操作失败!');
             }
             $this->assign('orderid', $orderid);
             //订单ID
             $this->assign('dingdanhao', $dingdanhao);
             //订单号
             $this->assign('order_sumPrice', $data['order_sumPrice']);
         } else {
             $this->error('生成订单失败!');
         }
     } else {
         if (isset($_GET['orderId'])) {
             $item_order = M('item_order');
             $orderId = $_GET['orderId'];
             //订单号
             $userId = $this->visitor->info['id'];
             $orders = $item_order->where("userId='{$userId}' and orderId='{$orderId}'")->find();
             if (!is_array($orders)) {
                 $this->_404();
             }
             if (empty($orders['supportmetho'])) {
                 $this->assign('orderid', $orders['id']);
                 //订单ID
                 $this->assign('dingdanhao', $orders['orderId']);
                 //订单号
                 $this->assign('order_sumPrice', $orders['order_sumPrice']);
             } else {
                 $alipay = M('alipay')->find();
                 echo "<script>location.href='api/wapalipay/alipayapi.php?WIDseller_email=" . $alipay['alipayname'] . "&WIDout_trade_no=" . $orderId . "&WIDsubject=" . $orderId . "&WIDtotal_fee=" . $orders['order_sumPrice'] . "'</script>";
                 exit;
             }
         } else {
             $this->redirect('Index/index?m=Item&a=index&id=127');
         }
     }
     $this->display();
 }
Exemplo n.º 3
0
 public function pay()
 {
     if (IS_POST && count($_SESSION['cart']) > 0) {
         import('Think.ORG.Cart');
         // 导入分页类
         $cart = new Cart();
         $user_address = M('user_address');
         $item_order = M('item_order');
         $order_detail = M('order_detail');
         $item_goods = M('item');
         $this->visitor->info['id'];
         //用户ID
         $this->visitor->info['username'];
         //用户账号
         //生成订单号
         $dingdanhao = date("Y-m-dH-i-s");
         $dingdanhao = str_replace("-", "", $dingdanhao);
         $dingdanhao .= rand(1000, 2000);
         $time = time();
         //订单添加时间
         $address_options = $this->_post('address_options', 'intval');
         //地址  0:刚填的地址 大于0历史的地址
         $shipping_id = $this->_post('shipping_id', 'intval');
         //配送方式
         $postscript = $this->_post('postscript', 'trim');
         //卖家留言
         if (!empty($postscript)) {
             //卖家留言
             $data['note'] = $postscript;
         }
         if (empty($shipping_id)) {
             //卖家包邮
             $data['freetype'] = 0;
             $data['order_sumPrice'] = $cart->getPrice();
         } else {
             $data['freetype'] = $shipping_id;
             $data['freeprice'] = $this->getFree($shipping_id);
             //取到运费
             $data['order_sumPrice'] = $cart->getPrice() + $this->getFree($shipping_id);
             //echo $cart->getPrice()+$this->getFree($shipping_id);exit;
         }
         $data['orderId'] = $dingdanhao;
         //订单号
         $data['add_time'] = $time;
         //添加时间
         $data['goods_sumPrice'] = $cart->getPrice();
         //商品总额
         $data['userId'] = $this->visitor->info['id'];
         //用户ID
         $data['userName'] = $this->visitor->info['username'];
         //用户名
         if ($address_options == 0) {
             $consignee = $this->_post('consignee', 'trim');
             //真实姓名
             $sheng = $this->_post('sheng', 'trim');
             //省
             $shi = $this->_post('shi', 'trim');
             //市
             $qu = $this->_post('qu', 'trim');
             //区
             $address = $this->_post('address', 'trim');
             //详细地址
             $phone_mob = $this->_post('phone_mob', 'trim');
             //电话号码
             $save_address = $this->_post('save_address', 'trim');
             //是否保存地址
             $data['address_name'] = $consignee;
             //收货人姓名
             $data['mobile'] = $phone_mob;
             //电话号码
             $data['address'] = $sheng . $shi . $qu . $address;
             //地址
             if ($save_address) {
                 //保存地址
                 $add_address['uid'] = $this->visitor->info['id'];
                 $add_address['consignee'] = $consignee;
                 $add_address['address'] = $address;
                 $add_address['mobile'] = $phone_mob;
                 $add_address['sheng'] = $sheng;
                 $add_address['shi'] = $shi;
                 $add_address['qu'] = $qu;
                 $user_address->data($add_address)->add();
             }
         } else {
             $address = $user_address->where('uid=' . $this->visitor->info['id'])->find($address_options);
             //取到地址
             $data['address_name'] = $address['consignee'];
             //收货人姓名
             $data['mobile'] = $address['mobile'];
             //电话号码
             $data['address'] = $address['sheng'] . $address['shi'] . $address['qu'] . $address['address'];
             //地址
         }
         if ($orderid = $item_order->data($data)->add()) {
             //添加订单成功
             $orders['orderId'] = $dingdanhao;
             foreach ($_SESSION['cart'] as $item) {
                 $item_goods->where('id=' . $item['id'])->setDec('goods_stock', $item['num']);
                 $orders['itemId'] = $item['id'];
                 //商品ID
                 $orders['title'] = $item['name'];
                 //商品名称
                 $orders['img'] = $item['img'];
                 //商品图片
                 $orders['price'] = $item['price'];
                 //商品价格
                 $orders['quantity'] = $item['num'];
                 //购买数量
                 $order_detail->data($orders)->add();
             }
             $cart->clear();
             //清空购物车
             $this->assign('orderid', $orderid);
             //订单ID
             $this->assign('dingdanhao', $dingdanhao);
             //订单号
             $this->assign('order_sumPrice', $data['order_sumPrice']);
         } else {
             $this->error('生成订单失败!');
         }
     } elseif (isset($_GET['orderId'])) {
         $item_order = M('item_order');
         $orderId = $_GET['orderId'];
         //订单号
         $orders = $item_order->where('userId=' . $this->visitor->info['id'] . ' and orderId=' . $orderId)->find();
         if (!is_array($orders)) {
             $this->_404();
         }
         if (empty($orders['supportmetho'])) {
             //是否已有支付方式
             $this->assign('orderid', $orders['id']);
             //订单ID
             $this->assign('dingdanhao', $orders['orderId']);
             //订单号
             $this->assign('order_sumPrice', $orders['order_sumPrice']);
         } else {
             $alipay = M('alipay')->find();
             echo "<script>location.href='wapapli/alipayapi.php?WIDseller_email=" . $alipay['alipayname'] . "&WIDout_trade_no=" . $orderId . "&WIDsubject=" . $orderId . "&WIDtotal_fee=" . $orders['order_sumPrice'] . "'</script>";
             exit;
         }
     } else {
         $this->redirect('user/index');
     }
     $this->display();
 }
Exemplo n.º 4
0
 public function jiesuan()
 {
     //结算
     $tokenTall = $this->getTokenTall();
     $this->assign('tokenTall', $tokenTall);
     if (count($_SESSION['cart']) > 0) {
         $user_address_mod = M('user_address');
         $address_list = $user_address_mod->where(array('uid' => $this->visitor->info['id']))->select();
         $this->assign('address_list', $address_list);
         //购物车按店铺分组
         $result = $this->cart_by_group();
         //按订单整合物流方式(合并各个商品的物流方式和金额)
         foreach ($result as $key => $value) {
             $free_style = 1;
             $pingyou = 0;
             $kuaidi = 0;
             $ems = 0;
             foreach ($value['item'] as $items) {
                 if ($items['free'] == '2') {
                     $free_style = 2;
                     $pingyou += floatval($items['pingyou']);
                     $kuaidi += floatval($items['kuaidi']);
                     $ems += floatval($items['ems']);
                 }
             }
             $result[$key]['free'] = $free_style;
             $result[$key]['pingyou'] = $pingyou;
             $result[$key]['kuaidi'] = $kuaidi;
             $result[$key]['ems'] = $ems;
         }
         //header("content-Type: text/html; charset=Utf-8");
         //dump($result);exit;
         $this->assign('allinfo', $result);
         import('Think.ORG.Cart');
         // 导入购物车类
         $cart = new Cart();
         $sumPrice = $cart->getPrice();
         $this->assign('sumPrice', $sumPrice);
         $this->_config_seo();
         $this->display();
     } else {
         $this->redirect('shopcart/index', array('tokenTall' => $tokenTall));
     }
 }
Exemplo n.º 5
0
 public function change_quantity()
 {
     import('Think.ORG.Cart');
     // 导入购物车类
     $cart = new Cart();
     $itemId = $this->_post('itemId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $spec_id = $this->_post('spec_id', 'intval');
     //购买数量
     $goods_stock = 0;
     $spec_1 = '';
     $spec_2 = '';
     $price = 0;
     $item = M('item')->field('id,title,img,price,goods_stock')->find($itemId);
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     }
     if ($spec_id == 0) {
         $goods_stock = $item['goods_stock'];
         $price = $item['price'];
     } else {
         $item_spec = M('item_spec')->field('spec_1,spec_2,price,stock')->find($spec_id);
         $goods_stock = $item_spec['stock'];
         $price = $item_spec['price'];
         $spec_1 = $item_spec['spec_1'];
         $spec_2 = $item_spec['spec_2'];
     }
     if ($goods_stock < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $cart->modNum($itemId, $spec_id, $quantity);
         $data = array('status' => 1, 'item' => $cart->getItem($itemId, $spec_id), 'sumPrice' => $cart->getPrice());
     }
     echo json_encode($data);
 }
Exemplo n.º 6
0
 public function pay()
 {
     $this->is_login();
     $userinfo = session('P');
     $wxpay_config = $this->ag_hongbao_config();
     if (empty($wxpay_config['Allow_type'])) {
         $this->error('暂不支持任何形式付款');
     }
     if (IS_POST && count($_SESSION['cart']) > 0) {
         import('@.ORG.Cart');
         $cart = new \Cart();
         $user_address = M('shop_useraddress');
         $item_order = M('shop_orders');
         $order_detail = M('order_detail');
         //生成订单号
         $dingdanhao = date("Y-m-dH-i-s");
         $dingdanhao = str_replace("-", "", $dingdanhao);
         $dingdanhao .= rand(1000, 9999);
         $time = time();
         //订单添加时间
         $address_options = I('post.address_options', '', 'intval');
         //地址  0:刚填的地址 大于0历史的地址
         $shipping_id = I('post.shipping_id', '', 'intval');
         //配送方式
         $postscript = I('post.postscript', '', 'trim');
         //卖家留言
         if (!empty($postscript)) {
             //卖家留言
             $data['note'] = $postscript;
         }
         //仅支持卖家包邮
         //if(empty($shipping_id)){//卖家包邮
         $data['freetype'] = 0;
         $data['order_sumPrice'] = $cart->getPrice();
         //} else{
         // $data['freetype']       = $shipping_id;
         // $data['freeprice']      = $this->getFree($shipping_id);//取到运费
         // $data['order_sumPrice'] = $cart->getPrice()+$this->getFree($shipping_id);
         //}
         $data['orderId'] = $dingdanhao;
         //订单号
         $data['add_time'] = $time;
         //添加时间
         $data['goods_sumPrice'] = $cart->getPrice();
         //商品总额
         $data['userId'] = $userinfo['id'];
         //用户ID
         if ($address_options == 0) {
             $consignee = I('post.consignee', '', 'trim');
             //真实姓名
             $sheng = I('post.sheng', '', 'trim');
             //省
             $shi = I('post.shi', '', 'trim');
             //市
             $qu = I('post.qu', '', 'trim');
             //区
             $address = I('post.address', '', 'trim');
             //详细地址
             $phone_mob = I('post.phone_mob', '', 'trim');
             //电话号码
             $save_address = I('post.save_address', '', 'trim');
             //是否保存地址
             $data['address_name'] = $consignee;
             //收货人姓名
             $data['mobile'] = $phone_mob;
             //电话号码
             $data['address'] = $sheng . $shi . $qu . $address;
             //地址
             //自动保存地址进数据库
             if ($save_address) {
                 $add_address['consignee'] = $consignee;
                 $add_address['address'] = $address;
                 $add_address['mobile'] = $phone_mob;
                 $add_address['sheng'] = $sheng;
                 $add_address['shi'] = $shi;
                 $add_address['qu'] = $qu;
                 $user_address->add($add_address);
             }
         } else {
             $userId = $userinfo['id'];
             //提取用户地址
             $address = $user_address->where("uid='{$userId}'")->find($address_options);
             //取到地址
             $data['address_name'] = $address['consignee'];
             //收货人姓名
             $data['mobile'] = $address['mobile'];
             //电话号码
             $data['address'] = $address['sheng'] . $address['shi'] . $address['qu'] . $address['address'];
             //地址
         }
         $orderid = $item_order->add($data);
         //添加订单
         if ($orderid) {
             $orders['orderId'] = $dingdanhao;
             $item_goods = M('docunment_shop');
             foreach ($_SESSION['cart'] as $item) {
                 //减少库存
                 $item_goods->where(array('id' => $item['id']))->setDec('shop_goods_stock', $item['num']);
                 //$item_goods->where('id ='.$item['id'])->setDec('goods_stock',$item['num']);
                 $orders['itemId'] = $item['id'];
                 //商品ID
                 $orders['title'] = $item['name'];
                 //商品名称
                 $orders['img'] = $item['img'];
                 //商品图片
                 $orders['price'] = $item['price'];
                 //商品价格
                 $orders['quantity'] = $item['num'];
                 //购买数量
                 $order_detail->add($orders);
             }
             $cart->clear();
             //清空购物车
             $this->assign('orderid', $orderid);
             //订单ID
             $this->assign('dingdanhao', $dingdanhao);
             //订单号
             $this->assign('order_sumPrice', $data['order_sumPrice']);
         } else {
             $this->error('生成订单失败!');
         }
     } else {
         if (isset($_GET['orderId'])) {
             $item_order = M('shop_orders');
             //订单号
             $userId = $userinfo['id'];
             //去除单号  安全后缀  空格
             $orderId = str_replace(' ', '', str_replace('.html?showwxpaytitle=1', '', $_GET['orderId']));
             $orders = $item_order->where("userId='{$userId}' and orderId='{$orderId}'")->find();
             if (!is_array($orders)) {
                 $this->error('该订单不存在');
             }
             Wxpay::get_prepay_id();
             if (empty($orders['supportmetho'])) {
                 //是否已有支付方式
                 $this->assign('orderid', $orders['id']);
                 //订单ID
                 $this->assign('dingdanhao', $orders['orderId']);
                 //订单号
                 $this->assign('order_sumPrice', $orders['order_sumPrice']);
             } else {
                 //微信支付
                 $alipay = M('alipay')->find();
                 echo "<script>location.href='wapapli/alipayapi.php?WIDseller_email=" . $alipay['alipayname'] . "&WIDout_trade_no=" . $orderId . "&WIDsubject=" . $orderId . "&WIDtotal_fee=" . $orders['order_sumPrice'] . "'</script>";
                 die;
             }
         }
     }
     $this->book_menu($userinfo);
     //选择支付方式  货到付款  微信支付
     if (!empty($wxpay_config['hb_dh_diyong'])) {
         $time = time();
         $map['hb_star'] = array('lt', $time);
         $map['hb_end'] = array('gt', $time);
         $map['status'] = 1;
         $map['userid'] = $userinfo['id'];
         $hblist = M('wxpay_userhongbao')->where($map)->select();
         $this->assign('hblist', $hblist);
     }
     $this->assign('paylist', $wxpay_config['Allow_type']);
     $this->display();
 }
Exemplo n.º 7
0
session_start();
require_once './function/DbConnect.php';
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    </head>
    <body>
<?php 
require_once './Cart.php';
$con = DbConnect::Connection();
$cart = new Cart(1);
echo "<table border=1>";
$data = $_SESSION['cart'];
echo "<tr><td>菜品名</td><td>单价</td><td>数量</td></tr>";
foreach ($data as $item) {
    $queryFood = DbConnect::queryFoodById($con, $item['id']);
    $resultFood = mysql_fetch_array($queryFood);
    echo "<tr><td>" . $resultFood['name'] . "</td><td>" . $item['price'] . "</td><td>" . $item['num'] . "</td></tr>";
}
echo "</table>";
echo $cart->getPrice();
echo "<form action='submit.php' method='post'>";
echo "</br>请选择配送方式,选择‘配送’即为配送到宿舍,如果您想自己顺路带回宿舍,请选择‘自取’,在学三楼下曙光打印店附近餐车处领餐</br>";
echo "<select name='type'><option value=\"配送\">配送</option><option value=\"自取\">自取</option><option value=\"订餐送TA\">订餐送TA</option></select></br>";
echo "<input type='submit'>";
?>
        
    </body>
</html>