UserRecharge.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 app\model\store\SystemStoreStaff;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\model;
  16. /**
  17. * Class UserRecharge
  18. * @package app\model\user
  19. */
  20. class UserRecharge extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'user_recharge';
  33. protected $insert = ['add_time'];
  34. protected function setAddTimeAttr()
  35. {
  36. return time();
  37. }
  38. /**
  39. * 关联user
  40. * @return model\relation\HasOne
  41. */
  42. public function user()
  43. {
  44. return $this->hasOne(User::class, 'uid', 'uid', false)->bind([
  45. 'nickname' => 'nickname',
  46. 'avatar' => 'avatar',
  47. 'phone' => 'phone',
  48. 'now_money' => 'now_money',
  49. 'integral' => 'integral',
  50. 'delete_time' => 'delete_time'
  51. ]);
  52. }
  53. /**
  54. * @return model\relation\HasOne
  55. */
  56. public function staff()
  57. {
  58. return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')
  59. ->field(['id', 'uid', 'store_id', 'staff_name'])
  60. ->bind([
  61. 'staff_uid' => 'uid',
  62. 'staff_store_id' => 'store_id',
  63. 'staff_name' => 'staff_name'
  64. ]);;
  65. }
  66. /**
  67. * 用户uid
  68. * @param Model $query
  69. * @param $value
  70. */
  71. public function searchUidAttr($query, $value)
  72. {
  73. if (is_array($value))
  74. $query->whereIn('uid', $value);
  75. else
  76. $query->where('uid', $value);
  77. }
  78. /**
  79. * 门店ID
  80. * @param $query
  81. * @param $value
  82. */
  83. public function searchStoreIdAttr($query, $value)
  84. {
  85. if ($value !== '') {
  86. if ($value == -1) {//所有门店
  87. $query->where('store_id', '>', 0);
  88. } else {
  89. $query->where('store_id', $value);
  90. }
  91. }
  92. }
  93. /**
  94. * 门店店员ID
  95. * @param $query
  96. * @param $value
  97. */
  98. public function searchStaffIdAttr($query, $value)
  99. {
  100. if ($value) $query->where('staff_id', $value);
  101. }
  102. /**
  103. * 订单号
  104. * @param Model $query
  105. * @param $value
  106. */
  107. public function searchOrderIdAttr($query, $value)
  108. {
  109. $query->where('order_id', $value);
  110. }
  111. /**
  112. * 充值类型
  113. * @param Model $query
  114. * @param $value
  115. */
  116. public function searchRechargeTypeAttr($query, $value)
  117. {
  118. $query->where('recharge_type', $value);
  119. }
  120. /**退款金额
  121. * @param $query
  122. * @param $value
  123. */
  124. public function searchRefundPriceAttr($query, $value)
  125. {
  126. $query->where('refund_price', $value);
  127. }
  128. /**
  129. * 是否支付
  130. * @param Model $query
  131. * @param $value
  132. */
  133. public function searchPaidAttr($query, $value)
  134. {
  135. if ($value !== '') $query->where('paid', $value);
  136. }
  137. /**
  138. * 模糊搜索
  139. * @param Model $query
  140. * @param $value
  141. */
  142. public function searchLikeAttr($query, $value)
  143. {
  144. $query->where(function ($query) use ($value) {
  145. $query->whereLike('uid|order_id', "%" . $value . "%")->whereOr('uid', 'in', function ($query) use ($value) {
  146. $query->name('user')->whereLike('nickname|real_name|phone', "%" . $value . "%")->field('uid')->select();
  147. });
  148. });
  149. }
  150. public function searchChannelTypeAttr($query, $value)
  151. {
  152. if ($value !== '') $query->where('channel_type', $value);
  153. }
  154. }