瀏覽代碼

调整电影支付

family 1 年之前
父節點
當前提交
27356b0259

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

@@ -57,6 +57,9 @@ class MovieOrderDao extends BaseDao
57 57
             ->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
58 58
                 $query->where('order_sn', '=', $where['order_sn']);
59 59
             })
60
+            ->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
61
+                $query->where('order_id', '=', $where['order_id']);
62
+            })
60 63
             ->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
61 64
                 $query->where('paid', $where['paid']);
62 65
             });

+ 151 - 7
app/common/repositories/movie/MovieRepository.php

@@ -230,12 +230,12 @@ class MovieRepository extends BaseRepository
230 230
                 'sched_seat' => $params['sched_seat'], // 场次座位
231 231
                 'create_time' => time()
232 232
             ];
233
-            $order_sn = Db::transaction(function () use ($userinfo, $_order) {
234
-                $_order = $this->dao->create($_order);
235
-                if ($_order) return $_order['order_sn'];
233
+            $order_id = Db::transaction(function () use ($userinfo, $_order) {
234
+                $orderModel = $this->dao->create($_order);
235
+                if ($orderModel) return $orderModel['order_id'];
236 236
                 throw new ValidateException('锁座下单失败');
237 237
             });
238
-            return $order_sn;
238
+            return $order_id;
239 239
         } else {
240 240
             throw new ValidateException($submitOrder['msg']);
241 241
         }
@@ -250,15 +250,15 @@ class MovieRepository extends BaseRepository
250 250
      * @throws \think\db\exception\DbException
251 251
      * @throws \think\db\exception\ModelNotFoundException
252 252
      */
253
-    public function confirmOrder($userinfo, $order_sn, $pay_type)
253
+    public function confirmOrder($userinfo, $order_id, $pay_type, $code)
254 254
     {
255
-        $orderinfo = $this->dao->search(['order_sn' => $order_sn, 'uid' => $userinfo['uid']])->find();
255
+        $orderinfo = $this->dao->search(['order_id' => $order_id])->find();
256 256
         if (empty($orderinfo)) throw new ValidateException('订单不存在');
257 257
         if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 2) throw new ValidateException('订单已超时');
258 258
         if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 3) throw new ValidateException('订单已取消');
259 259
         if ($orderinfo['paid'] == 1) throw new ValidateException('订单已支付');
260 260
 
261
-        $res = $this->pay($pay_type, $userinfo['wechat_user_id'], $orderinfo, $orderinfo['film_name'], env('APP_URL') . "/api/hf_notify/movie", 'delay');
261
+        $res = $this->movie_pay($pay_type, $code, $userinfo['wechat_user_id'], $orderinfo, $orderinfo['film_name'], env('APP_URL') . "/api/hf_notify/movie", 'delay');
262 262
         Db::name('log')->insert(['data' => '汇付电影票订单支付--- 返回参数' . json_encode($res)]);
263 263
         if (isset($res['id'])) {
264 264
             $type = 0;
@@ -352,6 +352,150 @@ class MovieRepository extends BaseRepository
352 352
     }
353 353
 
