Ver código fonte

电影票下单逻辑

family 1 ano atrás
pai
commit
a910e78a94

+ 302 - 0
app/common/dao/movie/order/MovieOrderDao.php

@@ -0,0 +1,302 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020/6/1
7
+ *
8
+ *
9
+ */
10
+
11
+namespace app\common\dao\movie\order;
12
+
13
+
14
+use app\common\dao\BaseDao;
15
+use app\common\model\movie\order\MovieOrder;
16
+use app\common\model\user\User;
17
+use think\facade\Db;
18
+
19
+/**
20
+ * Class MovieOrderDao
21
+ * @package app\common\dao\movie\order
22
+ * @author xaboy
23
+ * @day 2020/6/8
24
+ */
25
+class MovieOrderDao extends BaseDao
26
+{
27
+
28
+    /**
29
+     * @return string
30
+     * @author xaboy
31
+     * @day 2020/6/8
32
+     */
33
+    protected function getModel(): string
34
+    {
35
+        return MovieOrder::class;
36
+    }
37
+
38
+    /**
39
+     * @param array $where
40
+     * @param int $sysDel
41
+     * @return \think\db\BaseQuery
42
+     * @author xaboyCRMEB
43
+     * @day 2020/6/16
44
+     */
45
+    public function search(array $where, $sysDel = 0)
46
+    {
47
+
48
+        return MovieOrder::getDB()
49
+            ->when(($sysDel !== null), function ($query) use ($sysDel) {
50
+                $query->where('is_system_del', $sysDel);
51
+            })
52
+            ->when(isset($where['pay_type']) && $where['pay_type'] != -1 && $where['pay_type'] >= 0, function ($query) use ($where) {
53
+                $query->where('pay_type', $where['pay_type']);
54
+            })
55
+            ->when(isset($where['order_type']) && $where['order_type'] && $where['order_type'] >= 0, function ($query) use ($where) {
56
+                $query->where('order_type', $where['order_type']);
57
+            })
58
+            ->when(isset($where['distribution_mode']) && $where['distribution_mode'] && $where['distribution_mode'] >= 0, function ($query) use ($where) {
59
+                $query->where('distribution_mode', $where['distribution_mode']);
60
+            })
61
+            ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
62
+                if ($where['status'] == -2)
63
+                    $query->where('paid', 1);
64
+                else
65
+                    $query->where('status', $where['status']);
66
+            })
67
+            ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
68
+                $query->where('uid', $where['uid']);
69
+            })
70
+            ->when(isset($where['take_order']), function ($query) use ($where) {
71
+                $query->where('order_type', 1)->where('status', '>=', 2);
72
+            })
73
+            ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
74
+                $query->where('mer_id', $where['mer_id']);
75
+            })
76
+            ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
77
+                getModelTime($query, $where['date']);
78
+            })
79
+            ->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) {
80
+                getModelTime($query, $where['verify_date']);
81
+            })
82
+            ->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
83
+                $query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
84
+            })
85
+            ->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
86
+                $query->where('paid', $where['paid']);
87
+            })
88
+            ->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
89
+                $query->where('is_del', $where['is_del']);
90
+            })
91
+            ->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
92
+                $query->where('service_id', $where['service_id']);
93
+            })
94
+            ->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
95
+                $uid = User::where('nickname', 'like', "%{$where['username']}%")
96
+                    ->whereOr('phone', 'like', "%{$where['username']}%")
97
+                    ->column('uid');
98
+                $query->where('uid', 'in', $uid);
99
+            })
100
+            ->when(isset($where['gzc']) && $where['gzc'] !== '', function ($query) use ($where) {
101
+                $query->where('gzc', $where['gzc']);
102
+            })
103
+            ->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
104
+                $query->where(function ($query) use ($where) {
105
+                    $query->where('real_name', 'like', "%" . $where['keywords'] . "%")
106
+                        ->whereOr('user_phone', 'like', "%{$where['keywords']}%")
107
+                        ->whereOr('order_sn', 'like', '%' . $where['keywords'] . '%')
108
+                        ->whereOr('verify_code', 'like', '%' . $where['keywords'] . '%');
109
+                });
110
+            })
111
+            ->when(isset($where['reconciliation_type']) && $where['reconciliation_type'] !== '', function ($query) use ($where) {
112
+                $query->when($where['reconciliation_type'], function ($query) use ($where) {
113
+                    $query->where('reconciliation_id', '<>', 0);
114
+                }, function ($query) use ($where) {
115
+                    $query->where('reconciliation_id', 0);
116
+                });
117
+            })->order('create_time DESC');
118
+    }
119
+
120
+    /**
121
+     * @param array $where
122
+     * @param int $sysDel
123
+     * @return \think\db\BaseQuery
124
+     * @author xaboyCRMEB
125
+     * @day 2020/6/16
126
+     */
127
+    public function merSearch(array $where, $sysDel = 0)
128
+    {
129
+
130
+        return MovieOrder::getDB()
131
+            ->alias('so')
132
+            ->leftJoin('user_bill ub', 'ub.order_sn=so.order_sn')
133
+            ->when(($sysDel !== null), function ($query) use ($sysDel) {
134
+                $query->where('so.is_system_del', $sysDel);
135
+            })
136
+            ->when(isset($where['pay_type']) && $where['pay_type'] != -1 && $where['pay_type'] >= 0, function ($query) use ($where) {
137
+                $query->where('so.pay_type', $where['pay_type']);
138
+            })
139
+            ->when(isset($where['order_type']) && $where['order_type'] && $where['order_type'] >= 0, function ($query) use ($where) {
140
+                $query->where('so.order_type', $where['order_type']);
141
+            })
142
+            ->when(isset($where['distribution_mode']) && $where['distribution_mode'] && $where['distribution_mode'] >= 0, function ($query) use ($where) {
143
+                $query->where('so.distribution_mode', $where['distribution_mode']);
144
+            })
145
+            ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
146
+                if ($where['status'] == -2)
147
+                    $query->where('so.paid', 1);
148
+                else
149
+                    $query->where('so.status', $where['status']);
150
+            })
151
+            ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
152
+                $query->where('so.uid', $where['uid']);
153
+            })
154
+            ->when(isset($where['take_order']), function ($query) use ($where) {
155
+                $query->where('so.order_type', 1)->where('status', '>=', 2);
156
+            })
157
+            ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
158
+                $query->where('so.mer_id', $where['mer_id']);
159
+            })
160
+            ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
161
+                getModelTime($query, $where['date']);
162
+            })
163
+            ->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) {
164
+                getModelTime($query, $where['verify_date']);
165
+            })
166
+            ->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
167
+                $query->where('so.order_sn', 'like', '%' . $where['order_sn'] . '%');
168
+            })
169
+            ->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
170
+                $query->where('so.paid', $where['paid']);
171
+            })
172
+            ->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
173
+                $query->where('so.is_del', $where['is_del']);
174
+            })
175
+            ->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
176
+                $query->where('so.service_id', $where['service_id']);
177
+            })
178
+            ->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
179
+                $uid = User::where('so.nickname', 'like', "%{$where['username']}%")
180
+                    ->whereOr('so.phone', 'like', "%{$where['username']}%")
181
+                    ->column('so.uid');
182
+                $query->where('so.uid', 'in', $uid);
183
+            })
184
+            ->when(isset($where['gzc']) && $where['gzc'] !== '', function ($query) use ($where) {
185
+                $query->where('so.gzc', $where['gzc']);
186
+            })
187
+            ->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
188
+                $query->where(function ($query) use ($where) {
189
+                    $query->where('so.real_name', 'like', "%" . $where['keywords'] . "%")
190
+                        ->whereOr('so.user_phone', 'like', "%{$where['keywords']}%")
191
+                        ->whereOr('so.order_sn', 'like', '%' . $where['keywords'] . '%')
192
+                        ->whereOr('so.verify_code', 'like', '%' . $where['keywords'] . '%');
193
+                });
194
+            })
195
+            ->when(isset($where['reconciliation_type']) && $where['reconciliation_type'] !== '', function ($query) use ($where) {
196
+                $query->when($where['reconciliation_type'], function ($query) use ($where) {
197
+                    $query->where('so.reconciliation_id', '<>', 0);
198
+                }, function ($query) use ($where) {
199
+                    $query->where('so.reconciliation_id', 0);
200
+                });
201
+            })->order('so.create_time DESC');
202
+    }
203
+
204
+    /**
205
+     * @param $id
206
+     * @param $uid
207
+     * @return array|\think\Model|null
208
+     * @throws \think\db\exception\DataNotFoundException
209
+     * @throws \think\db\exception\DbException
210
+     * @throws \think\db\exception\ModelNotFoundException
211
+     * @author xaboy
212
+     * @day 2020/6/11
213
+     */
214
+    public function userOrder($id, $uid)
215
+    {
216
+        return MovieOrder::getDB()->where('order_id', $id)->where('uid', $uid)->where('is_del', 0)->where('paid', 1)->where('is_system_del', 0)->find();
217
+    }
218
+
219
+    /**
220
+     * @param array $where
221
+     * @param $ids
222
+     * @return \think\db\BaseQuery
223
+     * @author xaboy
224
+     * @day 2020/6/26
225
+     */
226
+    public function usersOrderQuery(array $where, $ids)
227
+    {
228
+        return MovieOrder::getDB()->whereIn('uid', $ids)->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
229
+            getModelTime($query, $where['date'], 'pay_time');
230
+        })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
231
+            $query->where('order_id|order_sn', $where['keyword']);
232
+        })->where('paid', 1)->order('pay_time DESC');
233
+    }
234
+
235
+    /**
236
+     * @param $field
237
+     * @param $value
238
+     * @param int|null $except
239
+     * @return bool
240
+     * @author xaboy
241
+     * @day 2020/6/11
242
+     */
243
+    public function fieldExists($field, $value, ?int $except = null): bool
244
+    {
245
+        return ($this->getModel()::getDB())->when($except, function ($query) use ($field, $except) {
246
+                $query->where($field, '<>', $except);
247
+            })->where($field, $value)->count() > 0;
248
+    }
249
+
250
+    public function orderUserNum($date, $paid = null, $merId = null)
251
+    {
252
+        return MovieOrder::getDB()->when($paid, function ($query, $paid) {
253
+            $query->where('paid', $paid);
254
+        })->when($merId, function ($query, $merId) {
255
+            $query->where('mer_id', $merId);
256
+        })->when($date, function ($query, $date) {
257
+            getModelTime($query, $date, 'pay_time');
258
+        })->group('uid')->count();
259
+    }
260
+
261
+    public function orderUserGroup($date, $paid = null, $merId = null)
262
+    {
263
+        return MovieOrder::getDB()->when($paid, function ($query, $paid) {
264
+            $query->where('paid', $paid);
265
+        })->when($merId, function ($query, $merId) {
266
+            $query->where('mer_id', $merId);
267
+        })->when($date, function ($query, $date) {
268
+            getModelTime($query, $date, 'pay_time');
269
+        })->group('uid')->field(Db::raw('uid,sum(pay_price) as pay_price'))->select();
270
+    }
271
+
272
+    public function orderPrice($date, $paid = null, $merId = null)
273
+    {
274
+        return MovieOrder::getDB()->when($paid, function ($query, $paid) {
275
+            $query->where('paid', $paid);
276
+        })->when($merId, function ($query, $merId) {
277
+            $query->where('mer_id', $merId);
278
+        })->when($date, function ($query, $date) {
279
+            getModelTime($query, $date, 'pay_time');
280
+        })->sum('pay_price');
281
+    }
282
+
283
+    public function orderGroupNum($date, $merId = null)
284
+    {
285
+        return MovieOrder::getDB()->field(Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`'))
286
+            ->where('paid', 1)->when($date, function ($query, $date) {
287
+                getModelTime($query, $date, 'pay_time');
288
+            })->when($merId, function ($query, $merId) {
289
+                $query->where('mer_id', $merId);
290
+            })->order('day ASC')->group('day')->select();
291
+    }
292
+
293
+    public function orderGroupNumPage($where, $page, $limit, $merId = null)
294
+    {
295
+        return MovieOrder::getDB()->when(isset($where['dateRange']), function ($query) use ($where) {
296
+            getModelTime($query, date('Y/m/d H:i:s', $where['dateRange']['start']) . '-' . date('Y/m/d H:i:s', $where['dateRange']['stop']), 'pay_time');
297
+        })->field(Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`'))
298
+            ->where('paid', 1)->when($merId, function ($query, $merId) {
299
+                $query->where('mer_id', $merId);
300
+            })->order('day DESC')->page($page, $limit)->group('day')->select();
301
+    }
302
+}

