PaymentBehavior.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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\RoutineRefund;
  14. use service\WechatService;
  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 $notify
  28. * @return bool|mixed
  29. */
  30. public static function wechatPaySuccess($notify)
  31. {
  32. if(isset($notify->attach) && $notify->attach){
  33. return HookService::listen('wechat_pay_success_'.strtolower($notify->attach),$notify->out_trade_no,$notify,true,self::class);
  34. }
  35. return false;
  36. }
  37. /**
  38. * 商品订单支付成功后 微信公众号
  39. * @param $orderId
  40. * @param $notify
  41. * @return bool
  42. */
  43. public static function wechatPaySuccessProduct($orderId, $notify)
  44. {
  45. try{
  46. if(StoreOrderWapModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  47. return StoreOrderWapModel::paySuccess($orderId);
  48. }catch (\Exception $e){
  49. return false;
  50. }
  51. }
  52. /**
  53. * 商品订单支付成功后 小程序
  54. * @param $orderId
  55. * @param $notify
  56. * @return bool
  57. */
  58. public static function wechatPaySuccessProductr($orderId, $notify)
  59. {
  60. try{
  61. if(StoreOrderRoutineModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  62. return StoreOrderRoutineModel::paySuccess($orderId);
  63. }catch (\Exception $e){
  64. return false;
  65. }
  66. }
  67. /**
  68. * 用户充值成功后
  69. * @param $orderId
  70. * @param $notify
  71. * @return bool
  72. */
  73. public static function wechatPaySuccessUserRecharge($orderId, $notify)
  74. {
  75. try{
  76. if(UserRecharge::be(['order_id'=>$orderId,'paid'=>1])) return true;
  77. return UserRecharge::rechargeSuccess($orderId);
  78. }catch (\Exception $e){
  79. return false;
  80. }
  81. }
  82. /**
  83. * 使用余额支付订单时
  84. * @param $userInfo
  85. * @param $orderInfo
  86. */
  87. public static function yuePayProduct($userInfo, $orderInfo)
  88. {
  89. }
  90. /**
  91. * 微信支付订单退款
  92. * @param $orderNo
  93. * @param array $opt
  94. */
  95. public static function wechatPayOrderRefund($orderNo, array $opt)
  96. {
  97. WechatService::payOrderRefund($orderNo,$opt);
  98. }
  99. /**
  100. * 小程序支付订单退款
  101. * @param $orderNo
  102. * @param array $opt
  103. */
  104. public static function routinePayOrderRefund($orderNo, array $opt)
  105. {
  106. $refundDesc = isset($opt['desc']) ? $opt['desc'] : '';
  107. $res = RoutineRefund::doRefund($opt['pay_price'],$opt['refund_price'],$orderNo,'',$orderNo,$refundDesc);
  108. }
  109. /**
  110. * 微信支付充值退款
  111. * @param $orderNo
  112. * @param array $opt
  113. */
  114. public static function userRechargeRefund($orderNo, array $opt)
  115. {
  116. WechatService::payOrderRefund($orderNo,$opt);
  117. }
  118. }