354 354
     /**
355
+     * 电影票支付
356
+     *
357
+     * @param $payType
358
+     * @param $code
359
+     * @param $wechat_user_id
360
+     * @param $orderinfo
361
+     * @param $title
362
+     * @param $notify_url
363
+     * @param $pay_mode
364
+     * @param $appid
365
+     * @return array|mixed|void
366
+     */
367
+    private function movie_pay($payType, $code, $wechat_user_id, $orderinfo, $title, $notify_url, $pay_mode = null, $appid = '')
368
+    {
369
+        if ($payType == 'wx') {
370
+            if (!$code || $code == '' || $code == 'undefined') {
371
+                throw new ValidateException('授权失败,code为空');
372
+            }
373
+            if ($appid == '') {
374
+                $pay_wx = systemConfig('pay_wx');
375
+                if ($pay_wx == 2) {
376
+                    $appid = env('WECHAT_MP.APPID');
377
+                    $new_secret = env('WECHAT_MP.SECRET');
378
+
379
+                    $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
380
+                    $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
381
+                } elseif ($pay_wx == 3) {
382
+                    $appid = env('WECHAT_TDYL.APPID');
383
+                    $new_secret = env('WECHAT_TDYL.SECRET');
384
+
385
+                    Db::name('log')->insert(['data' => 'appid---' . $appid]);
386
+                    Db::name('log')->insert(['data' => 'new_secret---' . $new_secret]);
387
+                    $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
388
+                    $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
389
+                }
390
+            } else {
391
+                $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
392
+                $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
393
+                $new_secret = "c8cbe24fa3b83f77a88b79554b3aeab4";
394
+            }
395
+
396
+            $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $new_secret . "&js_code=" . $code . "&grant_type=authorization_code";
397
+            $get = curlGet($url);
398
+            Db::name('log')->insert(['data' => 'open_id---' . json_encode($get)]);
399
+            if (!isset($get['openid']) || empty($get['openid'])) {
400
+                throw new ValidateException('授权失败');
401
+            }
402
+            $member_id = 0;
403
+            $type = '2';
404
+            $pay_channel = 'wx_lite';
405
+
406
+            $expend = ['open_id' => $get['openid'], 'wx_app_id' => $appid];
407
+            if (false) {
408
+//                if ($orderinfo['order_type'] = "movie") {
409
+                $cfb = sprintf("%01.2f", round(bcmul($orderinfo['order_price'], '0.094', 5), 2));//9.4%的分账
410
+                $cfb_member = "jsdk_member_1680162243019";
411
+                //  平台
412
+                $cxb = sprintf("%01.2f", round(bcsub($orderinfo['order_price'], $cfb, 5), 2));//剩下的归平台
413
+                $div_members = [
414
+//                    [
415
+//                        'member_id' => $member_id,
416
+//                        'amount' => $cxb,
417
+//                        'fee_flag' => 'Y'
418
+//                    ],
419
+//                    [
420
+//                        'member_id' => $cfb_member,
421
+//                        'amount' => $cfb,
422
+//                        'fee_flag' => 'N'
423
+//                    ]
424
+                ];
425
+            } else {
426
+                $div_members = [
427
+                    [
428
+                        'member_id' => $member_id,
429
+                        'amount' => $orderinfo['order_price'],
430
+                        'fee_flag' => 'Y'
431
+                    ]
432
+                ];
433
+            }
434
+
435
+            $params = [
436
+                'order_no' => $orderinfo['order_sn'],
437
+                'app_id' => $app_id,
438
+                'pay_channel' => $pay_channel,
439
+                'pay_amt' => (string)$orderinfo['order_price'],
440
+                'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
441
+                'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
442
+                'device_info' => [
443
+                    'device_ip' => app('request')->ip()
444
+                ],
445
+                'expend' => json_encode($expend),
446
+                'div_members' => json_encode($div_members),
447
+                'fee_mode' => 'I',
448
+                'notify_url' => $notify_url
449
+            ];
450
+            if ($pay_mode == 'delay') {
451
+                $params['pay_mode'] = 'delay';
452
+                unset($params['div_members']);
453
+                unset($params['fee_mode']);
454
+            }
455
+            return $this->Payment_create_traits_b($params, $type, $key);
456
+        } elseif ($payType == 'ALI') {
457
+            $member_id = 0;
458
+            $type = '1';
459
+            $pay_channel = 'alipay_qr';
460
+            // 天地博爱科技通道
461
+            $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
462
+            $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
463
+            // 天地博爱通道
464
+//            $app_id='app_0827b960-b932-45ec-b800-4e850091b419';
465
+//            $key='api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
466
+
467
+            $div_members = [
468
+                [
469
+                    'member_id' => $member_id,
470
+                    'amount' => $orderinfo['order_price'],
471
+                    'fee_flag' => 'Y'
472
+                ]
473
+            ];
474
+
475
+            $params = [
476
+                'order_no' => $orderinfo['order_sn'],
477
+                'app_id' => $app_id,
478
+                'pay_channel' => $pay_channel,
479
+                'pay_amt' => (string)$orderinfo['order_price'],
480
+                'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
481
+                'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
482
+                'device_info' => [
483
+                    'device_ip' => app('request')->ip()
484
+                ],
485
+                'div_members' => json_encode($div_members),
486
+                'fee_mode' => 'I',
487
+                'notify_url' => $notify_url
488
+            ];
489
+            if ($pay_mode == 'delay') {
490
+                $params['pay_mode'] = 'delay';
491
+                unset($params['div_members']);
492
+                unset($params['fee_mode']);
493
+            }
494
+            return $this->Payment_create_traits_a($params, $type, $key);
495
+        }
496
+    }
497
+
498
+    /**
355 499
      * @param $userinfo
356 500
      * @param $order_sn
357 501
      * @return mixed|string

+ 9 - 8
app/controller/api/movie/Movie.php

@@ -203,9 +203,9 @@ class Movie extends BaseController
203 203
         if (empty($params['sched_seat'])) return app('json')->fail('请选择观影座位');
204 204
 
205 205
         try {
206
-            $result = $this->repository->submitOrder($this->request->userInfo(), $params);
207
-            if (!empty($result)) {
208
-                return app('json')->success(['order_sn' => $result]);
206
+            $order_id = $this->repository->submitOrder($this->request->userInfo(), $params);
207
+            if (!empty($order_id)) {
208
+                return app('json')->success(['oid' => $order_id, 'code' => '', 'type' => 'wx']);
209 209
             } else {
210 210
                 return app('json')->fail('锁座下单失败');
211 211
             }
@@ -221,13 +221,14 @@ class Movie extends BaseController
221 221
      */
