PayNotifyServices.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // 小程序订单管理 (自提商品)
  39. if ($orderInfo['shipping_type'] == 2) {
  40. event('OrderShipping', ['product', $orderInfo]);
  41. }
  42. return $services->paySuccess($orderInfo->toArray(), $payType, ['trade_no' => $trade_no]);
  43. } catch (\Exception $e) {
  44. return false;
  45. }
  46. }
  47. /**
  48. * 充值成功后
  49. * @param string|null $order_id 订单id
  50. * @return bool
  51. */
  52. public function wechatUserRecharge(string $order_id = null, string $trade_no = null, string $payType = PayServices::WEIXIN_PAY)
  53. {
  54. try {
  55. /** @var UserRechargeServices $userRecharge */
  56. $userRecharge = app()->make(UserRechargeServices::class);
  57. if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
  58. return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no, 'pay_type' => $payType]);
  59. } catch (\Exception $e) {
  60. return false;
  61. }
  62. }
  63. /**
  64. * 购买会员
  65. * @param string|null $order_id
  66. * @return bool
  67. */
  68. public function wechatMember(string $order_id = null, string $trade_no = null, string $payType = PayServices::WEIXIN_PAY)
  69. {
  70. try {
  71. /** @var OtherOrderServices $services */
  72. $services = app()->make(OtherOrderServices::class);
  73. $orderInfo = $services->getOne(['order_id' => $order_id]);
  74. if (!$orderInfo) return true;
  75. if ($orderInfo->paid) return true;
  76. // 小程序订单服务
  77. event('OrderShipping', ['member', $orderInfo]);
  78. return $services->paySuccess($orderInfo->toArray(), $payType, ['trade_no' => $trade_no]);
  79. } catch (\Exception $e) {
  80. return false;
  81. }
  82. }
  83. }