Browse Source

Revert: refactor: - 放号设置重构

zhengzhibin 2 years ago
parent
commit
f9c5a1cdcb

+ 55 - 23
app/admin/controller/Appointment.php

@@ -4,6 +4,7 @@ namespace app\admin\controller;
 
 use app\admin\controller\base\Permissions;
 use app\common\model\Appointment as appointmentModel;
+use think\Db;
 use time\DateHelper;
 
 class Appointment extends Permissions
@@ -24,11 +25,11 @@ class Appointment extends Permissions
             if (isset($post['ids']) and !empty($post['ids'])) {
                 $where['id'] = ['in', $post['ids']];
             }
-            if (isset($post["daytime"]) and !empty($post["daytime"])) {
-                $timerang = explode(' - ', $post["daytime"]);
+            if (isset($post["start_time"]) and !empty($post["start_time"])) {
+                $timerang = explode(' - ', $post["start_time"]);
                 $min_time = strtotime($timerang[0]);
                 $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
-                $where["daytime"] = [['>=', $min_time], ['<=', $max_time]];
+                $where["start_time"] = [['>=', $min_time], ['<=', $max_time]];
             }
             if (isset($post["create_time"]) and !empty($post["create_time"])) {
                 $timerang = explode(' - ', $post["create_time"]);
@@ -39,7 +40,7 @@ class Appointment extends Permissions
 
             $model = $this->getModel();
             $count = $model->where($where)->count();
-            $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('daytime desc')->select();
+            $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
             foreach ($data as $key => $value) {
                 $value['specialist_name'] = $value->specialist->name;
                 $data[$key] = $value;
@@ -87,9 +88,7 @@ class Appointment extends Permissions
 
             //验证
             $validate = new \think\Validate([
-                ['title|服务名称', 'max:50'],
                 ['provider_id', 'require|number'],
-                ['phone|咨询电话', 'max:50'],
                 ['start_time', 'number', '排号日期格式不对'],
                 ['end_time', 'number', '排号日期格式不对'],
                 ['morning_num|上午放号个数', 'number'],
@@ -105,34 +104,56 @@ class Appointment extends Permissions
             if (!$validate->check($post)) {
                 $this->error('提交失败:' . $validate->getError());
             }
-        } else {
-            $this->assign('phone', (new \app\common\model\Specialist())->where('id', $pid)->value('phone'));
+
+            $weeks = $post['weeks']??[];
+            $weeks = array_keys($weeks);
+            $weeks = empty($weeks) ? "" : implode(',', $weeks);
         }
 
+        $model = $this->getModel();
         if ($id > 0) {
             //修改
+            $this->error('不允许修改');
         } else {
             //新增
             if ($this->request->isPost()) {
-                //判断是否时间跨度重叠
-                $exits = $this->getModel()->where(['provider_id' => $pid, 'daytime' => [['>=', $post['start_time']], ['<=', $post['end_time']]]])->count();
-                if ($exits > 0) {
-                    $this->error('该时间跨度内,已存在排号,请重新选择时间');
-                }
-                //生成号源
-                $daylist = DateHelper::dateTimeList(date('Y-m-d', $post['start_time']), date('Y-m-d', $post['end_time']), true);
-                if (count($daylist) == 2 && end($daylist) == current($daylist)) {
-                    array_pop($daylist);
-                }
-                $addressId = (new \app\common\model\Specialist())->where('id', $post['provider_id'])->value('address_id');
-                foreach ($daylist as $datetime) {
-                    $post['daytime'] = strtotime($datetime);
-                    $post['address_id'] = $addressId;
-                    if (false == $this->getModel()->allowField(true)->save($post)) {
+
+                if (empty($weeks)) {
+                    //判断是否时间跨度重叠
+                    $exits = (new \app\common\model\AppointmentTicket())->where(['provider_id' => $pid, 'appointment_daytime' => [['>=', $post['start_time']], ['<=', $post['end_time']]]])->count();
+                    if ($exits > 0) {
+                        $this->error('该时间跨度内,已存在排号,请重新选择时间');
+                    }
+                    if (false == $model->allowField(true)->save($post)) {
+                        $this->error('添加失败');
+                    } else {
+                        //生成号源
+                        $daylist = DateHelper::dateTimeList(date('Y-m-d', $post['start_time']), date('Y-m-d', $post['end_time']), true);
+                        if (count($daylist) == 2 && end($daylist) == current($daylist)) {
+                            array_pop($daylist);
+                        }
+                        $addressId = (new \app\common\model\Specialist())->where('id', $post['provider_id'])->value('address_id');
+                        foreach ($daylist as $datetime) {
+                            $post['appointment_id'] = $model->id;
+                            $post['appointment_daytime'] = strtotime($datetime);
+                            $post['address_id'] = $addressId;
+                            if (false == (new \app\common\model\AppointmentTicket())->allowField(true)->save($post)) {
+                                $this->error('添加失败');
+                            }
+                        }
+                    }
+
+                } else {
+                    $post['start_time'] = 0;
+                    $post['end_time'] = 0;
+                    $post['weeks'] = $weeks;
+                    if (false == $model->allowField(true)->save($post)) {
                         $this->error('添加失败');
                     }
                 }
+
                 $this->success('添加成功', 'index', ['pid' => $pid]);
+
             } else {
                 return $this->fetch();
             }
@@ -162,4 +183,15 @@ class Appointment extends Permissions
         }
     }
 
+    public function status()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            if (false == $this->getModel()->where('id', $post['id'])->update(['status' => $post['status']])) {
+                $this->error('设置失败');
+            } else {
+                $this->success('设置成功', 'index');
+            }
+        }
+    }
 }

+ 98 - 0
app/admin/controller/AppointmentTicket.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\controller\base\Permissions;
+use think\Db;
+
+class AppointmentTicket extends Permissions
+{
+    private function getModel()
+    {
+        return new \app\common\model\AppointmentTicket();
+    }
+
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->param();
+            $where = [
+            ];
+            if (isset($post["appointment_daytime"]) and !empty($post["appointment_daytime"])) {
+                $timerang = explode(' - ', $post["appointment_daytime"]);
+                $min_time = strtotime($timerang[0]);
+                $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
+                $where["appointment_daytime"] = [['>=', $min_time], ['<=', $max_time]];
+            }
+            if (isset($post["provider_id"]) and "" != $post["provider_id"]) {
+                $where["provider_id"] = $post["provider_id"];
+            }
+
+            $model = $this->getModel();
+            $count = $model->where($where)->count();
+            $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('appointment_daytime desc')->select();
+            foreach ($data as $key => $value) {
+                $value['specialist_name'] = $value->specialist->name;
+                $value['address_title'] = $value->address ? $value->address->title : '';
+                $value['morning_use'] = $value->morning_use;
+                $value['afternoon_use'] = $value->afternoon_use;
+                $value['night_use'] = $value->night_use;
+                $data[$key] = $value;
+            }
+            return array('code' => 0, 'count' => $count, 'data' => $data);
+        } else {
+            return $this->fetch();
+        }
+    }
+
+
+    public function delete()
+    {
+        if ($this->request->isAjax()) {
+            $id = $this->request->param('id', 0, 'intval');
+            $item = $this->getModel()->where('id', $id)->find();
+            if (!$item) {
+                $this->error('删除失败,id不存在');
+            }
+            if ($item->morning_use > 0 || $item->afternoon_use > 0 || $item->night_use > 0) {
+                $this->error("已有预约申请,不可删除");
+            }
+            if (false == $item->delete()) {
+                $this->error('删除失败');
+            } else {
+                $this->success('删除成功', 'index');
+            }
+        }
+    }
+
+    public function deletes()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->param();
+            $ids = $post['ids'];
+            $items = $this->getModel()->where('id', 'in', $ids)->select();
+            foreach ($items as $item) {
+                if ($item->morning_use > 0 || $item->afternoon_use > 0 || $item->night_use > 0) {
+                    $this->error("已有预约申请,不可删除");
+                }
+                if (false == $item->delete()) {
+                    $this->error('删除失败');
+                }
+            }
+            $this->success('删除成功', 'index');
+        }
+    }
+
+    public function status()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            if (false == $this->getModel()->where('id', $post['id'])->update(['status' => $post['status']])) {
+                $this->error('设置失败');
+            } else {
+                $this->success('设置成功', 'index');
+            }
+        }
+    }
+
+}

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