+ 28 - 0
app/common/model/movie/order/MovieOrder.php

@@ -0,0 +1,28 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020/6/1
7
+ *
8
+ *
9
+ */
10
+
11
+namespace app\common\model\movie\order;
12
+
13
+
14
+use app\common\model\BaseModel;
15
+
16
+class MovieOrder extends BaseModel
17
+{
18
+
19
+    public static function tablePk(): ?string
20
+    {
21
+        return 'order_id';
22
+    }
23
+
24
+    public static function tableName(): string
25
+    {
26
+        return 'order_movie';
27
+    }
28
+}

+ 1 - 1
app/common/repositories/movie/DouHuoMallFilmApiRequest.php

@@ -207,7 +207,7 @@ class DouHuoMallFilmApiRequest
207 207
      * @param $sched_sign
208 208
      * @return mixed|string
209 209
      */
210
-    public static function submitOrde($phone, $channel_type, $sched_sign, $third_order, $order_price)
210
+    public static function submitOrder($phone, $channel_type, $sched_sign, $third_order, $order_price)
211 211
     {
212 212
         $url = '/openapi/Movie/submitOrder';
213 213
         $body = [

+ 87 - 11
app/controller/api/movie/Movie.php

@@ -42,8 +42,8 @@ class Movie extends BaseController
42 42
     public function getMovieCity()
43 43
     {
44 44
         [$page, $limit] = $this->getPage();
45
-        $initial = $this->request->params(['initial']);
46
-        $city_name = $this->request->params(['city_name']);
45
+        $initial = $this->request->param('initial', '');
46
+        $city_name = $this->request->param('city_name', '');
47 47
 
48 48
         return app('json')->success($this->repository->getMovieCity($page, $limit, $initial, $city_name));
49 49
     }
@@ -55,7 +55,7 @@ class Movie extends BaseController
55 55
      */
56 56
     public function getArea()
57 57
     {
58
-        $city_sign = $this->request->params(['city_sign']);
58
+        $city_sign = $this->request->param('city_sign', '');
59 59
         if (empty($city_sign)) return app('json')->fail('请选择城市');
60 60
 
61 61
         return app('json')->success($this->repository->getMovieArea($city_sign));
@@ -69,8 +69,8 @@ class Movie extends BaseController
69 69
     public function getCinema()
70 70
     {
71 71
         [$page, $limit] = $this->getPage();
72
-        $city_sign = $this->request->params(['city_sign']);
73
-        $area_sign = $this->request->params(['area_sign']);
72
+        $city_sign = $this->request->param('city_sign', '');
73
+        $area_sign = $this->request->param('area_sign', '');
74 74
 
75 75
         return app('json')->success($this->repository->getCinema($page, $limit, $city_sign, $area_sign));
76 76
     }
@@ -83,8 +83,8 @@ class Movie extends BaseController
83 83
     public function getFilm()
84 84
     {
85 85
         [$page, $limit] = $this->getPage();
86
-        $cinema_sign = $this->request->params(['cinema_sign']);
87
-        $film_sign = $this->request->params(['film_sign']);
86
+        $cinema_sign = $this->request->param('cinema_sign', '');
87
+        $film_sign = $this->request->param('film_sign', '');
88 88
 
89 89
         return app('json')->success($this->repository->getFilm($page, $limit, $cinema_sign, $film_sign));
90 90
     }
@@ -96,10 +96,10 @@ class Movie extends BaseController
96 96
      */
97 97
     public function getCinemaSched()
98 98
     {
99
-        $cinema_sign = $this->request->params(['cinema_sign']);
99
+        $cinema_sign = $this->request->param('cinema_sign', '');
100 100
         if (empty($cinema_sign)) return app('json')->fail('请选择影院');
101 101
 
102
-        $film_sign = $this->request->params(['film_sign']);
102
+        $film_sign = $this->request->param('film_sign', '');
103 103
         if (empty($film_sign)) return app('json')->fail('请选择影片');
104 104
 
105 105
         return app('json')->success($this->repository->getCinemaSched($film_sign, $cinema_sign));
@@ -112,12 +112,88 @@ class Movie extends BaseController
112 112
      */
113 113
     public function getSchedSeat()
114 114
     {
115
-        $relation_id = $this->request->params(['relation_id']);
115
+        $relation_id = $this->request->param('relation_id', '');
116 116
         if (empty($cinema_sign)) return app('json')->fail('请选择场次');
117 117
 
118
-        $sched_sign = $this->request->params(['sched_sign']);
118
+        $sched_sign = $this->request->param('sched_sign', '');
119 119
         if (empty($film_sign)) return app('json')->fail('请选择场次');
120 120
 
121 121
         return app('json')->success($this->repository->getSchedSeat($relation_id, $sched_sign));
122 122
     }
123
+
124
+    /**
125
+     * 锁座订单
126
+     *
127
+     * @return mixed
128
+     */
129
+    public function submitOrder()
130
+    {
131
+        $params = $this->request->params(
132
+            ['price', 0.00],
133
+            ['number', 0],
134
+            ['channel_type', ''],
135
+            ['pay_type', ''],
136
+            ['city_sign', ''],
137
+            ['city_name', ''],
138
+            ['area_code', ''],
139
+            ['area_name', ''],
140
+            ['cinema_sign', ''],
141
+            ['cinema_name', ''],
142
+            ['address', ''],
143
+            ['longitude', ''],
144
+            ['latitude', ''],
145
+            ['hall_sign', ''],
146
+            ['hall_name', ''],
147
+            ['relation_id', ''],
148
+            ['sched_sign', ''],
149
+            ['film_sign', ''],
150
+            ['film_name', ''],
151
+            ['show_date', ''],
152
+            ['show_time', ''],
153
+            ['sched_seat', '']
154
+        );
155
+
156
+        if (empty($params['sched_sign'])) return app('json')->fail('请选择场次');
157
+        if (empty($params['seat_sign'])) return app('json')->fail('请选择座位');
158
+        if (empty($params['channel_type'])) return app('json')->fail('请选择购票类型');
159
+
160
+        $result = $this->repository->submitOrder($this->request->userInfo(), $params);
161
+        if ($result['code'] == 200) {
162
+            return app('json')->success($result);
163
+        } else {
164
+            return app('json')->fail($result);
165
+        }
166
+    }
167
+
168
+    /**
169
+     * 确认订单
170
+     *
171
+     * @return mixed
172
+     */
173
+    public function confirmOrder()
174
+    {
175
+        $relation_id = $this->request->param(['relation_id']);
176
+        if (empty($cinema_sign)) return app('json')->fail('请选择场次');
177
+
178
+        $sched_sign = $this->request->param(['sched_sign']);
179
+        if (empty($film_sign)) return app('json')->fail('请选择场次');
180
+
181
+        return app('json')->success($this->repository->confirmOrder($relation_id, $sched_sign));
182
+    }
183
+
184
+    /**
185
+     * 查询订单信息
186
+     *
187
+     * @return mixed
188
+     */
189
+    public function getOrderInfo()
190
+    {
191
+        $relation_id = $this->request->param(['relation_id']);
192
+        if (empty($cinema_sign)) return app('json')->fail('请选择场次');
193
+
194
+        $sched_sign = $this->request->param(['sched_sign']);
195
+        if (empty($film_sign)) return app('json')->fail('请选择场次');
196
+
197
+        return app('json')->success($this->repository->getOrderInfo($relation_id, $sched_sign));
198
+    }
123 199
 }

+ 3 - 0
route/api.php

@@ -1281,6 +1281,9 @@ Route::group('api/', function () {
1281 1281
 
1282 1282
     //电影 - 下单业务
1283 1283
     Route::group('movie', function () {
1284
+        Route::post('submit_order', '/submitOrder');
1285
+        Route::post('confirm_order', '/confirmOrder');
1286
+        Route::get('order_info', '/getOrderInfo');
1284 1287
     })->prefix('api.movie.Movie')->middleware(\app\common\middleware\UserTokenMiddleware::class, false);
1285 1288
 })
1286 1289
     ->middleware(\app\common\middleware\AllowOriginMiddleware::class)