PaymentBehavior.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 behavior\wechat;
  12. use app\wap\model\store\StoreOrder as StoreOrderRoutineModel;
  13. use app\wap\model\store\StoreOrder as StoreOrderWapModel;
  14. use app\wap\model\user\UserRecharge;
  15. use service\HookService;
  16. use service\RoutineRefund;
  17. use service\WechatService;
  18. use app\wap\model\activity\EventSignUp;
  19. class PaymentBehavior
  20. {
  21. /**
  22. * 下单成功之后
  23. * @param $order
  24. * @param $prepay_id
  25. */
  26. public static function wechatPaymentPrepare($order, $prepay_id)
  27. {
  28. }
  29. /**
  30. * 支付成功后
  31. * @param $notify
  32. * @return bool|mixed
  33. */
  34. public static function wechatPaySuccess($notify)
  35. {
  36. if(isset($notify->attach) && $notify->attach){
  37. return HookService::listen('wechat_pay_success_'.strtolower($notify->attach),$notify->out_trade_no,$notify,true,self::class);
  38. }
  39. return false;
  40. }
  41. /**
  42. * 商品订单支付成功后 微信公众号
  43. * @param $orderId
  44. * @param $notify
  45. * @return bool
  46. */
  47. public static function wechatPaySuccessGoods($orderId, $notify)
  48. {
  49. try{
  50. if(StoreOrderWapModel::be(['order_id'=>$orderId,'paid'=>1,'type'=>2])) return true;
  51. return StoreOrderWapModel::payGoodsSuccess($orderId);
  52. }catch (\Exception $e){
  53. return false;
  54. }
  55. }
  56. /**
  57. * 专题订单支付成功后 微信公众号 支付宝
  58. * @param $orderId
  59. * @param $notify
  60. * @return bool
  61. */
  62. public static function wechatPaySuccessSpecial($orderId, $notify)
  63. {
  64. try{
  65. if(StoreOrderWapModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  66. return StoreOrderWapModel::paySuccess($orderId);
  67. }catch (\Exception $e){
  68. return false;
  69. }
  70. }
  71. /**
  72. * 会员订单支付成功后 微信公众号 支付宝
  73. * @param $orderId
  74. * @param $notify
  75. * @return bool
  76. */
  77. public static function wechatPaySuccessMember($orderId, $notify)
  78. {
  79. try{
  80. if(StoreOrderWapModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  81. return StoreOrderWapModel::payMeSuccess($orderId);
  82. }catch (\Exception $e){
  83. return false;
  84. }
  85. }
  86. /**
  87. * 活动报名订单支付成功后 微信公众号 支付宝
  88. * @param $orderId
  89. * @param $notify
  90. * @return bool
  91. */
  92. public static function wechatPaySuccessSignup($orderId, $notify)
  93. {
  94. try{
  95. if(EventSignUp::be(['order_id'=>$orderId,'paid'=>1])) return true;
  96. return EventSignUp::paySuccess($orderId);
  97. }catch (\Exception $e){
  98. return false;
  99. }
  100. }
  101. /**
  102. * 商品订单支付成功后 小程序
  103. * @param $orderId
  104. * @param $notify
  105. * @return bool
  106. */
  107. public static function wechatPaySuccessProductr($orderId, $notify)
  108. {
  109. try{
  110. if(StoreOrderRoutineModel::be(['order_id'=>$orderId,'paid'=>1])) return true;
  111. return StoreOrderRoutineModel::paySuccess($orderId);
  112. }catch (\Exception $e){
  113. return false;
  114. }
  115. }
  116. /**
  117. * 用户充值成功后
  118. * @param $orderId
  119. * @param $notify
  120. * @return bool
  121. */
  122. public static function wechatPaySuccessRecharge($orderId, $notify)
  123. {
  124. try{
  125. if(UserRecharge::be(['order_id'=>$orderId,'paid'=>1])) return true;
  126. return UserRecharge::rechargeSuccess($orderId);
  127. }catch (\Exception $e){
  128. return false;
  129. }
  130. }
  131. /**
  132. * 使用余额支付订单时
  133. * @param $userInfo
  134. * @param $orderInfo
  135. */
  136. public static function yuePayProduct($userInfo, $orderInfo)
  137. {
  138. }
  139. /**
  140. * 微信支付订单退款
  141. * @param $orderNo
  142. * @param array $opt
  143. */
  144. public static function wechatPayOrderRefund($orderNo, array $opt)
  145. {
  146. WechatService::payOrderRefund($orderNo,$opt);
  147. }
  148. public static function routinePayOrderRefund($orderNo, array $opt)
  149. {
  150. $refundDesc = isset($opt['desc']) ? $opt['desc'] : '';
  151. $res = RoutineRefund::doRefund($opt['pay_price'],$opt['refund_price'],$orderNo,'',$orderNo,$refundDesc);
  152. }
  153. /**
  154. * 微信支付充值退款
  155. * @param $orderNo
  156. * @param array $opt
  157. */
  158. public static function userRechargeRefund($orderNo, array $opt)
  159. {
  160. WechatService::payOrderRefund($orderNo,$opt);
  161. }
  162. }