浏览代码

1、调整锁座
2、确认订单,发起支付

family 1 年之前
父节点
当前提交
67ab95f5e6
共有 2 个文件被更改,包括 53 次插入26 次删除
  1. 48 20
      app/common/repositories/movie/MovieRepository.php
  2. 5 6
      app/controller/api/movie/Movie.php

+ 48 - 20
app/common/repositories/movie/MovieRepository.php

@@ -128,14 +128,21 @@ class MovieRepository extends BaseRepository
128 128
         foreach ($schedSeatList as $key => $value) {
129 129
             $tmpprice = [];
130 130
             foreach ($value['price'] as $pKey => $pValue) {
131
-                $tmpprice[$pValue] = ['channel_type' => $pKey, 'price' => $pValue];
131
+                $tmpprice[$pKey] = ['channel_type' => $pKey, 'price' => $pValue];
132
+            }
133
+
134
+            $channel_price = [];
135
+            if (isset($tmpprice['P2'])) {
136
+                $channel_price = $tmpprice['P2'];
137
+            } elseif (isset($tmpprice['P1'])) {
138
+                $channel_price = $tmpprice['P1'];
139
+            } elseif (isset($tmpprice['P0'])) {
140
+                $channel_price = $tmpprice['P0'];
132 141
             }
133
-            ksort($tmpprice);
134
-            $tmpprice = array_shift($tmpprice);
135 142
             unset($schedSeatList[$key]['price']);
136 143
 
137
-            $pcYanglaojinGongxian = self::getPvYanglaojinScore($tmpprice['price']);
138
-            $schedSeatList[$key]['channel_type'] = $tmpprice['channel_type'];
144
+            $pcYanglaojinGongxian = self::getPvYanglaojinScore($channel_price['price']);
145
+            $schedSeatList[$key]['channel_sn'] = base64_encode(json_encode($channel_price, JSON_FORCE_OBJECT));
139 146
             $schedSeatList[$key]['price'] = $pcYanglaojinGongxian['cost_price'];
140 147
             $schedSeatList[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin'];
141 148
             $schedSeatList[$key]['pv'] = $pcYanglaojinGongxian['pv'];
@@ -172,9 +179,17 @@ class MovieRepository extends BaseRepository
172 179
         $sched = $cinemaSchedRepository->getCinemaSchedInfo($params['relation_id'], $params['sched_sign']);
173 180
         if (empty($sched)) throw new ValidateException('观影场次不存在');
174 181
 
175
-        $seat_sign = json_decode($params['seat_sign'], true);
176
-        $order_price = bcmul((string)$sched['cost_price'], (string)count($seat_sign), 2);
177
-        $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $params['channel_type'], $params['sched_sign'], $seat_sign, $order_sn, $order_price);
182
+        $channel_sn = json_decode(base64_decode($params['channel_sn']), true);
183
+        if (empty($channel_sn) || !isset($channel_sn['channel_type']) || empty($channel_sn['channel_type']) || !isset($channel_sn['price'])
184
+            || empty($channel_sn['price']) || json_last_error()) {
185
+            throw new ValidateException('请选择观影场次');
186
+        }
187
+
188
+        $sched_seat = json_decode($params['sched_seat'], true);
189
+        if (json_last_error()) throw new ValidateException('锁座下单失败');
190
+
191
+        $order_price = bcmul((string)$channel_sn['price'], (string)count($sched_seat), 2);
192
+        $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $channel_sn['channel_type'], $params['sched_sign'], array_column($sched_seat, 'seat_sign'), $order_sn, $order_price);
178 193
         if (!empty($submitOrder) && isset($submitOrder['code']) && ($submitOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE) && isset($submitOrder['data']['plat_order'])) {
179 194
             /** @var CinemaRepository $cinemaRepository */
180 195
             $cinemaRepository = app()->make(CinemaRepository::class);
@@ -185,10 +200,10 @@ class MovieRepository extends BaseRepository
185 200
                 'mobile' => $userinfo->phone,
186 201
                 'order_sn' => $order_sn,
187 202
                 'plat_order' => $submitOrder['data']['plat_order'],
188
-                'price' => $sched['price'],
189
-                'number' => count($seat_sign),
190
-                'order_price' => $order_price,
191
-                'channel_type' => $params['channel_type'],
203
+                'price' => $channel_sn['price'],
204
+                'number' => count($sched_seat),
205
+                'order_price' => bcadd((string)$order_price, bcmul((string)$order_price, (string)self::premium_ratio, 2), 2),
206
+                'channel_type' => $channel_sn['channel_type'],
192 207
                 'city_sign' => $cinema['city_sign'],
193 208
                 'city_name' => $cinema['city_name'],
194 209
                 'area_code' => $cinema['area_sign'],
@@ -206,10 +221,9 @@ class MovieRepository extends BaseRepository
206 221
                 'film_name' => $sched['film_name'],
207 222
                 'show_date' => $sched['show_date'],
208 223
                 'show_time' => $sched['show_time'],
209
-                'sched_seat' => $sched['sched_seat'],
224
+                'sched_seat' => $params['sched_seat'], // 场次座位
210 225
                 'create_time' => time()
211 226
             ];
