|
|
|
@ -31,6 +31,7 @@ class Message extends BaseController |
|
|
|
'content' => $m['content'], |
|
|
|
'time' => date('Y-m-d H:i:s', strtotime($m['created_at'])), |
|
|
|
'staffId' => $m['staff_id'] ?? null, |
|
|
|
'isRead' => $m['is_read'] ?? 0, |
|
|
|
]; |
|
|
|
}, $messages); |
|
|
|
|
|
|
|
@ -69,8 +70,36 @@ class Message extends BaseController |
|
|
|
'sender_type' => $senderType, |
|
|
|
'staff_id' => $staffId, |
|
|
|
'content' => $content, |
|
|
|
'is_read' => 0, // 默认未读
|
|
|
|
]); |
|
|
|
|
|
|
|
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']); |
|
|
|
} |
|
|
|
} |