vali 6 years ago
parent
commit
7c53dc6c48
2 changed files with 85 additions and 4 deletions
  1. 58 4
      app/Logic/UnSettmatchLogic.php
  2. 27 0
      datainf/lib/functions.php

+ 58 - 4
app/Logic/UnSettmatchLogic.php

@@ -127,18 +127,49 @@ class UnSettmatchLogic
         //关联用户
         //关联用户
         $userInents = $this->getAccountIdents($useraccs);
         $userInents = $this->getAccountIdents($useraccs);
         //用户资金变化记录,以后好一次性更新用户余额
         //用户资金变化记录,以后好一次性更新用户余额
-        $userInents_money = [];
+        $time = date("Y-m-d H:i:s");
+        $userMoneyChange = [];   //用户资金变化记录,好一次性更新
+
         foreach ($simples as $item) {
         foreach ($simples as $item) {
             $gain_money = $item->gain_money;
             $gain_money = $item->gain_money;
+            $accountIdent = $item->account_identity;
+
+            $mModel = new MoneyDetailsModel();
+            $mModel->info_identity = UUID();
+            $mModel->trade_id = $item->order_id;
+            $mModel->account_name = $userInents['accountIdent']->account;
+            $mModel->account_identity = $accountIdent;
+            $mModel->moneytime = $time;
+            $mModel->money_type = 3;
+            $mModel->trade_desc = '赛事取消返款--matchid=' . $this->match_id;
+
             if ($gain_money <= 0.01) {
             if ($gain_money <= 0.01) {
                 $return_money = $item->money * (1 - $this->fanshui);
                 $return_money = $item->money * (1 - $this->fanshui);
+                $mModel->money_type = 1;
+                $mModel->money = $return_money;
+                $userMoneyChange[$accountIdent] = isset($userMoneyChange[$accountIdent]) ? ($userMoneyChange[$accountIdent] + $return_money) : $return_money;
             } else {
             } else {
                 $return_money = $gain_money - $item->money * (1 - $this->fanshui);
                 $return_money = $gain_money - $item->money * (1 - $this->fanshui);
+                $mModel->money_type = 2;
+                $mModel->money = $return_money;
+                $userMoneyChange[$accountIdent] = isset($userMoneyChange[$accountIdent]) ? ($userMoneyChange[$accountIdent] - $return_money) : -1 * $return_money;
             }
             }
 
 
-
+            $mModel->save();
+            $item->status = 3;
+            $item->save();
         }
         }
 
 
+        if ($userMoneyChange) {
+            foreach ($userMoneyChange as $uident => $money) {
+                if (abs($money) > 0) {
+                    $userInents[$uident]->detail->available_cash = $userInents[$uident]->detail->available_cash + $money;
+                    $userInents[$uident]->detail->cash = $userInents[$uident]->detail->cash + $money;
+                    $userInents[$uident]->detail->save();
+                }
+            }
+        }
+        return true;
 
 
     }
     }
 
 
@@ -146,12 +177,35 @@ class UnSettmatchLogic
     //处理串式订单相关逻辑
     //处理串式订单相关逻辑
     public function doStr()
     public function doStr()
     {
     {
-        $simples = $this->getStrOrders($this->game_code, $this->match_id);
-        if (empty($simples)) {
+        $strOrders = $this->getStrOrders($this->game_code, $this->match_id);
+        if (empty($strOrders)) {
             return;
             return;
         }
         }
 
 
+        //这里只把结果改为平局,再提交到旧的重新结算订单接口处理
+        foreach ($strOrders as $item2) {
+            $mats = $item2->matchdatas;
+            foreach ($mats as $item3) {
+                $item3->result = 2;
+                $item3->matchresult = '赛事撤销!';
+                $item3->save();
+            }
+        }
 
 
+        $dataArr = [
+            'game_code' => $this->game_code,
+            'match_id' => $this->match_id,
+            'settype' => 2,
+            'bettype' => 2,
+            'change_status' => 0,
+        ];
+        $url = 'http://127.0.0.1:9094/Settelement';
+        foreach ($strOrders as $item) {
+
+            $dataArr['order_ids'] = $item->order_id;
+            post_curls($url, $dataArr);
+        }
+        return;
     }
     }
 
 
     //得到某个账户的信息,主要是余额情况
     //得到某个账户的信息,主要是余额情况

+ 27 - 0
datainf/lib/functions.php

@@ -47,3 +47,30 @@ function orders_to_strval($order_array)
         return strval($i);
         return strval($i);
     }, $order_array);
     }, $order_array);
 }
 }
+
+
+/**
+ * POST请求https接口返回内容
+ * @param  string $url [请求的URL地址]
+ * @param  string $post [请求的参数]
+ * @return  string
+ */
+function post_curls($url, $post)
+{
+    $curl = curl_init(); // 启动一个CURL会话
+    curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
+    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
+    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
+    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
+    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
+    curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
+    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
+    curl_setopt($curl, CURLOPT_POSTFIELDS, $post); // Post提交的数据包
+    curl_setopt($curl, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
+    curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
+    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
+    $res = curl_exec($curl); // 执行操作
+    curl_close($curl); // 关闭CURL会话
+    return $res; // 返回数据,json格式
+
+}