jace 6 лет назад
Родитель
Сommit
0cdfb27fe5

+ 1 - 1
normandcrm/service/backend/models/Deposit.php

@@ -44,7 +44,7 @@ class Deposit extends \yii\db\ActiveRecord
     {
         return [
             [['type', 'member_id', 'amount', 'rmb', 'rate', 'in_time', 'pay_name', 'login', 'order_sn'], 'required'],
-            [['type', 'member_id', 'in_time', 'login'], 'integer'],
+            [['type', 'member_id', 'in_time', 'login',''], 'integer'],
             [['amount', 'rmb', 'rate'], 'number'],
             [['memo', 'pay_name', 'admin_name', 'order_sn'], 'string', 'max' => 255],
         ];

+ 1 - 1
normandcrm/service/backend/models/Member.php

@@ -61,7 +61,7 @@ class Member extends \yii\db\ActiveRecord
             [['type', 'username', 'password'], 'required'],
             [['type', 'is_enable', 'gender', 'random_code_time', 'ref_id', 'in_time','group_sn'], 'integer'],
             [['birthday'], 'safe'],
-            [['username', 'password', 'ip', 'logins', 'name', 'id_no', 'address', 'mobile', 'main_login', 'random_code', 'avatar', 'ib_old_login_name'], 'string', 'max' => 255],
+            [['username', 'password', 'ip', 'logins', 'name', 'id_no', 'address', 'mobile', 'main_login', 'random_code', 'avatar', 'ib_old_login_name','address1','address2'], 'string', 'max' => 255],
             [['ref_path'], 'string', 'max' => 3000],
         ];
     }

+ 4 - 1
normandcrm/service/common/config/params.php

@@ -41,6 +41,9 @@ return [
     'jiedeng.merId' => '10002',                                       //商户号码
     'jiedeng.Key' => 'cc99ec153ba4e00767e9150f1d30379f',              //秘钥
 	
-	
+	//eagle支付网关项目
+    "eagle.payUrl" =>'https://api.eaglepay.pro/recharge_address',                                  //网关地址
+    'eagle.merId' => '2',                                                                           //商户号码
+    'eagle.Key' => 'A7Zs2LCSP1AepR5pnmOWxJNElkqkWrzw',                                              //md5key
 		
 ];

+ 3 - 0
normandcrm/service/common/pay/BasePayHandler.php

@@ -108,6 +108,9 @@ eot;
             case 14:
                 $handler = new \common\pay\jiedeng\PayHandler();
                 break;
+            case 15:
+                $handler = new \common\pay\eagle\PayHandler();
+                break;
             default:
                 $handler = null;
                 break;

+ 23 - 5
normandcrm/service/common/pay/PayForm.php

@@ -38,6 +38,7 @@ class PayForm extends Model
 		12 =>'银联支付B',
         13 =>'银联支付C',
         14 =>'JD通道A',
