PayController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. if ($model->handleNotify($data)) {
  34. return $this->outJson(1, $model->getOutNotifyResult());
  35. } else {
  36. return $this->outJson(0, $model->getOutNotifyResult());
  37. }
  38. }
  39. /**
  40. * 同步回调
  41. * @return \yii\web\Response
  42. */
  43. public function actionReturn()
  44. {
  45. $model = new PayForm();
  46. $data = Yii::$app->getRequest()->post();
  47. if ($model->handleReturn($data)) {
  48. return $this->outJson(1, $model->getOutReturnResult());
  49. } else {
  50. return $this->outJson(0, $model->getOutReturnResult());
  51. }
  52. }
  53. /**
  54. * 更新銀行數據庫信息
  55. * @return \yii\web\Response
  56. */
  57. public function actionUpdata()
  58. {
  59. $model = new PayForm();
  60. $data = Yii::$app->getRequest()->post(); //获取到传递过来的数据
  61. $reuslt = Deposit::find()->where(['order_sn' => $data['order']])->asArray()->limit(1)->one();
  62. //如果状态不为1
  63. if($reuslt['type'] == 2){
  64. $res = Deposit::updateAll(['type' => 0,'rmb'=>$data['money'],'amount'=>$data['amount'],'rate'=>$data['rate']], "order_sn =".$data['order']); //更新为成功的状态
  65. if ($res) {
  66. return $this->outJson(1, "success");
  67. } else {
  68. return $this->outJson(0, "false");
  69. }
  70. }else{
  71. return $this->outJson(0, "false");
  72. }
  73. }
  74. /**
  75. * 获取銀行數據庫信息
  76. * @return \yii\web\Response
  77. */
  78. public function actionGetmoney()
  79. {
  80. $model = new PayForm();
  81. $data = Yii::$app->getRequest()->post(); //获取到传递过来的数据
  82. $reuslt = Deposit::find()->where(['order_sn' => $data['order']])->asArray()->limit(1)->one();
  83. //如果状态为2 则表示已经锁定过了
  84. if($reuslt['type'] == 0){
  85. return $this->outJson(1, $reuslt['rmb']);
  86. }else{
  87. return $this->outJson(0, "false");
  88. }
  89. }
  90. }