CommentModel.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * CommentModel.php UTF-8
  4. * 评论
  5. *
  6. * @date : 2017/11/24 16:21
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\comment;
  13. use huo\model\common\CommonModel;
  14. class CommentModel extends CommonModel {
  15. protected $name = 'comment';
  16. //模型关联方法
  17. protected $relationFilter = ['mem', 'to_mem'];
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. /**
  21. * 关联 user表
  22. *
  23. * @return $this
  24. */
  25. public function mem() {
  26. return $this->belongsTo('\huo\model\member\MemberModel', 'mem_id');
  27. }
  28. public function toMem() {
  29. return $this->belongsTo('\huo\model\member\MemberModel', 'to_mem_id');
  30. }
  31. /**
  32. * 关联游戏
  33. *
  34. * @return \think\model\relation\BelongsTo
  35. */
  36. public function game() {
  37. return $this->belongsTo('\huo\model\game\GameModel', 'object_id')->field('id,name,icon');
  38. }
  39. /**
  40. * 基础查询
  41. *
  42. * @param $query
  43. */
  44. protected function base($query) {
  45. $query->where('delete_time', 0)
  46. ->where('status', 1);
  47. }
  48. /**
  49. * post_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. * more 自动转化
  60. *
  61. * @param $value
  62. *
  63. * @return array
  64. */
  65. public function getMoreAttr($value) {
  66. $more = json_decode($value, true);
  67. if (!empty($more['thumbnail'])) {
  68. $more['thumbnail'] = cmf_get_image_url($more['thumbnail']);
  69. }
  70. if (!empty($more['photos'])) {
  71. foreach ($more['photos'] as $key => $value) {
  72. $more['photos'][$key]['url'] = cmf_get_image_url($value['url']);
  73. }
  74. }
  75. if (!empty($more['files'])) {
  76. foreach ($more['files'] as $key => $value) {
  77. $more['files'][$key]['url'] = cmf_get_image_url($value['url']);
  78. }
  79. }
  80. return $more;
  81. }
  82. /**
  83. * 添加评论
  84. *
  85. * @param $data
  86. *
  87. * @return bool|mixed
  88. */
  89. public static function setComment($data) {
  90. if (!$data) {
  91. return false;
  92. }
  93. if ($obj = self::create($data)) {
  94. return $obj->id;
  95. } else {
  96. return false;
  97. }
  98. }
  99. }