212
-
213 227
             $order_sn = Db::transaction(function () use ($userinfo, $_order) {
214 228
                 $_order = $this->dao->create($_order);
215 229
                 if ($_order) return $_order['order_sn'];
@@ -224,9 +238,13 @@ class MovieRepository extends BaseRepository
224 238
     /**
225 239
      * @param $userinfo
226 240
      * @param $order_sn
227
-     * @return mixed|string
241
+     * @param $pay_type
242
+     * @return mixed
243
+     * @throws \think\db\exception\DataNotFoundException
244
+     * @throws \think\db\exception\DbException
245
+     * @throws \think\db\exception\ModelNotFoundException
228 246
      */
229
-    public function confirmOrder($userinfo, $order_sn)
247
+    public function confirmOrder($userinfo, $order_sn, $pay_type)
230 248
     {
231 249
         $orderinfo = $this->dao->getWhere(['order_sn' => $order_sn, 'uid' => $userinfo->uid])->find();
232 250
         if (empty($orderinfo)) throw new ValidateException('订单不存在');
@@ -234,10 +252,19 @@ class MovieRepository extends BaseRepository
234 252
         if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 3) throw new ValidateException('订单已取消');
235 253
         if ($orderinfo['paid'] == 1) throw new ValidateException('订单已支付');
236 254
 
237
-//                return $this->pay(
238
-//                    $_order['pay_type'], $userinfo->wechat_user_id, $_order, $_order['film_name'], env('APP_URL') . "/api/hf_notify/movie",
239
-//                    'delay');
240
-        return DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['order_price']);
255
+        $res = $this->pay($pay_type, $userinfo->wechat_user_id, $orderinfo, $orderinfo['film_name'], env('APP_URL') . "/api/hf_notify/movie", 'delay');
256
+        Db::name('log')->insert(['data' => '汇付电影票订单支付--- 返回参数' . json_encode($res)]);
257
+        if (isset($res['id'])) {
258
+            $type = 0;
259
+            if ($pay_type == 'wx') $type = 2;
260
+            if (strtolower($pay_type) == 'ali') $type = 1;
261
+            $orderinfo->pay_type = $type;
262
+            $orderinfo->save();
263
+
264
+            return app('json')->success($res);
265
+        }
266
+        throw new ValidateException('支付失败');
267
+//        return DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['order_price']);
241 268
     }
242 269
 
243 270
     /**
@@ -289,6 +316,7 @@ class MovieRepository extends BaseRepository
289 316
                 ];
290 317
                 break;
291 318
             case 'ALI':
319
+            case 'ali':
292 320
                 $type = '1';
293 321
                 // 天地博爱科技通道
294 322
                 $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';

+ 5 - 6
app/controller/api/movie/Movie.php

@@ -166,7 +166,6 @@ class Movie extends BaseController
166 166
     {
167 167
         $relation_id = $this->request->param('relation_id', '');
168 168
         if (empty($relation_id)) return app('json')->fail('请选择观影场次');
169
-
170 169
         $sched_sign = $this->request->param('sched_sign', '');
171 170
         if (empty($sched_sign)) return app('json')->fail('请选择观影场次');
172 171
 
@@ -181,14 +180,14 @@ class Movie extends BaseController
181 180
     public function submitOrder()
182 181
     {
183 182
         $params = $this->request->params(
184
-            ['channel_type', 'P2'],
185 183
             ['relation_id', ''], // 场次ID
186 184
             ['sched_sign', ''], // 场次编码
187 185
             ['seat_no', ''], // 座位
188
-            ['seat_sign', ''] // 座位编码
186
+            ['seat_sign', ''], // 座位编码
187
+            ['channel_sn', ''] // 实际价格
189 188
         );
190 189
 
191
-        if (empty($params['relation_id']) || empty($params['sched_sign'])) return app('json')->fail('请选择观影场次');
190
+        if (empty($params['relation_id']) || empty($params['sched_sign']) || $params['channel_sn']) return app('json')->fail('请选择观影场次');
192 191
         if (empty($params['seat_no']) || empty($params['seat_sign'])) return app('json')->fail('请选择观影座位');
193 192
 
194 193
         $result = $this->repository->submitOrder($this->request->userInfo(), $params);
@@ -209,9 +208,9 @@ class Movie extends BaseController
209 208
         $order_sn = $this->request->param('order_sn', '');
210 209
         if (empty($order_sn)) return app('json')->fail('订单不存在');
211 210
         $pay_type = $this->request->param('pay_type', '');
212
-        if (empty($pay_type)) return app('json')->fail('请选择支付方式');
211
+        if (empty($pay_type) || !in_array($pay_type, ['wx', 'ali'])) return app('json')->fail('请选择支付方式');
213 212
 
214
-        return app('json')->success($this->repository->confirmOrder($this->request->userInfo(), $order_sn));
213
+        return app('json')->success($this->repository->confirmOrder($this->request->userInfo(), $order_sn, $pay_type));
215 214
     }
216 215
 
217 216
     /**