| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?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 BaseJobController
- {
- public function actionRun()
- {
- $this->outLog("Creat start " . date('Y-m-d H:i:s'));
- $payUrl = "https://api.eaglepay.pro/recharge_list";
- $key = "fI30tbPtTsSN4ANNblMdpethfGVUweJ1";
- $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;
- }
- }
|