作者 lihan

.

... ... @@ -50,10 +50,8 @@ class OrderController extends AdminBaseController
if (request()->isPost()) {
$act = request()->param('act');
$status = 0;
if ($act == 'down_payment') {
$status = 2;
} elseif ($act == 'final_payment') {
$status = 4;
if ($act == 'final_payment') {
$status = 3;
} else {
$this->error('操作失败');
}
... ...
... ... @@ -112,15 +112,18 @@ class OrderController extends HomeBaseController
$data['is_use_discount_coupon'] = (empty($post['discount_coupon_id'])) ? 0 : 1;
$data['discount_coupon_id'] = $post['discount_coupon_id'];
$data['payment'] = $post['payment'];
$data['status'] = 0;
$data['status'] = 1;
$data['room'] = $post['room'];
$data['desc'] = $post['desc'];
$final_price = $this->getFinalPrice($data['activity_id'], $data['schedule_id'], $post['num'], $data['discount_coupon_id']);
$post['escort'] = substr($post['escort'], 0, strlen($post['escort']) - 1);
if (empty($post['escort'])) {
echo json_encode(['msg' => '请选择出行人', 'code' => 40000]);
exit();
}
$this->checkOrder($data['schedule_id'], $data['payment'], $post['escort'], $post['num'], $final_price);
Db::startTrans();
if (Db::name('order_info')->insert($data)) {
//☆在这就要将优惠券变为已使用☆
$oid = Db::name('order_info')->getLastInsID();
$detail = [];
$explode_escort = explode(',', $post['escort']);
... ... @@ -132,6 +135,17 @@ class OrderController extends HomeBaseController
];
}
if (Db::name('order_detail')->insertAll($detail)) {
//☆在这就要将优惠券变为已使用☆
if ($data['is_use_discount_coupon'] == 1 && !empty($data['discount_coupon_id'])) {
$coupons = [
'id' => $post['discount_coupon_id'],
'use_time' => time(),
'status' => 2
];
if (!(Db::name('discount_coupon')->update($coupons))) {
Db::rollback();
}
}
//插入订单记录表(包含订单总价)
$log = [
'oid' => $oid,
... ... @@ -140,6 +154,14 @@ class OrderController extends HomeBaseController
];
if (Db::name('order_log')->insert($log)) {
Db::commit();
//首次下单状态改变
Db::name('user')->update(['id' => session('user.id'), 'is_first' => 0]);
if ($data['payment'] == 1) {
echo json_encode(['msg' => '微信支付']);
exit();
} elseif ($data['payment'] == 2) {
} elseif ($data['payment'] == 0) {
$model = new OrderModel;
if ($model->orderCallBack($oid)) {
echo json_encode(['msg' => '下单成功', 'code' => 20000]);
... ... @@ -148,6 +170,10 @@ class OrderController extends HomeBaseController
echo json_encode(['msg' => '下单失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '未知错误', 'code' => 40000]);
exit();
}
}
}
} else {
... ... @@ -161,6 +187,63 @@ class OrderController extends HomeBaseController
}
}
//个人中心继续付款
public function done2()
{
$request = request();
if ($request->isPost()) {
$oid = $request->param('oid');
$info = Db::name('order_info')->alias('o')
->field('status,order_type,a.down_price,s.price')
->join('activity a', 'o.activity_id=a.id')
->join('activity_schedule s ', 'o.schedule_id=s.id')
->where(['o.id' => $oid])->find();
$num = Db::name('order_detail')->where(['oid' => $oid, 'status' => ['neq', 2]])->count();
if ($info['status'] == 1) {
if ($info['order_type'] == 0) {
$order_amount = $num * $info['price'];
} elseif ($info['order_type'] == 1) {
$order_amount = $num * $info['down_price'];
} else {
echo json_encode(['msg' => '未知错误', 'code' => 40000]);
exit();
}
} elseif ($info['status'] == 3) {
$order_amount = $num * $info['price'];
} else {
echo json_encode(['msg' => '未知错误', 'code' => 40000]);
exit();
}
//再次支付的支付方式
$payment = $request->param('payment');
Db::name('order_info')->update(['id' => $oid, 'payment' => $payment]);
if ($payment == 0) {
$model = new OrderModel;
if ($model->orderCallBack($oid, $order_amount)) {
//如果是有定金订单,则需要更新order_log
if ($info['order_type'] == 1) {
Db::name('order_log')->where(['oid' => $oid])->update(['type' => 0, 'order_amount' => $order_amount]);
}
echo json_encode(['msg' => '支付成功', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '支付失败', 'code' => 40000]);
exit();
}
} elseif ($payment == 1) {
} elseif ($payment == 2) {
} else {
echo json_encode(['msg' => '未知错误', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '非法操作', 'code' => 40000]);
exit();
}
}
/**
* 计算订单最终价格
* @param $activityId
... ...
... ... @@ -20,6 +20,8 @@ class OrderModel extends Model
}
if ($status != null) {
$where['status'] = ['eq', $status];
}else {
$where['status'] = ['neq', 7];
}
$res = Db::name('order_info')->alias('o')
->field('o.id as oid,o.order_sn,a.name,a.thumb,o.status,a.down_price,s.price')
... ... @@ -39,7 +41,7 @@ class OrderModel extends Model
//通用订单回调类(未完待续。。。)
//余额扣除(如果余额支付->钱包记录)->优惠券变为已使用(如果使用优惠券)->改变订单状态(必然)->相应批次库存减少(必然)
public function orderCallBack($oid)
public function orderCallBack($oid, $order_amount = null)
{
$orderInfo = Db::name('order_info')->alias('o')
->field('o.user_id,o.is_use_discount_coupon,discount_coupon_id,o.status,o.payment,o.order_type,o.activity_id,o.schedule_id,l.order_amount')
... ... @@ -49,7 +51,8 @@ class OrderModel extends Model
Db::startTrans();
$go = 'rollback';
if ($orderInfo['payment'] == 0) {
if (Db::name('user')->where(['id' => $orderInfo['user_id']])->setDec('balance', $orderInfo['order_amount'])) {
$amount = ($order_amount == null) ? $order_amount['order_amount'] : $order_amount;
if (Db::name('user')->where(['id' => $orderInfo['user_id']])->setDec('balance', $amount)) {
$wallet = [
'user_id' => $orderInfo['user_id'],
'type' => 0,
... ... @@ -65,24 +68,12 @@ class OrderModel extends Model
return false;
}
}
if ($orderInfo['is_use_discount_coupon'] == 1 && !empty($orderInfo['discount_coupon_id'])) {
$coupons = [
'id' => $orderInfo['discount_coupon_id'],
'use_time' => time(),
'status' => 2
];
if (Db::name('discount_coupon')->update($coupons)) {
$go = 'commit';
} else {
return false;
}
}
//订单状态无定金直接变为3,有定金变为1
if ($orderInfo['status'] == 0) {
//订单状态无定金直接变为4,有定金变为2
if ($orderInfo['status'] == 1) {
if ($orderInfo['order_type'] == 0) {
$status = 3;
$status = 4;
} elseif ($orderInfo['order_type'] == 1) {
$status = 1;
$status = 2;
} else {
$status = 0;
}
... ... @@ -102,6 +93,19 @@ class OrderModel extends Model
return false;
}
}
//待付尾款订单
if($orderInfo['status'] == 3) {
$status = 4;
$order = [
'id' => $oid,
'status' => $status
];
if(Db::name('order_info')->update($order)) {
$go = 'commit';
}else {
return false;
}
}
if ($go == 'commit') {
Db::commit();
return true;
... ...
... ... @@ -414,4 +414,58 @@ class CenterController extends HomeBaseController
}
}
public function cancelOrder()
{
$request = request();
if ($request->isAjax()) {
if (Db::name('order_info')->where(['id' => $request->param('oid')])->value('status') == 1) {
$data = [
'id' => $request->param('oid'),
'status' => 7
];
if (Db::name('order_info')->update($data)) {
echo json_encode(['msg' => '已取消订单', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '取消失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '该订单禁止取消', 'code' => 40000]);
exit();
}
}
}
public function confirmOrder() {
$request = request();
if($request->isAjax()) {
if (Db::name('order_info')->where(['id' => $request->param('oid')])->value('status') == 4) {
$data = [
'id' => $request->param('oid'),
'status' => 5
];
if (Db::name('order_info')->update($data)) {
echo json_encode(['msg' => '订单已确认', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '确认失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '该订单禁止确认', 'code' => 40000]);
exit();
}
}
}
public function comment(){
$request = request();
if($request->isAjax()) {
}else {
return $this->fetch(':comment');
}
}
}
\ No newline at end of file
... ...
... ... @@ -10,7 +10,7 @@
// [ 入口文件 ]
// 调试模式开关
define("APP_DEBUG", false);
define("APP_DEBUG", true);
// 定义CMF根目录,可更改此目录
define('CMF_ROOT', __DIR__ . '/../');
... ...
... ... @@ -52,21 +52,12 @@
</volist>
</div>
<div style="clear: left">&nbsp;</div>
<if condition="$order_info['status'] eq '1'">
<div style="width: 112px; margin: 0 auto; margin-top: 20px">
<form action="{:url('Order/detail')}" method="post">
<input type="hidden" name="id" value="{$order_info.id}">
<input type="hidden" name="act" value="down_payment">
<input type="submit" value="确定支付定金" class="btn btn-danger" onclick="return isConfirm()">
</form>
</div>
</if>
<if condition="$order_info['status'] eq '3'">
<if condition="$order_info['status'] eq '2'">
<div style="width: 112px; margin: 0 auto; margin-top: 20px">
<form action="{:url('Order/detail')}" method="post">
<input type="hidden" name="id" value="{$order_info.id}">
<input type="hidden" name="act" value="final_payment">
<input type="submit" value="确定支付尾款" class="btn btn-danger" onclick="return isConfirm()">
<input type="submit" value="已支付定金" class="btn btn-danger" onclick="return isConfirm()">
</form>
</div>
</if>
... ... @@ -86,7 +77,7 @@
</style>
<script>
function isConfirm() {
if(!window.confirm('是否确定支付尾款?')) {
if(!window.confirm('是否确定已支付定金?该订单即将变为待付尾款状态')) {
return false;
}else {
return true;
... ...
... ... @@ -749,6 +749,7 @@
}
})
var money_id='';
$(".agreepay").click(function () {
$.ajax({
url:"{:url('order/Order/done')}",
... ...
... ... @@ -750,8 +750,8 @@
single: false,
space: true,
starHalf: 'star-half.png',
starOff: '../images/no_stary.png',
starOn: '../images/stary.png',
starOff: '/themes/simpleboot3/static/images/no_stary.png',
starOn: '/themes/simpleboot3/static/images/stary.png',
starType: 'img',
target: undefined,
targetFormat: '{score}',
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>评价页面</title>
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="__TMPL__/static/assets/css/weui.min.css" />
<link rel="stylesheet" type="text/css" href="__TMPL__/static/assets/css/swiper-3.4.2.min.css" />
<link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_773803_1qg03k1415.css" />
<script type="text/javascript" src="__TMPL__/static/assets/font/iconfont.js"></script>
<script type="text/javascript" src="__TMPL__/static/js/base.js"></script>
<link rel="stylesheet" href="__TMPL__/static/css/jquery.raty.css" />
<link rel="stylesheet" href="__TMPL__/static/css/evaluate.css" />
</head>
<body>
<div class="travel">这次的旅行,您还满意吗?</div>
<div class="img_box" id='start'>
</div>
<div class="service">
<div class="fu">服务评价</div>
<div class="icon" id="icon">
<!--<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>-->
</div>
</div>
<div class="service">
<div class="fu">行程安排</div>
<div class="icon" id="wuxing">
<!--<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>
<i class="iconfont icon-wuxing "></i>-->
</div>
</div>
<div class="xing">
给五星好评可获得代金券一张
</div>
<div class="ideaout">
<textarea class="idea" placeholder="请留下您的宝贵意"></textarea>
</div>
<div class="save">
<div class="footer ok">
提交
</div>
</div>
</body>
<script type="text/javascript" src="__TMPL__/static/assets/js/jquery-2.1.0.js"></script>
<script type="text/javascript" src="__TMPL__/static/assets/js/jquery.raty.js"></script>
<script type="text/javascript">
var startnum = 0;
$('#start').raty({
click: function(s) {
console.log(s)
startnum = s;
}
})
var startnum_min1 = 0;
$('#icon').raty({
click: function(s) {
console.log(s)
startnum = s;
}
})
var startnum_min2 = 0;
$('#wuxing').raty({
click: function(s) {
console.log(s)
startnum = s;
}
})
</script>
</html>
\ No newline at end of file
... ...
... ... @@ -99,9 +99,23 @@
</div>
<div class="footer_out">
<if condition="$data.baseInfo.status eq '1' || $data.baseInfo.status eq '3'">
<div class="footer ok">
立即支付
</div>
</if>
<if condition="$data.baseInfo.status eq '4'">
<div class="footer ko">
确认完成
</div>
</if>
<if condition="$data.baseInfo.status eq '5'">
<div class="footer go">
去评价
</div>
</if>
</div>
<!--选择支付方式-->
<div class='move1'>
... ... @@ -153,8 +167,8 @@
<i class='iconfont'></i>
</div>
</div>
<div class="agreepay">
<div class="agreepay">
确认支付
</div>
</div>
... ... @@ -173,7 +187,7 @@
<script>
//点击选择支付方式
$('.footer').click(function() {
$('.ok').click(function() {
$('.move1').css('display', 'block');
})
$('.move1').click(function() {
... ... @@ -272,3 +286,46 @@
})
</script>
<script>
$(".agreepay").click(function () {
$.ajax({
url:"{:url('order/Order/done2')}",
data:{
oid:'{$data.baseInfo.oid}',
payment:0
},
type:"POST",
dataType:"JSON",
success: function (data) {
if(data.code == 20000) {
window.location.reload();
}
}
})
})
</script>
<script>
$(".ko").click(function () {
if(window.confirm('是否确认完成?')) {
$.ajax({
url:"{:url('user/Center/confirmOrder')}",
data:{
oid:'{$data.baseInfo.oid}'
},
type:"POST",
dataType:"JSON",
success: function (data) {
if(data.code == 20000) {
window.location.reload();
}
}
})
}else {
return false;
}
})
</script>
\ No newline at end of file
... ...
... ... @@ -102,7 +102,7 @@
</div>
<div <if condition="$status eq '4'">class="swiper-slide active_top"<else/>class="swiper-slide"</if> data-url="{:url('user/Center/orderList',['status'=>4])}">
已付尾款
待完成
</div>
<div <if condition="$status eq '5'">class="swiper-slide active_top"<else/>class="swiper-slide"</if> data-url="{:url('user/Center/orderList',['status'=>5])}">
... ... @@ -119,8 +119,7 @@
</div>
<volist name="data" id="vo">
<a href="{:url('user/Center/orderDetail',['oid'=>$vo['oid']])}">
<div class="good_out_stay" data-id="{$vo.oid}">
<div class="good_out_stay DETAIL" data-id="{$vo.oid}" data-url="{:url('user/Center/orderDetail',['oid'=>$vo['oid']])}">
<div class="good">
<span>订单号:{$vo.order_sn}</span>
<span class="confirmed">{$vo.status_text}</span>
... ... @@ -146,7 +145,7 @@
</div>
<if condition="$vo['status'] eq '1'">
<div class="btnlist">
<div class="btnleft can">取消</div>
<div class="btnleft can" data-id="{$vo['oid']}">取消</div>
<div class="btnright ">付款</div>
</div>
</if>
... ... @@ -159,11 +158,10 @@
<if condition="$vo['status'] eq '5'">
<div class="btnlist">
<div class="pingjia">评价</div>
<div class="pingjia" data-url="{:url('user/Center/comment',['oid'=>$vo['oid']])}">评价</div>
</div>
</if>
</div>
</a>
</volist>
... ... @@ -212,45 +210,44 @@
<script type="text/javascript" src="__TMPL__/static/assets/js/jquery-2.1.0.js"></script>
<script type="text/javascript" src="__TMPL__/static/js/swiper-3.4.2.jquery.min.js"></script>
<script>
//确认取消弹出框
$('.can').click(function() {
var id = $(this).parents('.good_out').data("id");
console.log(id);
$('.confirm_cancel').css('display', 'block');
$('.confirm_yes').click(function() {
console.log("点击确定按钮获取整个li的id为:" + id);
$('.confirm_cancel').css('display', 'none');
})
$('.confirm_no').click(function() {
$('.confirm_cancel').css('display', 'none');
})
$('.confirm_main').click(function() {
event.stopPropagation();
// $(this).css('display','none');
})
$(".DETAIL").click(function () {
window.location.href=$(this).attr('data-url');
})
var oid='';
//确认取消弹出框
$('.btnright').click(function() {
var id = $(this).parents('.good_out').data("id");
console.log(id);
$('.can').click(function() {
window.event.stopPropagation();
var id = $(this).attr('data-id');
$('.confirm_cancel').css('display', 'block');
$('.confirm_yes').click(function() {
console.log("点击确定按钮获取整个li的id为:" + id);
$('.confirm_cancel').css('display', 'none');
})
$('.confirm_no').click(function() {
$('.confirm_cancel').css('display', 'none');
$.ajax({
url:"{:url('user/Center/cancelOrder')}",
data:{
oid:id
},
type:"POST",
dataType:"JSON",
success: function (data) {
if(data.code == 20000) {
window.location.reload();
}
}
})
})
$('.confirm_main').click(function() {
event.stopPropagation();
// $(this).css('display','none');
})
})
//阻止按钮的点击冒泡
$('.btnlist').click(function(event) {
event.stopPropagation();
});
$('.choice .swiper-slide').click(function() {
$(this).addClass("active_top").siblings().removeClass("active_top");
})
... ... @@ -272,3 +269,12 @@
window.location.href=$(this).attr('data-url');
})
</script>
<script>
$('.pingjia').click(function() {
window.event.stopPropagation();
//评论页跳转
window.location.href=$(this).attr('data-url');
})
</script>
\ No newline at end of file
... ...