WithdrawDao.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Dao\Bank;
  3. use App\Consts\FinanceConsts;
  4. use App\Models\Withdraw\ChannelWithDrawCash;
  5. class WithdrawDao
  6. {
  7. /**
  8. * 获取多张卡今日提现记录
  9. *
  10. * @param $cardNumbers
  11. * @param $startTime
  12. * @param $endTime
  13. * @return mixed
  14. */
  15. public function getWithDrawLogsByBankAccountIds($cardNumbers, $startTime, $endTime)
  16. {
  17. return ChannelWithDrawCash::whereIn('bank_account', $cardNumbers)
  18. ->where('created_at', '>=', $startTime)
  19. ->where('created_at', '<=', $endTime)
  20. ->get();
  21. }
  22. /**
  23. * 提现记录
  24. *
  25. * @param $param
  26. * @return mixed
  27. */
  28. public function getWithdrawCashes($param)
  29. {
  30. $query = ChannelWithDrawCash::select('channel_withdraw_cashes.amount', 'channel_withdraw_cashes.status',
  31. 'bank_account', 'account_name', 'channel_withdraw_cashes.created_at', 'payments.pay_time')
  32. ->leftJoin('payments', 'payments.withdraw_cash_id', 'channel_withdraw_cashes.id');
  33. // 站点
  34. $channelId = (int)getProp($param, 'channel_id');
  35. if ($channelId) {
  36. $query->where('distribution_channel_id', $channelId);
  37. }
  38. // 状态
  39. $status = getProp($param, 'status');
  40. if ($status && in_array($status, [FinanceConsts::CHECK_PENDING, FinanceConsts::AUDIT_FAILED, '待打款', '已打款'])) {
  41. if ($status == '待打款') {
  42. $query->whereIn('channel_withdraw_cashes.status', [
  43. FinanceConsts::ARTIFICAL_WAITTING_PAID,
  44. FinanceConsts::AUTO_WAITTING_PAID
  45. ]);
  46. } elseif ($status == '已打款') {
  47. $query->whereIn('channel_withdraw_cashes.status', [
  48. FinanceConsts::ARTIFICAL_PAID_SUCCESS,
  49. FinanceConsts::AUTO_PAID_SUCCESS
  50. ]);
  51. } else {
  52. $query->where('channel_withdraw_cashes.status', $status);
  53. }
  54. }
  55. // 时间
  56. $dateRange = getProp($param, 'date_range');
  57. if ($dateRange) {
  58. [$startDate, $endDate] = explode(',', $dateRange);
  59. if ($startDate && $endDate && $startDate <= $endDate) {
  60. $query->where('channel_withdraw_cashes.created_at', '>=', date('Y-m-d 00:00:00', strtotime($startDate)));
  61. $query->where('channel_withdraw_cashes.created_at', '<=', date('Y-m-d 23:59:50', strtotime($endDate)));
  62. }
  63. }
  64. return $query->orderBy('channel_withdraw_cashes.id', 'desc')->paginate();
  65. }
  66. /**
  67. * 判断渠道在日期内是否有提现
  68. *
  69. * @param $channelId
  70. * @param $startTime
  71. * @param $endTime
  72. * @return mixed
  73. */
  74. public function checkChannelIdIsInWithDraw($channelId, $startTime, $endTime)
  75. {
  76. return ChannelWithDrawCash::where('distribution_channel_id', $channelId)
  77. ->where('created_at', '>=', $startTime)
  78. ->where('created_at', '<=', $endTime)
  79. ->exists();
  80. }
  81. /**
  82. * 增加提现单
  83. *
  84. * @param $data
  85. */
  86. public function addWithDrawCashes($data)
  87. {
  88. return ChannelWithDrawCash::create($data);
  89. }
  90. /**
  91. * 最近一笔提现中
  92. *
  93. * @param $channelId
  94. * @return mixed
  95. */
  96. public function getLatestWithdrawingCash($channelId)
  97. {
  98. return ChannelWithDrawCash::where('distribution_channel_id', $channelId)
  99. ->whereIn('status', [
  100. FinanceConsts::CHECK_PENDING, FinanceConsts::AUDITING,
  101. FinanceConsts::AUDIT_PASS, FinanceConsts::WAITTING_PAID
  102. ])
  103. ->orderBy('id', 'desc')
  104. ->first();
  105. }
  106. }