@@ -74,7 +74,7 @@ class Specialist extends Permissions
                 ['sex|性别', 'number'],
                 ['desc|简介', 'max:500'],
                 ['consultation_direction|咨询方向', 'max:500'],
-                ['address_id|地址', 'number'],
+                ['address_id|地址', 'require|number'],
                 ['phone|联系电话', 'max:50'],
             ]);
             if (!$validate->check($post)) {

+ 22 - 13
app/admin/view/appointment/index.html

@@ -42,17 +42,17 @@
         </div>
     </script>
 
-    <form class="layui-form serch" action="index" method="post">
-        <div class="layui-form-item" style="float: left;">
+    <!--<form class="layui-form serch" action="index" method="post">-->
+        <!--<div class="layui-form-item" style="float: left;">-->
 
-            <div class="layui-input-inline">
-                <input type="text" class="layui-input time_range" id="time_range_start_time" autocomplete="off"
-                       placeholder="排号日期" name="daytime">
-            </div>
+            <!--<div class="layui-input-inline">-->
+                <!--<input type="text" class="layui-input time_range" id="time_range_start_time" autocomplete="off"-->
+                       <!--placeholder="排号日期" name="start_time">-->
+            <!--</div>-->
 
-            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
-        </div>
-    </form>
+            <!--<button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>-->
+        <!--</div>-->
+    <!--</form>-->
 
     <script type="text/html" id="barDemo">
         <div class="layui-btn-group">
@@ -82,17 +82,24 @@
                 , page: true //开启分页
                 , cols: [[ //表头
                     {type: 'checkbox'},
-                    {field: "daytime", title: '排号日期'},
+                    {field: "start_time", title: '排号日期',width: 200,templet:function (row) {
+                        if(row.weeks!=""){
+                            return "每周"+row.weeks;
+                        }
+                        return row.start_time + ' ~ ' + row.end_time;
+                    }},
                     {field: "specialist_name", title: '专家名字'},
                     {field: "morning_num", title: '上午放号个数'},
-                    {field: "morning_use", title: '上午报名个数'},
                     {field: "afternoon_num", title: '下午放号个数'},
-                    {field: "afternoon_use", title: '下午报名个数'},
                     {field: "night_num", title: '晚上放号个数'},
-                    {field: "night_use", title: '晚上报名个数'},
+                    {
+                        field: 'status', title: '状态', align: 'center', width: 60, templet: function (row) {
+                        return '<a href="javascript:;" style="font-size:18px;" class="status" data-id="' + row.id + '" data-val="' + row.status + '">' + (row.status == 1 ? '<i class="fa fa-toggle-on"></i>' : '<i class="fa fa-toggle-off"></i>') + '</a>';
+                    }},
                     {field: 'action', title: '操作', toolbar: '#barDemo', fixed: 'right'}
                 ]],
                 done: function () {
+                    switchStatus('.status',"{:url('status')}");
                 }
             });
 
