UserBrokerage.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use app\model\order\StoreOrder;
  15. use think\model;
  16. /**
  17. * 用户佣金
  18. * Class UserBrokerage
  19. * @package app\model\user
  20. */
  21. class UserBrokerage extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'user_brokerage';
  34. /**
  35. * 关联订单表
  36. * @return UserBill|model\relation\HasOne
  37. */
  38. public function order()
  39. {
  40. return $this->hasOne(StoreOrder::class, 'id', 'link_id')->field(['id', 'total_num'])->bind(['total_num']);
  41. }
  42. /**
  43. * 关联用户
  44. * @return model\relation\HasOne
  45. */
  46. public function user()
  47. {
  48. return $this->hasOne(User::class, 'uid', 'uid', false);
  49. }
  50. /**
  51. * 用户uid
  52. * @param Model $query
  53. * @param $value
  54. */
  55. public function searchUidAttr($query, $value)
  56. {
  57. if ($value !== '') {
  58. if (is_array($value))
  59. $query->whereIn('uid', $value);
  60. else
  61. $query->where('uid', $value);
  62. }
  63. }
  64. /**
  65. * 关联id
  66. * @param Model $query
  67. * @param $value
  68. */
  69. public function searchLinkIdAttr($query, $value)
  70. {
  71. if (is_array($value))
  72. $query->whereIn('link_id', $value);
  73. else
  74. $query->where('link_id', $value);
  75. }
  76. /**
  77. * 支出|获得
  78. * @param Model $query
  79. * @param $value
  80. */
  81. public function searchPmAttr($query, $value)
  82. {
  83. if ($value !== '') $query->where('pm', $value);
  84. }
  85. /**
  86. * 类型
  87. * @param Model $query
  88. * @param $value
  89. */
  90. public function searchTypeAttr($query, $value)
  91. {
  92. if ($value !== '') {
  93. if (is_array($value))
  94. $query->whereIn('type', $value);
  95. else
  96. $query->where('type', $value);
  97. }
  98. }
  99. /**
  100. * @param Model $query
  101. * @param $value
  102. */
  103. public function searchNotTypeAttr($query, $value)
  104. {
  105. if ($value !== '') {
  106. if (is_array($value))
  107. $query->whereNotIn('type', $value);
  108. else
  109. $query->where('type', '<>', $value);
  110. }
  111. }
  112. /**
  113. * 状态 0:带确定 1:有效 -1:无效
  114. * @param Model $query
  115. * @param $value
  116. */
  117. public function searchStatusAttr($query, $value)
  118. {
  119. $query->where('status', $value);
  120. }
  121. /**
  122. * 是否收货 0:未收货 1:已收货
  123. * @param Model $query
  124. * @param $value
  125. */
  126. public function searchTakeAttr($query, $value)
  127. {
  128. $query->where('take', $value);
  129. }
  130. /**
  131. * 模糊搜索
  132. * @param Model $query
  133. * @param $value
  134. */
  135. public function searchLikeAttr($query, $value)
  136. {
  137. if ($value !== '') {
  138. $query->where(function ($query) use ($value) {
  139. $query->where('uid|title', 'like', "%$value%")->whereOr('uid', 'in', function ($query) use ($value) {
  140. $query->name('user')->whereLike('uid|account|nickname|phone', '%' . $value . '%')->field('uid')->select();
  141. });
  142. });
  143. }
  144. }
  145. /**
  146. * 时间
  147. * @param Model $query
  148. * @param $value
  149. */
  150. public function searchAddTimeAttr($query, $value)
  151. {
  152. if (is_string($value)) $query->whereTime($query, $value);
  153. if (is_array($value) && count($value) == 2) $query->whereTime('add_time', 'between', $value);
  154. }
  155. }