Withdraw.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Withdraw extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'withdraw';
  9. static public function audit($id)
  10. {
  11. $data = Withdraw::find($id);
  12. $res['code'] = false;
  13. if (!empty($data)) {
  14. $data = $data->toArray();
  15. unset($data['create_time']);
  16. $data['status'] = 1;
  17. $MemberBankcard = MemberBankcard::find($data['bid']);
  18. if (!empty($MemberBankcard)) {
  19. $MemberBankcard = $MemberBankcard->toArray();
  20. if ($MemberBankcard['ptype'] == 3) {
  21. if ($data['pay_from'] == 'mp') {
  22. $Openid = Openid::getMpOpenidbyuid($MemberBankcard['uid']);
  23. } else {
  24. $Openid = Openid::getWxappOpenidbyuid($MemberBankcard['uid']);
  25. }
  26. if (!empty($Openid)) {
  27. $wxpay_settings = Paymethod::getwx_settings();
  28. $actual_amounts = round($data['actual_amounts'], 2);
  29. $actual_amounts = intval($actual_amounts * 100);
  30. if ($wxpay_settings['transfertype'] == '1') {
  31. $payment = \app\samos\wechat\WxPaymethod::makepay($data['pay_from']);
  32. $result = $payment->transfer->toBalance([
  33. 'partner_trade_no' => $data['withdraw_sn'], // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  34. 'openid' => $Openid,
  35. 'check_name' => 'FORCE_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
  36. 're_user_name' => $MemberBankcard['name'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  37. 'amount' => $actual_amounts, // 企业付款金额,单位为分
  38. 'desc' => '提现', // 企业付款操作说明信息。必填
  39. ]);
  40. if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
  41. $res['code'] = Withdraw::update($data);
  42. } else {
  43. $res['code'] = false;
  44. $res['return_msg'] = $result['return_msg'];
  45. $res['err_code_des'] = $result['err_code_des'];
  46. }
  47. } elseif ($wxpay_settings['transfertype'] == '2') {
  48. $payment = \app\samos\wechat\WxPaymethod::makepayv3($data['pay_from']);
  49. $result = $payment->batchs([
  50. 'out_batch_no' => 'plfk' . $data['withdraw_sn'],
  51. 'batch_name' => '用户佣金提现',
  52. 'batch_remark' => '用户佣金提现',
  53. 'total_amount' => $actual_amounts,
  54. 'transfer_detail_list' => [
  55. [
  56. 'out_detail_no' => $data['withdraw_sn'],
  57. 'transfer_amount' => $actual_amounts,
  58. 'transfer_remark' => '用户佣金提现',
  59. 'openid' => $Openid,
  60. 'user_name' => ''
  61. ]
  62. ]
  63. ]);
  64. if (isset($result['code']) && isset($result['message'])) {
  65. $res['code'] = false;
  66. $res['return_msg'] = $result['message'];
  67. $res['err_code_des'] = $result['err_code_des'];
  68. }else{
  69. $res['code'] = Withdraw::update($data);
  70. }
  71. } else {
  72. $res['code'] = Withdraw::update($data);
  73. }
  74. }
  75. } else {
  76. $res['code'] = Withdraw::update($data);
  77. }
  78. }
  79. }
  80. return $res;
  81. }
  82. }