Prechádzať zdrojové kódy

Merge branch 'master' of git.code.tencent.com:FECAS/server

王亚超 1 rok pred
rodič
commit
6806b7dbee

+ 4 - 4
app/admin/view/public/foot.html

@@ -11,11 +11,11 @@
             $ = layui.jquery,
             layer = layui.layer;
         //将message设置为全局以便子页面调用
-        message = layui.message;
+//        message = layui.message;
         //主入口
-        app.set({
-            type: 'iframe'
-        }).init();
+//        app.set({
+//            type: 'iframe'
+//        }).init();
     });
 </script>
 <script type="text/javascript">

+ 22 - 16
app/admin/view/webconfig/appointment_config.html

@@ -20,23 +20,29 @@
     <form class="layui-form" id="admin">
 
         <div class="layui-form-item">
-            <div class="layui-inline">
-                <label class="layui-form-label"></label>
-                <div class="layui-input-inline" style="width: 60px;">
-                    <input type="number" name="break_the_promise_day_range" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.break_the_promise_day_range}">
-                </div>
-                <div class="layui-form-mid">天内</div>
-                <div class="layui-form-mid">用户爽约</div>
-                <div class="layui-input-inline" style="width: 60px;">
-                    <input type="number" name="break_the_promise_times" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.break_the_promise_times}">
-                </div>
-                <div class="layui-form-mid">次</div>
-                <div class="layui-form-mid">则限制</div>
-                <div class="layui-input-inline" style="width: 60px;">
-                    <input type="number" name="stop_appointment_day" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.stop_appointment_day}">
-                </div>
-                <div class="layui-form-mid">天无法再预约</div>
+            <label class="layui-form-label">爽约设置</label>
+            <div class="layui-input-inline" style="width: 60px;">
+                <input type="number" name="break_the_promise_day_range" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.break_the_promise_day_range}">
             </div>
+            <div class="layui-form-mid">天内</div>
+            <div class="layui-form-mid">用户爽约</div>
+            <div class="layui-input-inline" style="width: 60px;">
+                <input type="number" name="break_the_promise_times" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.break_the_promise_times}">
+            </div>
+            <div class="layui-form-mid">次</div>
+            <div class="layui-form-mid">则限制</div>
+            <div class="layui-input-inline" style="width: 60px;">
+                <input type="number" name="stop_appointment_day" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.stop_appointment_day}">
+            </div>
+            <div class="layui-form-mid">天无法再预约</div>
+        </div>
+
+        <div class="layui-form-item">
+            <label class="layui-form-label">取消设置</label>
+            <div class="layui-input-inline" style="width: 60px;">
+                <input type="number" name="cancel_appointment_time" placeholder="0" autocomplete="off" class="layui-input" value="{$web_config.cancel_appointment_time}">
+            </div>
+            <div class="layui-form-mid">小时内可取消预约</div>
         </div>
 
         <div class="layui-form-item">

+ 1 - 1
app/admin/view/webconfig/tab.html

@@ -1,7 +1,7 @@
 <div class="layui-tab">
     <ul class="layui-tab-title">
         <li {eq name="$Request.baseUrl" value=":url('admin/webconfig/index')"}class="layui-this"{/eq}><a href="{:url('admin/webconfig/index')}" class="a_menu">系统设置</a></li>
-        <li {eq name="$Request.baseUrl" value=":url('admin/webconfig/appointmentConfig')"}class="layui-this"{/eq}><a href="{:url('admin/webconfig/appointmentConfig')}" class="a_menu">爽约限制</a></li>
+        <li {eq name="$Request.baseUrl" value=":url('admin/webconfig/appointmentConfig')"}class="layui-this"{/eq}><a href="{:url('admin/webconfig/appointmentConfig')}" class="a_menu">预约设置</a></li>
         <li {eq name="$Request.baseUrl" value=":url('admin/webconfig/noticeConfig')"}class="layui-this"{/eq}><a href="{:url('admin/webconfig/noticeConfig')}" class="a_menu">来访须知</a></li>
         <!--扩展配置-->
         {foreach $tabs as $tab}

+ 43 - 39
app/api/controller/Appointment.php

@@ -12,6 +12,7 @@ use time\DateHelper;
 
 class Appointment extends Base
 {
+
     //获取地址列表
     public function addressList()
     {
@@ -37,7 +38,47 @@ class Appointment extends Base
     }
 
 
-    //按地址id获取号源信息
+    //按时间获取地址列表
+    public function addressListByDayTime()
+    {
+        $ticketModel = new AppointmentTicket();
+        $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'));
+
+        try {
+            //生成工作日号源
+            \app\common\model\Appointment::createWeekTicketAll($daytime);
+        } catch (Exception $e) {
+            $this->json_error($e->getMessage());
+        }
+
+        $addressIds = $ticketModel->where('appointment_daytime', strtotime($daytime))->distinct(true)->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("没有数据");
+        }
+        foreach ($datalist as $key => $item) {
+            $item['thumb_url'] = geturl($item->thumb, '', true);
+            $datalist[$key] = $item;
+        }
+        $this->json_success("查询成功", $datalist);
+    }
+
+
+    //获取号源列表
     public function getTicketByAddressId()
     {
         $post = $this->request->param();
@@ -68,7 +109,7 @@ class Appointment extends Base
             $item->specialist;
             $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
             //拆分预约时段
-            $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $item->id)->column('appointment_time');
+            $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $item->id)->where('finish_time', 0)->column('appointment_time');
             $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);
