CreatDespositJobController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace console\controllers;
  3. use backend\models\Deposit;
  4. use backend\models\SyncDesposit;
  5. use common\helpers\MtKit;
  6. use backend\models\Member;
  7. use Yii;
  8. class CreatDespositJobController extends Controller
  9. {
  10. public function actionRun()
  11. {
  12. $this->outLog("Creat start " . date('Y-m-d H:i:s'));
  13. $payUrl = "https://api.eaglepay.pro/recharge_address";
  14. $key = "A7Zs2LCSP1AepR5pnmOWxJNElkqkWrzw";
  15. $result = Deposit::find()->max('recharge_id'); //获取入金表的最大recharge_id
  16. $data['merchId'] = '2'; //商户号码
  17. $data['lastId'] = empty($result)?0:$result; //商户号码
  18. $data['limit'] = '20'; //商户号码
  19. $data['time'] = time(); //交易时间
  20. $data['sign'] = CreatDespositJobController::makeSign($data,$key); //加密sign
  21. $result_data = CreatDespositJobController::sendPost($payUrl, $data); //对数据判断,然后请求
  22. $result_array = json_decode($result_data,true);
  23. if($result_array['code']=='0'){
  24. $post_data = $result_array['data'];
  25. foreach ($post_data as $key => $value) {
  26. $Deposit = new Deposit();
  27. $syncDespositModel = new SyncDesposit();
  28. $result = Deposit::find()->where(['recharge_id' => $value['id']])->asArray()->limit(1)->one(); //查看数据库是否有数据
  29. $member_info = Member::find()->where(['logins' => $value['userId']])->asArray()->limit(1)->one(); // 根据用户的mt4用户的member的信息
  30. if($result){
  31. if($value['status']==1 && $result['type']==0){
  32. $res = Deposit::updateAll(['type' => 1], "recharge_id = $value[id]");
  33. if($res){
  34. $syncDespositModel->login = $value['userId'];
  35. $syncDespositModel->amount = $value['amount'];
  36. $syncDespositModel->comment = 'Deposit';
  37. $syncDespositModel->memo = $result['order_sn'];
  38. $syncDespositModel->type = 2;
  39. $syncDespositModel->in_time = time();
  40. $syncDespositModel->save();
  41. }
  42. }
  43. }else{
  44. $Deposit->type = $value['status'];
  45. $Deposit->order_sn = date('YmdHis').rand(1000,9999);
  46. $Deposit->member_id = $member_info['id'];
  47. $Deposit->amount = $value['amount'];
  48. $Deposit->rmb = $value['amount']*6.84;
  49. $Deposit->rate = 6.84;
  50. $Deposit->in_time = time();
  51. $Deposit->pay_name = "eagle";
  52. $Deposit->login = $value['userId'];
  53. $Deposit->mt4_status = '0';
  54. $Deposit->login = $value['userId'];
  55. $Deposit->recharge_id = $value['id'];
  56. $Deposit->save();
  57. if($value['status']==1){
  58. $syncDespositModel->login = $value['userId'];
  59. $syncDespositModel->amount = $value['amount'];
  60. $syncDespositModel->comment = 'Deposit';
  61. $syncDespositModel->memo = $Deposit->order_sn;
  62. $syncDespositModel->type = 2;
  63. $syncDespositModel->in_time = time();
  64. $syncDespositModel->save();
  65. }
  66. }
  67. }
  68. }
  69. $this->outLog("Creat end, " . date('Y-m-d H:i:s'));
  70. }
  71. public function outLog($msg)
  72. {
  73. \Yii::warning($msg, get_called_class());
  74. $this->stdout($msg . "\n");
  75. }
  76. // 加密方法
  77. public static function makeSign($data, $secretKey)
  78. {
  79. $str = '';
  80. ksort($data);
  81. foreach ($data as $key => $value) {
  82. if ($key == 'sign') {
  83. continue;
  84. }
  85. $value = strval($value);
  86. if ($value === '') {
  87. continue;
  88. }
  89. $str .= "{$key}={$value}&";
  90. }
  91. $str = rtrim($str, '&') . "&key={$secretKey}";
  92. file_put_contents('190903.txt',$str);
  93. file_put_contents('190903md5.txt',strtoupper(md5($str)));
  94. return strtoupper(md5($str));
  95. }
  96. // post请求方法
  97. public static function sendPost($url, $post_data) {
  98. $postdata = http_build_query($post_data);
  99. $options = array(
  100. 'http' => array(
  101. 'method' => 'POST',
  102. 'header' => 'Content-type:application/x-www-form-urlencoded',
  103. 'content' => $postdata,
  104. 'timeout' => 15 * 60 // 超时时间(单位:s)
  105. )
  106. );
  107. $context = stream_context_create($options);
  108. $result = file_get_contents($url, false, $context);
  109. return $result;
  110. }
  111. }