BankDao.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace App\Dao\Bank;
  3. use App\Cache\FinanceCache;
  4. use App\Consts\FinanceConsts;
  5. use App\Models\Bank\Banks;
  6. use App\Models\Bank\ChannelUserCashAccount;
  7. class BankDao
  8. {
  9. /**
  10. * @return mixed
  11. */
  12. public function bankList()
  13. {
  14. return Banks::select('id', 'name', 'code', 'source')
  15. ->where('is_show', 1)
  16. ->where('source', 'LIANLIANPAY')
  17. ->orderBy('id', 'asc')
  18. ->get();
  19. }
  20. /**
  21. * @param $bankId
  22. * @return mixed
  23. */
  24. public function getBank($bankId)
  25. {
  26. return Banks::select('id', 'name', 'code', 'source')
  27. ->where('id', $bankId)
  28. ->where('is_show', 1)
  29. ->first();
  30. }
  31. /**
  32. * @param $channelUserId
  33. * @param int $isCompany
  34. * @return array
  35. */
  36. public function getValidCashAccountsByChannelUserId($channelUserId, int $isCompany = -1): array
  37. {
  38. if (empty($channelUserId)) {
  39. return [];
  40. }
  41. $query = ChannelUserCashAccount::where('channel_user_id', $channelUserId)->where('deleted_at', '=', null);
  42. // 对公对私
  43. if (in_array($isCompany, [0, 1])) {
  44. $query->where('is_company', $isCompany);
  45. } else {
  46. $query->orderBy('is_company', 'desc');
  47. }
  48. $result = $query->orderBy('updated_at', 'desc')->get();
  49. return $result ? $result->toArray() : [];
  50. }
  51. /**
  52. * @param $id
  53. * @return array
  54. */
  55. public function getValidCashAccountById($id): array
  56. {
  57. if (empty($id)) {
  58. return [];
  59. }
  60. $result = ChannelUserCashAccount::where('id', $id)->where('deleted_at', '=', null)->first();
  61. return $result ? $result->toArray() : [];
  62. }
  63. /**
  64. * 添加银行账号
  65. *
  66. * @param $param
  67. * @return bool|int
  68. */
  69. public function addCashAccount($param)
  70. {
  71. $channelUserId = (int)getProp($param, 'channel_user_id');
  72. $cardNumber = trim(getProp($param, 'card_number'));
  73. if (empty($channelUserId) || empty($cardNumber) || empty($param)) {
  74. return false;
  75. }
  76. $data = [
  77. 'channel_user_id' => $channelUserId,
  78. 'account_name' => trim(getProp($param, 'account_name')),
  79. 'identity_card' => trim(getProp($param, 'identity_card')),
  80. 'card_number' => $cardNumber,
  81. 'account_bank' => trim(getProp($param, 'account_bank')),
  82. 'bank' => trim(getProp($param, 'bank')),
  83. 'province' => trim(getProp($param, 'province')),
  84. 'phone' => trim(getProp($param, 'phone')),
  85. 'bank_id' => (int)getProp($param, 'bank_id'),
  86. 'is_company' => (int)getProp($param, 'is_company'),
  87. 'status' => FinanceConsts::STATUS_FORBID_UPDATE,
  88. 'created_at' => date('Y-m-d H:i:s'),
  89. 'updated_at' => date('Y-m-d H:i:s'),
  90. ];
  91. return ChannelUserCashAccount::insertGetId($data);
  92. }
  93. /**
  94. * 删除账号
  95. *
  96. * @param $cardId
  97. * @return bool
  98. */
  99. public function deleteCashAccountByCardId($cardId): bool
  100. {
  101. if (empty($cardId)) {
  102. return false;
  103. }
  104. return ChannelUserCashAccount::where('id', $cardId)
  105. ->update(['deleted_at' => date('Y-m-d H:i:s')]);
  106. }
  107. /**
  108. * @param $channelUserId
  109. * @return bool
  110. */
  111. public function deleteCashAccountByChannelUserId($channelUserId): bool
  112. {
  113. if (empty($channelUserId)) {
  114. return false;
  115. }
  116. return ChannelUserCashAccount::where('channel_user_id', $channelUserId)
  117. ->update(['deleted_at' => date('Y-m-d H:i:s')]);
  118. }
  119. /**
  120. * 校验手机验证码
  121. *
  122. * @param $channelId
  123. * @param $phone
  124. * @param $code
  125. * @return bool
  126. */
  127. public function checkSmsCode($channelId, $phone, $code): bool
  128. {
  129. if (empty($code)) {
  130. return false;
  131. }
  132. // 对比验证码
  133. $phoneCode = FinanceCache::getSmsCode($channelId, $phone);
  134. if (empty($phoneCode) || (string)$code !== (string)$phoneCode) {
  135. return false;
  136. }
  137. return true;
  138. }
  139. }