123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\services\pay;
- use app\services\order\OtherOrderServices;
- use app\services\order\StoreOrderSuccessServices;
- use app\services\activity\integral\StoreIntegralOrderServices;
- use app\services\user\UserRechargeServices;
- /**
- * 支付成功回调
- * Class PayNotifyServices
- * @package app\services\pay
- */
- class PayNotifyServices
- {
- /**
- * 订单支付成功之后
- * @param string|null $order_id 订单id
- * @return bool
- */
- public function wechatProduct(string $order_id = null, string $trade_no = null)
- {
- try {
- /** @var StoreOrderSuccessServices $services */
- $services = app()->make(StoreOrderSuccessServices::class);
- $orderInfo = $services->getOne(['order_id' => $order_id]);
- if (!$orderInfo) {
- $orderInfo = $services->getOne(['unique' => $order_id]);
- if (!$orderInfo) return true;
- }
- if ($orderInfo->paid) return true;
- return $services->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * 积分商品 订单支付成功之后
- * @param string|null $order_id 订单id
- * @return bool
- */
- public function wechatIntegral(string $order_id = null, string $trade_no = null)
- {
- try {
- /** @var StoreIntegralOrderServices $integralOrderservices */
- $integralOrderservices = app()->make(StoreIntegralOrderServices::class);
- $orderInfo = $integralOrderservices->getOne(['order_id' => $order_id]);
- if (!$orderInfo) {
- $orderInfo = $integralOrderservices->getOne(['unique' => $order_id]);
- if (!$orderInfo) return true;
- }
- if ($orderInfo->paid) return true;
- return $integralOrderservices->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * 充值成功后
- * @param string|null $order_id 订单id
- * @return bool
- */
- public function wechatUserRecharge(string $order_id = null, string $trade_no = null)
- {
- try {
- /** @var UserRechargeServices $userRecharge */
- $userRecharge = app()->make(UserRechargeServices::class);
- if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
- return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no]);
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * 购买会员
- * @param string|null $order_id
- * @return bool
- */
- public function wechatMember(string $order_id = null, string $trade_no = null)
- {
- try {
- /** @var OtherOrderServices $services */
- $services = app()->make(OtherOrderServices::class);
- $orderInfo = $services->getOne(['order_id' => $order_id]);
- if (!$orderInfo) return true;
- if ($orderInfo->paid) return true;
- return $services->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * 支付宝支付异步回调处理事件
- * @param string|null $order_id
- * @param string|null $trade_no
- * @return bool
- */
- public function aliyunProduct(string $order_id = null, string $trade_no = null)
- {
- if (!$order_id || !$trade_no) {
- return false;
- }
- try {
- /** @var StoreOrderSuccessServices $services */
- $services = app()->make(StoreOrderSuccessServices::class);
- $orderInfo = $services->getOne(['order_id' => $order_id]);
- if (!$orderInfo) return true;
- if ($orderInfo->paid) return true;
- return $services->paySuccess($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['trade_no' => $trade_no]);
- } catch (\Throwable $e) {
- return false;
- }
- }
- /**
- * 积分商品 支付宝支付异步回调处理事件
- * @param string|null $order_id
- * @param string|null $trade_no
- * @return bool
- */
- public function aliyunIntegral(string $order_id = null, string $trade_no = null)
- {
- if (!$order_id || !$trade_no) {
- return false;
- }
- try {
- /** @var StoreIntegralOrderServices $integralOrderservices */
- $integralOrderservices = app()->make(StoreIntegralOrderServices::class);
- $orderInfo = $integralOrderservices->getOne(['order_id' => $order_id]);
- if (!$orderInfo) return true;
- if ($orderInfo->paid) return true;
- return $integralOrderservices->paySuccess($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['trade_no' => $trade_no]);
- } catch (\Throwable $e) {
- return false;
- }
- }
- /**
- * 购买会员卡支付宝异步回调
- * @param string|null $order_id
- * @param string|null $trade_no
- * @return bool
- */
- public function aliyunMember(string $order_id = null, string $trade_no = null)
- {
- if (!$order_id || !$trade_no) {
- return false;
- }
- try {
- /** @var OtherOrderServices $services */
- $services = app()->make(OtherOrderServices::class);
- $orderInfo = $services->getOne(['order_id' => $order_id]);
- if (!$orderInfo) return true;
- if ($orderInfo->paid) return true;
- return $services->paySuccess($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['trade_no' => $trade_no]);
- } catch (\Throwable $e) {
- return false;
- }
- }
- /**
- * 充值成功后
- * @param string|null $order_id 订单id
- * @return bool
- */
- public function aliyunUserRecharge(string $order_id = null, string $trade_no = null)
- {
- if (!$order_id || !$trade_no) {
- return false;
- }
- try {
- /** @var UserRechargeServices $userRecharge */
- $userRecharge = app()->make(UserRechargeServices::class);
- if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
- return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no]);
- } catch (\Exception $e) {
- return false;
- }
- }
- }
|