222 222
     public function confirmOrder()
223 223
     {
224
-        $order_sn = $this->request->param('order_sn', '');
225
-        if (empty($order_sn)) return app('json')->fail('订单不存在');
226
-        $pay_type = $this->request->param('pay_type', '');
227
-        if (empty($pay_type) || !in_array($pay_type, ['wx', 'ali'])) return app('json')->fail('请选择支付方式');
224
+        $order_id = $this->request->param('oid', '');
225
+        $code = $this->request->param('code', '');
226
+        $pay_type = $this->request->param('type', '');
227
+        if (empty($order_id)) return app('json')->fail('订单不存在');
228
+        if (empty($pay_type) || !in_array(strtolower($pay_type), ['wx', 'ali'])) return app('json')->fail('请选择支付方式');
228 229
 
229 230
         try {
230
-            return app('json')->success($this->repository->confirmOrder($this->request->userInfo(), $order_sn, $pay_type));
231
+            return app('json')->success($this->repository->confirmOrder($this->request->userInfo(), $order_id, $pay_type, $code));
231 232
         } catch (\Exception $exception) {
232 233
             return app('json')->fail($exception->getMessage());
233 234
         }

+ 1 - 0
route/api.php

@@ -1290,6 +1290,7 @@ Route::group('api/', function () {
1290 1290
     Route::group('movie', function () {
1291 1291
         Route::post('submit_order', '/submitOrder');
1292 1292
         Route::post('confirm_order', '/confirmOrder');
1293
+        Route::post('dy_pay_wechat_mp', '/confirmOrder');
1293 1294
         Route::get('order_list', '/getOrderList'); // 订单列表
1294 1295
         Route::get('order_info', '/getOrderInfo');
1295 1296
     })->prefix('api.movie.Movie')->middleware(\app\common\middleware\UserTokenMiddleware::class, false);