OrderPayService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\common\service;
  3. use addons\epay\library\Service;
  4. use app\common\model\Orders;
  5. use app\common\model\Payment;
  6. use fast\Arr;
  7. use think\App;
  8. class OrderPayService{
  9. /** @var Payment */
  10. protected $payment;
  11. /** @var string */
  12. protected $body;
  13. protected $expire=null;
  14. public static $methods=[
  15. Orders::PT_QYWY=>'companyBank',
  16. Orders::PT_WX=>'wechat',
  17. Orders::PT_ZFB=>'alipay',
  18. Orders::PT_YL=>'bankUnion',
  19. Orders::PT_DF=>'otherUser',
  20. Orders::PT_OFF=>'offline',
  21. ];
  22. /**
  23. * @param null $expire
  24. */
  25. public function setExpire($expire): void
  26. {
  27. $this->expire = $expire;
  28. }
  29. /**
  30. * @param Payment $payment
  31. */
  32. public function setPayment(Payment $payment): void
  33. {
  34. $this->payment = $payment;
  35. }
  36. /**
  37. * @param string $body
  38. */
  39. public function setBody(string $body): void
  40. {
  41. $this->body = $body;
  42. }
  43. /**
  44. * @return string
  45. */
  46. public function getBody(): string
  47. {
  48. return $this->body;
  49. }
  50. /**
  51. * @return mixed
  52. */
  53. public function getAmount($unit='y')
  54. {
  55. return moneyFormat($this->payment->amount,$unit);
  56. }
  57. public function companyBank(){}
  58. public function wechat(){
  59. $payData=Service::submitOrder(
  60. $this->getAmount('f'),
  61. $this->payment->order_no,
  62. 'wechat',
  63. $this->getBody(),
  64. $this->notifyUrl(),
  65. $this->returnUrl(),
  66. 'scan',
  67. '',
  68. $this->expire,
  69. );
  70. $str=$payData['code_url'];
  71. return [
  72. 'qr'=>makeQrcode($str),
  73. ];
  74. }
  75. public function notifyUrl(){
  76. return request()->root(true)."/index/payment/notify/order_no/".$this->payment->order_no;
  77. }
  78. public function returnUrl(){
  79. return request()->root(true);
  80. }
  81. public function alipay(){
  82. $payData=Service::submitOrder(
  83. $this->getAmount(),
  84. $this->payment->order_no,
  85. 'alipay',
  86. $this->getBody(),
  87. $this->notifyUrl(),
  88. $this->returnUrl(),
  89. 'scan',
  90. '',
  91. $this->expire,
  92. );
  93. $str=$payData['qr_code'];
  94. return [
  95. 'qr'=>makeQrcode($str),
  96. ];
  97. }
  98. public function bankUnion(){
  99. require __DIR__.'/../library/upacp_demo_b2c/demo/api_01_gateway/Form_6_2_FrontConsume.php';
  100. $html=ylUnifyOrder($this->payment->order_no,$this->getAmount('f'));
  101. return [
  102. 'html'=>$html
  103. ];
  104. }
  105. public function otherUser(){}
  106. public function offline(){}
  107. public function pay(){
  108. $method=Arr::get(self::$methods,$this->payment->pay_type);
  109. return App::invokeMethod([$this,$method]);
  110. }
  111. }