User.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Models\Coach;
  3. use App\Models\Service\Project;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Notifications\Notifiable;
  7. use Illuminate\Support\Facades\DB;
  8. class User extends Model
  9. {
  10. use HasFactory, Notifiable;
  11. protected $table = 'coach_users';
  12. /**
  13. * The attributes that are mass assignable.
  14. *
  15. * @var array<int, string>
  16. */
  17. protected $fillable = [];
  18. protected $guarded = [];
  19. protected $appends = [];
  20. /**
  21. * The attributes that should be hidden for serialization.
  22. *
  23. * @var array<int, string>
  24. */
  25. protected $hidden = [];
  26. /**
  27. * Get the attributes that should be cast.
  28. *
  29. * @return array<string, string>
  30. */
  31. protected function casts(): array
  32. {
  33. return [
  34. // 'password' => 'hashed',
  35. 'verify_time' => 'datetime',
  36. 'auth_time' => 'datetime'
  37. ];
  38. }
  39. public function getVerifyStatusAttribute()
  40. {
  41. return '1232';
  42. }
  43. public function info($attribute, $file = ['*']): array
  44. {
  45. (gettype($attribute) === "string" || gettype($attribute) === "integer") && ($attribute = ['id' => $attribute]);
  46. if (gettype($attribute) === "NULL") return [];
  47. $data = $this::query()->where($attribute)->first($file);
  48. return !empty($data) ? $data->toArray() : [];
  49. }
  50. public function getProject($category_id, $is_add = 0)
  51. {
  52. $project_ids = DB::table('service_project_has_category')->where('category_id', $category_id)->pluck('project_id');
  53. $project_ids = DB::table('service_project_has_coach')->whereIn('project_id', $project_ids)->where('coach_id', $this->attributes['id'])->where('status', 1)->pluck('project_id');
  54. $select = ['id', 'title', 'sub_title as subTitle', 'cover', 'price', 'init_price as initPrice', 'total_sale as totalSale', 'time_long as timeLong'];
  55. return Project::query()->whereIn('id', $project_ids)->where('status', 0)->where('is_add', $is_add)->select($select)->orderByDesc('sort')->get();
  56. }
  57. public function verify()
  58. {
  59. return $this->hasOne(Verify::class, 'coach_id');
  60. }
  61. public function member(): \Illuminate\Database\Eloquent\Relations\HasOne
  62. {
  63. return $this->hasOne(\App\Models\Member\User::class, 'id', 'user_id');
  64. }
  65. public function site(): \Illuminate\Database\Eloquent\Relations\HasOne
  66. {
  67. return $this->hasOne(Site::class, 'coach_id', 'id');
  68. }
  69. }