vali há 6 anos atrás
pai
commit
57eacaef75
1 ficheiros alterados com 33 adições e 8 exclusões
  1. 33 8
      datainf/logic/HttpServerOnlySet.php

+ 33 - 8
datainf/logic/HttpServerOnlySet.php

@@ -241,18 +241,23 @@ class HttpServerOnlySet
         //先前赢过钱的得先扣回来,写流水,再重新计算,
         $money_time = date("Y-m-d H:i:s");
 
-        foreach ($nowArray as $tmp_orderid => $ttttobj) {
+
+        $moneys_this = $this->CountDetailsTounSet($ids);
+        foreach ($moneys_this as $tmp_orderid => $ttttobj) {
             $now_order = $this->PDatas['Money_buy_Orders_Array'][$tmp_orderid];
-            if ($now_order->gain_money * 100 > 0 && ($now_order->settle_status == 2 || $now_order->settle_status == 3)) {
+            if (abs($ttttobj['cha']) > 0) {
                 $order_id = $now_order->order_id;
                 $account_identity = $now_order->account_identity;
                 $account = $this->PDatas['account_map_array'][$account_identity]->account;
-                $returnMoney = $now_order->gain_money;
-                $info_identity = uuid();
+                $returnMoney = abs($ttttobj['cha']);
+                if ($returnMoney == 0) {
+                    continue;
+                }
 
+                $info_identity = uuid();
                 $trade_desc = '重结算[撤销之前]';
                 $reason = '重结算[撤销之前]';
-                $money_type = 2;
+                $money_type = $ttttobj['cha'] > 0 ? 1 : 2;
 
                 $user_money_cash = $this->PDatas['account_indentity_map_array'][$account_identity]->cash - $now_order->gain_money;
                 $this->PDatas['account_indentity_map_array'][$account_identity]->cash = $user_money_cash;
@@ -301,15 +306,35 @@ class HttpServerOnlySet
         }, $ids);
         $ids_array = implode(",", $ids_array);
 
-        $sql = "select trade_id,sum(money) as msum,money_type from money_details where trade_id in ($ids_array) and money_type = 4  group by trade_id,money_type  ";
+        $sql = "select trade_id,sum(money) as msum,money_type,account_identity from money_details where trade_id in ($ids_array) and trade_type = 4  group by trade_id,account_identity,money_type  ";
         $ret = DB::select($sql);
 
         $return = [];
         foreach ($ret as $val) {
-            $order_id = $val->trace_id;
+            $order_id = $val->trade_id;
             $money_type = $val->money_type;
             $money = $val->msum;
-            $return[$order_id][$money_type] = $money;
+            $acc = $val->account_identity;
+            if (!isset($return[$order_id][$money_type])) {
+                $return[$order_id][$money_type] = $money;
+            }
+            if (!isset($return[$order_id]['account'])) {
+                $return[$order_id]['account'] = $acc;
+            }
+        }
+
+        foreach ($return as $order_id => $val) {
+            if (!isset($return[$order_id]['1'])) {
+                $return[$order_id]['1'] = 0;
+            }
+            if (!isset($return[$order_id]['2'])) {
+                $return[$order_id]['2'] = 0;
+            }
+        }
+
+        foreach ($return as $order_id => $val) {
+            //收入 支出差  如果为正则扣多了要加钱,为负则加多了钱要扣回来
+            $return[$order_id]['cha'] = -1 * ($return[$order_id]['1'] - $return[$order_id]['2']);
         }
         return $return;
     }