PayTransferNotifyServices.php 4.4 KB

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