PayTransferNotifyServices.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\services\pay;
  3. use app\services\activity\lottery\LuckLotteryRecordServices;
  4. use app\services\statistic\CapitalFlowServices;
  5. use app\services\user\UserExtractServices;
  6. use app\services\user\UserServices;
  7. use crmeb\exceptions\AdminException;
  8. class PayTransferNotifyServices
  9. {
  10. /**
  11. * 提现
  12. * @param string|null $order_id 订单id
  13. * @return bool
  14. */
  15. public function wechatTx(string $order_id = null, string $trade_no = null, string $state = null, string $fail_reason = null)
  16. {
  17. try {
  18. $userExtractServices = app()->make(UserExtractServices::class);
  19. $userExtractInfo = $userExtractServices->getOne(['transfer_bill_no' => $trade_no]);
  20. if (!$userExtractInfo) {
  21. return true;
  22. }
  23. $infoData['state'] = $state;
  24. if ($fail_reason) {
  25. $infoData['fail_reason'] = $fail_reason;
  26. }
  27. $userExtractServices->update($userExtractInfo['id'], $infoData);
  28. if ($state == 'SUCCESS') {
  29. /** @var UserServices $userService */
  30. $userService = app()->make(UserServices::class);
  31. $user = $userService->getUserInfo($userExtractInfo['uid']);
  32. $extractNumber = bcsub($userExtractInfo['extract_price'], $userExtractInfo['extract_fee'], 2);
  33. /** @var CapitalFlowServices $capitalFlowServices */
  34. $capitalFlowServices = app()->make(CapitalFlowServices::class);
  35. $capitalFlowServices->setFlow([
  36. 'order_id' => $order_id,
  37. 'uid' => $userExtractInfo['uid'],
  38. 'price' => bcmul('-1', $extractNumber, 2),
  39. 'pay_type' => $userExtractInfo['extract_type'],
  40. 'nickname' => $user['nickname'],
  41. 'phone' => $user['phone']
  42. ], 'extract');
  43. event('NoticeListener', [['uid' => $userExtractInfo['uid'], 'userType' => strtolower($user['user_type']), 'extractNumber' => $extractNumber, 'nickname' => $user['nickname']], 'user_extract']);
  44. //自定义通知-用户提现成功
  45. $userExtract['nickname'] = $user['nickname'];
  46. $userExtract['phone'] = $user['phone'];
  47. $userExtract['time'] = date('Y-m-d H:i:s');
  48. $userExtract['price'] = $extractNumber;
  49. event('CustomNoticeListener', [$userExtract['uid'], $userExtract, 'extract_success']);
  50. //自定义事件-用户提现成功
  51. event('CustomEventListener', ['admin_extract_success', [
  52. 'uid' => $userExtract['uid'],
  53. 'price' => $extractNumber,
  54. 'pay_type' => $userExtract['extract_type'],
  55. 'nickname' => $user['nickname'],
  56. 'phone' => $user['phone'],
  57. 'success_time' => date('Y-m-d H:i:s')
  58. ]]);
  59. } else {
  60. $userExtractServices->changeFail($userExtractInfo['id'], $userExtractInfo, '提现失败,原因:超时未领取');
  61. }
  62. } catch (\Exception $e) {
  63. return false;
  64. }
  65. return true;
  66. }
  67. /**
  68. * 红包
  69. * @param string|null $order_id 订单id
  70. * @return bool
  71. */
  72. public function wechatHb(string $order_id = null, string $trade_no = null, string $state = null, string $fail_reason = null)
  73. {
  74. try {
  75. $info = app()->make(LuckLotteryRecordServices::class)->getOne(['transfer_bill_no' => $trade_no]);
  76. if (!$info) {
  77. return true;
  78. }
  79. $info->state = $state;
  80. if ($fail_reason) {
  81. $info->fail_reason = $fail_reason;
  82. }
  83. $info->save();
  84. } catch (\Exception $e) {
  85. return false;
  86. }
  87. }
  88. }