PayHandler.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. $money = sprintf("%.2f",$deposit['rmb']);
  35. $PublicAccount = new PublicAccount();
  36. $result = $PublicAccount->getAccountConfig();
  37. $result_account = $result['account']; // 卡号
  38. $result_name = $result['name']; // 收款姓名
  39. $result_bank = $result['bank']; // 收款开户行
  40. return PayHandler::createGetHtml($money,$result_account,$result_name,$result_bank);
  41. }
  42. /**
  43. * @param array $data
  44. * @return bool
  45. */
  46. public function handleNotify($data)
  47. {
  48. // Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
  49. if (isset($data['sign']) && trim($data['sign']) !== '') {
  50. if (PayUtils::verify($data, $this->publicKey)) {
  51. if ($data['status'] == '1') {
  52. $merOrderId = trim($data['orderNo']);
  53. $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
  54. if ($reuslt['type'] != 1) {
  55. $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
  56. $configData = Config::find()->asArray()->one();
  57. if ($configData['auto_deposit'] == 1 && $res) {
  58. $syncDespositModel = new SyncDesposit();
  59. $syncDespositModel->login = $reuslt['login'];
  60. $syncDespositModel->amount = $reuslt['amount'];
  61. $syncDespositModel->comment = 'Deposit';
  62. $syncDespositModel->memo = $merOrderId; //存储入金表的订单id
  63. $syncDespositModel->type = 2;
  64. $syncDespositModel->in_time = time();
  65. $syncDespositModel->save();
  66. }
  67. return success;
  68. }
  69. }
  70. }
  71. }
  72. return false;
  73. }
  74. public function outNotify($success)
  75. {
  76. if ($success == true) {
  77. return "success";
  78. } else {
  79. // 返回的数据格式
  80. return "FAIL";
  81. }
  82. }
  83. /**
  84. * @param array $data
  85. * @return bool
  86. */
  87. public function handleReturn($data)
  88. {
  89. //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
  90. if (isset($data['sign']) && trim($data['sign']) !== '') {
  91. if (PayUtils::verify($data, $this->publicKey)) {
  92. if ($data['status'] == '1') {
  93. $merOrderId = trim($data['orderNo']);
  94. $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
  95. if ($reuslt) {
  96. return success;
  97. }
  98. }
  99. }
  100. }
  101. return false;
  102. }
  103. public function outReturn($success)
  104. {
  105. }
  106. // 生成html模板文件
  107. public static function createGetHtml($money,$result_account,$result_name,$result_bank)
  108. {
  109. $html = <<<eot
  110. <div style="border: 1px solid green;width:500px;height: 200px;margin:10% auto;text-align:left;border-radius:30px;padding:70px; ">
  111. <h4 style="text-align: center;">请转账到如下账户:</h4>
  112. <p>订单金额为:<span style="color:red;">{$money}元</span></p>
  113. <p>收款账号为:{$result_account}</p>
  114. <p>收款姓名为:$result_name</p>
  115. <p>收款开户行为:{$result_bank}</p>
  116. </div>
  117. eot;
  118. return $html;
  119. }
  120. }