UserProfile.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 02/03/2017
  6. * Time: 18:25
  7. */
  8. namespace app\common\models\user;
  9. use app\common\models\BaseModel;
  10. use Illuminate\Database\Eloquent\SoftDeletes;
  11. use Illuminate\Support\Facades\Schema;
  12. use Illuminate\Validation\Rule;
  13. class UserProfile extends BaseModel
  14. {
  15. public $table = 'users_profile';
  16. public $timestamps = false;
  17. //protected $guarded = [''];
  18. protected $guarded = [''];
  19. public $attributes =[
  20. 'nickname' => '',
  21. 'avatar' => '',
  22. 'qq' => '',
  23. 'fakeid' => '',
  24. 'vip' => 0,
  25. 'gender' => 0,
  26. 'birthyear' => 0,
  27. 'birthmonth' => 0,
  28. 'birthday' => 0,
  29. 'constellation' => '',
  30. 'zodiac' => '',
  31. 'telephone' => '',
  32. 'idcard' => '',
  33. 'studentid' => '',
  34. 'grade' => '',
  35. 'address' => '',
  36. 'zipcode' => '',
  37. 'nationality' => '',
  38. 'resideprovince' => '',
  39. 'residecity' => '',
  40. 'residedist' => '',
  41. 'graduateschool' => '',
  42. 'company' => '',
  43. 'education' => '',
  44. 'occupation' => '',
  45. 'position' => '',
  46. 'revenue' => '',
  47. 'affectivestatus' => '',
  48. 'lookingfor' => '',
  49. 'bloodtype' => '',
  50. 'height' => '',
  51. 'weight' => '',
  52. 'alipay' => '',
  53. 'msn' => '',
  54. 'email' => '',
  55. 'taobao' => '',
  56. 'site' => '',
  57. 'bio' => '',
  58. 'interest' => '',
  59. 'workerid' => '',
  60. ];
  61. public function __construct()
  62. {
  63. parent::__construct();
  64. if (config('app.framework') == 'platform') {
  65. $this->table = 'yz_users_profile';
  66. $this->attributes = [
  67. 'avatar' => '',
  68. ];
  69. $this->timestamps = true;
  70. } else {
  71. if(Schema::hasColumn($this->table, 'edittime')){ //用于兼容新版微擎新增的字段
  72. $this->attributes = array_merge($this->attributes, ['edittime' =>time()]);
  73. }
  74. if(Schema::hasColumn($this->table, 'is_send_mobile_status')){ //用于兼容新版微擎新增的字段
  75. $this->attributes = array_merge($this->attributes, ['is_send_mobile_status' =>0]);
  76. }
  77. if(Schema::hasColumn($this->table, 'send_expire_status')){ //用于兼容新版微擎新增的字段
  78. $this->attributes = array_merge($this->attributes, ['send_expire_status' =>0]);
  79. }
  80. }
  81. }
  82. /*
  83. * 通过uid获取单条数据
  84. *
  85. * @params int $uid
  86. *
  87. * @return object */
  88. public static function getProfileByUid($uid)
  89. {
  90. return static::where('uid', $uid)->first();
  91. }
  92. public function relationValidator($data)
  93. {
  94. $userProfile = new static();
  95. $userProfile->fill($data);
  96. return $userProfile->validator();
  97. }
  98. /*
  99. * @parms array $data
  100. * @parms boject $model
  101. *
  102. * @return bool
  103. * */
  104. public function addUserProfile($data, $model)
  105. {
  106. static::fill($data);
  107. $this->uid = $model->id;
  108. $this->createtime = $model->starttime;
  109. return $this->save();
  110. }
  111. /**
  112. * 定义字段名
  113. *
  114. * @return array */
  115. public function atributeNames() {
  116. return [
  117. 'realname'=> "姓名",
  118. 'mobile' => "手机号码"
  119. ];
  120. }
  121. /**
  122. * 字段规则
  123. *
  124. * @return array */
  125. public function rules()
  126. {
  127. $rules = [
  128. 'realname' => 'required|max:10',
  129. 'mobile' => ['regex:/^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/',Rule::unique($this->table)->ignore(request()->id,'uid')],
  130. Rule::unique($this->table)->ignore(request()->id, 'uid')
  131. ];
  132. return $rules;
  133. }
  134. }