浏览代码

fix: bug修复

zhengzhibin 1 年之前
父节点
当前提交
e38bca5781

+ 11 - 4
app/admin/controller/Appointment.php

@@ -119,11 +119,13 @@ class Appointment extends Permissions
             if ($this->request->isPost()) {
 
                 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 {
@@ -134,16 +136,21 @@ class Appointment extends Permissions
                         }
                         $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)) {
+                            $data = [
+                                'appointment_id' => $model->id,
+                                'appointment_daytime' => strtotime($datetime),
+                                'address_id' => $addressId,
+                                'provider_id' => $post['provider_id'],
+                                'status' => \app\common\model\AppointmentTicket::STATUS_OPEN
+                            ];
+                            if (false == (new \app\common\model\AppointmentTicket())->allowField(true)->save($data)) {
                                 $this->error('添加失败');
                             }
                         }
                     }
 
                 } else {
+                    //按工作日排号,保存放号设置
                     $post['start_time'] = 0;
                     $post['end_time'] = 0;
                     $post['weeks'] = $weeks;

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

@@ -92,10 +92,10 @@
                     {field: "morning_num", title: '上午放号个数'},
                     {field: "afternoon_num", title: '下午放号个数'},
                     {field: "night_num", 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: '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 () {

+ 13 - 13
app/admin/view/appointment/publish.html

@@ -46,21 +46,11 @@
 
         <div class="layui-tab">
             <ul class="layui-tab-title">
-                <li class="layui-this">按时间跨度排号</li>
-                <li>按工作日排号</li>
+                <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">
@@ -68,12 +58,22 @@
                             <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[5]" title="周五" checked>
                             <input type="checkbox" name="weeks[6]" title="周六">
                             <input type="checkbox" name="weeks[7]" title="周日">
                         </div>
                     </div>
                 </div>
+                <div class="layui-tab-item">
+                    <!-- 时间 -->
+                    <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>
         </div>
 

+ 4 - 4
app/admin/view/appointment_ticket/index.html

@@ -82,10 +82,10 @@
                     {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: '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 () {

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

@@ -102,7 +102,7 @@
                 id: 'table'
                 , elem: '#table'
                 , size: 'sm' //小尺寸的表格
-                , toolbar: '#toolbarDemo'
+//                , toolbar: '#toolbarDemo'
 //                , defaultToolbar: []
                 , limit: 15
                 , limits: [15, 20, 30, 40, 50, 100]

+ 6 - 6
app/admin/view/webconfig/appointment_config.html

@@ -21,21 +21,21 @@
 
         <div class="layui-form-item">
             <div class="layui-inline">
-                <label class="layui-form-label">限制</label>
-                <div class="layui-input-inline" style="width: 100px;">
+                <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: 100px;">
+                <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: 100px;">
+                <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 class="layui-form-mid">天无法再预约</div>
             </div>
         </div>
 

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

@@ -36,34 +36,6 @@ class Appointment extends Base
     }
 
 
-    //可预约的地址
-    public function availableAddressList()
-    {
-        $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 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);
-        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);
-    }
-
-
     //按地址id获取号源信息
     public function getTicketByAddressId()
     {
@@ -79,6 +51,9 @@ class Appointment extends Base
         $address_id = $this->request->param('address_id');
         $daytime = $this->request->param('daytime', date('Y-m-d'));
 
+        //生成工作日号源
+        \app\common\model\Appointment::createWeekTicketAll($daytime);
+
         $ticketModel = new AppointmentTicket();
         $tickets = $ticketModel->where('address_id', $address_id)->where('appointment_daytime', strtotime($daytime))->select();
 
@@ -146,6 +121,10 @@ class Appointment extends Base
         }
 
         $daytime = $this->request->param('daytime', date('Y-m-d'));
+
+        //生成工作日号源
+        \app\common\model\Appointment::createWeekTicketAll($daytime);
+
         $addressIds = $ticketModel->where('appointment_daytime', strtotime($daytime))->distinct(true)->column('address_id');
 
         $where = [];

+ 11 - 11
app/api/controller/User.php

@@ -86,7 +86,7 @@ class User extends Permissions
         }
 
         //检测预约号源是否可预约
-        $ticket = AppointmentTicket::get($post['appointment_ticket_id']);
+        $ticket = (new AppointmentTicket())->where(['id' => $post['appointment_ticket_id'], 'status' => AppointmentTicket::STATUS_OPEN])->find();
         if (!$ticket) {
             $this->json_error("获取预约号失败");
         }
