Withdraw.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. *
  5. * User: king/QQ:995265288
  6. * Date: 2018/1/30 上午10:08
  7. * Email: livsyitian@163.com
  8. */
  9. namespace app\backend\modules\finance\models;
  10. class Withdraw extends \app\common\models\Withdraw
  11. {
  12. public function scopeRecords($query)
  13. {
  14. $query->with(['hasOneMember' => function ($query) {
  15. return $query->select('uid', 'mobile', 'realname', 'nickname', 'avatar');
  16. }]);
  17. return parent::scopeRecords($query);
  18. }
  19. public function scopeSearch($query, $search)
  20. {
  21. if($search['member_id']) {
  22. $query->where('member_id',$search['member_id']);
  23. }
  24. if (isset($search['status']) && $search['status'] != "") {
  25. $query->ofStatus($search['status']);
  26. }
  27. if($search['withdraw_sn']) {
  28. $query->ofWithdrawSn($search['withdraw_sn']);
  29. }
  30. if($search['type']) {
  31. $query->whereType($search['type']);
  32. }
  33. if($search['pay_way']) {
  34. $query->where('pay_way', $search['pay_way']);
  35. }
  36. if($search['searchtime']){
  37. $range = [strtotime($search['time']['start']), strtotime($search['time']['end'])];
  38. $query->whereBetween('created_at', $range);
  39. }
  40. if($search['member']) {
  41. $query->whereHas('hasOneMember', function($query)use($search){
  42. return $query->searchLike($search['member']);
  43. });
  44. }
  45. return $query;
  46. }
  47. public static function getTypes()
  48. {
  49. $configs = \app\backend\modules\income\Income::current()->getItems();
  50. return $configs;
  51. }
  52. protected $appends = ['type_data'];
  53. public static function getWithdrawList($search = [])
  54. {
  55. $Model = self::uniacid();
  56. if ($search['status'] == '3') {
  57. $Model->whereNotNull(arrival_at);
  58. } elseif (isset($search['status'])) {
  59. $Model->where('status', $search['status']);
  60. }
  61. if($search['member']) {
  62. $Model->whereHas('hasOneMember', function($query)use($search){
  63. return $query->searchLike($search['member']);
  64. });
  65. }
  66. if($search['withdraw_sn']) {
  67. $Model->where('withdraw_sn', $search['withdraw_sn']);
  68. }
  69. if($search['type']) {
  70. $Model->where('type', $search['type']);
  71. }
  72. if($search['searchtime']){
  73. if($search['times']){
  74. $range = [$search['times']['start'], $search['times']['end']];
  75. $Model->whereBetween('created_at', $range);
  76. }
  77. }
  78. $Model->with(['hasOneMember' => function ($query) {
  79. return $query->select('uid', 'mobile', 'realname', 'nickname', 'avatar');
  80. }]);
  81. return $Model;
  82. }
  83. public static function getAllWithdraw($type)
  84. {
  85. $ids = '';
  86. $total = 0;
  87. $data = self::getWithdrawListForType($type)->get();
  88. if (!is_null($data)) {
  89. foreach ($data as $rows) {
  90. $ids .= $rows->id . ',';
  91. }
  92. }
  93. $ids = rtrim($ids, ',');
  94. $total = count($data);
  95. if ($total == 0 && $ids == '') {
  96. $status = 0;
  97. $msg = '暂无数据';
  98. } elseif ($total != count(explode(',', $ids))) {
  99. $status = -1;
  100. $msg = '数据不符';
  101. } else {
  102. $status = 1;
  103. $msg = 'ok';
  104. }
  105. return ['status' => $status, 'totals' => $total, 'ids' => $ids, 'msg' => $msg];
  106. }
  107. public static function getWithdrawListForType($type, $limit=800, $status=1)
  108. {
  109. $Model = self::uniacid();
  110. switch ($type) {
  111. case 1:
  112. $Model->whereIn('type', ['balance']);
  113. break;
  114. case 2:
  115. $Model->whereNotIn('type', ['balance']);
  116. break;
  117. }
  118. $Model->where('status', $status)
  119. ->where('pay_way', 'alipay')
  120. ->limit($limit)
  121. ->orderBy('created_at', 'desc')
  122. ->get();
  123. return $Model;
  124. }
  125. public static function updateWidthdrawOrderStatus($withdrawId)
  126. {
  127. return self::uniacid()
  128. ->whereIn('id', $withdrawId)
  129. ->update(['status' => 4]);
  130. }
  131. public function rules()
  132. {
  133. return [
  134. 'poundage' => 'numeric|min:0|max:999999999|regex:/^\d+(\.\d{1,2})?$/',
  135. 'withdrawmoney' => 'numeric|min:0|max:999999999',
  136. 'roll_out_limit' => 'regex:/^[0-9]+(.[0-9]{1,2})?$/',
  137. 'poundage_rate' => 'numeric|min:0|max:100|regex:/^[\d]{1,3}+(\.[0-9]{1,2})?$/',
  138. ];
  139. }
  140. public function atributeNames()
  141. {
  142. return [
  143. 'poundage' => "提现手续费",
  144. 'withdrawmoney' => "提现限制金额",
  145. 'roll_out_limit' => "提现额度",
  146. 'poundage_rate' => "提现手续费"
  147. ];
  148. }
  149. }