PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/shop/controller/ctl.paycenter.php

http://phpfor.googlecode.com/
PHP | 181 lines | 149 code | 15 blank | 17 comment | 33 complexity | a0ddfb529a4dfe8a9ffb8e561020e53f MD5 | raw file
  1. <?php
  2. class ctl_paycenter extends shopPage{
  3. var $noCache = true;
  4. function ctl_paycenter(&$system){
  5. parent::shopPage($system);
  6. $this->payment = &$this->system->loadModel('trading/payment');
  7. $this->_verifyMember(false);
  8. }
  9. /**
  10. * order ?????
  11. *
  12. * @access public
  13. * @return void
  14. */
  15. function order(){
  16. // $this->begin($this->system->mkUrl("order","pay",array($_POST['order_id'])));
  17. if(floatval($_POST['money']) <= 0){
  18. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('???????????'));
  19. return false;
  20. }
  21. $oOrder = &$this->system->loadModel('trading/order');
  22. $order = $oOrder->load($_POST['order_id']);
  23. if($order['status'] != 'active'){
  24. $this->splash('failed', $this->system->mkUrl("order","index",array($_POST['order_id'])), __('????????????'));
  25. }
  26. if($order['pay_status'] > 0 && $order['pay_status'] != 3){
  27. $this->splash('failed', $this->system->mkUrl("order","index",array($_POST['order_id'])), __('?????????????'));
  28. }
  29. if(!($_POST['money'] = $oOrder->chgPayment($_POST['order_id'], $_POST['payment']['payment'], $_POST['money']))){
  30. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('??????????'));
  31. }
  32. if(empty($_POST['currency'])){
  33. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('?????????????'));
  34. }
  35. if(count($oOrder->checkPaymentCfg($_POST['payment']['payment']))<1){
  36. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('???????????????????'));
  37. }
  38. $payment=$this->system->loadModel('trading/payment');
  39. $tmpRow=$payment->getPaymentById($_POST['payment']['payment']);
  40. $payment->getExtendOfPlug('',$tmpRow['pay_type'],$extfields);
  41. if ($extfields){
  42. foreach($extfields as $key => $val){
  43. if (isset($_POST[$val]))
  44. $extend[$val]=$_POST[$val];
  45. }
  46. }else{
  47. $extend='';
  48. }
  49. $cur = $this->system->loadModel('trading/cur');
  50. $def_cur = $cur->getDefault();
  51. $oOrder->updateExtend($_POST['order_id'],$extend);
  52. $this->_init($_POST['payment']['payment']);
  53. $this->payment->order_id = $_POST['order_id'];
  54. $this->payment->member_id = $this->member['member_id'];
  55. if (strtoupper($_POST['currency'])<>$def_cur['cur_code'])
  56. $this->payment->money = number_format($_POST['cur_money'],2,'.','');
  57. else
  58. $this->payment->money = $_POST['money'];
  59. $this->payment->cur_money = $_POST['cur_money'];
  60. $this->payment->currency = $_POST['currency'];
  61. if($this->payment->pay_type == 'deposit'){
  62. $oAdvance = &$this->system->loadModel("member/advance");
  63. $status = $oAdvance->checkAccount($this->member['member_id'], $_POST['money'], $message,$rows);
  64. if(!$status){
  65. if($status === 0){
  66. $this->pagedata['payment'] = array_merge($_POST,$rows[0]);
  67. $this->output();
  68. }else{
  69. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('?????').$message);
  70. }
  71. }else{
  72. $this->payment->pay_account = $this->member['uname'];
  73. if(!$this->payment->doPay('',$_POST['order_id'])){
  74. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('??????'));
  75. }
  76. setcookie('S[order_payed]', 1);
  77. // $oOrder->addLog(__('??'.$_POST['order_id'].'??').$_POST['money']);
  78. }
  79. }else{
  80. if(!$this->payment->doPay('',$_POST['order_id'])){
  81. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('??????'));
  82. }
  83. // $oOrder->addLog(__('??'.$_POST['order_id'].'??').$_POST['money']);
  84. }
  85. // $this->end()
  86. }
  87. /**
  88. * recharge ?? ??????
  89. *
  90. * @access public
  91. * @return void
  92. */
  93. function recharge(){
  94. $this->_init($_POST['payment']['payment']);
  95. if($this->payment->type == 'deposit'){
  96. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('??????????????'));
  97. }
  98. $this->payment->pay_type = 'recharge';
  99. $this->payment->cur_money = $_POST['money'];
  100. $this->payment->member_id = $_POST['member_id']; //??id?????????????
  101. $oCur = &$this->system->loadModel("system/cur");
  102. $aCur = $oCur->getcur($_POST['payment']['currency'], true);
  103. if(empty($aCur['cur_code'])){
  104. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('?????????????'));
  105. }
  106. $this->payment->currency = $aCur['cur_code'];
  107. $this->payment->money = $aCur['cur_rate'] ? ($_POST['money'] / $aCur['cur_rate']) : $_POST['money'];
  108. if($this->payment->config['method']==1){
  109. $this->payment->paycost = $this->payment->fee ==0.00000?0:$this->payment->money*$this->payment->fee;
  110. $this->payment->money = $this->payment->fee ==0.00000?$this->payment->money:$this->payment->money*(1+$this->payment->fee);
  111. }
  112. elseif($this->payment->config['method']==2){
  113. $this->payment->money = $this->payment->fee ==0.00000?$this->payment->money:$this->payment->money+$this->payment->fee;
  114. $this->payment->paycost = $this->payment->fee ==0.00000?0:$this->payment->fee;
  115. }
  116. else
  117. $this->payment->money = $this->payment->money;
  118. $this->payment->doPay('recharge');
  119. }
  120. function result(){
  121. $pyd=array_merge($_GET,$_POST);
  122. $payment = $this->payment->getById($pyd['payment_id']);
  123. echo '<script>new Request({url:\'http://localhost/shopex/ver485/src/shopadmin/index.php?ctl=trading/payment&act=sendOrderInfo&p[0]='.$payment['payment_id'].'&p[1]='.$payment['money'].'&p[2]='.$payment['order_id'].'&p[3]='.$payment['status'].'&p[4]='.$payment['t_begin'].'\',onComplete:function(){}}).send();</script>';
  124. $this->_verifyMember(false);
  125. if(!$payment['member_id'] || $payment['member_id']==$this->member['member_id']){
  126. if($payment['status'] == 'succ' && $_COOKIE['order_payed']){
  127. /* ???? */
  128. setcookie('S[order_payed]', '');
  129. }
  130. $this->pagedata['payment'] = &$payment;
  131. $this->output();
  132. }else{
  133. $this->system->error(404);
  134. exit;
  135. }
  136. }
  137. function _init($payment_id){
  138. $aPayment = $this->payment->getPaymentById($payment_id);
  139. if($aPayment['id'] < 1){
  140. $this->splash('failed',$_SERVER["HTTP_REFERER"],__('?????????????'));
  141. }elseif($aPayment['pay_type'] == 'offline'){
  142. if($this->member['member_id'])
  143. $this->splash('failed',$this->system->mkUrl("member","orderdetail",array($_POST['order_id'])),__('????????:').$aPayment['custom_name']);
  144. else $this->splash('failed',$this->system->mkUrl("order","index",array($_POST['order_id'])),__('????????:').$aPayment['custom_name']);
  145. }else{
  146. if($aPayment['pay_type'] == 'deposit'){
  147. $this->_verifyMember();
  148. $this->payment->pay_type = 'deposit';
  149. }else{
  150. $this->payment->pay_type = 'online';
  151. }
  152. $this->payment->fee = $aPayment['fee'];
  153. $this->payment->type = $aPayment['pay_type'];
  154. $this->payment->bank = $aPayment['pay_type'];
  155. $aPayment['config'] = unserialize($aPayment['config']);
  156. $this->payment->config = $aPayment['config'];
  157. $this->payment->account = $aPayment['config']['member_id'];
  158. $this->payment->payment = $payment_id;
  159. $this->payment->paymethod = $aPayment['custom_name'];
  160. $this->payment->status = 'ready';
  161. $this->payment->ip = remote_addr();
  162. $this->payment->t_begin = time();
  163. $this->payment->memo = __('????????');
  164. }
  165. }
  166. }