UserRecharge.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 UserRecharge
  17. * @package app\model\user
  18. */
  19. class UserRecharge 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_recharge';
  32. protected $insert = ['add_time'];
  33. protected function setAddTimeAttr()
  34. {
  35. return time();
  36. }
  37. /**
  38. * 关联user
  39. * @return model\relation\HasOne
  40. */
  41. public function user()
  42. {
  43. return $this->hasOne(User::class, 'uid', 'uid')->bind([
  44. 'nickname' => 'nickname',
  45. 'avatar' => 'avatar'
  46. ]);
  47. }
  48. /**
  49. * 用户uid
  50. * @param Model $query
  51. * @param $value
  52. */
  53. public function searchUidAttr($query, $value)
  54. {
  55. if (is_array($value))
  56. $query->whereIn('uid', $value);
  57. else
  58. $query->where('uid', $value);
  59. }
  60. /**
  61. * 订单号
  62. * @param Model $query
  63. * @param $value
  64. */
  65. public function searchOrderIdAttr($query, $value)
  66. {
  67. $query->where('order_id', $value);
  68. }
  69. /**
  70. * 充值类型
  71. * @param Model $query
  72. * @param $value
  73. */
  74. public function searchRechargeTypeAttr($query, $value)
  75. {
  76. $query->where('recharge_type', $value);
  77. }
  78. /**
  79. * 不等于充值类型
  80. * @param Model $query
  81. * @param $value
  82. */
  83. public function searchNoRechargeTypeAttr($query, $value)
  84. {
  85. $query->where('recharge_type', '<>', $value);
  86. }
  87. /**退款金额
  88. * @param $query
  89. * @param $value
  90. */
  91. public function searchRefundPriceAttr($query, $value)
  92. {
  93. $query->where('refund_price', $value);
  94. }
  95. /**
  96. * 是否支付
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchPaidAttr($query, $value)
  101. {
  102. $query->where('paid', $value);
  103. }
  104. /**
  105. * 模糊搜索
  106. * @param Model $query
  107. * @param $value
  108. */
  109. public function searchLikeAttr($query, $value)
  110. {
  111. $query->where(function ($query) use ($value) {
  112. $query->whereLike('uid|order_id', "%" . $value . "%")->whereOr('uid', 'in', function ($query) use ($value) {
  113. $query->name('user')->whereLike('nickname', "%" . $value . "%")->field('uid')->select();
  114. });
  115. });
  116. }
  117. public function searchChannelTypeAttr($query, $value)
  118. {
  119. if ($value !== '') $query->where('channel_type', $value);
  120. }
  121. }