Pay.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Pay.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: https://www.niushop.com
  9. * =========================================================
  10. * @author : niuteam
  11. * @date : 2022.8.8
  12. * @version : v5.0.0.1
  13. */
  14. namespace app\api\controller;
  15. use app\model\order\Order as OrderModel;
  16. use app\model\system\Pay as PayModel;
  17. use app\model\order\Config;
  18. use app\model\system\PayBalance;
  19. /**
  20. * 支付控制器
  21. */
  22. class Pay extends BaseApi
  23. {
  24. /**
  25. * 支付信息
  26. */
  27. public function info()
  28. {
  29. $out_trade_no = $this->params[ 'out_trade_no' ];
  30. $pay = new PayModel();
  31. $info = $pay->getPayInfo($out_trade_no)[ 'data' ] ?? [];
  32. if (!empty($info)) {
  33. if (in_array($info[ 'event' ], [ 'OrderPayNotify', 'CashierOrderPayNotify' ])) {
  34. $order_model = new OrderModel();
  35. $order_info = $order_model->getOrderInfo([ [ 'out_trade_no', '=', $out_trade_no ] ], 'order_id,order_type')[ 'data' ];
  36. if (!empty($order_info)) {
  37. $info[ 'order_id' ] = $order_info[ 'order_id' ];
  38. $info[ 'order_type' ] = $order_info[ 'order_type' ];
  39. }
  40. }
  41. }
  42. return $this->response($this->success($info));
  43. }
  44. /**
  45. * 支付调用
  46. */
  47. public function pay()
  48. {
  49. $token = $this->checkToken();
  50. if ($token[ 'code' ] < 0) return $this->response($token);
  51. $pay_type = $this->params[ 'pay_type' ];
  52. $out_trade_no = $this->params[ 'out_trade_no' ];
  53. $app_type = $this->params[ 'app_type' ];
  54. $return_url = isset($this->params[ 'return_url' ]) && !empty($this->params[ 'return_url' ]) ? urldecode($this->params[ 'return_url' ]) : null;
  55. $scene = $this->params[ 'scene' ] ?? 0;
  56. $is_balance = $this->params[ 'is_balance' ] ?? 0;
  57. $storeid = $this->params['store_id'];
  58. $pay = new PayModel();
  59. $info = $pay->pay($pay_type, $out_trade_no, $app_type, $this->member_id, $return_url, $is_balance, $scene,$storeid);
  60. return $this->response($info);
  61. }
  62. /**
  63. * 支付方式
  64. */
  65. public function type()
  66. {
  67. $pay = new PayModel();
  68. $info = $pay->getPayType($this->params);
  69. $temp = empty($info) ? [] : $info;
  70. $type = [];
  71. foreach ($temp[ 'data' ] as $k => $v) {
  72. array_push($type, $v[ "pay_type" ]);
  73. }
  74. $type = implode(",", $type);
  75. return $this->response(success(0, '', [ 'pay_type' => $type ]));
  76. }
  77. /**
  78. * 获取订单支付状态
  79. */
  80. public function status()
  81. {
  82. $pay = new PayModel();
  83. $out_trade_no = $this->params[ 'out_trade_no' ];
  84. $res = $pay->getPayStatus($out_trade_no);
  85. return $this->response($res);
  86. }
  87. /**
  88. * 获取余额支付配置
  89. */
  90. public function getBalanceConfig()
  91. {
  92. $config_model = new Config();
  93. $res = $order_evaluate_config = $config_model->getBalanceConfig($this->site_id);
  94. return $this->response($this->success($res[ 'data' ][ 'value' ]));
  95. }
  96. /**
  97. * 重置支付
  98. */
  99. public function resetPay()
  100. {
  101. $token = $this->checkToken();
  102. if ($token[ 'code' ] < 0) return $this->response($token);
  103. $out_trade_no = $this->params[ 'out_trade_no' ];
  104. $pay = new PayModel();
  105. $result = $pay->resetPay([ 'out_trade_no' => $out_trade_no ]);
  106. return $this->response($result);
  107. }
  108. /**
  109. * 会员付款码
  110. */
  111. public function memberPayCode()
  112. {
  113. $token = $this->checkToken();
  114. if ($token[ 'code' ] < 0) return $this->response($token);
  115. $data = ( new PayBalance() )->create([ 'member_id' => $this->member_id, 'site_id' => $this->site_id ]);
  116. return $this->response($data);
  117. }
  118. /**
  119. * 查询会员付款码信息
  120. * @return false|string
  121. */
  122. public function memberPayInfo()
  123. {
  124. $token = $this->checkToken();
  125. if ($token[ 'code' ] < 0) return $this->response($token);
  126. $auth_code = $this->params[ 'auth_code' ] ?? '';
  127. $data = ( new PayBalance() )->getInfo([ [ 'member_id', '=', $this->member_id ], [ 'site_id', '=', $this->site_id ], [ 'auth_code', '=', $auth_code ] ], 'status,out_trade_no');
  128. return $this->response($data);
  129. }
  130. }