CashAccountService.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/4
  6. * Time: 上午10:20
  7. */
  8. namespace App\Modules\Finance\Services;
  9. use App\Modules\Finance\Models\Bank;
  10. use App\Modules\Finance\Models\CashAccount;
  11. class CashAccountService
  12. {
  13. /**
  14. * 获取渠道银行账号信息
  15. * @param $channelId
  16. * @return mixed
  17. */
  18. public static function getCashAccountSingle($channelId) {
  19. $cashAccount = CashAccount::getByDistributionChannel($channelId);
  20. return $cashAccount;
  21. }
  22. /**
  23. * 添加银行账号
  24. * @param $channelId
  25. * @param $account_name
  26. * @param $identity_card
  27. * @param $card_number
  28. * @param $account_bank 开户支行
  29. * @param $bank_id 交易银行ID
  30. * @param $bank 交易银行
  31. * @param $province
  32. * @param $is_company 0:私人; 1:公司
  33. * @param String $phone 电话号码
  34. * @return mixed
  35. */
  36. public static function addCashAccount($channelId, $account_name, $identity_card, $card_number, $account_bank, $bank_id, $bank, $province = '', $is_company = 0, $phone = '') {
  37. $bankD = BankService::getBankSingle($bank_id);
  38. if($is_company == 0 || $is_company == 1) {
  39. } else {
  40. $is_company = 0;
  41. }
  42. $data['distribution_channel_id'] = $channelId;
  43. $data['account_name'] = trim($account_name);
  44. $data['identity_card'] = trim($identity_card);
  45. $data['card_number'] = trim($card_number);
  46. $data['account_bank'] = trim($account_bank);
  47. $data['bank'] = trim($bank);
  48. $data['bank_id'] = $bank_id;
  49. $data['province'] = trim($province);
  50. $data['status'] = -1;
  51. $data['is_company'] = $is_company;
  52. $data['phone'] = trim($phone);
  53. $cashAccount = CashAccount::create($data);
  54. return $cashAccount;
  55. }
  56. /**
  57. * 账号是否可以编辑
  58. * @param $channelId
  59. * @return bool true:可以编辑 false:不可以编辑
  60. */
  61. public static function isEditCashAccount($channelId) {
  62. $cashAccount = self::getCashAccountSingle($channelId);
  63. if(!empty($cashAccount) && $cashAccount['status'] == -1) {
  64. return false;
  65. }
  66. return true;
  67. }
  68. /**
  69. * 更新账号信息
  70. * @param $channelId
  71. * @param string $account_name
  72. * @param string $identity_card
  73. * @param string $card_number
  74. * @param string $account_bank
  75. * @param string $bank_id 交易银行ID
  76. * @param string $bank
  77. * @param string $province
  78. * @param string $is_company 0:私人; 1:公司
  79. * @param String $phone 电话号码
  80. * @return mixed|void
  81. */
  82. public static function updateCashAccount($channelId, $account_name='', $identity_card='', $card_number='', $account_bank='', $bank_id = '', $bank='', $province='', $is_company = '', $phone = '') {
  83. $cashAccount = self::getCashAccountSingle($channelId);
  84. if(empty($cashAccount)) {
  85. return '';
  86. }
  87. if($is_company == 0 || $is_company == 1) {
  88. } else {
  89. $is_company = '';
  90. }
  91. if($channelId) {
  92. $cashAccount['distribution_channel_id'] = $channelId;
  93. }
  94. if($account_name) {
  95. $cashAccount['account_name'] = $account_name;
  96. }
  97. if($identity_card) {
  98. $cashAccount['identity_card'] = $identity_card;
  99. }
  100. if($card_number) {
  101. $cashAccount['card_number'] = $card_number;
  102. }
  103. if($account_bank) {
  104. $cashAccount['account_bank'] = $account_bank;
  105. }
  106. if($bank_id) {
  107. $cashAccount['bank_id'] = $bank_id;
  108. }
  109. if($bank) {
  110. $cashAccount['bank'] = $bank;
  111. }
  112. if($province) {
  113. $cashAccount['province'] = $province;
  114. }
  115. if(is_numeric($is_company) && in_array($is_company, [0, 1])) {
  116. $cashAccount['is_company'] = $is_company;
  117. }
  118. if($phone) {
  119. $cashAccount['phone'] = $phone;
  120. }
  121. $cashAccount['status'] = -1;
  122. $cashAccount->save();
  123. return $cashAccount;
  124. }
  125. /**
  126. * 更新账号可编辑修改
  127. * @param $channelId
  128. * @return mixed|void
  129. */
  130. public static function updateCashAccountEdit($channelId) {
  131. $cashAccount = self::getCashAccountSingle($channelId);
  132. if(empty($cashAccount)) {
  133. return;
  134. }
  135. $cashAccount['status'] = 0;
  136. $cashAccount->save();
  137. return $cashAccount;
  138. }
  139. /**
  140. * 渠道账户是否设置
  141. * @param $channelId
  142. * @return bool true:已经设置 false:没有设置
  143. */
  144. public static function isCashAccountExits($channelId) {
  145. $cashAccount = self::getCashAccountSingle($channelId);
  146. if(empty($cashAccount)) {
  147. return false;
  148. }
  149. if(empty($cashAccount['account_name'])
  150. || empty($cashAccount['card_number'])
  151. || empty($cashAccount['bank'])) {
  152. return false;
  153. }
  154. return true;
  155. }
  156. }