Przeglądaj źródła

feat:
- 按时间获取预约列表接口

zhengzhibin 2 lat temu
rodzic
commit
f1500cb882

+ 1 - 1
app/admin/controller/Appointment.php

@@ -86,7 +86,7 @@ class Appointment extends Permissions
             $validate = new \think\Validate([
                 ['title|服务名称', 'max:50'],
                 ['provider_id', 'require|number'],
-                ['phone|咨询电话', 'require|max:50'],
+//                ['phone|咨询电话', 'require|max:50'],
                 ['start_time', 'number', '排号日期格式不对'],
                 ['end_time', 'number', '排号日期格式不对'],
                 ['morning_num|上午放号个数', 'number'],

+ 1 - 1
app/admin/view/appointment/index.html

@@ -98,7 +98,7 @@
                     {field: "start_time", title: '排号日期',width: 200,templet:function (row) {
                         return row.start_time + ' ~ ' + row.end_time;
                     }},
-                    {field: "title", title: '服务名称'},
+//                    {field: "title", title: '服务名称'},
                     {field: "morning_num", title: '上午放号个数'},
                     {field: "afternoon_num", title: '下午放号个数'},
                     {field: "night_num", title: '晚上放号个数'},

+ 15 - 17
app/admin/view/appointment/publish.html

@@ -94,23 +94,21 @@
             </div>
         </div>
 
-        <!-- 输入框 -->
-        <div class="layui-form-item">
-            <label class="layui-form-label">服务名称</label>
-            <div class="layui-input-inline" style="max-width:300px;">
-                <input name="title" autocomplete="off" placeholder="请输入" class="layui-input" type="text"
-                       value="{notempty name="$data"}{$data.title}{else/}咨询服务{/notempty}">
-            </div>
-        </div>
-        <!-- 输入框 -->
-        <div class="layui-form-item">
-            <label class="layui-form-label">咨询电话</label>
-            <div class="layui-input-inline" style="max-width:300px;">
-                <input name="phone" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input"
-                       type="text" value="{notempty name="$data"}{notempty name="$data.phone"}{$data.phone}{else/}{$data.specialist.phone}{/notempty}{else/}{$phone}{/notempty}">
-            </div>
-            <div class="layui-form-mid layui-word-aux">必填</div>
-        </div>
+        <!--<div class="layui-form-item">-->
+            <!--<label class="layui-form-label">服务名称</label>-->
+            <!--<div class="layui-input-inline" style="max-width:300px;">-->
+                <!--<input name="title" autocomplete="off" placeholder="请输入" class="layui-input" type="text"-->
+                       <!--value="{notempty name="$data"}{$data.title}{else/}咨询服务{/notempty}">-->
+            <!--</div>-->
+        <!--</div>-->
+        <!--<div class="layui-form-item">-->
+            <!--<label class="layui-form-label">咨询电话</label>-->
+            <!--<div class="layui-input-inline" style="max-width:300px;">-->
+                <!--<input name="phone" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input"-->
+                       <!--type="text" value="{notempty name="$data"}{notempty name="$data.phone"}{$data.phone}{else/}{$data.specialist.phone}{/notempty}{else/}{$phone}{/notempty}">-->
+            <!--</div>-->
+            <!--<div class="layui-form-mid layui-word-aux">必填</div>-->
+        <!--</div>-->
 
 
 

+ 80 - 7
app/api/controller/Appointment.php

@@ -3,23 +3,96 @@
 namespace app\api\controller;
 
 use app\api\controller\base\Base;
+use app\common\model\Address;
+use app\common\model\AppointmentTicket;
 
 class Appointment extends Base
 {
-    private function getModel()
+    //获取地址列表
+    public function addressList()
     {
-        return new \app\common\model\Appointment();
+        $post = $this->request->param();
+        $validate = new \think\Validate([
+            ['page', 'number'],
+            ['pagenum', 'number|<=:1000']
+        ]);
+        if (!$validate->check($post)) {
+            $this->json_error('提交失败:' . $validate->getError());
+        }
+
+        $where = [];
+        $addressIds = (new \app\common\model\Appointment())->availableAddressIds();
+        $where['id'] = ['in', $addressIds];
+        $pagenum = $this->request->param('pagenum', 20, 'intval');
+        $datalist = (new Address())->where($where)->paginate($pagenum, true);
+        if (empty($datalist)) {
+            $this->json_error("没有数据");
+        }
+        $this->json_success("查询成功", $datalist);
     }
 
-    //按地点预约列表接口
-    public function listByAddress()
+
+    //按地址id获取号源信息
+    public function getTicketByAddressId()
     {
-        $this->json_success("查询成功", $this->getModel()->listByAddress());
+        $post = $this->request->param();
+        $validate = new \think\Validate([
+            ['address_id', 'require|number'],
+            ['daytime', 'dateFormat:Y-m-d'],
+        ]);
+        if (!$validate->check($post)) {
+            $this->json_error('提交失败:' . $validate->getError());
+        }
+
+        $address_id = $this->request->param('address_id');
+        $daytime = $this->request->param('daytime', date('Y-m-d'));
+
+        $ticketModel = new AppointmentTicket();
+        $tickets = $ticketModel->where('address_id', $address_id)->where('appointment_daytime', strtotime($daytime))->select();
+
+        foreach ($tickets as $k => $item) {
+            //专家信息
+            $item->specialist;
+            //剩余预约号码
+            //拆分预约时段
+            //价格?
+            $tickets[$k] = $item;
+        }
+
+        $this->json_success($tickets);
     }
 
-    //按时间预约列表接口
-    public function listByDayTime()
+    //按时间获取地址列表
+    public function addressListByDayTime()
     {
+        \app\common\model\Appointment::createTicketFromAllAppointment();
+        $ticketModel = new AppointmentTicket();
+
+        //可预约日期列表
+//        $maxEndTime = $ticketModel->max('end_time');
+//        $daylist = DateHelper::getDateList(date('Y-m-d'), date('Y-m-d', $maxEndTime), true);
+
+
+        $post = $this->request->param();
+        $validate = new \think\Validate([
+            ['daytime', 'date|dateFormat:Y-m-d'],
+            ['page', 'number'],
+            ['pagenum', 'number|<=:1000']
+        ]);
+        if (!$validate->check($post)) {
+            $this->json_error('提交失败:' . $validate->getError());
+        }
+
+        $daytime = $this->request->param('daytime', date('Y-m-d'));
+        $addressIds = $ticketModel->where('appointment_daytime', strtotime($daytime))->column('address_id');
 
+        $where = [];
+        $where['id'] = ['in', $addressIds];
+        $pagenum = $this->request->param('pagenum', 20, 'intval');
+        $datalist = (new Address())->where($where)->paginate($pagenum, true);
+        if (empty($datalist)) {
+            $this->json_error("没有数据");
+        }
+        $this->json_success("查询成功", $datalist);
     }
 }

+ 92 - 23
app/api/controller/接口文档.md

@@ -1,4 +1,5 @@
 # 登入接口
+
 接口地址:/api/common/login
 
 请求方式:跳转地址方式
@@ -16,7 +17,8 @@
 ```
 
 
-# 提交反馈接口
+# 提交反馈
+
 接口地址:/api/user/feedback
 
 请求方式:post
@@ -29,8 +31,8 @@
 | content | 内容 |  max:500 |
 
 
-响应数据:(json格式)
-```
+响应数据:
+```json
 {
     "code": 1, // 返回状态,1代表成功,0代表失败
     "msg": "success", // 返回消息
@@ -41,6 +43,7 @@
 
 
 # 查询公告列表
+
 接口地址:/api/announcement/index
 
 请求方式:get
@@ -53,8 +56,8 @@
 |  pagenum | 每页几条,默认20        |  int,<=1000 |
 
 
-响应数据:(json格式)
-```
+响应数据:
+```json
 {
     "code": 1,
     "err_code": 0,
@@ -88,6 +91,7 @@
 ```
 
 # 查询专家列表
+
 接口地址:/api/specialist/index
 
 请求方式:get / post
@@ -100,8 +104,8 @@
 |  pagenum | 每页几条,默认20        |  int,<=:1000 |
 
 
-响应数据:(json格式)
-```
+响应数据:
+```json
 {
     "code": 1,
     "err_code": 0,
@@ -128,31 +132,96 @@
 }
 ```
 
-# 按地点预约列表接口
-接口地址:/api/appointment/listByAddress
+# 获取地址列表
+
+接口地址:/api/appointment/addressList
+
+请求方式:get / post
+
+请求数据:
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+|  page    | 第几页,默认1           |  int   |
+|  pagenum | 每页几条,默认20        |  int,<=:1000 |
+
+响应数据:
+```json
+{
+    "code": 1,
+    "err_code": 0,
+    "msg": "查询成功",
+    "time": "1682257527",
+    "data": {
+        "per_page": 20,
+        "current_page": 1,
+        "has_more": false,
+        "next_item": null,
+        "data": [
+            {
+                "id": 1,
+                "title": "厦门曙光医院",
+                "address": "福建省厦门市湖里区金尚路127号"
+            },
+            {
+                "id": 2,
+                "title": "厦门前埔医院",
+                "address": "地址 : 福建省厦门市湖里区仙岳路3777号\r\n电话 : 0592-5262666"
+            }
+        ]
+    }
+}
+```
+
+# 按地址获取号源信息
+
+接口地址:/api/appointment/getTicketByAddressId
 
 请求方式:get / post
 
-请求数据:无
+请求数据:
 
 响应数据:(json格式)
+```json
+
 ```
+
+
+
+# 按时间获取地址列表
+
+接口地址:/api/appointment/addressListByDayTime
+
+请求方式:get / post
+
+请求数据:
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+|  daytime | 日期,默认今天     |  dateFormat:y-m-d   |
+|  page    | 第几页,默认1      |  int   |
+|  pagenum | 每页几条,默认20   |  int,<=:1000 |
+
+响应数据:
+
+```json
 {
     "code": 1,
     "err_code": 0,
     "msg": "查询成功",
-    "time": "1682250564",
-    "data": [
-        {
-            "id": 1,
-            "title": "厦门曙光医院",
-            "address": "福建省厦门市湖里区金尚路127号"
-        },
-        {
-            "id": 2,
-            "title": "厦门前埔医院",
-            "address": "地址 : 福建省厦门市湖里区仙岳路3777号\r\n电话 : 0592-5262666"
-        }
-    ]
+    "time": "1682261424",
+    "data": {
+        "per_page": 20,
+        "current_page": 1,
+        "has_more": false,
+        "next_item": null,
+        "data": [
+            {
+                "id": 1,
+                "title": "厦门曙光医院",
+                "address": "福建省厦门市湖里区金尚路127号"
+            }
+        ]
+    }
 }
 ```

+ 31 - 13
app/common/model/Appointment.php

@@ -24,12 +24,16 @@ class Appointment extends Model
     public function createTicket()
     {
         if (!$this->ifExitsTicket()) {
-            $daylist = DateHelper::getDateList($this->start_time, $this->end_time);
+            $daylist = DateHelper::getDateList($this->start_time, $this->end_time, true);
             foreach ($daylist as $datetime) {
                 (new AppointmentTicket())->save([
                     'appointment_id' => $this->id,
                     'appointment_daytime' => strtotime($datetime),
-                    'address_id' => $this->specialist->address_id
+                    'provider_id' => $this->provider_id,
+                    'address_id' => $this->specialist->address_id,
+                    'morning_num' => $this->morning_num,
+                    'afternoon_num' => $this->afternoon_num,
+                    'night_num' => $this->night_num,
                 ]);
             }
             $this->save(['ticket_status' => 1]);
@@ -42,27 +46,41 @@ class Appointment extends Model
         return $this->ticket_status > 0;
     }
 
-    //是否已存在预约订单
-    public function ifExitsAppointmentApplication()
-    {
-
-    }
 
     /**
-     * 按地点获取预约列表
-     * @return false|\PDOStatement|string|\think\Collection
+     * 生成号源,保证预约取号正常运行
      */
-    public static function listByAddress()
+    public static function createTicketFromAllAppointment()
     {
-        //未结束的预约都保证生成了号源
-        $all = (new Appointment())->where('end_time', '>', time())->select();
+        $all = (new Appointment())->where('end_time', '>', time())->where('ticket_status', 0)->select();
         /** @var  $item Appointment */
         foreach ($all as $item) {
             $item->createTicket();
         }
+    }
 
+    /**
+     * 获取可预约地点列表
+     * @return array
+     */
+    public static function availableAddressIds()
+    {
+        self::createTicketFromAllAppointment();
         $addressIds = (new AppointmentTicket())->where('appointment_daytime', '>=', strtotime(date('Y-m-d')))->distinct('true')->column('address_id');
-        return (new Address())->where('id', 'in', $addressIds)->select();
+        return $addressIds;
+    }
+
+    //按时间预约列表接口
+    public static function listByDayTime()
+    {
+        self::createTicketFromAllAppointment();
+
+    }
+
+    //是否已存在预约订单
+    public function ifExitsAppointmentApplication()
+    {
+
     }
 
     //关联专家

+ 6 - 0
app/common/model/AppointmentTicket.php

@@ -7,4 +7,10 @@ use think\Model;
 class AppointmentTicket extends Model
 {
     protected $autoWriteTimestamp = false;
+
+    //关联专家
+    public function specialist()
+    {
+        return $this->belongsTo('Specialist', 'provider_id');
+    }
 }

Plik diff jest za duży
+ 85 - 54
app/install/data/db.sql


+ 10 - 2
extend/time/DateHelper.php

@@ -90,20 +90,22 @@ class DateHelper
 
 
     /**
-     * 获取指定范围内的日期列表,不含首尾日期
+     * 获取指定范围内的日期列表
      *
      * @param $startTime string 起始日期
      * @param $endTime string 结束日期
+     * @param $inclued bool 是否包含首尾日期,默认不含首尾日期
      * @param $format string 返回的日期格式
      * @param $interval string 日期的间隔
      * @return array
      * @throws Exception
      */
-    public static function getDateList($startTime, $endTime, $format = 'Y-m-d', $interval = 'tomorrow')
+    public static function getDateList($startTime, $endTime, $inclued = false, $format = 'Y-m-d', $interval = 'tomorrow')
     {
         $starttime = strtotime($startTime);
         $endtime = strtotime($endTime);
         /**
+         * 日期的间隔写法如下:
          * +1 week 3 days 7 hours 5 seconds 获取一周后+3天+7小时+5秒的时间戳
          * -1 year 3 month 一年前-3个月
          * +1 month 获取下个月最后一天:如果是1月31号计算得到的却是3月3号,应该是2月最后一天才对,改为last day of +1 month即可
@@ -124,6 +126,9 @@ class DateHelper
          */
         $i = 0;
         $arr = [];
+        if ($inclued) {
+            $arr[] = date($format, $starttime);
+        }
         while (($starttime = strtotime($interval, $starttime)) < $endtime) {
             $arr[] = date($format, $starttime);
             if ($i++ > 500) {
@@ -131,6 +136,9 @@ class DateHelper
                 throw new Exception('循环超过限制');//防止死循环
             }
         }
+        if ($inclued) {
+            $arr[] = date($format, $endtime);
+        }
         return $arr;
     }
 

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików