where(['user_id' => $data['user_id']]) ->find(); if(!$row){ $findModel->user_id = $data['user_id']; $findModel->user_no = Random::nozero(9); $findModel->save(); $user_no = $findModel->user_no; }else{ $user_no = $row->user_no; } return $user_no; } public function getIsselfAttr($value, $data) { return $data['isself']; } protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); } public function getStateList() { return ['0' => __('State 0'), '1' => __('State 1'), '2' => __('State 2')]; } public function getStatusList() { return ['normal' => __('Normal'), 'hidden' => __('Hidden')]; } public function getTypeList() { return ['shop' => __('Shop'), 'page' => __('Page')]; } public function getStateTextAttr($value, $data) { $value = $value ? $value : (isset($data['state']) ? $data['state'] : ''); $list = $this->getStateList(); return isset($list[$value]) ? $list[$value] : ''; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } }