PayNotifyServices.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\order\OtherOrderServices;
  13. use app\services\order\StoreOrderSuccessServices;
  14. use app\services\user\UserRechargeServices;
  15. /**
  16. * 支付成功回调 所有的异步通知回调都会走下面的三个方法,不在取分微信/支付宝支付回调
  17. * Class PayNotifyServices
  18. * @package app\services\pay
  19. */
  20. class PayNotifyServices
  21. {
  22. /**
  23. * 订单支付成功之后
  24. * @param string|null $order_id 订单id
  25. * @param string|null $trade_no
  26. * @param string $payType
  27. * @return bool
  28. * @throws \Psr\SimpleCache\InvalidArgumentException
  29. */
  30. public function wechatProduct(string $order_id = null, string $trade_no = null, string $payType = PayServices::WEIXIN_PAY)
  31. {
  32. try {
  33. /** @var StoreOrderSuccessServices $services */
  34. $services = app()->make(StoreOrderSuccessServices::class);
  35. $orderInfo = $services->getOne(['order_id' => $order_id]);
  36. if (!$orderInfo) return true;
  37. if ($orderInfo->paid) return true;
  38. return $services->paySuccess($orderInfo->toArray(), $payType, ['trade_no' => $trade_no]);
  39. } catch (\Exception $e) {
  40. return false;
  41. }
  42. }
  43. /**
  44. * 充值成功后
  45. * @param string|null $order_id 订单id
  46. * @return bool
  47. */
  48. public function wechatUserRecharge(string $order_id = null, string $trade_no = null, string $payType = PayServices::WEIXIN_PAY)
  49. {
  50. try {
  51. /** @var UserRechargeServices $userRecharge */
  52. $userRecharge = app()->make(UserRechargeServices::class);
  53. if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
  54. return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no, 'pay_type' => $payType]);
  55. } catch (\Exception $e) {
  56. return false;
  57. }
  58. }
  59. /**
  60. * 购买会员
  61. * @param string|null $order_id
  62. * @return bool
  63. */
  64. public function wechatMember(string $order_id = null, string $trade_no = null, string $payType = PayServices::WEIXIN_PAY)
  65. {
  66. try {
  67. /** @var OtherOrderServices $services */
  68. $services = app()->make(OtherOrderServices::class);
  69. $orderInfo = $services->getOne(['order_id' => $order_id]);
  70. if (!$orderInfo) return true;
  71. if ($orderInfo->paid) return true;
  72. return $services->paySuccess($orderInfo->toArray(), $payType, ['trade_no' => $trade_no]);
  73. } catch (\Exception $e) {
  74. return false;
  75. }
  76. }
  77. }