PaymentBehavior.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/26
  6. */
  7. namespace behavior\wechat;
  8. use app\admin\model\wechat\WechatMessage;
  9. use app\routine\model\store\StoreOrder as StoreOrderRoutineModel;
  10. use app\wap\model\store\StoreOrder as StoreOrderWapModel;
  11. use app\wap\model\user\UserRecharge;
  12. use service\HookService;
  13. use service\WechatService;
  14. use service\MiniProgramService;
  15. class PaymentBehavior
  16. {
  17. /**
  18. * 公众号下单成功之后
  19. * @param $order
  20. * @param $prepay_id
  21. */
  22. public static function wechatPaymentPrepare($order, $prepay_id)
  23. {
  24. }
  25. /**
  26. * 小程序下单成功之后
  27. * @param $order
  28. * @param $prepay_id
  29. */
  30. public static function wechatPaymentPrepareProgram($order, $prepay_id)
  31. {
  32. }
  33. /**
  34. * 支付成功后
  35. * @param $notify
  36. * @return bool|mixed
  37. */
  38. public static function wechatPaySuccess($notify)
  39. {
  40. if(isset($notify->attach) && $notify->attach){
  41. return HookService::listen('wechat_pay_success_'.strtolower($notify->attach),$notify->out_trade_no,$notify,true,self::class);
  42. }
  43. return false;
  44. }
  45. /**
  46. * 商品订单支付成功后 微信公众号
  47. * @param $orderId
  48. * @param $notify
  49. * @return bool
  50. */
  51. public static function wechatPaySuccessProduct($orderId, $notify)
  52. {
  53. try{
  54. if(StoreOrderWapModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  55. return StoreOrderWapModel::paySuccess($orderId);
  56. }catch (\Exception $e){
  57. return false;
  58. }
  59. }
  60. /**
  61. * 商品订单支付成功后 小程序
  62. * @param $orderId
  63. * @param $notify
  64. * @return bool
  65. */
  66. public static function wechatPaySuccessProductr($orderId, $notify)
  67. {
  68. try{
  69. if(StoreOrderRoutineModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  70. return StoreOrderRoutineModel::paySuccess($orderId);
  71. }catch (\Exception $e){
  72. return false;
  73. }
  74. }
  75. /**
  76. * 用户充值成功后
  77. * @param $orderId
  78. * @param $notify
  79. * @return bool
  80. */
  81. public static function wechatPaySuccessUserRecharge($orderId, $notify)
  82. {
  83. try{
  84. if(UserRecharge::be(['order_id'=>$orderId,'paid'=>1])) return true;
  85. return UserRecharge::rechargeSuccess($orderId);
  86. }catch (\Exception $e){
  87. return false;
  88. }
  89. }
  90. /**
  91. * 使用余额支付订单时
  92. * @param $userInfo
  93. * @param $orderInfo
  94. */
  95. public static function yuePayProduct($userInfo, $orderInfo)
  96. {
  97. }
  98. /**
  99. * 微信支付订单退款
  100. * @param $orderNo
  101. * @param array $opt
  102. */
  103. public static function wechatPayOrderRefund($orderNo, array $opt)
  104. {
  105. WechatService::payOrderRefund($orderNo,$opt);
  106. }
  107. /**
  108. * 小程序支付订单退款
  109. * @param $orderNo
  110. * @param array $opt
  111. */
  112. public static function routinePayOrderRefund($orderNo, array $opt)
  113. {
  114. $refundDesc = isset($opt['desc']) ? $opt['desc'] : '';
  115. $res = MiniProgramService::payOrderRefund($orderNo,$opt);//2.5.36
  116. // $res = RoutineRefund::doRefund($opt['pay_price'],$opt['refund_price'],$orderNo,'',$orderNo,$refundDesc);
  117. }
  118. /**
  119. * 微信支付充值退款
  120. * @param $orderNo
  121. * @param array $opt
  122. */
  123. public static function userRechargeRefund($orderNo, array $opt)
  124. {
  125. WechatService::payOrderRefund($orderNo,$opt);
  126. }
  127. }