UserSpread.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\user;
  12. use app\model\system\admin\SystemAdmin;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\model;
  16. /**
  17. * Class UserSpread
  18. * @package app\model\user
  19. */
  20. class UserSpread extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'user_spread';
  33. /**
  34. * 用户
  35. * @return model\relation\HasOne
  36. */
  37. public function user()
  38. {
  39. return $this->hasOne(User::class, 'uid', 'uid')->field('uid,nickname,avatar')->bind([
  40. 'nickname' => 'nickname',
  41. 'avatar' => 'avatar'
  42. ]);
  43. }
  44. /**
  45. * 推荐人
  46. * @return model\relation\HasOne
  47. */
  48. public function spreadUser()
  49. {
  50. return $this->hasOne(User::class, 'uid', 'spread_uid')->field('uid,nickname,avatar')->bind([
  51. 'nickname' => 'nickname',
  52. 'avatar' => 'avatar'
  53. ]);
  54. }
  55. /**
  56. * 管理员姓名
  57. * @return model\relation\HasOne
  58. */
  59. public function admin()
  60. {
  61. return $this->hasOne(SystemAdmin::class, 'id', 'admin_id')->field('id,real_name')->bind([
  62. 'real_name' => 'real_name'
  63. ]);
  64. }
  65. /**
  66. * 用户uid
  67. * @param Model $query
  68. * @param $value
  69. */
  70. public function searchUidAttr($query, $value)
  71. {
  72. if (is_array($value))
  73. $query->whereIn('uid', $value);
  74. else
  75. $query->where('uid', $value);
  76. }
  77. /**
  78. * 门店ID
  79. * @param $query
  80. * @param $value
  81. */
  82. public function searchStoreIdAttr($query, $value)
  83. {
  84. if ($value !== '') $query->where('store_id', $value);
  85. }
  86. /**
  87. * 门店店员ID
  88. * @param $query
  89. * @param $value
  90. */
  91. public function searchStaffIdAttr($query, $value)
  92. {
  93. if ($value) $query->where('staff_id', $value);
  94. }
  95. /**
  96. * 推广人uid
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchSpreadUidAttr($query, $value)
  101. {
  102. if (is_array($value))
  103. $query->whereIn('spread_uid', $value);
  104. else
  105. $query->where('spread_uid', $value);
  106. }
  107. }