MemberModel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 会员-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * Class MemberModel
  17. * @package App\Models
  18. */
  19. class MemberModel extends BaseModel
  20. {
  21. // 设置数据表
  22. protected $table = 'member';
  23. /**
  24. * 商家
  25. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  26. */
  27. public function merchant()
  28. {
  29. return $this->belongsTo(MerchantModel::class, 'id','user_id')
  30. ->where(['mark'=>1])
  31. ->select(['id','user_id','usdt','name','category','audit_remark','status']);
  32. }
  33. /**
  34. * 承兑商
  35. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  36. */
  37. public function acceptor()
  38. {
  39. return $this->belongsTo(AcceptorModel::class, 'id','user_id')
  40. ->where(['mark'=>1])
  41. ->select(['id','user_id','realname','mobile','usdt','quota','audit_remark','status']);
  42. }
  43. /**
  44. * 上级
  45. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  46. */
  47. public function parent()
  48. {
  49. return $this->hasOne(MemberModel::class, 'id','parent_id')
  50. ->where(['mark'=>1])
  51. ->select(['id','realname','email','mobile','status']);
  52. }
  53. /**
  54. * 获取会员信息
  55. * @param int $id 会员ID
  56. * @return array|string
  57. * @author laravel开发员
  58. * @since 2020/11/11
  59. */
  60. public function getInfo($id)
  61. {
  62. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  63. if ($info) {
  64. // 头像
  65. if ($info['avatar']) {
  66. $info['avatar'] = get_image_url($info['avatar']);
  67. }
  68. // 出生日期
  69. if ($info['birthday']) {
  70. $info['birthday'] = datetime($info['birthday']);
  71. }
  72. // 城市
  73. if ($info['province_id'] && $info['city_id'] && $info['district_id']) {
  74. $city = [];
  75. $city[] = $info['province_id'];
  76. $city[] = $info['city_id'];
  77. $city[] = $info['district_id'];
  78. $info['city'] = $city;
  79. }
  80. }
  81. return $info;
  82. }
  83. }