UserRecharge.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * @param $query
  80. * @param $value
  81. */
  82. public function searchRefundPriceAttr($query, $value)
  83. {
  84. $query->where('refund_price', $value);
  85. }
  86. /**
  87. * 是否支付
  88. * @param Model $query
  89. * @param $value
  90. */
  91. public function searchPaidAttr($query, $value)
  92. {
  93. $query->where('paid', $value);
  94. }
  95. /**
  96. * 模糊搜索
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchLikeAttr($query, $value)
  101. {
  102. $query->where(function ($query) use ($value) {
  103. $query->whereLike('uid|order_id', "%" . $value . "%")->whereOr('uid', 'in', function ($query) use ($value) {
  104. $query->name('user')->whereLike('nickname', "%" . $value . "%")->field('uid')->select();
  105. });
  106. });
  107. }
  108. public function searchChannelTypeAttr($query, $value)
  109. {
  110. if ($value !== '') $query->where('channel_type', $value);
  111. }
  112. }