'显示','hidden' => '隐藏']; } public function getSexList() { return ['1' => '男频', '2' => '女频', '3'=> '活动']; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getSexTextAttr($value, $data) { $value = $value ? $value : $data['sex']; $list = $this->getSexList(); return isset($list[$value]) ? $list[$value] : ''; } /** * 随机获取一个标题 * * @author liues@dianzhong.com * @date 2018-08-24 10:21:33 * @param array $sex * @return mixed */ public function getRandTitle(array $sex = [1,2,3]){ $where = ['status' => 'normal', 'sex' => ['in', $sex]]; $ids = $this->where($where)->column('id'); if($ids){ $id = $ids ? array_rand($ids) : 0; $title = $this->where(['id' => $ids[$id]])->value('title'); return $title; } return null; } }