apisubmit.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace WY\app\controller;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class apisubmit extends api
  8. {
  9. public function index()
  10. {
  11. extract($this->params);
  12. if ($this->userData['is_verify_siteurl']) {
  13. $fromurl = $fromurl ? $fromurl : $this->req->server('HTTP_REFERER');
  14. $userinfo = $this->model()->select('siteurl')->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($this->userData['id'])))->fetchRow();
  15. if ($fromurl == '' || !strpos($fromurl, $userinfo['siteurl'])) {
  16. echo $this->ret->put('206', $cardnum ? true : false);
  17. exit;
  18. }
  19. }
  20. $signStr = 'version=' . $version . '&customerid=' . $customerid . '&total_fee=' . $total_fee . '&sdorderno=' . $sdorderno . '&notifyurl=' . $notifyurl . '&returnurl=' . $returnurl . '&' . $this->userData['apikey'];
  21. $mysign = md5($signStr);
  22. if ($sign != $mysign) {
  23. echo $this->ret->put('201', $cardnum ? true : false);
  24. exit;
  25. }
  26. switch ($paytype) {
  27. case 'bank':
  28. case 'qq':
  29. case 'alipay':
  30. case 'tenpay':
  31. case 'weixin':
  32. case 'qqrcode':
  33. case 'tenpaywap':
  34. case 'alipaywap':
  35. case 'wxh5':
  36. case 'Wxh5':
  37. case 'qqwallet':
  38. case 'gzhpay':
  39. case 'yinlian':
  40. case 'quickbank':
  41. case 'quickwap':
  42. case 'jdpay':
  43. $this->submit();
  44. break;
  45. default:
  46. echo $this->ret->put('106', $cardnum ? true : false);
  47. exit;
  48. }
  49. }
  50. protected function submit()
  51. {
  52. extract($this->params);
  53. $bankcode = $paytype == 'bank' ? $bankcode : $paytype;
  54. if ($this->model()->select()->from('orders')->where(array('fields' => 'userid=? and sdorderno=?', 'values' => array($this->userData['id'], $sdorderno)))->count()) {
  55. echo $this->ret->put('205', $cardnum ? true : false);
  56. exit;
  57. }
  58. $acw = $this->model()->select('id')->from('acw')->where(array('fields' => 'code=?', 'values' => array($paytype)))->fetchRow();
  59. if (!$acw) {
  60. echo $this->ret->put('500', $cardnum ? true : false);
  61. exit;
  62. }
  63. /*$acc=$this->model()->select()->from('acc')->where(array('fields'=>'acwid=? and is_state=?','values'=>array($acw['id'],0)))->fetchAll();if(!$acc){echo $this->ret->put('103',$cardnum ? true : false);exit;}$userprice=$this->model()->select()->from('userprice')->where(array('fields'=>' userid=?','values'=>array($customerid)))->fetchAll();if(!$userprice){echo $this->ret->put('101',$cardnum ? true : false);exit;}$is_state=$channelid=$acpcode=$gateway=$is_state_acc='';foreach($userprice as $key=>$val){foreach($acc as $key2=>$val2){if($val['channelid']==$val2['id']){$is_state=$val['is_state'];$channelid=$val['channelid'];$acpcode=$val2['acpcode'];$gateway=$val2['gateway'];$is_state_acc=$val2['is_state'];break;}}}if($acpcode=='' || $gateway==''){echo $this->ret->put('103',$cardnum ? true : false);exit;}if($is_state=='1'){echo $this->ret->put('100',$cardnum ? true : false);exit;}if($is_state_acc=='1'){echo $this->ret->put('102',$cardnum ? true : false);exit;}*/
  64. $acc = $this->model()->select('a.id,a.acpcode,a.gateway,a.is_state,b.is_state as is_state_acc,b.channelid')->from('acc a')->left('userprice b')->on('b.channelid=a.id')->join()->where(array('fields' => 'b.userid=? and a.acwid=?', 'values' => array($customerid, $acw['id'])))->fetchRow();
  65. if (!$acc) {
  66. echo $this->ret->put('103', $cardnum ? true : false);
  67. exit;
  68. }
  69. if ($acc['is_state'] == '1') {
  70. echo $this->ret->put('100', $cardnum ? true : false);
  71. exit;
  72. }
  73. if ($acc['is_state_acc'] == '1') {
  74. echo $this->ret->put('102', $cardnum ? true : false);
  75. exit;
  76. }
  77. $channelid = $acc['channelid'];
  78. $acpcode = $acc['acpcode'];
  79. $gateway = $acc['gateway'];
  80. $orderid = $this->res->getOrderID();
  81. $addtime = time();
  82. $orderinfo = array('userid' => $customerid, 'paytype' => $paytype, 'bankcode' => $bankcode, 'notifyurl' => $notifyurl, 'returnurl' => $returnurl, 'remark' => $remark, 'addtime' => $addtime);
  83. if (!($orderinfoid = $this->model()->from('orderinfo')->insertData($orderinfo)->insert())) {
  84. echo $this->ret->put('209', $cardnum ? true : false);
  85. exit;
  86. }
  87. $orderdata = array('userid' => $customerid, 'agentid' => $this->userData['superid'], 'orderid' => $orderid, 'sdorderno' => $sdorderno, 'total_fee' => $total_fee, 'channelid' => $channelid, 'addtime' => $addtime, 'lastime' => $addtime, 'is_paytype' => 0, 'orderinfoid' => $orderinfoid);
  88. if (!($orid = $this->model()->from('orders')->insertData($orderdata)->insert())) {
  89. echo $this->ret->put('210', $cardnum ? true : false);
  90. exit;
  91. }
  92. $ordernotify = array('orid' => $orid, 'addtime' => $addtime);
  93. if (!$this->model()->from('ordernotify')->insertData($ordernotify)->insert()) {
  94. echo $this->ret->put('211', $cardnum ? true : false);
  95. exit;
  96. }
  97. $url = 'http://' . $this->req->server('HTTP_HOST') . '/pay/' . $acpcode . '_' . $gateway . '/send.php';
  98. $url .= '?orderid=' . $orderid . '&price=' . $total_fee . '&bankcode=' . $bankcode . '&remark=' . $remark;
  99. $this->res->redirect($url);
  100. }
  101. }
  102. ?>