123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace App\Dao\Bank;
- use App\Cache\FinanceCache;
- use App\Consts\FinanceConsts;
- use App\Models\Bank\Banks;
- use App\Models\Bank\ChannelUserCashAccount;
- class BankDao
- {
- /**
- * @return mixed
- */
- public function bankList()
- {
- return Banks::select('id', 'name', 'code', 'source')
- ->where('is_show', 1)
- ->where('source', 'LIANLIANPAY')
- ->orderBy('id', 'asc')
- ->get();
- }
- /**
- * @param $bankId
- * @return mixed
- */
- public function getBank($bankId)
- {
- return Banks::select('id', 'name', 'code', 'source')
- ->where('id', $bankId)
- ->where('is_show', 1)
- ->first();
- }
- /**
- * @param $channelUserId
- * @param int $isCompany
- * @return array
- */
- public function getValidCashAccountsByChannelUserId($channelUserId, int $isCompany = -1): array
- {
- if (empty($channelUserId)) {
- return [];
- }
- $query = ChannelUserCashAccount::where('channel_user_id', $channelUserId)->where('deleted_at', '=', null);
- // 对公对私
- if (in_array($isCompany, [0, 1])) {
- $query->where('is_company', $isCompany);
- } else {
- $query->orderBy('is_company', 'desc');
- }
- $result = $query->orderBy('updated_at', 'desc')->get();
- return $result ? $result->toArray() : [];
- }
- /**
- * @param $id
- * @return array
- */
- public function getValidCashAccountById($id): array
- {
- if (empty($id)) {
- return [];
- }
- $result = ChannelUserCashAccount::where('id', $id)->where('deleted_at', '=', null)->first();
- return $result ? $result->toArray() : [];
- }
- /**
- * 添加银行账号
- *
- * @param $param
- * @return bool|int
- */
- public function addCashAccount($param)
- {
- $channelUserId = (int)getProp($param, 'channel_user_id');
- $cardNumber = trim(getProp($param, 'card_number'));
- if (empty($channelUserId) || empty($cardNumber) || empty($param)) {
- return false;
- }
- $data = [
- 'channel_user_id' => $channelUserId,
- 'account_name' => trim(getProp($param, 'account_name')),
- 'identity_card' => trim(getProp($param, 'identity_card')),
- 'card_number' => $cardNumber,
- 'account_bank' => trim(getProp($param, 'account_bank')),
- 'bank' => trim(getProp($param, 'bank')),
- 'province' => trim(getProp($param, 'province')),
- 'phone' => trim(getProp($param, 'phone')),
- 'bank_id' => (int)getProp($param, 'bank_id'),
- 'is_company' => (int)getProp($param, 'is_company'),
- 'status' => FinanceConsts::STATUS_FORBID_UPDATE,
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ];
- return ChannelUserCashAccount::insertGetId($data);
- }
- /**
- * 删除账号
- *
- * @param $cardId
- * @return bool
- */
- public function deleteCashAccountByCardId($cardId): bool
- {
- if (empty($cardId)) {
- return false;
- }
- return ChannelUserCashAccount::where('id', $cardId)
- ->update(['deleted_at' => date('Y-m-d H:i:s')]);
- }
- /**
- * @param $channelUserId
- * @return bool
- */
- public function deleteCashAccountByChannelUserId($channelUserId): bool
- {
- if (empty($channelUserId)) {
- return false;
- }
- return ChannelUserCashAccount::where('channel_user_id', $channelUserId)
- ->update(['deleted_at' => date('Y-m-d H:i:s')]);
- }
- /**
- * 校验手机验证码
- *
- * @param $channelId
- * @param $phone
- * @param $code
- * @return bool
- */
- public function checkSmsCode($channelId, $phone, $code): bool
- {
- if (empty($code)) {
- return false;
- }
- // 对比验证码
- $phoneCode = FinanceCache::getSmsCode($channelId, $phone);
- if (empty($phoneCode) || (string)$code !== (string)$phoneCode) {
- return false;
- }
- return true;
- }
- }
|