PayHandler.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace common\pay\duigong;
  3. use backend\models\Config;
  4. use backend\models\Deposit;
  5. use backend\models\SyncDesposit;
  6. use common\pay\BasePayHandler;
  7. use backend\models\PublicAccount;
  8. use Yii;
  9. use yii\helpers\VarDumper;
  10. class PayHandler extends BasePayHandler
  11. {
  12. public $payUrl;
  13. public $merId;
  14. /**
  15. * @inheritdoc
  16. */
  17. public function init()
  18. {
  19. parent::init();
  20. if ($this->payUrl == null) {
  21. $this->payUrl ='';
  22. }
  23. if ($this->merId == null) {
  24. $this->merId ='';
  25. }
  26. }
  27. /**
  28. * @param array $deposit
  29. * @param array $params
  30. * @return string
  31. */
  32. public function outPay($deposit, $params = [])
  33. {
  34. $data = [];
  35. $money = sprintf("%.2f",$deposit['rmb']);
  36. $PublicAccount = new PublicAccount();
  37. $result = $PublicAccount->getAccountConfig();
  38. $result_account = $result['account']; // 卡号
  39. $result_name = $result['name']; // 收款姓名
  40. $result_bank = $result['bank']; // 收款开户行
  41. return PayHandler::createGetHtml($money,$result_account,$result_name,$result_bank);
  42. }
  43. /**
  44. * @param array $data
  45. * @return bool
  46. */
  47. public function handleNotify($data)
  48. {
  49. // Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
  50. if (isset($data['sign']) && trim($data['sign']) !== '') {
  51. if (PayUtils::verify($data, $this->publicKey)) {
  52. if ($data['status'] == '1') {
  53. $merOrderId = trim($data['orderNo']);
  54. $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
  55. if ($reuslt['type'] != 1) {
  56. $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
  57. $configData = Config::find()->asArray()->one();
  58. if ($configData['auto_deposit'] == 1 && $res) {
  59. $syncDespositModel = new SyncDesposit();
  60. $syncDespositModel->login = $reuslt['login'];
  61. $syncDespositModel->amount = $reuslt['amount'];
  62. $syncDespositModel->comment = 'Deposit';
  63. $syncDespositModel->memo = $merOrderId; //存储入金表的订单id
  64. $syncDespositModel->type = 2;
  65. $syncDespositModel->in_time = time();
  66. $syncDespositModel->save();
  67. }
  68. return success;
  69. }
  70. }
  71. }
  72. }
  73. return false;
  74. }
  75. public function outNotify($success)
  76. {
  77. if ($success == true) {
  78. return "success";
  79. } else {
  80. // 返回的数据格式
  81. return "FAIL";
  82. }
  83. }
  84. /**
  85. * @param array $data
  86. * @return bool
  87. */
  88. public function handleReturn($data)
  89. {
  90. //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
  91. if (isset($data['sign']) && trim($data['sign']) !== '') {
  92. if (PayUtils::verify($data, $this->publicKey)) {
  93. if ($data['status'] == '1') {
  94. $merOrderId = trim($data['orderNo']);
  95. $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
  96. if ($reuslt) {
  97. return success;
  98. }
  99. }
  100. }
  101. }
  102. return false;
  103. }
  104. public function outReturn($success)
  105. {
  106. }
  107. // 生成html模板文件
  108. public static function createGetHtml($money,$result_account,$result_name,$result_bank)
  109. {
  110. $html = <<<eot
  111. <div style="border: 1px solid green;width:800px;height: 350px;margin:10% auto;text-align:left;border-radius:30px;padding-top:70px; ">
  112. <p>请转账到如下账户</p>
  113. <p>订单金额为:<span style="color:red;">{$money}</span></p>
  114. <p>收款账号为:{$result_account}</p>
  115. <p>收款姓名为:$result_name</p>
  116. <p>收款开户行为:{$result_bank}</p>
  117. </div>
  118. eot;
  119. return $html;
  120. }
  121. }