12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\data\model;
- use think\admin\Model;
- /**
- * 用户数据模型
- * Class DataUser
- * @package app\data\model
- */
- class DataUser extends Model
- {
- #是否将real_name赋值给nickname
- public static $copyRealName=false;
- /**
- * 格式化创建时间
- * @param string $value
- * @return string
- */
- public function getCreateAtAttr(string $value): string
- {
- return format_datetime($value);
- }
- public static function onBeforeInsert(self $model)
- {
- if(empty($model['nickname'])){
- $model['nickname']='船员';
- }
- if(empty($model['username'])){
- $model['username']=session_create_id();
- }
- }
- public function pooltalent(){
- return $this->hasOne(DataPoolTalent::class,'uuid');
- }
- public function maintenance(){
- return $this->hasOne(DataMaintenance::class,'uuid');
- }
- public function shipyard(){
- return $this->hasOne(DataShipyard::class,'uuid');
- }
- public function merchants(){
- return $this->hasOne(DataMerchants::class,'uuid');
- }
- public function getNicknameAttr($nickname,$model){
- if(self::$copyRealName && !empty($model['real_name'])){
- return $model['real_name'];
- }
- return $nickname;
- }
- }
|