Kaynağa Gözat

fix: delte after event deal

jiangzixin 1 yıl önce
ebeveyn
işleme
5431c03798

+ 22 - 0
app/admin/controller/Specialist.php

@@ -139,6 +139,7 @@ class Specialist extends Permissions
             if (false == $this->getModel()->where('id', $id)->delete()) {
                 $this->error('删除失败');
             } else {
+                $this->deleteAfter($id);
                 $this->success('删除成功', 'index');
             }
         }
@@ -150,9 +151,30 @@ class Specialist extends Permissions
             $post = $this->request->param();
             $ids = $post['ids'];
             if ($this->getModel()->where('id', 'in', $ids)->delete()) {
+               $this->deleteAfter($ids);
                 $this->success('删除成功');
             }
         }
     }
 
+    /**
+     * 删除后操作
+     * @param $id
+     * @author jiang
+     */
+    private function deleteAfter($id)
+    {
+        $where = [];
+        if (!is_array($id)) {
+            $where['provider_id'] = $id;
+        } else {
+            $where['provider_id'] = ['in', $id];
+        }
+
+        //删除该专家所有号源和记录
+        (new \app\common\model\Appointment())->where($where)->delete();
+        (new \app\common\model\AppointmentTicket())->where($where)->delete();
+        (new \app\common\model\AppointmentApplication())->where($where)->delete();
+    }
+
 }

+ 2 - 2
app/admin/view/specialist/index.html

@@ -164,7 +164,7 @@
                     });
                 }
                 else if (obj.event == 'del') {
-                    layer.confirm('确定要删除?', function (index) {
+                    layer.confirm('删除专家将删除该专家所有号源和预约记录,确定要删除?', function (index) {
                         $.ajax({
                             url: "{:url('delete')}",
                             dataType: 'json',
@@ -199,7 +199,7 @@
                         data.forEach(function (item, key) {
                             ids[key] = item.id;
                         })
-                        layer.confirm('是否删除?', function (index, layero) {
+                        layer.confirm('删除这些专家将删除这些专家所有号源和预约记录,确定要删除吗?', function (index, layero) {
                             $.ajax({
                                 url: "{:url('deletes')}",
                                 dataType: 'json',

+ 2 - 3
app/api/controller/Appointment.php

@@ -103,13 +103,12 @@ class Appointment extends Base
         $tickets     = $ticketModel->where('address_id', $address_id)->where('appointment_daytime', strtotime($daytime))->select();
 
         foreach ($tickets as $k => $item) {
-            $appoint = $item->appointment;
-            if (empty($appoint)) {
+            if (empty($item->appointment) || empty($item->specialist)) {
                 unset($item);
                 continue;
             }
+            $appoint = $item->appointment;
             //专家信息
-            $item->specialist;
             $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
             //已经预约的时间段
             $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $item->id)->where('finish_time', 0)->column('appointment_time');

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

@@ -63,6 +63,9 @@ class Appointment extends Model
             if (in_array($daytimeWeek, $weeks)) {
                 //生成号源记录
                 if (0 == (new AppointmentTicket())->where(['appointment_id' => $appoint->id, 'appointment_daytime' => $daytimestamp])->count()) {
+                    if (empty($appoint->specialist)) {
+                        continue;
+                    }
                     (new AppointmentTicket())->allowField(true)->save([
                         'appointment_id' => $appoint->id,
                         'appointment_daytime' => $daytimestamp,

+ 3 - 0
app/install/data/20240413_hotfix.sql

@@ -0,0 +1,3 @@
+delete from tplay_appointment where provider_id not in (7,8,9);
+delete from tplay_appointment_ticket where provider_id not in (7,8,9);
+delete from tplay_appointment_application where provider_id not in (7,8,9);