@@ -111,42 +152,5 @@ class Appointment extends Base
         return $arr;
     }
 
-    //按时间获取地址列表
-    public function addressListByDayTime()
-    {
-        $ticketModel = new AppointmentTicket();
-        $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'));
 
-        try {
-            //生成工作日号源
-            \app\common\model\Appointment::createWeekTicketAll($daytime);
-        } catch (Exception $e) {
-            $this->json_error($e->getMessage());
-        }
-
-        $addressIds = $ticketModel->where('appointment_daytime', strtotime($daytime))->distinct(true)->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("没有数据");
-        }
-        foreach ($datalist as $key => $item) {
-            $item['thumb_url'] = geturl($item->thumb, '', true);
-            $datalist[$key] = $item;
-        }
-        $this->json_success("查询成功", $datalist);
-    }
 }

+ 54 - 20
app/api/controller/User.php

@@ -18,7 +18,7 @@ use time\DateHelper;
 
 class User extends Permissions
 {
-    //个人资料接口
+    //个人资料
     public function info()
     {
         $user = $this->getUser();
@@ -49,20 +49,20 @@ class User extends Permissions
             ['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'],
             ['home_address|家庭住址', 'max:255'],
             ['marriage|婚姻情况', 'number|in:0,1,2'],
             ['problem_type|咨询问题类别', 'number|in:0,1,2,3,4,5'],
-            ['childs_age1|一孩年龄', 'number'],
-            ['childs_age2|二孩年龄', 'number'],
-            ['childs_age3|三孩年龄', 'number'],
-            ['childs_sex1|一孩性别', 'number'],
-            ['childs_sex2|二孩性别', 'number'],
-            ['childs_sex3|三孩性别', 'number'],
+            ['childs_num_str|子女数量', 'max:255'],
+//            ['childs_num|子女数量', 'number|in:1,2,3'],
+//            ['childs_age1|一孩年龄', 'number'],
+//            ['childs_age2|二孩年龄', 'number'],
+//            ['childs_age3|三孩年龄', 'number'],
+//            ['childs_sex1|一孩性别', 'number'],
+//            ['childs_sex2|二孩性别', 'number'],
+//            ['childs_sex3|三孩性别', 'number'],
         ]);
         if (!$validate->check($post)) {
             $this->json_error('提交失败:' . $validate->getError());
@@ -113,7 +113,7 @@ class User extends Permissions
         }
 
         //已经预约的时间段
-        $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $ticket->id)->column('appointment_time');
+        $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $ticket->id)->where('finish_time', 0)->column('appointment_time');
         foreach ($ticketPeriods as $period) {
             if ($period == $post['appointment_time']) {
                 $this->json_error("该时段已被预约,请重新选择时间");
@@ -129,7 +129,6 @@ class User extends Permissions
             'sex' => $post['sex']??0,
             'phone' => $post['phone'],
             'id_card' => $this->request->param('id_card', '', 'htmlspecialchars'),
-            'childs_num' => $post['childs_num']??0,
             'problem_desc' => $this->request->param('problem_desc', '', 'htmlspecialchars'),
             'requirement_desc' => $this->request->param('requirement_desc', '', 'htmlspecialchars'),
             'address_id' => $ticket->address_id,
@@ -145,12 +144,13 @@ class User extends Permissions
             'marriage' => $post['marriage']??0,
             'problem_type' => $post['problem_type']??0,
             'childs_num_str' => $this->request->param('childs_num_str', '', 'htmlspecialchars'),
-            '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,
+//            'childs_num' => $post['childs_num']??0,
+//            '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("预约入库失败");
@@ -160,7 +160,41 @@ class User extends Permissions
     }
 
 
-    //我的预约列表接口
+    //取消预约
+    public function cancelApplication()
+    {
+        $post = $this->request->param();
+        $validate = new \think\Validate([
+            ['id', 'require|number'],
+        ]);
+        if (!$validate->check($post)) {
+            $this->json_error('提交失败:' . $validate->getError());
+        }
+
+        $application = (new AppointmentApplication())->where(['id' => $post['id'], 'user_id' => $this->getUserId()])->find();
+        if (!$application) {
+            $this->json_error("预约不存在");
+        }
+
+        if ($application->finish_time > 0) {
+            $this->json_error("已完成,不可取消");
+        }
+
+        // n 小时后不可取消
+        $cancel_appointment_time = Webconfig::getValue('cancel_appointment_time');
+        if ($cancel_appointment_time && time() > ($application->getData('create_time') + $cancel_appointment_time * 3600)) {
+            $this->json_error("超过{$cancel_appointment_time}小时后,不可取消");
+        }
+
+        if (false === $application->save(['status' => AppointmentApplication::STATUS_CANCEL, 'finish_time' => time()])) {
+            $this->json_error("提交失败");
+        } else {
+            $this->json_success("提交成功");
+        }
+    }
+
+
+    //我的预约列表
     public function applicationList()
     {
         $post = $this->request->param();
@@ -214,9 +248,9 @@ class User extends Permissions
             'content' => $this->request->param('content', '', 'htmlspecialchars')
         ];
         if (false === $model->allowField(true)->save($data)) {
-            $this->json_error("失败");
+            $this->json_error("提交失败");
         } else {
-            $this->json_success("成功");
+            $this->json_success("提交成功");
         }
     }
 }

