hasOne(ActivityTemplateType::class,"id","type_id")->bind(["type_text"=>"name"]); } /** * 设置内容 * */ public function setWinnerAttr($value,$data) { $content = array_column($value,null,"sort"); $contentKey = array_keys($content); sort($contentKey); $contentData =[]; foreach ($contentKey as $ck){ $contentData[]= $content[$ck]; } return json_encode($contentData,JSON_UNESCAPED_UNICODE); } /** * 设置内容 * */ public function getWinnerAttr($value,$data) { return json_decode($value,true); } public static function onAfterInsert( $template) { $template->sort = $template->id; $template->save(); } }