You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\model\user;
  3. use app\model\system\admin\SystemAdmin;
  4. use crmeb\basic\BaseModel;
  5. use crmeb\traits\ModelTrait;
  6. use think\model;
  7. /**
  8. * Class UserSpread
  9. * @package app\model\user
  10. */
  11. class UserSpread extends BaseModel
  12. {
  13. use ModelTrait;
  14. /**
  15. * 数据表主键
  16. * @var string
  17. */
  18. protected $pk = 'id';
  19. /**
  20. * 模型名称
  21. * @var string
  22. */
  23. protected $name = 'user_spread';
  24. /**
  25. * 用户
  26. * @return model\relation\HasOne
  27. */
  28. public function user()
  29. {
  30. return $this->hasOne(User::class, 'uid', 'uid')->field('uid,nickname,nickname as title,avatar')->bind([
  31. 'nickname' => 'nickname',
  32. 'title' => 'title',
  33. 'avatar' => 'avatar'
  34. ]);
  35. }
  36. /**
  37. * 推荐人
  38. * @return model\relation\HasOne
  39. */
  40. public function spreadUser()
  41. {
  42. return $this->hasOne(User::class, 'uid', 'spread_uid')->field('uid,nickname,avatar')->bind([
  43. 'nickname' => 'nickname',
  44. 'avatar' => 'avatar'
  45. ]);
  46. }
  47. /**
  48. * 管理员姓名
  49. * @return model\relation\HasOne
  50. */
  51. public function admin()
  52. {
  53. return $this->hasOne(SystemAdmin::class, 'id', 'admin_id')->field('id,real_name')->bind([
  54. 'real_name' => 'real_name'
  55. ]);
  56. }
  57. /**
  58. * 用户uid
  59. * @param Model $query
  60. * @param $value
  61. */
  62. public function searchUidAttr($query, $value)
  63. {
  64. if (is_array($value))
  65. $query->whereIn('uid', $value);
  66. else
  67. $query->where('uid', $value);
  68. }
  69. /**
  70. * 门店ID
  71. * @param $query
  72. * @param $value
  73. */
  74. public function searchStoreIdAttr($query, $value)
  75. {
  76. if ($value) $query->where('store_id', $value);
  77. }
  78. /**
  79. * 门店店员ID
  80. * @param $query
  81. * @param $value
  82. */
  83. public function searchStaffIdAttr($query, $value)
  84. {
  85. if ($value) $query->where('staff_id', $value);
  86. }
  87. /**
  88. * 推广人uid
  89. * @param Model $query
  90. * @param $value
  91. */
  92. public function searchSpreadUidAttr($query, $value)
  93. {
  94. if (is_array($value))
  95. $query->whereIn('spread_uid', $value);
  96. else
  97. $query->where('spread_uid', $value);
  98. }
  99. }