1
|
<?php
|
1
|
<?php
|
2
|
namespace app\order\controller;
|
2
|
namespace app\order\controller;
|
|
|
3
|
+use app\coupons\model\CouponModel;
|
3
|
use cmf\controller\HomeBaseController;
|
4
|
use cmf\controller\HomeBaseController;
|
4
|
use think\Db;
|
5
|
use think\Db;
|
5
|
|
6
|
|
|
@@ -9,21 +10,129 @@ use think\Db; |
|
@@ -9,21 +10,129 @@ use think\Db; |
9
|
class OrderController extends HomeBaseController
|
10
|
class OrderController extends HomeBaseController
|
10
|
{
|
11
|
{
|
11
|
|
12
|
|
|
|
13
|
+ function __construct()
|
|
|
14
|
+ {
|
|
|
15
|
+ if (empty(session('user.id'))) {
|
|
|
16
|
+ echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
|
|
|
17
|
+ exit();
|
|
|
18
|
+ }
|
|
|
19
|
+ }
|
|
|
20
|
+
|
12
|
/**
|
21
|
/**
|
13
|
- * @title 活动列表
|
22
|
+ * @title 下单页面
|
14
|
* @description 默认访问接口
|
23
|
* @description 默认访问接口
|
15
|
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
|
24
|
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
|
16
|
* @url /order/Order/confirm
|
25
|
* @url /order/Order/confirm
|
17
|
* @method POST
|
26
|
* @method POST
|
|
|
27
|
+ *
|
|
|
28
|
+ * @param name:activity_id type:int require:1 default:19 desc:上一页选中的活动id
|
|
|
29
|
+ * @param name:schedule_id type:int require:1 default:68 desc:上一页选中的批次id
|
|
|
30
|
+ * @param name:num type:int require:1 default:2 desc:上一页选中的购买数量
|
18
|
*/
|
31
|
*/
|
19
|
public function confirm()
|
32
|
public function confirm()
|
20
|
{
|
33
|
{
|
21
|
$request = request();
|
34
|
$request = request();
|
22
|
- $activity_id = $request->param('activity_id');
|
35
|
+ $post = $request->param();
|
|
|
36
|
+ $coupons = new CouponModel;
|
|
|
37
|
+ $couponsList = $coupons->orderCoupon($post['activity_id'], $post['schedule_id'], $post['num'], session('user.id'));
|
|
|
38
|
+ $schedule = Db::name('activity_schedule')
|
|
|
39
|
+ ->field('id as schedule_id,start_time,end_time,maximum,real_join_num,addition_join_num')
|
|
|
40
|
+ ->where(['activity_id' => $post['activity_id']])
|
|
|
41
|
+ ->select();
|
|
|
42
|
+ foreach ($schedule as $k => $v) {
|
|
|
43
|
+ $v['start_time'] = date('Y.m.d', $v['start_time']);
|
|
|
44
|
+ $v['end_time'] = date('Y.m.d', $v['end_time']);
|
|
|
45
|
+ $allowMaximum = $v['maximum'] - ($v['real_join_num'] + $v['addition_join_num']);
|
|
|
46
|
+ $v['allow_maximum'] = $allowMaximum;
|
|
|
47
|
+ unset($v['real_join_num']);
|
|
|
48
|
+ unset($v['addition_join_num']);
|
|
|
49
|
+ unset($v['maximum']);
|
|
|
50
|
+ $schedule[$k] = $v;
|
|
|
51
|
+ }
|
|
|
52
|
+ $result = [
|
|
|
53
|
+ 'activity' => Db::name('activity')->field('id as activity,name')->where(['id' => $post['activity_id']])->find(),
|
|
|
54
|
+ 'schedule' => $schedule,
|
|
|
55
|
+ 'coupons' => $couponsList
|
|
|
56
|
+ ];
|
|
|
57
|
+ echo json_encode(['data' => $result]);
|
|
|
58
|
+ exit();
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ /**
|
|
|
62
|
+ * @title 提交订单
|
|
|
63
|
+ * @description 默认访问接口
|
|
|
64
|
+ * @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
|
|
|
65
|
+ * @url /order/Order/done
|
|
|
66
|
+ * @method POST
|
|
|
67
|
+ *
|
|
|
68
|
+ * @param name:activity_id type:int require:1 default:19 desc:上一页选中的活动id
|
|
|
69
|
+ * @param name:schedule_id type:int require:1 default:68 desc:上一页选中的批次id
|
|
|
70
|
+ * @param name:num type:int require:1 default:2 desc:上一页选中的购买数量
|
|
|
71
|
+ * @param name:escort type:char require:1 default:同行人id字符串(逗号分隔) desc:1,2,3
|
|
|
72
|
+ * @param name:payment type:int require:1 default:支付方式 desc:0余额,1微信,2支付宝
|
|
|
73
|
+ * @param name:discount_coupon_id type:int require:1 default:1 desc:优惠券id
|
|
|
74
|
+ * @param name:room type:char require:1 default:1 desc:房间信息
|
|
|
75
|
+ * @param name:desc type:text require:1 default:1 desc:商家备注
|
|
|
76
|
+ */
|
|
|
77
|
+ public function done()
|
|
|
78
|
+ {
|
|
|
79
|
+ $request = request();
|
23
|
if ($request->isPost()) {
|
80
|
if ($request->isPost()) {
|
24
|
- $activity = Db::name('activity')->field('name')->find();
|
81
|
+ $post = $request->param();
|
|
|
82
|
+ $data['user_id'] = session('user.id');
|
|
|
83
|
+ $data['order_sn'] = date('YmdHis') . rand(0, 9999);
|
|
|
84
|
+ $data['activity_id'] = $post['activity_id'];
|
|
|
85
|
+ $data['schedule_id'] = $post['schedule_id'];
|
|
|
86
|
+ $data['add_time'] = time();
|
|
|
87
|
+ $activity = Db::name('activity')->field('is_down_payment,down_price')->where(['id' => $post['activity_id']])->find();
|
|
|
88
|
+ $schedule = Db::name('activity_schedule')->field('deadline,price')->where(['id' => $post['schedule_id']])->find();
|
|
|
89
|
+ $data['order_type'] = $activity['is_down_payment'];
|
|
|
90
|
+ $data['is_use_discount_coupon'] = (empty($post['discount_coupon_id'])) ? 0 : 1;
|
|
|
91
|
+ $data['discount_coupon_id'] = $post['discount_coupon_id'];
|
|
|
92
|
+ $data['status'] = 0;
|
|
|
93
|
+ if ($data['order_type'] == 0) {
|
|
|
94
|
+ $data['payment1'] = $post['payment'];
|
|
|
95
|
+ } else {
|
|
|
96
|
+ $post['payment2'] = $post['payment'];
|
|
|
97
|
+ }
|
|
|
98
|
+ Db::startTrans();
|
|
|
99
|
+ if (Db::name('order_info')->insert($data)) {
|
|
|
100
|
+ $oid = Db::name('order_info')->getLastInsID();
|
|
|
101
|
+ $detail = [];
|
|
|
102
|
+ $explode_escort = explode(',', $post['escort']);
|
|
|
103
|
+ for ($i = 0; $i < $post['num']; $i++) {
|
|
|
104
|
+ $detail[$i] = [
|
|
|
105
|
+ 'oid' => $oid,
|
|
|
106
|
+ 'escort_id' => $explode_escort[$i],
|
|
|
107
|
+ 'down_price' => $activity['down_price'],
|
|
|
108
|
+ 'final_payment' => $schedule['price'],
|
|
|
109
|
+ 'status' => 0
|
|
|
110
|
+ ];
|
|
|
111
|
+ }
|
|
|
112
|
+ if (Db::name('order_detail')->insertAll($detail)) {
|
|
|
113
|
+ Db::commit();
|
|
|
114
|
+ //选择支付方式0,1,2
|
|
|
115
|
+ //余额支付
|
|
|
116
|
+ if ($post['payment'] == 0) {
|
|
|
117
|
+
|
|
|
118
|
+ } elseif ($post['payment'] == 1) {
|
|
|
119
|
+
|
|
|
120
|
+ } elseif ($post['payment'] == 2) {
|
|
|
121
|
+
|
|
|
122
|
+ } else {
|
|
|
123
|
+ echo json_encode(['msg' => '请选择支付方式', 'code' => 40000]);
|
|
|
124
|
+ exit();
|
|
|
125
|
+ }
|
|
|
126
|
+ }
|
|
|
127
|
+ } else {
|
|
|
128
|
+ Db::rollback();
|
|
|
129
|
+ echo json_encode(['msg' => '下单失败', 'code' => 40000]);
|
|
|
130
|
+ exit();
|
|
|
131
|
+ }
|
|
|
132
|
+
|
25
|
} else {
|
133
|
} else {
|
26
|
- return $this->fetch();
|
134
|
+ echo json_encode(['msg' => '非法操作', 'code' => 40000]);
|
|
|
135
|
+ exit();
|
27
|
}
|
136
|
}
|
28
|
}
|
137
|
}
|
29
|
|
138
|
|