PersonMsg.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * 私聊消息
  4. * @author solu
  5. */
  6. class PersonMsg extends Model {
  7. protected $tableName = 'person_msg';
  8. protected $dbKey = 'dw_chat';
  9. const MAX_REPEAL_TIME = 180; // 三分钟撤销时间
  10. /**
  11. * 撤销消息
  12. * @author solu
  13. * @param $from
  14. * @param $session_id
  15. * @param $hash
  16. * @return bool
  17. * @throws Exception
  18. */
  19. public function repeal($from, $session_id, $hash) {
  20. $where = compact('hash', 'session_id');
  21. $msg = $this->objTable->getRow($where);
  22. if (!$msg) {
  23. throw new Exception('message not found', CODE_NORMAL_ERROR);
  24. }
  25. if ($msg['from'] != $from) {
  26. throw new Exception('no permission', CODE_NO_PERMITION);
  27. }
  28. if ((time() - strtotime($msg['create_time']) > self::MAX_REPEAL_TIME)) {
  29. throw new Exception('repeal message time out', CODE_NORMAL_ERROR);
  30. }
  31. $this->objTable->updateObject(['state' => 0], $where);
  32. ThirdApi::pushPersonEvent($msg['to'], [
  33. 'type' => 'repeal',
  34. 'from' => $from,
  35. 'to' => $msg['to'],
  36. 'hash' => $hash,
  37. ]);
  38. return true;
  39. }
  40. }