WithdrawController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1;
  12. use app\jobs\system\CapitalFlowJob;
  13. use app\Request;
  14. use app\services\user\UserExtractServices;
  15. use app\services\user\UserServices;
  16. use crmeb\basic\BaseController;
  17. use crmeb\services\WithdrawService;
  18. /**
  19. * 公共类
  20. * Class PublicController
  21. * @package app\controller\api
  22. */
  23. class WithdrawController extends BaseController
  24. {
  25. public function notify(Request $request)
  26. {
  27. $data = $request->post();
  28. if (!isset($data['sign'])) {
  29. @file_put_contents('notify.txt', '未接受到签名' . json_encode($data) . PHP_EOL, FILE_APPEND);
  30. echo 'FAIL';
  31. return;
  32. }
  33. $sign = $data['sign'];
  34. unset($data['sign']);
  35. /** @var UserExtractServices $extract_service */
  36. $extract_service = app()->make(UserExtractServices::class);
  37. if (WithdrawService::init()::checkSign($data, $sign)) {
  38. switch ($data['type']) {
  39. case 'create_batch_order':
  40. if ($data['return_code'] == 'SUCCESS') {
  41. $info = WithdrawService::init()::decode($data['resoult']);
  42. @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
  43. $list = $extract_service->getList(['trade_number' => $info['trade_number'], 'status' => 2]);
  44. if ($info['data'][0]['result_code'] != 'SUCCESS') {
  45. foreach ($list as $v) {
  46. $extract_service->update($v['id'], ['status' => 0, 'mark' => '业务处理失败']);
  47. }
  48. } else {
  49. foreach ($list as $v) {
  50. $extract_service->update($v['id'], ['enterprise_order_id' => $info['data'][0]['enterprise_order_id']]);
  51. }
  52. }
  53. }
  54. break;
  55. case 'refuse_order':
  56. if ($data['return_code'] == 'SUCCESS') {
  57. $info = WithdrawService::init()::decode($data['resoult']);
  58. @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
  59. $list = $extract_service->getList(['enterprise_order_id' => $info['enterprise_order_id'], 'status' => 2]);
  60. foreach ($list as $v) {
  61. $extract_service->refuse($v['id'], $info['remarks']);
  62. }
  63. }
  64. break;
  65. case 'payment_resout':
  66. if ($data['return_code'] == 'SUCCESS') {
  67. $info = WithdrawService::init()::decode($data['resoult']);
  68. @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
  69. $id = explode('_', $info['request_no'])[1] ?? 0;
  70. if ($id) {
  71. $list = $extract_service->getList(['id' => $id, 'status' => 2]);
  72. foreach ($list as $v) {
  73. if ($info['payment_status'] == 2) {
  74. $extract_service->update($v['id'], ['status' => 0, 'mark' => '失败']);
  75. }
  76. if ($info['payment_status'] == 4) {
  77. $extract_service->update($v['id'], ['status' => 1, 'mark' => '成功']);
  78. /** @var UserServices $userServices */
  79. $userServices = app()->make(UserServices::class);
  80. $userType = $userServices->value(['uid' => $v['uid']], 'user_type');
  81. $nickname = $userServices->value(['uid' => $v['uid']], 'nickname');
  82. $phone = $userServices->value(['uid' => $v['uid']], 'phone');
  83. switch ($v['extract_type']) {
  84. case 'bank':
  85. $order_id = $v['bank_code'];
  86. break;
  87. case 'weixin':
  88. $order_id = $v['wechat'];
  89. break;
  90. case 'alipay':
  91. $order_id = $v['alipay_code'];
  92. break;
  93. default:
  94. $order_id = '';
  95. break;
  96. }
  97. //记录资金流水队列
  98. CapitalFlowJob::dispatch([['order_id' => $order_id, 'store_id' => 0, 'uid' => $v['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $v['extract_price'], 'pay_type' => $v['extract_type']], 'extract']);
  99. //消息推送
  100. event('notice.notice', [['uid' => $v['uid'], 'userType' => strtolower($userType), 'extractNumber' => $v['extract_price'], 'nickname' => $nickname], 'user_extract']);
  101. }
  102. }
  103. }
  104. }
  105. break;
  106. default:
  107. $info = WithdrawService::init()::decode($data['resoult']);
  108. @file_put_contents('notify.txt', $data['type'] . json_encode($info) . PHP_EOL, FILE_APPEND);
  109. break;
  110. }
  111. echo 'SUCCESS';
  112. } else {
  113. @file_put_contents('notify.txt', '签名校验失败' . PHP_EOL, FILE_APPEND);
  114. echo 'FAIL';
  115. }
  116. }
  117. }