| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace common\pay\duigong;
- use backend\models\Config;
- use backend\models\Deposit;
- use backend\models\SyncDesposit;
- use common\pay\BasePayHandler;
- use backend\models\PublicAccount;
- use Yii;
- use yii\helpers\VarDumper;
- class PayHandler extends BasePayHandler
- {
- public $payUrl;
- public $merId;
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl ='';
- }
- if ($this->merId == null) {
- $this->merId ='';
- }
- }
- /**
- * @param array $deposit
- * @param array $params
- * @return string
- */
- public function outPay($deposit, $params = [])
- {
- $money = sprintf("%.2f",$deposit['rmb']);
- $PublicAccount = new PublicAccount();
- $result = $PublicAccount->getAccountConfig();
- if($result['id']){
- PublicAccount::updateAll([
- 'is_used'=> 1,
- ], "id =".$result['id']);
- $result_account = $result['account']; // 卡号
- $result_name = $result['name']; // 收款姓名
- $result_bank = $result['bank']; // 收款开户行
- return PayHandler::createGetHtml($money,$result_account,$result_name,$result_bank);
- }else{
- return '该通道已关闭';
- }
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
-
- // Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- if (isset($data['sign']) && trim($data['sign']) !== '') {
-
- if (PayUtils::verify($data, $this->publicKey)) {
- if ($data['status'] == '1') {
-
- $merOrderId = trim($data['orderNo']);
- $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
- if ($reuslt['type'] != 1) {
- $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
- $configData = Config::find()->asArray()->one();
- if ($configData['auto_deposit'] == 1 && $res) {
- $syncDespositModel = new SyncDesposit();
- $syncDespositModel->login = $reuslt['login'];
- $syncDespositModel->amount = $reuslt['amount'];
- $syncDespositModel->comment = 'Deposit';
- $syncDespositModel->memo = $merOrderId; //存储入金表的订单id
- $syncDespositModel->type = 2;
- $syncDespositModel->in_time = time();
- $syncDespositModel->save();
- }
- return success;
- }
- }
- }
- }
- return false;
- }
- public function outNotify($success)
- {
- if ($success == true) {
- return "success";
- } else {
- // 返回的数据格式
- return "FAIL";
- }
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleReturn($data)
- {
- //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- if (isset($data['sign']) && trim($data['sign']) !== '') {
- if (PayUtils::verify($data, $this->publicKey)) {
- if ($data['status'] == '1') {
- $merOrderId = trim($data['orderNo']);
- $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
- if ($reuslt) {
- return success;
- }
- }
- }
- }
- return false;
- }
- public function outReturn($success)
- {
- }
- // 生成html模板文件
- public static function createGetHtml($money,$result_account,$result_name,$result_bank)
- {
- $html = <<<eot
- <div style="border: 1px solid green;width:500px;height: 200px;margin:10% auto;text-align:left;border-radius:30px;padding:70px; ">
- <h4 style="text-align: center;">请转账到如下账户:</h4>
- <p>订单金额为:<span style="color:red;">{$money}元</span></p>
- <p>收款账号为:{$result_account}</p>
- <p>收款姓名为:$result_name</p>
- <p>收款开户行为:{$result_bank}</p>
- </div>
- eot;
- return $html;
- }
- }
|