DataUser.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\data\model;
  3. use think\admin\Model;
  4. /**
  5. * 用户数据模型
  6. * Class DataUser
  7. * @package app\data\model
  8. */
  9. class DataUser extends Model
  10. {
  11. #是否将real_name赋值给nickname
  12. public static $copyRealName=false;
  13. /**
  14. * 格式化创建时间
  15. * @param string $value
  16. * @return string
  17. */
  18. public function getCreateAtAttr(string $value): string
  19. {
  20. return format_datetime($value);
  21. }
  22. public static function onBeforeInsert(self $model)
  23. {
  24. if(empty($model['nickname'])){
  25. $model['nickname']='船员';
  26. }
  27. if(empty($model['username'])){
  28. $model['username']=session_create_id();
  29. }
  30. }
  31. public function pooltalent(){
  32. return $this->hasOne(DataPoolTalent::class,'uuid');
  33. }
  34. public function maintenance(){
  35. return $this->hasOne(DataMaintenance::class,'uuid');
  36. }
  37. public function shipyard(){
  38. return $this->hasOne(DataShipyard::class,'uuid');
  39. }
  40. public function merchants(){
  41. return $this->hasOne(DataMerchants::class,'uuid');
  42. }
  43. public function getNicknameAttr($nickname,$model){
  44. if(self::$copyRealName && !empty($model['real_name'])){
  45. return $model['real_name'];
  46. }
  47. return $nickname;
  48. }
  49. }