@@ -122,7 +129,9 @@
             });
 
             table.on('tool(table)', function (obj) {
+
                 if (obj.event == 'edit') {
+                    location.href = "{:url('publish',['pid'=>$Request.param.pid])}?id=" + obj.data.id;
                 }
                 else if (obj.event == 'del') {
                     layer.confirm('确定要删除?', function (index) {

+ 34 - 7
app/admin/view/appointment/publish.html

@@ -40,19 +40,46 @@
     </div>
 
 
+
     <div style="margin-top: 20px;"></div>
     <form class="layui-form" id="publish" method="post">
 
-        <!-- 时间 -->
-        <div class="layui-form-item">
-            <label class="layui-form-label">排号日期跨度</label>
-            <div class="layui-input-inline" style="width:600px;">
-                <input name="start_time" id="start_time" autocomplete="off" placeholder="开始日期 - 结束日期" class="layui-input"
-                       type="text">
+        <div class="layui-tab">
+            <ul class="layui-tab-title">
+                <li class="layui-this">按时间跨度排号</li>
+                <li>按工作日排号</li>
+            </ul>
+            <div class="layui-tab-content" style="padding: 0;padding-top: 10px;">
+                <div class="layui-tab-item layui-show">
+                    <!-- 时间 -->
+                    <div class="layui-form-item">
+                        <label class="layui-form-label">日期跨度</label>
+                        <div class="layui-input-inline" style="width:600px;">
+                            <input name="start_time" id="start_time" autocomplete="off" placeholder="开始日期 - 结束日期" class="layui-input"
+                                   type="text">
+                        </div>
+                    </div>
+                </div>
+                <div class="layui-tab-item">
+                    <div class="layui-form-item">
+                        <label class="layui-form-label">工作日</label>
+                        <div class="layui-input-block">
+                            <input type="checkbox" name="weeks[1]" title="周一">
+                            <input type="checkbox" name="weeks[2]" title="周二">
+                            <input type="checkbox" name="weeks[3]" title="周三">
+                            <input type="checkbox" name="weeks[4]" title="周四">
+                            <input type="checkbox" name="weeks[5]" title="周五">
+                            <input type="checkbox" name="weeks[6]" title="周六">
+                            <input type="checkbox" name="weeks[7]" title="周日">
+                        </div>
+                    </div>
+                </div>
             </div>
         </div>
 
 
+
+
         <!-- 数字 -->
         <div class="layui-form-item">
             <label class="layui-form-label">上午放号个数</label>
@@ -118,7 +145,7 @@
     </form>
 
     <script>
-        layui.use(['layer', 'form', 'laydate'], function () {
+        layui.use(['layer', 'form', 'laydate','element'], function () {
             var layer = layui.layer,
                 $ = layui.jquery,
                 form = layui.form;

+ 177 - 0
app/admin/view/appointment_ticket/index.html

@@ -0,0 +1,177 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>layui</title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    <link rel="stylesheet" href="/static/public/layui/css/layui.css" media="all">
+    <link rel="stylesheet" href="/static/public/font-awesome/css/font-awesome.min.css" media="all"/>
+    <link rel="stylesheet" href="/static/admin/css/admin.css" media="all">
+    <style type="text/css">
+        /* tooltip */
+        #tooltip {
+            position: absolute;
+            border: 1px solid #ccc;
+            background: #333;
+            padding: 2px;
+            display: none;
+            color: #fff;
+        }
+
+        .tooltip > img {
+            width: 20px;
+            height: 20px;
+        }
+    </style>
+</head>
+<body style="padding:10px;">
+<div class="tplay-body-div">
+
+
+    <script type="text/html" id="toolbarDemo">
+        <div class="layui-btn-container">
+            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
+        </div>
+    </script>
+
+    <form class="layui-form serch" action="index" method="post">
+        <div class="layui-form-item" style="float: left;">
+
+            <div class="layui-input-inline">
+                <input type="text" class="layui-input time_range" id="time_range_appointment_daytime" autocomplete="off"
+                       placeholder="排号日期" name="appointment_daytime">
+            </div>
+            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
+        </div>
+    </form>
+
+    <script type="text/html" id="barDemo">
+        <div class="layui-btn-group">
+            <button class="layui-btn layui-btn-xs delete" lay-event="del"><i class="layui-icon"
+                                                                             style="margin-right: 0;"></i></button>
+        </div>
+    </script>
+
+    <table class="layui-table" id="table" lay-filter="table"></table>
+    {include file="public/foot"}
+
+    <script type="text/javascript">
+        layui.use(['table', 'layer', 'form', 'laydate'], function () {
+            var table = layui.table,
+                form = layui.form,
+                layer = layui.layer;
+            var laydate = layui.laydate;
+            //第一个实例
+            table.render({
+                id: 'table'
+                , elem: '#table'
+                , size: 'sm' //小尺寸的表格
+                , toolbar: '#toolbarDemo'
+                , limit: 15
+                , limits: [15, 20, 30, 40, 50, 100]
+                , url: "{:url('index',['pid'=>$Request.param.pid])}" //数据接口
+                , page: true //开启分页
+                , cols: [[ //表头
+                    {type: 'checkbox'},
+                    {field: 'id', title: 'ID', width: 60},
+                    {field: "appointment_daytime", title: '排号日期'},
+                    {field: "specialist_name", title: '专家名字'},
+                    {field: "address_title", title: '地址'},
+                    {field: "morning_use", title: '上午报名个数'},
+                    {field: "afternoon_use", title: '中午报名个数'},
+                    {field: "night_use", title: '晚上报名个数'},
+                    {
+                        field: 'status', title: '状态', align: 'center', width: 60, templet: function (row) {
+                        return '<a href="javascript:;" style="font-size:18px;" class="status" data-id="' + row.id + '" data-val="' + row.status + '">' + (row.status == 1 ? '<i class="fa fa-toggle-on"></i>' : '<i class="fa fa-toggle-off"></i>') + '</a>';
+                    }},
+                    {field: 'action', title: '操作', toolbar: '#barDemo', fixed: 'right'}
+                ]],
+                done: function () {
+                    switchStatus('.status',"{:url('status')}");
+                }
+            });
+
+            laydate.render({
+                elem: '#time_range_appointment_daytime'
+                , type: 'datetime'
+                , range: true
+                , theme: 'molv'
+                , calendar: true
+                , done: function (value, date, endDate) {
+                    if (endDate.hours == 0 && endDate.minutes == 0 && endDate.seconds == 0) {
+                        setTimeout(function () {
+                            $('#time_range_appointment_daytime').val(value.replace(/00:00:00$/, '23:59:59'))
+                        }, 100)
+                    }
+                }
+            });
+
+            form.on('submit(serch)', function (data) {
+                table.reload('table', {
+                    where: data.field
+                    , page: {
+                        curr: 1 //重新从第 1 页开始
+                    }
+                });
+                return false;
+            });
+
+            table.on('tool(table)', function (obj) {
+                if (obj.event == 'edit') {
+                    location.href = "{:url('publish',['pid'=>$Request.param.pid])}?id=" + obj.data.id;
+                }
+                else if (obj.event == 'del') {
+                    layer.confirm('确定要删除?', function (index) {
+                        $.ajax({
+                            url: "{:url('delete')}",
+                            dataType: 'json',
+                            data: {id: obj.data.id},
+                            success: function (res) {
+                                layer.msg(res.msg);
+                                if (res.code == 1) {
+                                    table.reload('table');
+                                }
+                            }
+                        })
+                    })
+                }
+            });
+            //监听事件
+            table.on('toolbar(table)', function (obj) {
+                if (obj.event == 'deletes') {
+                    var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
+                    var data = checkStatus.data;
+                    if (data.length > 0) {
+                        var ids = [];//数组
+                        data.forEach(function (item, key) {
+                            ids[key] = item.id;
+                        })
+                        layer.confirm('是否删除?', function (index, layero) {
+                            $.ajax({
+                                url: "{:url('deletes')}",
+                                dataType: 'json',
+                                data: {"ids": ids},
+                                type: 'post',
+                                success: function (res) {
+                                    layer.msg(res.msg);
+                                    if (res.code == 1) {
+                                        table.reload('table');
+                                    }
+                                }
+                            })
+                            layer.close(index)
+                        });
+                    } else {
+                        layer.msg('请先勾选需要操作的记录');
+                    }
+                }
+            });
+        });
+    </script>
+
+
+</div>
+</body>
+</html>

+ 1 - 1
app/admin/view/specialist/publish.html

@@ -83,7 +83,7 @@
         <div class="layui-form-item">
             <label class="layui-form-label">地址</label>
             <div class="layui-input-inline" style="max-width:300px;">
-                <select name="address_id" lay-filter="" lay-search="" lay-verify="">
+                <select name="address_id" lay-filter="" lay-search="" lay-verify="required">
                     <option value="">请选择</option>
                     {volist name="$addresslist" id="vo"}
                     <option value="{$vo.id}"

+ 10 - 8
app/api/controller/Appointment.php

@@ -6,6 +6,7 @@ use app\api\controller\base\Base;
 use app\common\model\Address;
 use app\common\model\Appointment as appointmentModel;
 use app\common\model\AppointmentApplication;
+use app\common\model\AppointmentTicket;
 use time\DateHelper;
 
 class Appointment extends Base
@@ -48,7 +49,7 @@ class Appointment extends Base
         }
 
         $where = [];
-        $addressIds = (new appointmentModel())->where('daytime', '>=', strtotime(date('Y-m-d')))->distinct(true)->column('address_id');
+        $addressIds = (new AppointmentTicket())->where('appointment_daytime', '>=', strtotime(date('Y-m-d')))->distinct(true)->column('address_id');
         $where['id'] = ['in', $addressIds];
         $pagenum = $this->request->param('pagenum', 20, 'intval');
         $datalist = (new Address())->where($where)->paginate($pagenum, true);
@@ -78,18 +79,19 @@ class Appointment extends Base
         $address_id = $this->request->param('address_id');
         $daytime = $this->request->param('daytime', date('Y-m-d'));
 
-        $ticketModel = new appointmentModel();
-        $tickets = $ticketModel->where('address_id', $address_id)->where('daytime', strtotime($daytime))->select();
+        $ticketModel = new AppointmentTicket();
+        $tickets = $ticketModel->where('address_id', $address_id)->where('appointment_daytime', strtotime($daytime))->select();
 
         foreach ($tickets as $k => $item) {
+            $appoint = $item->appointment;
             //专家信息
             $item->specialist;
             $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
             //拆分预约时段
             $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $item->id)->column('appointment_time');
-            $item['morning_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($item->morning_start_time, $item->morning_end_time, $item->morning_num), $ticketPeriods);
-            $item['afternoon_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($item->afternoon_start_time, $item->afternoon_end_time, $item->afternoon_num), $ticketPeriods);
-            $item['night_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($item->night_start_time, $item->night_end_time, $item->night_num), $ticketPeriods);
+            $item['morning_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($appoint->morning_start_time, $appoint->morning_end_time, $appoint->morning_num), $ticketPeriods);
+            $item['afternoon_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($appoint->afternoon_start_time, $appoint->afternoon_end_time, $appoint->afternoon_num), $ticketPeriods);
+            $item['night_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($appoint->night_start_time, $appoint->night_end_time, $appoint->night_num), $ticketPeriods);
             //剩余预约号码
             $item['morning_remaining'] = count($item['morning_time_period']);
             $item['afternoon_remaining'] = count($item['afternoon_time_period']);
@@ -132,7 +134,7 @@ class Appointment extends Base
     //按时间获取地址列表
     public function addressListByDayTime()
     {
-        $ticketModel = new appointmentModel();
+        $ticketModel = new AppointmentTicket();
         $post = $this->request->param();
         $validate = new \think\Validate([
             ['daytime', 'date|dateFormat:Y-m-d'],
@@ -144,7 +146,7 @@ class Appointment extends Base
         }
 
         $daytime = $this->request->param('daytime', date('Y-m-d'));
-        $addressIds = $ticketModel->where('daytime', strtotime($daytime))->distinct(true)->column('address_id');
+        $addressIds = $ticketModel->where('appointment_daytime', strtotime($daytime))->distinct(true)->column('address_id');
 
         $where = [];
         $where['id'] = ['in', $addressIds];

+ 23 - 9
app/api/controller/User.php

@@ -11,7 +11,7 @@ namespace app\api\controller;
 
 use app\api\controller\base\Permissions;
 use app\common\model\AppointmentApplication;
-use app\common\model\Appointment;
+use app\common\model\AppointmentTicket;
 use app\common\model\Feedback;
 use app\common\model\Webconfig;
 use time\DateHelper;
@@ -44,12 +44,13 @@ class User extends Permissions
             ['sex|性别', 'number|in:1,2'],
             ['phone|电话', 'require|max:50'],
             ['id_card|身份证', 'max:50'],
-            ['childs_num|子女数量', 'number|in:1,2,3'],
             ['problem_desc|问题描述', 'max:200'],
             ['requirement_desc|需求描述', 'max:200'],
             ['appointment_ticket_id', 'require|number'],
             ['appointment_period', 'require|number|in:1,2,3'],
             ['appointment_time|预约时间段', 'require|dateFormat:H:i:s - H:i:s'],
+            ['childs_num|子女数量', 'number|in:1,2,3'],
+            ['childs_num_str|子女数量', 'max:255'],
             ['city|来自城市', 'max:50'],
             ['job|职业', 'max:50'],
             ['education_level|受教育程度', 'number|in:0,1,2,3,4'],
@@ -67,7 +68,6 @@ class User extends Permissions
             $this->json_error('提交失败:' . $validate->getError());
         }
 
-
         $model = new AppointmentApplication();
 
         //爽约多少次后,多少天内不能再预约
@@ -86,18 +86,19 @@ class User extends Permissions
         }
 
         //检测预约号源是否可预约
-        $ticket = Appointment::get($post['appointment_ticket_id']);
+        $ticket = AppointmentTicket::get($post['appointment_ticket_id']);
         if (!$ticket) {
             $this->json_error("获取预约号失败");
         }
 
+        $appoint = $ticket->appointment;
         //判断该时间段,存在于时间列表中才行
         if ($post['appointment_period'] == 1) {
-            $timePeriods = DateHelper::splitTimePeriod($ticket->morning_start_time, $ticket->morning_end_time, $ticket->morning_num);
+            $timePeriods = DateHelper::splitTimePeriod($appoint->morning_start_time, $appoint->morning_end_time, $appoint->morning_num);
         } elseif ($post['appointment_period'] == 2) {
-            $timePeriods = DateHelper::splitTimePeriod($ticket->afternoon_start_time, $ticket->afternoon_end_time, $ticket->afternoon_num);
+            $timePeriods = DateHelper::splitTimePeriod($appoint->afternoon_start_time, $appoint->afternoon_end_time, $appoint->afternoon_num);
         } else {
-            $timePeriods = DateHelper::splitTimePeriod($ticket->night_start_time, $ticket->night_end_time, $ticket->night_num);
+            $timePeriods = DateHelper::splitTimePeriod($appoint->night_start_time, $appoint->night_end_time, $appoint->night_num);
         }
         if (!in_array($post['appointment_time'], $timePeriods)) {
             $this->json_error("该时间段不存在,请重新选择时间");
@@ -107,7 +108,7 @@ class User extends Permissions
         $timerang = explode(' - ', $post['appointment_time']);
         $period_end = $timerang[1];
 
-        if (time() > strtotime($ticket->daytime . ' ' . $period_end)) {
+        if (time() > strtotime($ticket->appointment_daytime . ' ' . $period_end)) {
             $this->json_error("该时段已经过期,请重新选择时间");
         }
 
@@ -136,7 +137,20 @@ class User extends Permissions
             'appointment_ticket_id' => $post['appointment_ticket_id'],
             'appointment_time' => $post['appointment_time'],
             'appointment_period' => $post['appointment_period'],
-            'status' => AppointmentApplication::STATUS_NOT_SIGN
+            'status' => AppointmentApplication::STATUS_NOT_SIGN,
+            'city' => $post['city']??'',
+            'job' => $post['job']??'',
+            'education_level' => $post['education_level']??0,
+            'home_address' => $post['home_address']??'',
+            'marriage' => $post['marriage']??0,
+            'problem_type' => $post['problem_type']??0,
+            'childs_num_str' => $post['childs_num_str']??'',
+            'childs_age1' => $post['childs_age1']??0,
+            'childs_age2' => $post['childs_age2']??0,
+            'childs_age3' => $post['childs_age3']??0,
+            'childs_sex1' => $post['childs_sex1']??0,
+            'childs_sex2' => $post['childs_sex2']??0,
+            'childs_sex3' => $post['childs_sex3']??0,
         ];
         if (false === $model->allowField(true)->save($data)) {
             $this->json_error("预约入库失败");

+ 48 - 58
app/api/controller/接口文档.md

@@ -336,65 +336,49 @@
 |  daytime     |  日期,默认今天     |  dateFormat:y-m-d   |
 
 响应数据:(json格式)
+
 ```json
 {
     "code": 1,
     "err_code": 0,
+    "msg": "查询成功",
+    "time": "1682911870",
     "data": [
         {
-            "id": 3,               //号源ID
-            "appointment_id": 1,
-            "appointment_daytime": 1682265600,         //排号日期
-            "appointment_daytime_text": "2023-04-24",   //排号日期
-            "provider_id": 3,
+            "id": 19,               //号源ID
+            "appointment_id": 5,
+            "appointment_daytime": "2023-05-01",  //排号日期
+            "provider_id": 18,
             "address_id": 1,
-            "morning_use": 1,              // 上午已被领取(预约号个数)
-            "afternoon_use": 11,           // 下午已被领取
-            "night_use": 0,               // 晚上已被领取
-            "price": 12,                  //服务价格
-            "morning_remaining": 29,      // 上午剩余(预约号个数)
-            "afternoon_remaining": 10,    // 下午剩余
-            "night_remaining": 10,        // 晚上剩余
-            "morning_num": 30,          // 上午放号个数
-            "morning_start_time": "08:00:00",
-            "morning_end_time": "12:00:00",
-            "afternoon_num": 1,          // 下午放号个数
-            "afternoon_start_time": "14:00:00",
-            "afternoon_end_time": "18:00:00",
-            "night_num": 10,             //晚上放号个数
-            "night_start_time": "20:00:00",
-            "night_end_time": "23:59:59",
+            "morning_remaining": 3,   // 上午剩余(预约号个数)
+            "afternoon_remaining": 20,  // 下午剩余
+            "night_remaining": 11,     // 晚上剩余
             "status": 1,
-            "create_time": "2023-04-22 16:24:02",
             "morning_time_period": [
                 {
-                    "period": "08:00:00 - 08:08:00",   // 上午可预约时间段
-                    "status": 0                        // 状态 , 0 可预约 , 1 已被预约
+                    "period": "11:24:00 - 11:36:00",  // 上午可预约时间段
+                    "status": 0                       // 状态 , 0 可预约 , 1 已被预约
                 },
                 {
-                    "period": "08:08:00 - 08:16:00",
+                    "period": "11:36:00 - 11:48:00",
                     "status": 0
                 },
                 {
-                    "period": "08:16:00 - 08:24:00",
+                    "period": "11:48:00 - 12:00:00",
                     "status": 0
-                },
+                }
+            ],
+            "afternoon_time_period": [             // 下午可预约时间段
                 {
-                    "period": "08:24:00 - 08:32:00",
+                    "period": "14:00:00 - 14:12:00",
                     "status": 0
                 },
                 {
-                    "period": "08:32:00 - 08:40:00",
+                    "period": "14:12:00 - 14:24:00",
                     "status": 0
                 }
             ],
-            "afternoon_time_period": [                 // 下午可预约时间段
-                {
-                    "period": "14:00:00 - 18:00:00",
-                    "status": 0
-                }
-            ],
-            "night_time_period": [                     // 晚上可预约时间段
+            "night_time_period": [              // 晚上可预约时间段
                 {
                     "period": "20:00:00 - 20:23:59",
                     "status": 0
@@ -402,38 +386,43 @@
                 {
                     "period": "20:23:59 - 20:47:58",
                     "status": 0
-                },
-                {
-                    "period": "20:47:58 - 21:11:57",
-                    "status": 0
                 }
             ],
-            "specialist": {        //专家信息
-                "id": 3,
-                "name": "王医生",
-                "title": "妇科大夫",
+            "appointment": {     //放号设置信息
+                "id": 5,
+                "provider_id": 18,
+                "price": 1,          //服务价格
+                "start_time": "2023-05-01", //按时间跨度排号
+                "end_time": "2023-05-09",   //按时间跨度排号
+                "weeks": 0,  //按工作日排号
+                "morning_num": 20,    // 上午放号个数
+                "morning_start_time": "08:00:00",
+                "morning_end_time": "12:00:00",
+                "afternoon_num": 20,    // 下午放号个数
+                "afternoon_start_time": "14:00:00",
+                "afternoon_end_time": "18:00:00",
+                "night_num": 10,        //晚上放号个数
+                "night_start_time": "20:00:00",
+                "night_end_time": "23:59:59",
+                "status": 1,
+                "create_time": "2023-05-01 11:25:41"
+            },
+            "specialist": {   //专家信息
+                "id": 18,
+                "name": "庄奕漩",
+                "title": "社会",
                 "head_pic": "",
                 "sex": 0,
-                "desc": "妇科大夫",
-                "consultation_direction": "妇科大夫",
+                "desc": "",
+                "consultation_direction": "",
                 "address_id": 1,
                 "phone": ""
             }
-        },
-        {
-            //其他号源信息
-        },
-        {
-            //其他号源信息
         }
-    ],
-    "time": "1682318054",
-    "msg": "查询成功"
+    ]
 }
 ```
 
-
-
 # 按时间获取地址列表
 
 接口地址:/api/appointment/addressListByDayTime
@@ -493,19 +482,20 @@
 | appointment_ticket_id   | 号源id |  require, int |
 | appointment_period   | 时段:1上午,2下午,3晚上 |  require, int |
 | appointment_time   | 预约时间段 |  require, dateFormat: H:i:s - H:i:s |
-| childs_num   | 子女数量:0无,1一孩、2二孩、3三孩 |  int, in:1,2,3 |
 | city | 来自城市 | max:50 |
 | job | 职业 |  max:50 |
 | education_level | 受教育程度:1小学,2初中,3高中,4大学及以上 | number, in:0,1,2,3,4 |
 | home_address|家庭住址 | max:255 |
 | marriage| 婚姻情况:0未婚,1己婚,2离异 | number, in:0,1,2 |
 | problem_type| 咨询问题类别:0其他,1自我意识,2人际关系,3亲子关系,4情绪问题,5学习问题 | number, in:0,1,2,3,4,5 |
+| childs_num   | 子女数量:0无,1一孩、2二孩、3三孩 |  int, in:1,2,3 |
 | childs_age1| 一孩年龄 | number |
 | childs_age2| 二孩年龄 | number |
 | childs_age3| 三孩年龄 | number |
 | childs_sex1 | 一孩性别 | number |
 | childs_sex2 | 二孩性别 | number |
 | childs_sex3 | 三孩性别 | number |
+| childs_num_str   | 子女数量,年龄,性别 ,字符串格式 |  max:255 |
 
 
 响应数据:

+ 6 - 2
app/common/model/Appointment.php

@@ -10,8 +10,12 @@ class Appointment extends Model
 {
     protected $updateTime = false;
 
-    //daytime
-    public function getDaytimeAttr($value, $data)
+    public function getStartTimeAttr($value, $data)
+    {
+        return $value ? date('Y-m-d', $value) : '';
+    }
+
+    public function getEndTimeAttr($value, $data)
     {
         return $value ? date('Y-m-d', $value) : '';
     }

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

@@ -8,6 +8,10 @@ class AppointmentApplication extends Model
 {
     protected $updateTime = false;
 
+    const APPOINTMENT_PERIOD_MORNING = 1;
+    const APPOINTMENT_PERIOD_AFTERNOON = 2;
+    const APPOINTMENT_PERIOD_NIGHT = 3;
+
     const STATUS_NOT_SIGN = 0;
     const STATUS_SIGN = 1;
     const STATUS_NOT_COME = 2;
@@ -61,6 +65,8 @@ class AppointmentApplication extends Model
     //childs_text
     public function getChildsTextAttr($value, $data)
     {
+        return $data['childs_num_str'];
+
         if ($data['childs_num'] == 0) {
             return 0;
         } elseif ($data['childs_num'] == 1) {

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

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class AppointmentTicket extends Model
+{
+    protected $autoWriteTimestamp = false;
+
+    public function getAppointmentDaytimeAttr($value, $data)
+    {
+        return $value ? date('Y-m-d', $value) : '';
+    }
+
+    //morning_use
+    public function getMorningUseAttr($value, $data)
+    {
+        return (new AppointmentApplication())->where([
+            'appointment_period' => AppointmentApplication::APPOINTMENT_PERIOD_MORNING,
+            'appointment_ticket_id' => $this->id,
+        ])->count();
+    }
+
+    //afternoon_use
+    public function getAfternoonUseAttr($value, $data)
+    {
+        return (new AppointmentApplication())->where([
+            'appointment_period' => AppointmentApplication::APPOINTMENT_PERIOD_AFTERNOON,
+            'appointment_ticket_id' => $this->id,
+        ])->count();
+    }
+
+    //night_use
+    public function getNightUseAttr($value, $data)
+    {
+        return (new AppointmentApplication())->where([
+            'appointment_period' => AppointmentApplication::APPOINTMENT_PERIOD_NIGHT,
+            'appointment_ticket_id' => $this->id,
+        ])->count();
+    }
+
+    //关联专家
+    public function specialist()
+    {
+        return $this->belongsTo('Specialist', 'provider_id');
+    }
+
+    //关联放号配置
+    public function appointment()
+    {
+        return $this->belongsTo('Appointment');
+    }
+
+    //关联地址
+    public function address()
+    {
+        return $this->belongsTo('Address');
+    }
+}

+ 29 - 1
app/install/data/db.sql

@@ -877,6 +877,8 @@ ALTER TABLE `tplay_specialist`
 	CHANGE COLUMN `address_id` `address_id` INT(11) NOT NULL DEFAULT '0' COMMENT '地址' AFTER `consultation_direction`;
 
 
+
+
 ALTER TABLE `tplay_appointment_application`
 	ADD COLUMN `city` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '来自城市' AFTER `id_card`,
 	ADD COLUMN `job` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '职业' AFTER `city`,
@@ -893,4 +895,30 @@ ALTER TABLE `tplay_appointment_application`
 	ADD COLUMN `childs_age3` TINYINT(4) NOT NULL DEFAULT '0' AFTER `childs_age2`,
 	ADD COLUMN `childs_sex1` TINYINT(4) NOT NULL DEFAULT '0' AFTER `childs_age3`,
 	ADD COLUMN `childs_sex2` TINYINT(4) NOT NULL DEFAULT '0' AFTER `childs_sex1`,
-	ADD COLUMN `childs_sex3` TINYINT(4) NOT NULL DEFAULT '0' AFTER `childs_sex2`;
+	ADD COLUMN `childs_sex3` TINYINT(4) NOT NULL DEFAULT '0' AFTER `childs_sex2`;
+
+ALTER TABLE `tplay_appointment`
+	ALTER `daytime` DROP DEFAULT;
+ALTER TABLE `tplay_appointment`
+	CHANGE COLUMN `daytime` `start_time` INT(11) NOT NULL COMMENT '排号日期' AFTER `price`,
+	ADD COLUMN `end_time` INT(11) NOT NULL COMMENT '排号日期' AFTER `start_time`,
+	DROP COLUMN `address_id`,
+	DROP COLUMN `morning_use`,
+	DROP COLUMN `afternoon_use`,
+	DROP COLUMN `night_use`;
+
+ALTER TABLE `tplay_appointment`
+	ADD COLUMN `weeks` INT(11) NOT NULL COMMENT '排号工作日' AFTER `end_time`;
+
+ALTER TABLE `tplay_appointment_ticket`
+	ADD COLUMN `status` TINYINT NOT NULL DEFAULT '1' COMMENT '状态:1启用0停用' AFTER `night_use`;
+
+ALTER TABLE `tplay_appointment_application`
+	ADD COLUMN `childs_num_str` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '子女数量,字符串格式' AFTER `childs_num`;
+
+ALTER TABLE `tplay_appointment_ticket`
+	DROP COLUMN `morning_use`,
+	DROP COLUMN `afternoon_use`,
+	DROP COLUMN `night_use`;
+
+