+        15 =>'eagle',
     ];
 
     /**
@@ -107,7 +108,7 @@ class PayForm extends Model
             $model->amount = $this->amount;
 			
 			
-			if($payType=='11'||$payType=='12'||$payType=='13'|| $payType=='14'){
+			if($payType=='11'||$payType=='12'||$payType=='13'|| $payType=='14'  || $payType=='15'){
                 $model->rate = $rate['exchangeRate'];
             }else{
                 $model->rate = $rate['sellRate'];
@@ -120,19 +121,36 @@ class PayForm extends Model
             $model->pay_name = isset(self::$payNames[$payType]) ? trim(self::$payNames[$payType]) : '';
             $model->login = $this->login;
             $model->order_sn = $this->orderSn;
-            if ($model->save()) {
+            if($payType=='15'){
                 $handler = BasePayHandler::getPayHandlerByPayType($payType);
                 if ($handler == null) {
                     $this->addError('amount', '支付方式不存在');
                     return false;
                 }
-                $handler->notifyUrl = $this->notifyUrl;
-                $handler->returnUrl = $this->returnUrl;
                 $params = [];
+                $params['login'] = $this->login;
+                $params['member_id'] = $this->memberId;
                 $params['bankCode'] = $this->bankCode;
                 $params['ip'] = $this->ip;
-                $this->_outPayResult = $handler->outPay($model->getAttributes(), $params);
+                $this->_outPayResult = $handler->outPay('', $params);
+            }else{
+
+                if ($model->save()) {
+                    $handler = BasePayHandler::getPayHandlerByPayType($payType);
+                    if ($handler == null) {
+                        $this->addError('amount', '支付方式不存在');
+                        return false;
+                    }
+                    $handler->notifyUrl = $this->notifyUrl;
+                    $handler->returnUrl = $this->returnUrl;
+                    $params = [];
+                    $params['bankCode'] = $this->bankCode;
+                    $params['ip'] = $this->ip;
+                    $this->_outPayResult = $handler->outPay($model->getAttributes(), $params);
+                }
+
             }
+            
         }
         return !$this->hasErrors();
     }

+ 158 - 0
normandcrm/service/common/pay/eagle/PayHandler.php

@@ -0,0 +1,158 @@
+<?php
+
+namespace common\pay\eagle;
+
+use backend\models\Config;
+use backend\models\Deposit;
+use backend\models\SyncDesposit;
+
+use backend\models\Member;
+use backend\helpers\MailHelper;
+
+use common\pay\BasePayHandler;
+use Yii;
+use yii\helpers\VarDumper;
+
+class PayHandler extends BasePayHandler
+{
+    public $payUrl;        //网关地址
+    public $merId;         //mid
+    public $privateKey;    //商户私钥   
+    
+
+    /**
+     * @inheritdoc  
+     */
+    public function init()
+    {
+        parent::init();
+        if ($this->payUrl == null) {
+            $this->payUrl = Yii::$app->params['eagle.payUrl'];             //网关地址
+        }
+        if ($this->merId == null) {
+            $this->merId = Yii::$app->params['eagle.merId'];              //商户号码
+        }
+        if ($this->privateKey == null) {
+            $this->privateKey = Yii::$app->params['eagle.Key'];            //商户私钥
+        }
+       
+    }
+
+    /**
+     * @param array $deposit 
+     * @param array $params
+     * @return string
+     */
+    public function outPay($deposit, $params = [])
+    {
+        $data['merchId'] = $this->merId;                     //商户号码
+        $data['time'] = time();                              //交易时间
+        $data['userId']  = $params['login'];                //用户唯一标识 
+        $data['coin']  = 'USDT';                             //订单号码 
+        $data['sign'] = PayUtils::makeSign($data,$this->privateKey);
+        $result = PayUtils::sendPost($this->payUrl, $data);  //对数据判断,然后发生邮件
+        // 对返回的数据进行转化
+        $result_array = json_decode($result,true);
+        $member_id = $params['member_id'];   // 通过用户id拿到用户的信息  获取到用户的邮箱地址
+        
+        if($result_array['code']==0){
+            $res = Member::updateAll(['address1' =>$result_array['data'][1]['address'],'address2' => $result_array['data'][0]['address']], "id = $member_id");
+            return PayHandler::createGetHtml($result_array['data'][1]['address'],$result_array['data'][0]['address']);
+        }else{
+            return $result_array['message'];
+        }
+    }
+
+    /**
+     * @param array $data
+     * @return bool
+     */
+    public function handleNotify($data)
+    {
+        $string = print_r($data,true);
+        file_put_contents('postshuju.txt',$string);
+        if (isset($data['sign']) && trim($data['sign']) !== '') {
+            
+            if (PayUtils::checkSign($data,$this->privateKey)) {
+                file_put_contents('huidiao.txt','验签成功');
+                if ($data['respCode'] == '00') {
+                    $merOrderId = trim($data['orderId']);     //data函数
+                    $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;
+                            $syncDespositModel->type = 2;
+                            $syncDespositModel->in_time = time();
+                            $syncDespositModel->save();
+                        }
+                    }
+                    return true;
+                }else{
+                    return false;
+                }
+            }
+
+        }
+        return false;
+    }
+
+    public function outNotify($success)
+    {
+        if ($success == true) {
+            return "ok";
+        } 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::checkSign($data,$this->privateKey)) {
+                if ($data['respCode'] == '00') {
+                    $merOrderId = trim($data['orderId']);
+                    $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
+                    if ($reuslt) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    public function outReturn($success)
+    {
+
+    }
+
+
+    // 生成html模板文件
+    public static function createGetHtml($address1,$address2)
+    {
+        $html = <<<eot
+        <div style="border: 1px solid green;width:800px;height: 300px;margin:10% auto;text-align: center;border-radius:30px;padding-top:70px; ">
+        <h4>重要通知</h4>
+        <p>你的钱包绑定成功.</p>
+        <p>地址1:<span style="color:red;">$address1</span>.</p>
+        <p>地址2:<span style="color:red;">$address2</span>.</p>
+        </div>
+eot;
+
+        return $html;
+    }
+
+    
+}

+ 71 - 0
normandcrm/service/common/pay/eagle/PayUtils.php

@@ -0,0 +1,71 @@
+<?php
+namespace common\pay\eagle;
+
+class PayUtils
+{
+
+     /**
+     * @param array $data
+     * @param string $secretKey
+     * @return string
+     */
+    public static function makeSign($data, $secretKey)
+    {
+        $str = '';
+        ksort($data);
+        foreach ($data as $key => $value) {
+            if ($key == 'sign') {
+                continue;
+            }
+            $value = strval($value);
+            if ($value === '') {
+                continue;
+            }
+            $str .= "{$key}={$value}&";
+        }
+        $str = rtrim($str, '&') . "&key={$secretKey}";
+        file_put_contents('190903.txt',$str);
+        file_put_contents('190903md5.txt',strtoupper(md5($str)));
+        return strtoupper(md5($str));
+    }
+
+    /**
+     * @param array $data  参数
+     * @param string $secretKey
+     * @return bool
+     */
+    public static function checkSign($data, $secretKey)
+    {
+        $sign = isset($data['sign']) ? $data['sign'] : null;
+        if ($sign == null) {
+            return false;
+        }
+        return self::makeSign($data, $secretKey) === $sign;
+	}
+	
+
+	/**
+     * 发送post请求
+     * @param string $url 请求地址
+     * @param array $post_data post键值对数据
+     * @return string
+     */
+    public static function sendPost($url, $post_data) {
+
+        $postdata = http_build_query($post_data);
+        $options = array(
+            'http' => array(
+                'method' => 'POST',
+                'header' => 'Content-type:application/x-www-form-urlencoded',
+                'content' => $postdata,
+                'timeout' => 15 * 60 // 超时时间(单位:s)
+            )
+        );
+        $context = stream_context_create($options);
+        $result = file_get_contents($url, false, $context);
+
+        return $result;
+    }
+
+
+}

+ 123 - 0
normandcrm/service/console/controllers/CreatDespositJobController.php

@@ -0,0 +1,123 @@
+<?php
+namespace console\controllers;
+
+use backend\models\Deposit;
+use backend\models\SyncDesposit;
+use common\helpers\MtKit;
+use backend\models\Member;
+use Yii;
+
+class CreatDespositJobController extends Controller
+{
+    public function actionRun()
+    {
+        $this->outLog("Creat start " . date('Y-m-d H:i:s'));
+        $payUrl = "https://api.eaglepay.pro/recharge_address";
+        $key = "A7Zs2LCSP1AepR5pnmOWxJNElkqkWrzw";
+        $result = Deposit::find()->max('recharge_id');   //获取入金表的最大recharge_id
+        $data['merchId'] = '2';                          //商户号码
+        $data['lastId'] = empty($result)?0:$result;      //商户号码
+        $data['limit'] = '20';                           //商户号码
+        $data['time'] = time();                          //交易时间
+        $data['sign'] = CreatDespositJobController::makeSign($data,$key);     //加密sign
+        $result_data = CreatDespositJobController::sendPost($payUrl, $data);  //对数据判断,然后请求
+        $result_array = json_decode($result_data,true);
+        if($result_array['code']=='0'){
+           
+            $post_data = $result_array['data'];
+            foreach ($post_data as $key => $value) {
+                $Deposit = new Deposit();
+                $syncDespositModel = new SyncDesposit();
+                $result = Deposit::find()->where(['recharge_id' => $value['id']])->asArray()->limit(1)->one();      //查看数据库是否有数据
+                $member_info = Member::find()->where(['logins' => $value['userId']])->asArray()->limit(1)->one();   // 根据用户的mt4用户的member的信息
+                if($result){
+                    if($value['status']==1 && $result['type']==0){
+
+                        $res = Deposit::updateAll(['type' => 1], "recharge_id = $value[id]");
+                        if($res){
+                            $syncDespositModel->login = $value['userId'];
+                            $syncDespositModel->amount = $value['amount'];
+                            $syncDespositModel->comment = 'Deposit';
+                            $syncDespositModel->memo = $result['order_sn'];
+                            $syncDespositModel->type = 2;
+                            $syncDespositModel->in_time = time();
+                            $syncDespositModel->save();
+                        }
+                    } 
+                }else{
+                    
+                    $Deposit->type = $value['status']; 
+                    $Deposit->order_sn = date('YmdHis').rand(1000,9999);
+                    $Deposit->member_id =  $member_info['id'];
+                    $Deposit->amount = $value['amount'];
+                    $Deposit->rmb = $value['amount']*6.84;
+                    $Deposit->rate = 6.84;
+                    $Deposit->in_time = time();
+                    $Deposit->pay_name = "eagle";
+                    $Deposit->login = $value['userId'];
+                    $Deposit->mt4_status = '0';
+                    $Deposit->login = $value['userId'];
+                    $Deposit->recharge_id = $value['id'];
+                    $Deposit->save();
+                    if($value['status']==1){
+                        $syncDespositModel->login = $value['userId'];
+                        $syncDespositModel->amount = $value['amount'];
+                        $syncDespositModel->comment = 'Deposit';
+                        $syncDespositModel->memo = $Deposit->order_sn;
+                        $syncDespositModel->type = 2;
+                        $syncDespositModel->in_time = time();
+                        $syncDespositModel->save(); 
+                    }
+                }
+            }
+        }
+        $this->outLog("Creat end, " . date('Y-m-d H:i:s'));
+    }
+    public function outLog($msg)
+    {
+        \Yii::warning($msg, get_called_class());
+        $this->stdout($msg . "\n");
+    }
+
+
+    // 加密方法
+    public static function makeSign($data, $secretKey)
+    {
+        $str = '';
+        ksort($data);
+        foreach ($data as $key => $value) {
+            if ($key == 'sign') {
+                continue;
+            }
+            $value = strval($value);
+            if ($value === '') {
+                continue;
+            }
+            $str .= "{$key}={$value}&";
+        }
+        $str = rtrim($str, '&') . "&key={$secretKey}";
+        file_put_contents('190903.txt',$str);
+        file_put_contents('190903md5.txt',strtoupper(md5($str)));
+        return strtoupper(md5($str));
+    }
+
+
+    // post请求方法
+    public static function sendPost($url, $post_data) {
+
+        $postdata = http_build_query($post_data);
+        $options = array(
+            'http' => array(
+                'method' => 'POST',
+                'header' => 'Content-type:application/x-www-form-urlencoded',
+                'content' => $postdata,
+                'timeout' => 15 * 60 // 超时时间(单位:s)
+            )
+        );
+        $context = stream_context_create($options);
+        $result = file_get_contents($url, false, $context);
+
+        return $result;
+    }
+
+}

+ 2 - 1
normandcrm/xxx/backend/models/forms/PayForm.php

@@ -31,6 +31,7 @@ class PayForm extends Model
 		12 =>'银联支付B',
         13 =>'银联支付C',
         14 =>'JD通道A',
+        15 =>'eagle',
     ]; 
     public static $payMethods = [
         'renren' => 1,
@@ -47,7 +48,7 @@ class PayForm extends Model
 		'yinliantiaozhuan2'=>12,
 		'yinliantiaozhuan3'=>13,
 		'jiedeng'=>14,
-		
+		'eagle'=>15,
     ];
 
     /**

+ 3 - 0
normandcrm/xxx/backend/modules/user/controllers/PayController.php

@@ -44,6 +44,9 @@ class PayController extends BaseController
             }
             if ($data['payType'] == 14) {
                 $data['amount'] = 0.00;
+            }
+            if ($data['payType'] == 15) {
+                $data['amount'] = 0.00;
             }
 			//echo "<pre>";
 			//var_dump($data);die;

+ 2 - 2
normandcrm/xxx/backend/modules/user/views/bankdeposit/index.php

@@ -338,7 +338,7 @@ $this->title = '入金';
         var usd = parseFloat($('#usd').val());
 		var payMethod = $("#payMethod").val();
         var money = isNaN(usd) ? 0 : (usd * <?= isset($rate['sellRate']) ? $rate['sellRate'] : 0 ?>).toFixed(2);
-		if(payMethod == 'yinliantiaozhuan' || payMethod == 'yinliantiaozhuan2' || payMethod == 'yinliantiaozhuan3' || payMethod == 'jiedeng'){
+		if(payMethod == 'yinliantiaozhuan' || payMethod == 'yinliantiaozhuan2' || payMethod == 'yinliantiaozhuan3' || payMethod == 'jiedeng' || payMethod == 'eagle' ){
            var money = isNaN(usd) ? 0 : (usd * <?= isset($rate['exchangeRate']) ? $rate['exchangeRate'] : 0 ?>).toFixed(2);
 		   $('#guojiyinlian').css('display','none');
            $('.guojiyinlian').css('display','none');
@@ -374,7 +374,7 @@ $this->title = '入金';
         }
 	
 		//银联支付
-		if (payMethod == 'yinliantiaozhuan' || payMethod == 'yinliantiaozhuan2' || payMethod == 'yinliantiaozhuan3' || payMethod == 'jiedeng') {
+		if (payMethod == 'yinliantiaozhuan' || payMethod == 'yinliantiaozhuan2' || payMethod == 'yinliantiaozhuan3' || payMethod == 'jiedeng' ||  payMethod == 'eagle') {
             let num = <?= isset($rate['exchangeRate']) ? $rate['exchangeRate'] : 0 ?>;
             $("#sellRate").text(num);
             $('#RMBcode').text('港币');