UserExchange.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 UserExchange 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_exchange';
  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 searchStatusAttr($query, $value)
  73. {
  74. if (is_array($value)) {
  75. if ($value) {
  76. $query->whereIn('status', $value);
  77. }
  78. }else {
  79. if ($value !== '') {
  80. $query->where('status', $value);
  81. }
  82. }
  83. }
  84. /**
  85. * 模糊搜索
  86. * @param Model $query
  87. * @param $value
  88. */
  89. public function searchLikeAttr($query, $value)
  90. {
  91. if ($value) {
  92. $query->where(function ($query) use ($value) {
  93. $query->where('real_name|id|bank_code', 'LIKE', "%$value%")->whereOr('uid', 'in', function ($query) use ($value) {
  94. $query->name('user')->whereLike('nickname', '%' . $value . '%')->field('uid')->select();
  95. });
  96. });
  97. }
  98. }
  99. }