UserExtract.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 think\model;
  15. /**
  16. * Class UserExtract
  17. * @package app\model\user
  18. */
  19. class UserExtract extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'user_extract';
  32. //审核中
  33. const AUDIT_STATUS = 0;
  34. //未通过
  35. const FAIL_STATUS = -1;
  36. //已提现
  37. const SUCCESS_STATUS = 1;
  38. /**
  39. * 状态
  40. * @var string[]
  41. */
  42. protected static $status = [
  43. -1 => '未通过',
  44. 0 => '审核中',
  45. 1 => '已提现',
  46. 2 => '待二次审核',
  47. ];
  48. /**
  49. * 关联user
  50. * @return model\relation\HasOne
  51. */
  52. public function user()
  53. {
  54. return $this->hasOne(User::class, 'uid', 'uid');
  55. }
  56. /**
  57. * 用户uid
  58. * @param Model $query
  59. * @param $value
  60. */
  61. public function searchUidAttr($query, $value)
  62. {
  63. if (is_array($value))
  64. $query->whereIn('uid', $value);
  65. else
  66. $query->where('uid', $value);
  67. }
  68. /**
  69. * 提现方式
  70. * @param Model $query
  71. * @param $value
  72. */
  73. public function searchExtractTypeAttr($query, $value)
  74. {
  75. if ($value != '') $query->where('extract_type', $value);
  76. }
  77. /**
  78. * 提现方式
  79. * @param Model $query
  80. * @param $value
  81. */
  82. public function searchTradeNumberAttr($query, $value)
  83. {
  84. if ($value != '') $query->where('trade_number', $value);
  85. }
  86. /**
  87. * 提现方式
  88. * @param Model $query
  89. * @param $value
  90. */
  91. public function searchEnterpriseOrderIdAttr($query, $value)
  92. {
  93. if ($value != '') $query->where('enterprise_order_id', $value);
  94. }
  95. /**
  96. * 审核状态
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchStatusAttr($query, $value)
  101. {
  102. if (is_array($value)) {
  103. if ($value) {
  104. $query->whereIn('status', $value);
  105. }
  106. }else {
  107. if ($value !== '') {
  108. $query->where('status', $value);
  109. }
  110. }
  111. }
  112. /**
  113. * 模糊搜索
  114. * @param Model $query
  115. * @param $value
  116. */
  117. public function searchLikeAttr($query, $value)
  118. {
  119. if ($value) {
  120. $query->where(function ($query) use ($value) {
  121. $query->where('real_name|id|bank_code|alipay_code', 'LIKE', "%$value%")->whereOr('uid', 'in', function ($query) use ($value) {
  122. $query->name('user')->whereLike('nickname', '%' . $value . '%')->field('uid')->select();
  123. });
  124. });
  125. }
  126. }
  127. }