MessageModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * MessageModel.php UTF-8
  4. * huosdk_mobi
  5. *
  6. * @date : 2017/11/24 18:24
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\message;
  13. use huo\model\common\CommonModel;
  14. use huo\model\game\GameModel;
  15. use huo\model\member\MemberModel;
  16. class MessageModel extends CommonModel {
  17. protected $name = 'message';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. public function memMsg() {
  21. return $this->hasOne(MemMessageModel::className(), 'message_id', 'id');
  22. }
  23. public function game() {
  24. return $this->belongsTo(GameModel::className(), 'app_id', 'id');
  25. }
  26. public function mem() {
  27. return $this->belongsTo(MemberModel::className(), 'mem_id', 'id');
  28. }
  29. /**
  30. * 基础查询
  31. *
  32. * @param $query
  33. */
  34. protected function base($query) {
  35. $query->where('delete_time', 0)
  36. ->where('is_delete', 2);
  37. }
  38. /**
  39. * post_content 自动转化
  40. *
  41. * @param $value
  42. *
  43. * @return string
  44. */
  45. public function setMessageAttr($value) {
  46. return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
  47. }
  48. /**
  49. * content 自动转化
  50. *
  51. * @param $value
  52. *
  53. * @return string
  54. */
  55. public function getContentAttr($value) {
  56. return cmf_replace_content_file_url(htmlspecialchars_decode($value));
  57. }
  58. /**
  59. * content 自动转化
  60. *
  61. * @param $value
  62. *
  63. * @return string
  64. */
  65. public function setContentAttr($value) {
  66. return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
  67. }
  68. /**
  69. * 添加评论
  70. *
  71. * @param $data
  72. *
  73. * @return bool|mixed
  74. */
  75. public static function addMessage($data) {
  76. if (!$data) {
  77. return false;
  78. }
  79. if ($obj = self::create($data)) {
  80. return $obj->id;
  81. } else {
  82. return false;
  83. }
  84. }
  85. public static function updateMessage($data, $id) {
  86. $_map['id'] = $id;
  87. $_data = $data;
  88. $_rs = self::update($_data, $_map, true);
  89. if (false == $_rs) {
  90. return false;
  91. } else {
  92. return true;
  93. }
  94. }
  95. }