save(['weigh' => $row['id']]); }); self::afterWrite(function ($row) use ($config) { $changedData = $row->getChangedData(); if (isset($changedData['status']) && $changedData['status'] == 'normal') { if ($config['baidupush']) { //推送到熊掌号+百度站长 $urls = [$row->fullurl]; \think\Hook::listen("baidupush", $urls); } } if ($config['searchtype'] == 'xunsearch') { //更新全文搜索 FulltextSearch::update($row->id); } }); self::afterDelete(function ($row) use ($config) { if ($config['searchtype'] == 'xunsearch') { //更新全文搜索 FulltextSearch::del($row); } }); } public function getUrlAttr($value, $data) { $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id']; $catename = isset($this->category) && $this->category ? $this->category->diyname : 'all'; $cateid = isset($this->category) && $this->category ? $this->category->id : 0; return addon_url('blog/post/index', [':id' => $data['id'], ':diyname' => $diyname, ':catename' => $catename, ':cateid' => $cateid]); } public function getFullurlAttr($value, $data) { $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id']; $catename = isset($this->category) && $this->category ? $this->category->diyname : 'all'; $cateid = isset($this->category) && $this->category ? $this->category->id : 0; return addon_url('blog/post/index', [':id' => $data['id'], ':diyname' => $diyname, ':catename' => $catename, ':cateid' => $cateid], true, true); } public function getFlagList() { return ['hot' => __('Hot'), 'index' => __('Index'), 'recommend' => __('Recommend')]; } public function getStatusList() { return ['normal' => __('Normal'), 'hidden' => __('Hidden')]; } public function getFlagTextAttr($value, $data) { $value = $value ? $value : $data['flag']; $valueArr = explode(',', $value); $list = $this->getFlagList(); return implode(',', array_intersect_key($list, array_flip($valueArr))); } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } protected function setFlagAttr($value) { return is_array($value) ? implode(',', $value) : $value; } public function category() { return $this->belongsTo('BlogCategory', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0); } }