luck-draw/app/model/ActivityTemplate.php

45 lines
959 B
PHP

<?php
namespace app\model;
//抽奖模板
use think\Model;
class ActivityTemplate extends Base
{
public function adminType(){
return $this->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();
}
}