+ 28 - 1
app/api/controller/接口文档.md

@@ -503,6 +503,9 @@
 | 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_str   | 子女数量,年龄,性别 ,字符串格式 |  max:255 |
+
+
 | childs_num   | 子女数量:0无,1一孩、2二孩、3三孩 |  int, in:1,2,3 |
 | childs_age1| 一孩年龄 | number |
 | childs_age2| 二孩年龄 | number |
@@ -510,7 +513,6 @@
 | childs_sex1 | 一孩性别 | number |
 | childs_sex2 | 二孩性别 | number |
 | childs_sex3 | 三孩性别 | number |
-| childs_num_str   | 子女数量,年龄,性别 ,字符串格式 |  max:255 |
 
 
 响应数据:
@@ -533,6 +535,31 @@
 }
 ```
 
+# 取消预约
+
+接口地址: /api/user/cancelApplication
+
+更新时间: 2023-05-12 
+
+请求方式:get / post
+
+请求数据:
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+| x-token   | 登入令牌jwt      |  必填 |
+| id   | 预约id   |  int  |
+
+响应数据:
+```json
+{
+    "code": 1,
+    "msg": " 提交成功",
+    "time": "1682332924",
+    "data": null
+}
+```
+
 # 我的预约列表
 
 接口地址:/api/user/applicationList

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

@@ -15,11 +15,13 @@ class AppointmentApplication extends Model
     const STATUS_NOT_SIGN = 0;
     const STATUS_SIGN = 1;
     const STATUS_NOT_COME = 2;
+    const STATUS_CANCEL = 3;
 
     const STATUS = [
         self::STATUS_NOT_SIGN => '未签到',
         self::STATUS_SIGN => '已签到',
         self::STATUS_NOT_COME => '爽约',
+        self::STATUS_CANCEL => '已取消',
     ];
 
     const SEX_UNKNOW = 0;

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

@@ -24,6 +24,7 @@ class AppointmentTicket extends Model
         return (new AppointmentApplication())->where([
             'appointment_period' => AppointmentApplication::APPOINTMENT_PERIOD_MORNING,
             'appointment_ticket_id' => $this->id,
+            'status' => ['<>', AppointmentApplication::STATUS_CANCEL]
         ])->count();
     }
 
@@ -33,6 +34,7 @@ class AppointmentTicket extends Model
         return (new AppointmentApplication())->where([
             'appointment_period' => AppointmentApplication::APPOINTMENT_PERIOD_AFTERNOON,
             'appointment_ticket_id' => $this->id,
+            'status' => ['<>', AppointmentApplication::STATUS_CANCEL]
         ])->count();
     }
 
@@ -42,6 +44,7 @@ class AppointmentTicket extends Model
         return (new AppointmentApplication())->where([
             'appointment_period' => AppointmentApplication::APPOINTMENT_PERIOD_NIGHT,
             'appointment_ticket_id' => $this->id,
+            'status' => ['<>', AppointmentApplication::STATUS_CANCEL]
         ])->count();
     }
 

+ 3 - 0
app/install/data/db.sql

@@ -814,3 +814,6 @@ ALTER TABLE `tplay_webconfig`
 
 ALTER TABLE `tplay_config`
 	ADD COLUMN `image_aux` VARCHAR(50) NOT NULL DEFAULT '' AFTER `image_label`;
+
+ALTER TABLE `tplay_webconfig`
+	ADD COLUMN `cancel_appointment_time` INT NOT NULL DEFAULT 0 COMMENT '多少小时内可以取消' AFTER `notice_content`;

+ 3 - 1
extend/time/DateHelper.php

@@ -152,7 +152,9 @@ class DateHelper
      */
     public static function splitTimePeriod($start, $end, $count, $format = 'H:i:s')
     {
-        $count = $count <= 0 ? 1 : $count;
+        if ($count <= 0) {
+            return [];
+        }
         $second_total = strtotime($end) - strtotime($start);
         $arr = [];
         if ($count > 1) {