123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /**
- * CommentModel.php UTF-8
- * 评论
- *
- * @date : 2017/11/24 16:21
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\model\comment;
- use huo\model\common\CommonModel;
- class CommentModel extends CommonModel {
- protected $name = 'comment';
- //模型关联方法
- protected $relationFilter = ['mem', 'to_mem'];
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- /**
- * 关联 user表
- *
- * @return $this
- */
- public function mem() {
- return $this->belongsTo('\huo\model\member\MemberModel', 'mem_id');
- }
- public function toMem() {
- return $this->belongsTo('\huo\model\member\MemberModel', 'to_mem_id');
- }
- /**
- * 关联游戏
- *
- * @return \think\model\relation\BelongsTo
- */
- public function game() {
- return $this->belongsTo('\huo\model\game\GameModel', 'object_id')->field('id,name,icon');
- }
- /**
- * 基础查询
- *
- * @param $query
- */
- protected function base($query) {
- $query->where('delete_time', 0)
- ->where('status', 1);
- }
- /**
- * post_content 自动转化
- *
- * @param $value
- *
- * @return string
- */
- public function getContentAttr($value) {
- return cmf_replace_content_file_url(htmlspecialchars_decode($value));
- }
- /**
- * more 自动转化
- *
- * @param $value
- *
- * @return array
- */
- public function getMoreAttr($value) {
- $more = json_decode($value, true);
- if (!empty($more['thumbnail'])) {
- $more['thumbnail'] = cmf_get_image_url($more['thumbnail']);
- }
- if (!empty($more['photos'])) {
- foreach ($more['photos'] as $key => $value) {
- $more['photos'][$key]['url'] = cmf_get_image_url($value['url']);
- }
- }
- if (!empty($more['files'])) {
- foreach ($more['files'] as $key => $value) {
- $more['files'][$key]['url'] = cmf_get_image_url($value['url']);
- }
- }
- return $more;
- }
- /**
- * 添加评论
- *
- * @param $data
- *
- * @return bool|mixed
- */
- public static function setComment($data) {
- if (!$data) {
- return false;
- }
- if ($obj = self::create($data)) {
- return $obj->id;
- } else {
- return false;
- }
- }
- }
|