PayNotifyServices.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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\services\pay;
  12. use app\services\order\OtherOrderServices;
  13. use app\services\order\StoreOrderSuccessServices;
  14. use app\services\activity\integral\StoreIntegralOrderServices;
  15. use app\services\user\UserRechargeServices;
  16. /**
  17. * 支付成功回调
  18. * Class PayNotifyServices
  19. * @package app\services\pay
  20. */
  21. class PayNotifyServices
  22. {
  23. /**
  24. * 订单支付成功之后
  25. * @param string|null $order_id 订单id
  26. * @return bool
  27. */
  28. public function wechatProduct(string $order_id = null, string $trade_no = null)
  29. {
  30. try {
  31. /** @var StoreOrderSuccessServices $services */
  32. $services = app()->make(StoreOrderSuccessServices::class);
  33. $orderInfo = $services->getOne(['order_id' => $order_id]);
  34. if (!$orderInfo) {
  35. $orderInfo = $services->getOne(['unique' => $order_id]);
  36. if (!$orderInfo) return true;
  37. }
  38. if ($orderInfo->paid) return true;
  39. return $services->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
  40. } catch (\Exception $e) {
  41. return false;
  42. }
  43. }
  44. /**
  45. * 积分商品 订单支付成功之后
  46. * @param string|null $order_id 订单id
  47. * @return bool
  48. */
  49. public function wechatIntegral(string $order_id = null, string $trade_no = null)
  50. {
  51. try {
  52. /** @var StoreIntegralOrderServices $integralOrderservices */
  53. $integralOrderservices = app()->make(StoreIntegralOrderServices::class);
  54. $orderInfo = $integralOrderservices->getOne(['order_id' => $order_id]);
  55. if (!$orderInfo) {
  56. $orderInfo = $integralOrderservices->getOne(['unique' => $order_id]);
  57. if (!$orderInfo) return true;
  58. }
  59. if ($orderInfo->paid) return true;
  60. return $integralOrderservices->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
  61. } catch (\Exception $e) {
  62. return false;
  63. }
  64. }
  65. /**
  66. * 充值成功后
  67. * @param string|null $order_id 订单id
  68. * @return bool
  69. */
  70. public function wechatUserRecharge(string $order_id = null, string $trade_no = null)
  71. {
  72. try {
  73. /** @var UserRechargeServices $userRecharge */
  74. $userRecharge = app()->make(UserRechargeServices::class);
  75. if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
  76. return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no]);
  77. } catch (\Exception $e) {
  78. return false;
  79. }
  80. }
  81. /**
  82. * 购买会员
  83. * @param string|null $order_id
  84. * @return bool
  85. */
  86. public function wechatMember(string $order_id = null, string $trade_no = null)
  87. {
  88. try {
  89. /** @var OtherOrderServices $services */
  90. $services = app()->make(OtherOrderServices::class);
  91. $orderInfo = $services->getOne(['order_id' => $order_id]);
  92. if (!$orderInfo) return true;
  93. if ($orderInfo->paid) return true;
  94. return $services->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
  95. } catch (\Exception $e) {
  96. return false;
  97. }
  98. }
  99. /**
  100. * 支付宝支付异步回调处理事件
  101. * @param string|null $order_id
  102. * @param string|null $trade_no
  103. * @return bool
  104. */
  105. public function aliyunProduct(string $order_id = null, string $trade_no = null)
  106. {
  107. if (!$order_id || !$trade_no) {
  108. return false;
  109. }
  110. try {
  111. /** @var StoreOrderSuccessServices $services */
  112. $services = app()->make(StoreOrderSuccessServices::class);
  113. $orderInfo = $services->getOne(['order_id' => $order_id]);
  114. if (!$orderInfo) return true;
  115. if ($orderInfo->paid) return true;
  116. return $services->paySuccess($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['trade_no' => $trade_no]);
  117. } catch (\Throwable $e) {
  118. return false;
  119. }
  120. }
  121. /**
  122. * 积分商品 支付宝支付异步回调处理事件
  123. * @param string|null $order_id
  124. * @param string|null $trade_no
  125. * @return bool
  126. */
  127. public function aliyunIntegral(string $order_id = null, string $trade_no = null)
  128. {
  129. if (!$order_id || !$trade_no) {
  130. return false;
  131. }
  132. try {
  133. /** @var StoreIntegralOrderServices $integralOrderservices */
  134. $integralOrderservices = app()->make(StoreIntegralOrderServices::class);
  135. $orderInfo = $integralOrderservices->getOne(['order_id' => $order_id]);
  136. if (!$orderInfo) return true;
  137. if ($orderInfo->paid) return true;
  138. return $integralOrderservices->paySuccess($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['trade_no' => $trade_no]);
  139. } catch (\Throwable $e) {
  140. return false;
  141. }
  142. }
  143. /**
  144. * 购买会员卡支付宝异步回调
  145. * @param string|null $order_id
  146. * @param string|null $trade_no
  147. * @return bool
  148. */
  149. public function aliyunMember(string $order_id = null, string $trade_no = null)
  150. {
  151. if (!$order_id || !$trade_no) {
  152. return false;
  153. }
  154. try {
  155. /** @var OtherOrderServices $services */
  156. $services = app()->make(OtherOrderServices::class);
  157. $orderInfo = $services->getOne(['order_id' => $order_id]);
  158. if (!$orderInfo) return true;
  159. if ($orderInfo->paid) return true;
  160. return $services->paySuccess($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['trade_no' => $trade_no]);
  161. } catch (\Throwable $e) {
  162. return false;
  163. }
  164. }
  165. /**
  166. * 充值成功后
  167. * @param string|null $order_id 订单id
  168. * @return bool
  169. */
  170. public function aliyunUserRecharge(string $order_id = null, string $trade_no = null)
  171. {
  172. if (!$order_id || !$trade_no) {
  173. return false;
  174. }
  175. try {
  176. /** @var UserRechargeServices $userRecharge */
  177. $userRecharge = app()->make(UserRechargeServices::class);
  178. if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
  179. return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no]);
  180. } catch (\Exception $e) {
  181. return false;
  182. }
  183. }
  184. }