@@ -122,29 +122,29 @@ class User extends Permissions
 
         //入库
         $data = [
-            'name' => $post['name'],
+            'name' => htmlspecialchars($post['name']),
             'user_id' => $this->getUserId(),
             'age' => $post['age']??0,
-            'birthday' => $post['birthday']??'',
+            'birthday' => $this->request->param('birthday', '', 'htmlspecialchars'),
             'sex' => $post['sex']??0,
             'phone' => $post['phone'],
-            'id_card' => $post['id_card']??'',
+            'id_card' => $this->request->param('id_card', '', 'htmlspecialchars'),
             'childs_num' => $post['childs_num']??0,
-            'problem_desc' => $post['problem_desc']??'',
-            'requirement_desc' => $post['requirement_desc']??'',
+            'problem_desc' => $this->request->param('problem_desc', '', 'htmlspecialchars'),
+            'requirement_desc' => $this->request->param('requirement_desc', '', 'htmlspecialchars'),
             'address_id' => $ticket->address_id,
             'provider_id' => $ticket->provider_id,
             'appointment_ticket_id' => $post['appointment_ticket_id'],
             'appointment_time' => $post['appointment_time'],
             'appointment_period' => $post['appointment_period'],
             'status' => AppointmentApplication::STATUS_NOT_SIGN,
-            'city' => $post['city']??'',
-            'job' => $post['job']??'',
+            'city' => $this->request->param('city', '', 'htmlspecialchars'),
+            'job' => $this->request->param('job', '', 'htmlspecialchars'),
             'education_level' => $post['education_level']??0,
-            'home_address' => $post['home_address']??'',
+            'home_address' => $this->request->param('home_address', '', 'htmlspecialchars'),
             'marriage' => $post['marriage']??0,
             'problem_type' => $post['problem_type']??0,
-            'childs_num_str' => $post['childs_num_str']??'',
+            '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,
@@ -211,7 +211,7 @@ class User extends Permissions
         $model = new Feedback();
         $data = [
             'user_id' => $this->getUserId(),
-            'content' => $post['content']
+            'content' => $this->request->param('content', '', 'htmlspecialchars')
         ];
         if (false === $model->allowField(true)->save($data)) {
             $this->json_error("失败");

+ 37 - 7
app/common/model/Appointment.php

@@ -3,6 +3,7 @@
 namespace app\common\model;
 
 use think\Db;
+use think\Exception;
 use think\Model;
 use time\DateHelper;
 
@@ -10,27 +11,56 @@ class Appointment extends Model
 {
     protected $updateTime = false;
 
+    const STATUS_OPEN = 1;
+    const STATUS_CLOSE = 0;
+
+
+    //start_time
     public function getStartTimeAttr($value, $data)
     {
         return $value ? date('Y-m-d', $value) : '';
     }
 
+    //end_time
     public function getEndTimeAttr($value, $data)
     {
         return $value ? date('Y-m-d', $value) : '';
     }
 
 
-    /**
-     * 可预约日期列表
-     */
-    public static function availableDayList()
+    //是否为工作日排号模式
+    public function isWeekMode()
     {
-        $maxEndTime = (new Appointment())->max('daytime');
-        $daylist = DateHelper::dateTimeList(date('Y-m-d'), date('Y-m-d', $maxEndTime), true);
-        return $daylist;
+        return $this->weeks ? true : false;
     }
 
+    //生成工作日号源
+    public static function createWeekTicketAll($daytime)
+    {
+        $daytimestamp = strtotime($daytime);
+        if (strtotime(date('Y-m-d')) > $daytimestamp) {
+            throw new Exception("该时间已过期,请重新选择时间");
+        }
+
+        $daytimeWeek = date('w', $daytimestamp);
+
+        $appoints = (new Appointment())->where('weeks', '<>', '')->where('status', self::STATUS_OPEN)->select();
+        foreach ($appoints as $appoint) {
+            $weeks = explode(',', $appoint->weeks);
+            if (in_array($daytimeWeek, $weeks)) {
+                //生成号源记录
+                if (0 == (new AppointmentTicket())->where(['appointment_id' => $appoint->id, 'appointment_daytime' => $daytimestamp])->count()) {
+                    (new AppointmentTicket())->allowField(true)->save([
+                        'appointment_id' => $appoint->id,
+                        'appointment_daytime' => $daytimestamp,
+                        'address_id' => $appoint->address_id,
+                        'provider_id' => $appoint->provider_id,
+                        'status' => AppointmentTicket::STATUS_OPEN
+                    ]);
+                }
+            }
+        }
+    }
 
     //关联专家
     public function specialist()

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

@@ -8,6 +8,11 @@ class AppointmentTicket extends Model
 {
     protected $autoWriteTimestamp = false;
 
+    const STATUS_OPEN = 1;
+    const STATUS_CLOSE = 0;
+
+
+    //appointment_daytime
     public function getAppointmentDaytimeAttr($value, $data)
     {
         return $value ? date('Y-m-d', $value) : '';
@@ -40,6 +45,7 @@ class AppointmentTicket extends Model
         ])->count();
     }
 
+
     //关联专家
     public function specialist()
     {

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

@@ -921,4 +921,10 @@ ALTER TABLE `tplay_appointment_ticket`
 	DROP COLUMN `afternoon_use`,
 	DROP COLUMN `night_use`;
 
+ALTER TABLE `tplay_appointment`
+	ALTER `weeks` DROP DEFAULT;
+ALTER TABLE `tplay_appointment`
+	CHANGE COLUMN `weeks` `weeks` VARCHAR(50) NOT NULL COMMENT '排号工作日' AFTER `end_time`;
 
+ALTER TABLE `tplay_appointment`
+	CHANGE COLUMN `weeks` `weeks` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '排号工作日' AFTER `end_time`;