Example #1
0
/**
 * 返回优惠券可抵用金额
 */
function get_fcoupon_fee($code, $total)
{
    $lowfee = get_fcoupon_lowpayment($code);
    //优惠券最低消费金额
    if ($lowfee < $total) {
        $codeid = M("fcoupon")->where("code='{$code}' and status='1'")->getField('id');
        //获取优惠券主键id
        $fee = get_coupon_price($codeid);
        //获取优惠券等值金额
        //获取会员uid
        $uid = D("member")->uid();
        $usercouponid = M("usercoupon")->where("couponid='{$codeid}' and status='1' and uid='{$uid}'")->getField('id');
        //获取用户可用优惠券主键id
        if ($usercouponid) {
            $deccode = $fee;
            M("usercoupon")->where("couponid='{$codeid}' and uid='{$uid}'")->setField('status', 2);
            //设置优惠券已用
        } else {
            $deccode = 0;
        }
    } else {
        $deccode = 0;
    }
}
 public function makeorder()
 {
     /* 菜单调用*/
     $menu = R('index/menulist');
     $this->assign('categoryq', $menu);
     /* 购物车调用*/
     $cart = R("shopcart/usercart");
     $this->assign('usercart', $cart);
     if (!session('user_auth')) {
         $usercart = $_SESSION['cart'];
         $this->assign('usercart', $usercart);
     }
     /* 热词调用*/
     $hotsearch = R("Index/getHotsearch");
     $this->assign('hotsearch', $hotsearch);
     $id = $_POST["orderid"];
     $del = M("order")->where("total=''")->delete();
     $order = D("order");
     //计算提交的订单的商品总额
     $total = $this->getPricetotal($id);
     //计算提交的订单的商品运费
     if ($total < C('LOWWEST')) {
         $trans = C('SHIPPRICE');
     } else {
         $trans = 0;
     }
     //计算提交的积分兑换
     if ($_POST["score"]) {
         $score = $_POST["score"];
         //读取配置,1000积分兑换1元
         $ratio = $score / C('RATIO');
         $data['score'] = $score;
     } else {
         $ratio = 0;
     }
     //计算提交的优惠券
     if ($_POST["couponcode"]) {
         $code = $_POST["couponcode"];
         $codeid = M("fcoupon")->where("code='{$code}'")->getfield('id');
         $deccode = get_coupon_price($codeid);
         $data['codeid'] = $codeid;
     } else {
         $deccode = 0;
     }
     $senderid = $_POST["sender"];
     $data['addressid'] = $senderid;
     $data['total'] = $total;
     $data['ptime'] = NOW_TIME;
     $data['shipprice'] = $trans;
     //计算提交的订单的总费用
     $all = $total + $trans - $ratio - $deccode;
     $data['pricetotal'] = $all;
     //修改订单状态为用户已提交
     if ($_POST["PayType"] == "1") {
         $data['status'] = "1";
         $data['backinfo'] = "已提交等待发货";
         //增加取消订单
         $cid = $order->where("id='{$id}'")->getField('orderid');
         $cancle = "<A href='http://" . $_SERVER['HTTP_HOST'] . "/index.php?s=/Home/Order/cancel/id/" . $cid . "'>取消订单</a>";
         $data['act_cancel'] = $cancle;
         //根据订单id保存对应的费用数据
         $order->where("id='{$id}'")->save($data);
         //根据订单id获取购物清单
         $del = M("shoplist")->where("orderid='{$id}'")->select();
         //获取会员uid
         $member = D("member");
         $uid = $member->uid();
         //遍历购物清单,删除登录用户购物车中的货物id
         foreach ($del as $k => $val) {
             //获取购物清单数据表产品id,字段goodid
             $delbyid = $val["goodid"];
             //删除购物车中用户的产品id
             M("shopcart")->where("goodid='{$delbyid}'and uid='{$uid}'")->delete();
         }
         $ordercode = $order->where("id='{$id}'")->getField('orderid');
         $this->assign('codeid', $ordercode);
         $this->display('success');
     } else {
         //设置订单状态为用户为未能完成,不删除数据
         $data['backinfo'] = "等待支付";
         $data['ispay'] = "1";
         //根据订单id保存对应的费用数据
         $order->where("id='{$id}'")->save($data);
         $ordercode = $order->where("id='{$id}'")->getField('orderid');
         $this->assign('codeid', $ordercode);
         $this->assign('goodprice', $all);
         //支付页
         $this->display('Pay/index');
     }
 }
                echo get_cover(get_icon($vo["couponid"]), 'path');
                ?>
"  width="170" height="170"/></a></p>
				<p><a href="javascript:vod(0);"><span class="red"><?php 
                echo get_coupon_name($vo["couponid"]);
                ?>
