Browse Source

混合支付

Panda 2 weeks ago
parent
commit
58bdd790a5

+ 58 - 7
application/api/controller/Hotel.php

@@ -104,6 +104,50 @@ class Hotel extends Api
         return $this->success('success', $info);
     }
 
+    public function order_page()
+    {
+        $params = $this->request->param();
+        if (empty($params['room_id'])) {
+            return $this->error('参数缺失');
+        }
+        if (empty($params['start_date'])) {
+            return $this->error('参数缺失');
+        }
+        if (empty($params['end_date'])) {
+            return $this->error('参数缺失');
+        }
+        if (empty($params['num'])) {
+            return $this->error('参数缺失');
+        }
+        $model = new HotelRoomModel();
+        $info = $model->getDetail(
+            params: ['id' => $params['room_id']],
+            with: [
+                'hotel'=>function ($query) {
+                    $query->field(['id','name','image','images','price','original_price']);
+                }
+            ]
+        );
+        if (!$info) {
+            return $this->error('房间不存在');
+        }
+        if (empty($info['hotel'])) {
+            return $this->error('酒店信息有误');
+        }
+        $days = (int)((strtotime($params['end_date']) - strtotime($params['start_date'])) / 86400);
+        $pay_amount = bcmul(bcmul($info['price'], $days, 2),$params['num'],2);
+        return $this->success('获取成功', [
+            'info'  => $info,
+            'order' => [
+                'room_id'    => $params['room_id'],
+                'start_date' => $params['start_date'],
+                'end_date'   => $params['end_date'],
+                'days'       => $days,
+                'pay_amount' => $pay_amount,
+            ]
+        ]);
+    }
+
     public function apply()
     {
         $params = $this->request->param();
@@ -126,11 +170,15 @@ class Hotel extends Api
             return $this->error('参数缺失');
         }
         $user_id = $this->auth->id;
-        $info = HotelRoomModel::with([
-            'hotel'=>function ($query) {
-                $query->field(['id','name','image','images','price','original_price']);
-            }
-        ])->where('id',$params['room_id'])->where('status',1)->find();
+        $model = new HotelRoomModel();
+        $info = $model->getDetail(
+            params: ['id' => $params['room_id']],
+            with: [
+                'hotel'=>function ($query) {
+                    $query->field(['id','name','image','images','price','original_price']);
+                }
+            ]
+        );
         if (!$info) {
             return $this->error('房间不存在');
         }
@@ -151,14 +199,17 @@ class Hotel extends Api
             'days' => $days,
             'order_no' => createUniqueNo('H', $user_id),
             'pay_amount' => bcmul(bcmul($info['price'], $days, 2),$params['num'],2),
-            'status' => 1,
             'create_time' => time()
         ];
         if (!Db::name('hotel_order')->insertGetId($data)) {
             return $this->error('订单创建失败');
         }
 
-        return $this->success('提交成功');
+        return $this->success('提交成功',[
+            'order_no' => $data['order_no'],
+            'pay_amount' => $data['pay_amount'],
+            'order_type' => 'hotel_order',
+        ]);
     }
 
     // 订单列表

+ 43 - 0
application/api/controller/Payment.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace app\api\controller;
+
+use addons\epay\library\Service;
+use app\common\controller\Api;
+use app\common\model\HotelModel;
+use app\common\model\HotelOrderModel;
+use app\common\model\HotelRoomModel;
+use app\common\model\PayOrderModel;
+use app\common\model\UniversityEventModel;
+use app\common\model\Wallet;
+use app\utils\CurlUtil;
+use app\utils\Service\Tencent\TencentIm;
+use think\Db;
+
+/**
+ * 老年大学 活动板块
+ */
+class Payment extends Api
+{
+    protected $noNeedLogin = [''];
+    protected $noNeedRight = ['*'];
+    protected const ORDER_TYPE = [
+        'hotel_order'            => '酒店订单',
+        'hotel_canteen_order'    => '餐厅订单',
+        'university_event_apply' => '活动订单',
+        'offline_shop_order'     => '线下订单',
+    ];
+
+    // 活动列表
+    public function page()
+    {
+        $user_id = $this->auth->id;
+        $params = $this->request->param();
+        if (empty($params['order_no']) || empty($params['order_type'])) {
+            return $this->error('请选择订单');
+        }
+        dd(array_keys(self::ORDER_TYPE));
+        if (!in_array($params['order_type'], array_keys(self::ORDER_TYPE))) {}
+
+    }
+}

+ 3 - 0
application/common/model/HotelRoomModel.php

@@ -20,6 +20,9 @@ class HotelRoomModel extends BaseModel
     protected $updateTime = false;
     protected $deleteTime = false;
 
+    protected int $is_status_search = 1;// 默认使用 status = 1 筛选
+    protected int $is_delete_search = 0;// 默认使用 is_delete = 0 筛选
+
     public function getWifiPhoneAttr($value, $data)
     {
         return explode(',',$value);