PayController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * PayController.php UTF-8
  4. * 支付
  5. *
  6. * @date : 2018/2/1 16:40
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : linjiebin <ljb@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace web\pc\controller\v8;
  13. use think\Session;
  14. use web\common\controller\WebBaseController;
  15. use web\pc\logic\PayLogic;
  16. class PayController extends WebBaseController {
  17. private function setorderid($mem_id) {
  18. list($usec, $sec) = explode(" ", microtime());
  19. // 取微秒前3位+再两位随机数+渠道ID后四位
  20. $orderid = $sec.substr($usec, 2, 3).rand(10, 99).sprintf("%04d", $mem_id % 10000);
  21. return $orderid;
  22. }
  23. /**
  24. * 充值平台币下单操作
  25. * @return array|mixed
  26. */
  27. public function doPay() {
  28. $_class = new PayLogic();
  29. $type = request()->param('type','alipay');
  30. $ptb_cnt = request()->param('amount'); // 获取平台币数量
  31. $username = request()->param('username');
  32. if(empty($type) || empty($ptb_cnt) || empty($username)) {
  33. $this->error('参数错误');
  34. }
  35. switch ($type) {
  36. case 'alipay' : // 支付宝
  37. $_res = $_class->_alipayweb();
  38. if (isset($_res['error']) && $_res['error'] > 0) {
  39. $this->error($_res['msg']);
  40. }
  41. break;
  42. case 'spay' : // 微信支付
  43. $_res = $_class->_spayweb();
  44. if (isset($_res['status']) && $_res['status'] == 1) {
  45. $this->assign($_res['data']);
  46. return $this->fetch('Pay/spay');
  47. } else {
  48. $this->error('支付失败');
  49. }
  50. break;
  51. default :
  52. return array('error' => 2, 'msg' => '请选择正确的支付方式');
  53. }
  54. }
  55. /**
  56. * 平台币支付宝充值回调
  57. */
  58. public function ptb_alipay_notify() {
  59. $_class = new PayLogic();
  60. $_class->alipay_notify();
  61. }
  62. /**
  63. * 平台币威富通充值回调
  64. */
  65. public function ptb_spay_notify() {
  66. $_class = new PayLogic();
  67. $_class->spay_notify();
  68. }
  69. /**
  70. * 威富通充值状态查询
  71. * @return array
  72. */
  73. public function spay_status(){
  74. $_order_id = $this->request->param('order_id');
  75. $_class = new PayLogic();
  76. return $_class->spayStatus($_order_id);
  77. }
  78. }