PayController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace backend\controllers;
  3. use common\pay\PayForm;
  4. use backend\models\Deposit;
  5. use Yii;
  6. class PayController extends BaseController
  7. {
  8. /**
  9. * 支付
  10. * @return \yii\web\Response
  11. */
  12. public function actionOutpay()
  13. {
  14. $model = new PayForm();
  15. $data = Yii::$app->getRequest()->post();
  16. $model->setAttributes($data);
  17. if ($model->outPay()) {
  18. $result['type'] = 'html';
  19. $result['html'] = $model->getOutPayResult();
  20. return $this->outJson(1, $result, 'OK');
  21. } else {
  22. return $this->outJson(0, [], $model->getErrors());
  23. }
  24. }
  25. /**
  26. * 异步回调
  27. * @return \yii\web\Response
  28. */
  29. public function actionNotify()
  30. {
  31. $model = new PayForm();
  32. $data = Yii::$app->getRequest()->post();
  33. $tt = print_r($data,true);
  34. file_put_contents('huiqi3.txt',$tt);
  35. if ($model->handleNotify($data)) {
  36. return $this->outJson(1, $model->getOutNotifyResult());
  37. } else {
  38. return $this->outJson(0, $model->getOutNotifyResult());
  39. }
  40. }
  41. /**
  42. * 同步回调
  43. * @return \yii\web\Response
  44. */
  45. public function actionReturn()
  46. {
  47. $model = new PayForm();
  48. $data = Yii::$app->getRequest()->post();
  49. if ($model->handleReturn($data)) {
  50. return $this->outJson(1, $model->getOutReturnResult());
  51. } else {
  52. return $this->outJson(0, $model->getOutReturnResult());
  53. }
  54. }
  55. /**
  56. * 更新銀行數據庫信息
  57. * @return \yii\web\Response
  58. */
  59. public function actionUpdata()
  60. {
  61. $model = new PayForm();
  62. $data = Yii::$app->getRequest()->post(); //获取到传递过来的数据
  63. $reuslt = Deposit::find()->where(['order_sn' => $data['order']])->asArray()->limit(1)->one();
  64. //如果状态不为1
  65. if($reuslt['type'] == 2){
  66. $res = Deposit::updateAll(['type' => 0,'rmb'=>$data['money'],'amount'=>$data['amount'],'rate'=>$data['rate']], "order_sn =".$data['order']); //更新为成功的状态
  67. if ($res) {
  68. return $this->outJson(1, "success");
  69. } else {
  70. return $this->outJson(0, "false");
  71. }
  72. }else{
  73. return $this->outJson(0, "false");
  74. }
  75. }
  76. /**
  77. * 获取銀行數據庫信息
  78. * @return \yii\web\Response
  79. */
  80. public function actionGetmoney()
  81. {
  82. $model = new PayForm();
  83. $data = Yii::$app->getRequest()->post(); //获取到传递过来的数据
  84. $reuslt = Deposit::find()->where(['order_sn' => $data['order']])->asArray()->limit(1)->one();
  85. //如果状态为2 则表示已经锁定过了
  86. if($reuslt['type'] == 0){
  87. return $this->outJson(1, $reuslt['rmb']);
  88. }else{
  89. return $this->outJson(0, "false");
  90. }
  91. }
  92. }