56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\common\model;
|
||
|
||
class Experience extends _Init
|
||
{
|
||
/**
|
||
* 模型初始化【事件注册】
|
||
*/
|
||
protected static function init()
|
||
{
|
||
self::beforeInsert(function ($data) {
|
||
$data->status = 1;
|
||
});
|
||
}
|
||
|
||
public function user()
|
||
{
|
||
return $this->hasOne('MemberInfo', 'uid', 'uid');
|
||
}
|
||
|
||
public function comment()
|
||
{
|
||
return $this->hasMany('Experience', 'pid', 'id')->order('id asc');
|
||
}
|
||
|
||
public function getCountAttr($value, $data)
|
||
{
|
||
$res = ExperienceTags::where(['experience_id' => $data['id']])->count();
|
||
return $res;
|
||
}
|
||
|
||
public function gettags()
|
||
{
|
||
return $this->hasMany('ExperienceTags', 'experience_id', 'id');
|
||
}
|
||
|
||
public function getTagsNicknameAttr($value, $data)
|
||
{
|
||
$list = ExperienceTags::where(['experience_id' => $data['id']])->select();
|
||
$name = [];
|
||
foreach ($list as $key => $value) {
|
||
if (!empty($value->user->nickname)) {
|
||
$name[] = $value->user->nickname;
|
||
}
|
||
}
|
||
return implode('、', $name);
|
||
}
|
||
}
|