...
|
...
|
@@ -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,12 +154,24 @@ class OrderController extends HomeBaseController |
|
|
];
|
|
|
if (Db::name('order_log')->insert($log)) {
|
|
|
Db::commit();
|
|
|
$model = new OrderModel;
|
|
|
if ($model->orderCallBack($oid)) {
|
|
|
echo json_encode(['msg' => '下单成功', 'code' => 20000]);
|
|
|
//首次下单状态改变
|
|
|
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]);
|
|
|
exit();
|
|
|
} else {
|
|
|
echo json_encode(['msg' => '下单失败', 'code' => 40000]);
|
|
|
exit();
|
|
|
}
|
|
|
} else {
|
|
|
echo json_encode(['msg' => '下单失败', 'code' => 40000]);
|
|
|
echo json_encode(['msg' => '未知错误', 'code' => 40000]);
|
|
|
exit();
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -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
|
...
|
...
|
|