Explorar el Código

Merge branch 'master' of http://git.huxiukeji.com/lizhen/xiaoshan

lizhen_gitee hace 1 mes
padre
commit
599e5e03b9

+ 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',
+        ]);
     }
 
     // 订单列表

+ 53 - 0
application/api/controller/OfflineShop.php

@@ -65,6 +65,59 @@ class OfflineShop extends Api
         }
 
         $list = $model->getList(params: $params,orderBy: array_merge($orderBy,['weigh' => 'desc']),select: $select);
+        foreach ($list as &$item) {
+            [$distance,$unit] = \app\utils\Common::distanceTo($item['distance']);
+            $item['distance'] = "{$distance}{$unit}";
+        }
         return $this->success('success',$list);
     }
+
+    // 商铺列表
+    public function info()
+    {
+        $params = $this->request->param();
+        $userLng = $this->auth->lng;
+        $userLat = $this->auth->lat;
+        $model = new OfflineShopModel();
+        $select = ['*'];
+        if (!empty($userLng) && !empty($userLat)) {
+            $select[] = Db::raw("(st_distance(point ({$userLng}, {$userLat}),point(lng,lat))*111195) as distance");
+        }
+        $info = $model->getDetail(params: $params,select: $select);
+        if (!empty($info)) {
+            $info['images'] = explode(',',$info['image']);
+        }
+        return $this->success('success',$info);
+    }
+
+    // 评价
+    public function comment()
+    {
+        $params = $this->request->param();
+        if (empty($params['shop_id'])) {
+            return $this->error('请选择评价门店');
+        }
+        if (empty($params['star'])){
+            return $this->error('请选择评分');
+        }
+        if (empty($params['remark'])){
+            return $this->error('请填写评价');
+        }
+
+        $data = [
+            'shop_id' => $params['shop_id'],
+            'user_id' => $this->auth->id,
+            'star' => $params['star'],
+            'remark' => $params['remark'],
+            'images' => $params['images'] ?? '',
+            'status' => 1,
+            'create_time' => time(),
+        ];
+        Db::name('offline_shop_comment')->insert($data);
+
+        $comment = Db::name('offline_shop_comment')->where('shop_id',$params['shop_id'])->field([Db::raw('sum(star) as star'),Db::raw('count(*) as num')])->find();
+        $star = bcdiv($comment['star'] ?? 0,$comment['num'] ?? 0,2);
+        Db::name('offline_shop')->where('id',$params['shop_id'])->update(['star'=>$star]);
+        return $this->success('评价成功');
+    }
 }

+ 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))) {}
+
+    }
+}

+ 34 - 0
application/api/controller/ShopOffline.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use app\common\model\OfflineShopModel;
+use app\common\model\OfflineTypeModel;
+use app\utils\DataUtil;
+use think\Db;
+/**
+ * 示例接口
+ */
+class ShopOffline extends Api
+{
+    protected $noNeedLogin = [''];
+    protected $noNeedRight = ['*'];
+
+    public function home()
+    {
+        $user_id = $this->auth->id;
+
+        $model = new OfflineShopModel();
+        $info = $model->getDetail(params: ['user_id' => $user_id],select: ['id','user_id','type_id','name','keyword','image','images','work_time','lng','lat','address','telephone']);
+        if (!$info){
+            return $this->success('未开通线下门店');
+        }
+        $info['image'] = cdnurl($info['images']);
+        $info['images'] = array_domain_image(!empty($info['images']) ? explode(',',$info['images']) : []);
+
+        return $this->success('success',[
+            'info' => $info,
+        ]);
+    }
+}

+ 1 - 1
application/common/library/Auth.php

@@ -27,7 +27,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'group_id','idcard_status'];
+    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'group_id','idcard_status','shop_type','lng','lat','city'];
 
     public function __construct($options = [])
     {

+ 1 - 1
application/common/model/BaseModel.php

@@ -120,7 +120,7 @@ class BaseModel extends Model
         count($with) > 0 && $query->with($with);
 
         // 规避 禁用 和 删除 数据
-        $this->is_status_search === 1 && $query->where('status', 'normal');
+        $this->is_status_search === 1 && $query->where('status', 1);
         $this->is_delete_search === 1 && $query->whereNull('deletetime');
 
         $detail = $query->find();

+ 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);

+ 9 - 1
application/common/model/OfflineShopModel.php

@@ -20,7 +20,7 @@ class OfflineShopModel extends BaseModel
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
 
-    protected int $is_status_search = 1;// 默认使用 status = 1 筛选
+    protected int $is_status_search = 0;// 默认使用 status = 1 筛选
     protected int $is_delete_search = 0;// 默认使用 is_delete = 0 筛选
 
     /**
@@ -40,6 +40,14 @@ class OfflineShopModel extends BaseModel
         return $query->where('type_id', $value);
     }
 
+    public function searchUserIdAttribute($query, $value, array $params)
+    {
+        if (empty($value)) {
+            return $query;
+        }
+        return $query->where('user_id', $value);
+    }
+
     public function searchKeywordAttribute($query, $value, array $params)
     {
         if (empty($value)) {

+ 19 - 0
application/utils/Common.php

@@ -189,6 +189,25 @@ class Common
         return round($s, $decimal);
     }
 
+    public static function distanceTo($distance,$len_type = 2,$decimal = 2)
+    {
+        // 单位
+        $unit = 'm';
+        // 1 kilometer / 2 meter
+        if ($len_type == 1) {
+            $distance    /= 1000;
+            $unit = 'km';
+        }
+        // 自动转换
+        if ($len_type == 2) {
+            if ($distance >= 1000) {
+                $distance    /= 1000;
+                $unit = 'km';
+            }
+        }
+        return [round($distance, $decimal), $unit];
+    }
+
     /**
      * 获取随机昵称
      * @return string