Files
tuiguangzhushou/application/common/model/Suggest.php
2020-08-06 15:26:41 +08:00

79 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Suggest extends _Init
{
/**
* 模型初始化【事件注册】
*/
protected static function init()
{
self::beforeInsert(function ($data) {
$data->status = 1;
});
}
public function member()
{
return $this->hasOne('Member', 'id', 'uid');
}
public function child()
{
return $this->hasMany('Suggest', 'pid', 'id')->order('create_time asc');
}
public function last()
{
return $this->hasOne('Suggest', 'pid', 'id')->order('create_time desc');
}
protected function getCreateTimeAttr($value, $data)
{
return $data['create_time'] ? date('Y-m-d H:i:s', $data['create_time']) : '无';
}
protected function getStatusTextAttr($value, $data)
{
switch ($data['status']) {
case 2:
return '关闭';
break;
case 1:
return '正常';
break;
default:
return '状态错误';
break;
}
}
public function getWhoAttr($value, $data)
{
return ($data['uid'] == UID) ? 'me' : 'user';
}
//是否是新消息
public function getIsNewAttr($value, $data)
{
$last = $this->last;
if (!$last) {
return 0;
} else {
if ($last->uid != UID && $last->read != 1) {
return 1;
} else {
return 0;
}
}
}
}