123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- /**
- * 私聊消息
- * @author solu
- */
- class PersonMsg extends Model {
- protected $tableName = 'person_msg';
- protected $dbKey = 'dw_chat';
- const MAX_REPEAL_TIME = 180; // 三分钟撤销时间
- /**
- * 撤销消息
- * @author solu
- * @param $from
- * @param $session_id
- * @param $hash
- * @return bool
- * @throws Exception
- */
- public function repeal($from, $session_id, $hash) {
- $where = compact('hash', 'session_id');
- $msg = $this->objTable->getRow($where);
- if (!$msg) {
- throw new Exception('message not found', CODE_NORMAL_ERROR);
- }
- if ($msg['from'] != $from) {
- throw new Exception('no permission', CODE_NO_PERMITION);
- }
- if ((time() - strtotime($msg['create_time']) > self::MAX_REPEAL_TIME)) {
- throw new Exception('repeal message time out', CODE_NORMAL_ERROR);
- }
- $this->objTable->updateObject(['state' => 0], $where);
- // 如果撤销的是最后一条
- if ($msg['msg_num'] == Session::getLastMsgNum($session_id)) {
- Session::setLastMsg($session_id, Session::MSG_TYPE_REPEAL, '', $from, '');
- }
- ThirdApi::pushPersonEvent($msg['to'], [
- 'type' => 'repeal',
- 'from' => (int) $from,
- 'nick_name' => User::getUserNameById($from),
- 'to' => (int) $msg['to'],
- 'hash' => $hash,
- ]);
- return true;
- }
- }
|