Withdraw.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: scstf
  5. * Date: 2019/4/18
  6. * Time: 14:09
  7. */
  8. namespace App\Api\Model;
  9. use \System\Model;
  10. use Biz\Account\AccountManager;
  11. class Withdraw extends Model
  12. {
  13. /**
  14. * 中奖记录
  15. *
  16. * @access public
  17. * @return String
  18. */
  19. public function withdrawalRequest()
  20. {
  21. // 获取用户信息
  22. $accountManagerClass = new AccountManager;
  23. $userInfo = $accountManagerClass -> getCurrentUser();
  24. if (empty($userInfo['identity'])) {
  25. Render([], '2001', lang('Common','Api') -> get('user does login'));
  26. }
  27. // 验证提款金额小于一百
  28. if (!$_POST['money'] || $_POST['money'] < 100) {
  29. Render([], '2112', lang('Common','Api') -> get('cash withdrawal less than 100'));
  30. }
  31. $accountDetailedWhere = array();
  32. // 用户ID
  33. $accountDetailedWhere['account_identity'] = $userInfo['identity'];
  34. $accountDetailedSelect = ['available_cash', 'cash'];
  35. $accountDetailed = lm('account_detailed', "commons");
  36. // 获取用户可提现金额
  37. $accountInfo = $accountDetailed -> accountDetailed($accountDetailedSelect, $accountDetailedWhere);
  38. // 验证提款额度大于可提现余额
  39. if($accountInfo['available_cash'] < $_POST['money']) {
  40. Render([], '2112', lang('Common','Api') -> get('insufficient amount of account'));
  41. }
  42. //验证交易密码
  43. $payPasswordWhere['account_identity'] = $userInfo['identity'];
  44. $payPasswordSelect = ['encryption'];
  45. $payPassword = lm('pay_password', "commons");
  46. // 获取加密盐值
  47. $accountPwdInfo = $payPassword -> payPassword($payPasswordSelect, $payPasswordWhere);
  48. $pwd = $_POST['payPassword'];
  49. $encryptionPwd = md5(md5($accountPwdInfo["encryption"] . $pwd));
  50. $verifyPayPwdWhere['account_identity'] = $userInfo['identity'];
  51. $verifyPayPwdWhere['pay_password'] = $encryptionPwd;
  52. $verifyPayPwdSelect = ['id'];
  53. // 验证支付密码
  54. $verifyPayPwd = $payPassword -> payPassword($verifyPayPwdSelect, $verifyPayPwdWhere);
  55. if (!$verifyPayPwd['id']) {
  56. Render([], '2020', lang('Common','Api') -> get('payment password error'));
  57. }
  58. // 用户银行卡
  59. $bankCardWhere['account_identity'] = $userInfo['identity'];
  60. $bankCardWhere['bank_number'] = $_POST['bank_number'];
  61. $bankCardSelect = ['bank_number', 'account_name', 'bank_address', 'bank_name'];
  62. $getBankCardInfo = lm('account_bank', "commons");
  63. // 用户是否绑定该银行卡
  64. $bankCardInfo = $getBankCardInfo -> bankCard($bankCardSelect, $bankCardWhere);
  65. if(!$bankCardInfo['bank_number']) {
  66. Render([], '2114', lang('Common','Api') -> get('the bank card is not bound'));
  67. }
  68. //生成订单id
  69. $order_id = OrderID();
  70. //提现后总金额
  71. $cashMoney = floatval($accountInfo['cash']) - floatval($_POST['money']);
  72. //提现后可提现金额
  73. $availableCashMoney = floatval($accountInfo['available_cash']) - floatval($_POST['money']);
  74. $moneyTakeData = array(
  75. 'info_identity' => UUID(),
  76. 'order_id' => $order_id,
  77. 'account_identity' => $userInfo['identity'],
  78. 'account_name' => $userInfo['name'],
  79. 'money' => $_POST['money'],
  80. 'apply_time' => date('Y-m-d H:i:s', time()),
  81. 'apply_date' => date('Y-m-d', time()),
  82. 'bank_info' => $bankCardInfo['bank_name'],
  83. 'bank_no' => $_POST['bank_number'],
  84. 'bank_address' => $bankCardInfo['bank_address'],
  85. 'bank_user' => $bankCardInfo['account_name'],
  86. 'money_cash' => $cashMoney,
  87. );
  88. //验证三分钟内不能重复提交提现申请
  89. $moneyTake = lm('money_take', 'commons');
  90. $takeRecordWhere['account_identity'] = $userInfo['identity'];
  91. $takeRecordSelect = ['apply_time'];
  92. $moneyTakeInfo = $moneyTake -> takeRecord($takeRecordSelect, $takeRecordWhere);
  93. $applyTime = date('Y-m-d H:i:s', time() - 300);
  94. if ($moneyTakeInfo) {
  95. if (!empty($moneyTakeInfo['apply_time']) && $moneyTakeInfo['apply_time'] >= $applyTime) {
  96. Render([], '2051', lang('Common','Api') -> get('you have submitted your application for withdrawal'));
  97. }
  98. }
  99. // 添加提现记录
  100. _beginTransaction();
  101. try {
  102. $insertTake = $moneyTake -> insertTake($moneyTakeData);
  103. if ($insertTake) {
  104. $accountUpdateData = [
  105. 'available_cash' => $availableCashMoney,
  106. 'cash' => $cashMoney,
  107. ];
  108. $updateAccountWhere['account_identity'] = $userInfo['identity'];
  109. // 修改用户信息表剩余金额
  110. $updateResult = $accountDetailed -> updateDetailed($updateAccountWhere, $accountUpdateData);
  111. if ($updateResult > 0) {
  112. _commit();
  113. Render([], '40453', lang('Common','Api') -> get('application has been submitted and customer service is under review'));
  114. }
  115. }
  116. } catch (PDOException $e) {
  117. _rollBack();
  118. Render([], '141313', lang('Common','Api') -> get('the application failed. Please try again'));
  119. }
  120. }
  121. }