</span></a>[<?php 
                echo $vo["info"];
                ?>
]</p> 
				<p>优惠券代码:<?php 
                echo get_coupon_code($vo["couponid"]);
                ?>
</a></p> 
                 <p>价值:<span class="red"><?php 
                echo get_coupon_price($vo["couponid"]);
                ?>
元</span>
                 </p><?php 
            }
        }
    } else {
        echo "";
    }
    ?>
	</ul><?php 
}
?>
	<span class="red" style="display: block;padding:15px;font-size:17px;">优惠券</span>
	 <ul class="userhas">
	  <?php 
 public function makeorder()
 {
     /* 菜单调用*/
     $menu = R('index/menulist');
     $this->assign('categoryq', $menu);
     /* 购物车调用*/
     $cart = R("shopcart/usercart");
     $this->assign('usercart', $cart);
     if (!session('user_auth')) {
         $usercart = $_SESSION['cart'];
         $this->assign('usercart', $usercart);
     }
     /* 热词调用*/
     $hotsearch = R("Index/getHotsearch");
     $this->assign('hotsearch', $hotsearch);
     $id = $_POST["orderid"];
     $order = D("order");
     //计算提交的订单的商品总额
     $total = $this->getPricetotal($id);
     //计算提交的订单的商品运费
     if ($total < C('LOWWEST')) {
         $trans = C('SHIPMONEY');
     } else {
         $trans = 0;
     }
     //计算提交的积分兑换
     if ($_POST["score"]) {
         $score = $_POST["score"];
         //读取配置,1000积分兑换1元
         $ratio = $score / C('RATIO');
         $data['score'] = $score;
         $user = session('user_auth');
         $uid = $user["uid"];
         M("member")->where("uid='{$uid}'")->setField('score', 0);
     } else {
         $ratio = 0;
     }
     $del = M("order")->where("total='0'")->delete();
     //计算提交的优惠券
     if ($_POST["couponcode"]) {
         $code = $_POST["couponcode"];
         $codeid = M("fcoupon")->where("code='{$code}' and status='1'")->getField('id');
         //获取优惠券主键id
         $deccode = get_coupon_price($codeid);
         //获取优惠券等值金额
         $usercouponid = M("usercoupon")->where("couponid='{$codeid}' and status='1'")->getField('id');
         //获取用户可用优惠券主键id
         if ($usercouponid) {
             $data['codeid'] = $codeid;
             M("usercoupon")->where("couponid='{$codeid}'")->setField('status', 2);
             //设置优惠券已用
         } else {
             $deccode = 0;
         }
     } else {
         $deccode = 0;
     }
     $senderid = $_POST["sender"];
     $data['addressid'] = $senderid;
     $data['total'] = $total;
     $data['ptime'] = NOW_TIME;
     $data['shipprice'] = $trans;
     //计算提交的订单的总费用
     $all = $total + $trans - $ratio - $deccode;
     $data['pricetotal'] = $all;
     //修改订单状态为用户已提交
     if ($_POST["PayType"] == "1") {
         $data['status'] = "1";
         $data['backinfo'] = "已提交等待发货";
         //增加取消订单
         //根据订单id保存对应的费用数据
         $order->where("id='{$id}'")->save($data);
         //根据订单id获取购物清单
         $del = M("shoplist")->where("orderid='{$id}'")->select();
         //获取会员uid
         $member = D("member");
         $uid = $member->uid();
         //遍历购物清单,删除登录用户购物车中的货物id
         foreach ($del as $k => $val) {
             //获取购物清单数据表产品id,字段goodid
             $delbyid = $val["goodid"];
             //删除购物车中用户的产品id
             M("shopcart")->where("goodid='{$delbyid}'and uid='{$uid}'")->delete();
         }
         $ordercode = $order->where("id='{$id}'")->getField('orderid');
         $this->assign('codeid', $ordercode);
         $mail = get_email($ordercode);
         //获取会员邮箱
         $title = "交易提醒";
         $content = "您在<a href=\"" . C('DAMAIN') . "\" target='_blank'>" . C('SITENAME') . '</a>提交了订单,订单号' . $param['order_id'];
         if (C('MAIL_PASSWORD')) {
             SendMail($mail, $title, $content);
         }
         $this->display('success');
     } else {
         //设置订单状态为用户为未能完成,不删除数据
         $data['backinfo'] = "等待支付";
         $data['ispay'] = "1";
         $data['status'] = "13";
         //根据订单id保存对应的费用数据
         $order->where("id='{$id}'")->save($data);
         $ordercode = $order->where("id='{$id}'")->getField('orderid');
         $this->assign('codeid', $ordercode);
         $this->assign('goodprice', $all);
         //支付页
         $this->display('Pay/index');
     }
 }