MessageService.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\Messages;
  4. use app\common\traits\ServiceTrait;
  5. use think\Log;
  6. class MessageService
  7. {
  8. use ServiceTrait;
  9. /** @var Messages */
  10. public static $Model = Messages::class;
  11. /**
  12. * @param $to_user_id
  13. * @param $title
  14. * @param $content
  15. * @param $extra_json
  16. * @param $from_user_id
  17. * @return mixed
  18. * @throws \Exception
  19. */
  20. public static function createData($to_user_id, $title, $content, $extra_json = [], $from_user_id = 0)
  21. {
  22. $data = [
  23. 'message_type' => CommonService::NO,
  24. 'from_user_id' => $from_user_id,
  25. 'to_user_id' => $to_user_id,
  26. 'title' => $title,
  27. 'content' => $content,
  28. 'extra_json' => $extra_json,
  29. 'is_read' => CommonService::STATUS_OFF,
  30. ];
  31. $res = self::create($data);
  32. if (!$res) {
  33. Log::info(__METHOD__ . '-写入数据失败失败:' . json_encode($data, JSON_UNESCAPED_UNICODE));
  34. exception('写入数据失败失败');
  35. }
  36. return $res;
  37. }
  38. }