UserExtract.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. ];
  47. /**
  48. * 关联user
  49. * @return model\relation\HasOne
  50. */
  51. public function user()
  52. {
  53. return $this->hasOne(User::class, 'uid', 'uid');
  54. }
  55. /**
  56. * 用户uid
  57. * @param Model $query
  58. * @param $value
  59. */
  60. public function searchUidAttr($query, $value)
  61. {
  62. if (is_array($value))
  63. $query->whereIn('uid', $value);
  64. else
  65. $query->where('uid', $value);
  66. }
  67. /**
  68. * 提现方式
  69. * @param Model $query
  70. * @param $value
  71. */
  72. public function searchExtractTypeAttr($query, $value)
  73. {
  74. if ($value != '') $query->where('extract_type', $value);
  75. }
  76. /**
  77. * 审核状态
  78. * @param Model $query
  79. * @param $value
  80. */
  81. public function searchStatusAttr($query, $value)
  82. {
  83. if ($value !== '') {
  84. $query->where('status', $value);
  85. }
  86. }
  87. /**
  88. * 模糊搜索
  89. * @param Model $query
  90. * @param $value
  91. */
  92. public function searchLikeAttr($query, $value)
  93. {
  94. if ($value) {
  95. $query->where(function ($query) use ($value) {
  96. $query->where('real_name|id|bank_code|alipay_code', 'LIKE', "%$value%")->whereOr('uid', 'in', function ($query) use ($value) {
  97. $query->name('user')->whereLike('nickname', '%' . $value . '%')->field('uid')->select();
  98. });
  99. });
  100. }
  101. }
  102. }