Browse Source

fix(R19): 消息is_read+禁聊

dev
cursor 1 day ago
parent
commit
b65f5de9b4
3 changed files with 43 additions and 2 deletions
  1. +29
    -0
      app/controller/Message.php
  2. +12
    -1
      app/model/Message.php
  3. +2
    -1
      route/app.php

+ 29
- 0
app/controller/Message.php View File

@ -31,6 +31,7 @@ class Message extends BaseController
'content' => $m['content'], 'content' => $m['content'],
'time' => date('Y-m-d H:i:s', strtotime($m['created_at'])), 'time' => date('Y-m-d H:i:s', strtotime($m['created_at'])),
'staffId' => $m['staff_id'] ?? null, 'staffId' => $m['staff_id'] ?? null,
'isRead' => $m['is_read'] ?? 0,
]; ];
}, $messages); }, $messages);
@ -69,8 +70,36 @@ class Message extends BaseController
'sender_type' => $senderType, 'sender_type' => $senderType,
'staff_id' => $staffId, 'staff_id' => $staffId,
'content' => $content, 'content' => $content,
'is_read' => 0, // 默认未读
]); ]);
return json(['code' => 0, 'data' => ['id' => $msg->id], 'msg' => 'ok']); return json(['code' => 0, 'data' => ['id' => $msg->id], 'msg' => 'ok']);
} }
// 标记消息为已读
public function read()
{
$cardNo = $this->request->post('card_no', '');
$staffId = $this->request->post('staff_id', null);
if (empty($cardNo)) {
return json(['code' => -1, 'data' => null, 'msg' => '缺少号码牌']);
}
// 顾客端标记员工消息为已读
if ($staffId === null) {
MessageModel::where('card_no', $cardNo)
->where('sender_type', 'staff')
->where('is_read', 0)
->update(['is_read' => 1]);
} else {
// 员工端标记顾客消息为已读
MessageModel::where('card_no', $cardNo)
->where('sender_type', 'customer')
->where('is_read', 0)
->update(['is_read' => 1]);
}
return json(['code' => 0, 'data' => null, 'msg' => 'ok']);
}
} }

+ 12
- 1
app/model/Message.php View File

@ -1,4 +1,4 @@
<?php
<?php
namespace app\model; namespace app\model;
use think\Model; use think\Model;
@ -10,4 +10,15 @@ class Message extends Model
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
protected $createTime = 'created_at'; protected $createTime = 'created_at';
protected $updateTime = false; protected $updateTime = false;
// 允许写入的字段
protected $schema = [
'id' => 'int',
'card_no' => 'string',
'sender_type' => 'string',
'staff_id' => 'int',
'content' => 'text',
'is_read' => 'int',
'created_at' => 'datetime',
];
} }

+ 2
- 1
route/app.php View File

@ -1,4 +1,4 @@
<?php
<?php
use think\facade\Route; use think\facade\Route;
// ── 顾客端(无需认证) ── // ── 顾客端(无需认证) ──
@ -12,6 +12,7 @@ Route::get('api/order/list', 'Order/list');
Route::post('api/order/remind', 'Order/remind'); Route::post('api/order/remind', 'Order/remind');
Route::get('api/message/list', 'Message/list'); Route::get('api/message/list', 'Message/list');
Route::post('api/message/send', 'Message/send'); Route::post('api/message/send', 'Message/send');
Route::post('api/message/read', 'Message/read');
// ── 员工端(需Token中间件) ── // ── 员工端(需Token中间件) ──
Route::post('api/staff/login', 'Staff/login'); Route::post('api/staff/login', 'Staff/login');


Loading…
Cancel
Save