|
|
@@ -11,6 +11,7 @@ namespace App\Logic;
|
|
|
use App\Http\Response\Response;
|
|
|
use App\Lib\Settlement\SettlementBase;
|
|
|
use Illuminate\Database\Capsule\Manager as DB;
|
|
|
+use swoole;
|
|
|
|
|
|
trait SettelementLogic
|
|
|
{
|
|
|
@@ -45,61 +46,74 @@ trait SettelementLogic
|
|
|
if (empty($chekArr) || count($chekArr) != 1) {
|
|
|
throw new \Exception('不同场比赛不能同时结算!');
|
|
|
}
|
|
|
+ unset($chekArr);
|
|
|
}
|
|
|
|
|
|
- if (!$this->DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status)) {
|
|
|
- throw new \Exception('没找到订单信息');
|
|
|
- }
|
|
|
- $this->UndoSettlement();
|
|
|
|
|
|
+ //分页处理数据
|
|
|
+ $PageOrder_ids_1 = array_chunk($order_ids, 500);
|
|
|
+ unset($order_ids);
|
|
|
+ //$PageOrder_ids[0] = $PageOrder_ids_1['0'];
|
|
|
|
|
|
- while (true) {
|
|
|
- if ($this->httpserver->taskWorkingNum->get() > intval($this->config['sets']['task_worker_num'])) {
|
|
|
- co::sleep(30);
|
|
|
- } else {
|
|
|
- $order_id = trim(array_shift($order_ids));
|
|
|
-
|
|
|
- if (empty($order_id)) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ foreach ($PageOrder_ids_1 as $p_order_ids) {
|
|
|
|
|
|
+ if (!$this->DataPre($p_order_ids, $bettype, $settype, $game_code, $match_id, 0)) {
|
|
|
+ throw new \Exception('没找到订单信息');
|
|
|
+ }
|
|
|
|
|
|
- $nowBuyDatasMainModel = $this->PDatas['Money_buy_Orders_Array'][$order_id];
|
|
|
- if ($nowBuyDatasMainModel->settle_status == 2 && $settype == 1) {
|
|
|
- continue;
|
|
|
+ $this->UndoSettlement();
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ if ($this->httpserver->taskWorkingNum->get() >= intval($this->config['sets']['task_worker_num'])) {
|
|
|
+ //echo "Work coutn: " . $this->httpserver->taskWorkingNum->get() . "\n";
|
|
|
+ \co::sleep(0.01);
|
|
|
+ } else {
|
|
|
+ $order_id = trim(array_shift($p_order_ids));
|
|
|
+
|
|
|
+ if (empty($order_id)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $nowBuyDatasMainModel = $this->PDatas['Money_buy_Orders_Array'][$order_id];
|
|
|
+ if ($nowBuyDatasMainModel->settle_status == 2 && $settype == 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $account_indent = $nowBuyDatasMainModel->account_identity;
|
|
|
+ $batch_id = $nowBuyDatasMainModel->batch_id;
|
|
|
+
|
|
|
+ $paras = [
|
|
|
+ 'type' => 'Settelement',
|
|
|
+ 'bet_type' => $bettype,
|
|
|
+ 'set_type' => $settype,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'game_code' => $nowBuyDatasMainModel->game_code,
|
|
|
+ 'match_id' => $match_id,
|
|
|
+ 'simplexData' => $nowBuyDatasMainModel,
|
|
|
+ 'matchDatas' => $this->PDatas['Money_buy_Match_array'][$batch_id],
|
|
|
+ 'settelementMidDataID' => isset($this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]) ? $this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]->id : 0,
|
|
|
+ 'account' => $this->PDatas['account_map_array'][$account_indent]->account,
|
|
|
+ 'money_prize' => isset($this->PDatas['money_prize_map'][$order_id]) ? $this->PDatas['money_prize_map'][$order_id]->id : 0
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->onTask($this->httpserver, $paras);
|
|
|
}
|
|
|
-
|
|
|
- $account_indent = $nowBuyDatasMainModel->account_identity;
|
|
|
- $batch_id = $nowBuyDatasMainModel->batch_id;
|
|
|
-
|
|
|
- $paras = [
|
|
|
- 'type' => 'Settelement',
|
|
|
- 'bet_type' => $bettype,
|
|
|
- 'set_type' => $settype,
|
|
|
- 'order_id' => $order_id,
|
|
|
- 'game_code' => $nowBuyDatasMainModel->game_code,
|
|
|
- 'match_id' => $match_id,
|
|
|
- 'simplexData' => $nowBuyDatasMainModel,
|
|
|
- 'matchDatas' => $this->PDatas['Money_buy_Match_array'][$batch_id],
|
|
|
- 'settelementMidDataID' => isset($this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]) ? $this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]->id : 0,
|
|
|
- 'account' => $this->PDatas['account_map_array'][$account_indent]->account,
|
|
|
- 'money_prize' => isset($this->PDatas['money_prize_map'][$order_id]) ? $this->PDatas['money_prize_map'][$order_id]->id : 0
|
|
|
- ];
|
|
|
-
|
|
|
- $this->onTask($this->httpserver, $paras);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
$this->cgStatus($game_code, $match_id, $change_status);
|
|
|
|
|
|
LABRETURN:
|
|
|
$data = Response::generate('', 1, ['cost' => (microtime(true) - $request->server['request_time_float'])], 'succes ');
|
|
|
$response->end($data);
|
|
|
+ unset($bettype, $settype, $game_code, $match_id, $change_status, $PageOrder_ids_1, $p_order_id, $data);
|
|
|
return;
|
|
|
} catch (\Exception $e) {
|
|
|
$this->PDatas = [];
|
|
|
|
|
|
$data = Response::generate('', 10, '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
|
|
|
$response->end($data);
|
|
|
+ unset($data);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -122,7 +136,9 @@ trait SettelementLogic
|
|
|
$e = str_replace(";", ";", $e->getMessage());
|
|
|
$sql = "update $table set remark='$e' where order_id='$order_id' ";
|
|
|
$this->PushSqlToArray($sql);
|
|
|
+ unset($sql, $e);
|
|
|
}
|
|
|
+ unset($order_id, $bet_type, $table);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -186,6 +202,7 @@ trait SettelementLogic
|
|
|
$money_prize
|
|
|
);
|
|
|
|
|
|
+ unset($matchDatas, $simplexData, $account_identity, $bet_type, $order_id, $match_id, $game_code, $account, $money_prize, $returnMoney);
|
|
|
}
|
|
|
|
|
|
private function WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_ident, $money)
|
|
|
@@ -254,6 +271,7 @@ trait SettelementLogic
|
|
|
$chuanNum = intval(substr($simplexData->str_type, 0, 1));
|
|
|
$lasPeilv = $settlementBase->stringComputing([$in_array, $chuanNum]);
|
|
|
$money = floatPointDigit($this->BuyDatasMainModel->money * $lasPeilv);
|
|
|
+ unset($chuanNum, $lasPeilv);
|
|
|
|
|
|
} else {
|
|
|
$money = $simplexData->money;
|
|
|
@@ -264,6 +282,8 @@ trait SettelementLogic
|
|
|
$this->WriteOrAddSettlement($this->game_code, $this->match_id, $this->orderType, $order_id, $this->BuyDatasMainModel->account_identity, $money);
|
|
|
$this->insertData($order_id, $money, $this->BuyDatasMainModel->account_identity, 2, $val->game_code, $this->BuyDatasMainModel->info_identity, $this->BuyDatasMainModel->money, $this->match_id, $account, $money_prize);
|
|
|
|
|
|
+ unset($matchDatas, $simplexData, $account_identity, $bet_type, $order_id, $match_id, $game_code, $account, $money_prize, $money);
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -280,7 +300,6 @@ trait SettelementLogic
|
|
|
*/
|
|
|
private function insertData($order_id, $returnMoney, $account_identity, $type, $game_name, $buy_identity, $money, $match_id = 0, $account = '', $money_prizeID = 0)
|
|
|
{
|
|
|
-
|
|
|
// 添加流水记录
|
|
|
$info_identity = UUID();
|
|
|
$money_time = date('Y-m-d H:i:s', time());
|
|
|
@@ -311,23 +330,38 @@ trait SettelementLogic
|
|
|
$sql .= "('$info_identity','$order_id','$account_identity','$account','$game_name','$buy_identity',$money,'$money_time',1,$returnMoney,$returnMoney - $money)";
|
|
|
$this->PushSqlToArray($sql);
|
|
|
}
|
|
|
+ unset($info_identity, $money_time, $trade_desc, $reason, $content, $sql);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private function resetPDatas()
|
|
|
+ {
|
|
|
+ $bettype = $this->PDatas['bettype'];
|
|
|
+ $settype = $this->PDatas['settype'];
|
|
|
+ $game_code = $this->PDatas['game_code'];
|
|
|
+ $match_id = $this->PDatas['match_id'];
|
|
|
+ $this->PDatas = [];
|
|
|
+
|
|
|
+ $this->PDatas['bettype'] = $bettype;
|
|
|
+ $this->PDatas['settype'] = $settype;
|
|
|
+ $this->PDatas['game_code'] = $game_code;
|
|
|
+ $this->PDatas['match_id'] = $match_id;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
//数据预批量获取
|
|
|
private function DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status)
|
|
|
{
|
|
|
+ $this->resetPdatas();
|
|
|
|
|
|
- //DB::connection()->enableQueryLog();
|
|
|
if ($bettype == 1) {
|
|
|
$moneytable = 'money_buy_simplex';
|
|
|
- $ret = DB::table('money_buy_simplex')->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
|
|
|
+ $ret = DB::table($moneytable)->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
|
|
|
} else {
|
|
|
$moneytable = 'money_buy_str';
|
|
|
- $ret = DB::table('money_buy_str')->whereIn('order_id', $order_ids)->get();
|
|
|
+ $ret = DB::table($moneytable)->whereIn('order_id', $order_ids)->get();
|
|
|
}
|
|
|
- //print_r(DB::getQueryLog());
|
|
|
|
|
|
if (empty($ret) || count($ret) <= 0) {
|
|
|
return false;
|
|
|
@@ -384,6 +418,7 @@ trait SettelementLogic
|
|
|
$sql_tmp = "update $moneytable set settle_status=1, gain_money=0 where order_id in ($order_str) ";
|
|
|
}
|
|
|
$this->PushSqlToArray($sql_tmp);
|
|
|
+ unset($sql_tmp);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -394,6 +429,7 @@ trait SettelementLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ unset($ret, $tmpbatchid, $userindentys, $moneytable);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -434,6 +470,8 @@ trait SettelementLogic
|
|
|
|
|
|
$ret = [$order_ids, $bettype, $settype, $game_code, $match_id, $change_status];
|
|
|
|
|
|
+ unset($bettype, $idoarr, $settype, $game_code, $match_id, $change_status);
|
|
|
+
|
|
|
return $ret;
|
|
|
}
|
|
|
|
|
|
@@ -455,6 +493,7 @@ trait SettelementLogic
|
|
|
$this->PushSqlToArray("update $table1 set status=3 where match_id=$match_id ");
|
|
|
$this->PushSqlToArray("update $table2 set status=3 where match_id=$match_id ");
|
|
|
}
|
|
|
+ unset($table1, $table2);
|
|
|
}
|
|
|
|
|
|
//得么一个临时变量
|
|
|
@@ -478,7 +517,6 @@ trait SettelementLogic
|
|
|
$ret = DB::select($sql);
|
|
|
|
|
|
return $ret;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -496,8 +534,10 @@ trait SettelementLogic
|
|
|
foreach ($nowArray as $order => $val) {
|
|
|
$money = abs(floatval($val->money));
|
|
|
$acc = $val->account_identity;
|
|
|
- $sql = "update account_detailed set cash=cash-$money where identity='$acc' ";
|
|
|
- $this->sqlArray[] = $sql;
|
|
|
+ $sql1 = "update account_detailed set cash=cash-$money where identity='$acc' ";
|
|
|
+ $sql2 = "update money_prize set prize_money=0,get_money=0 where order_id='$val->order_id' and account_identity='$acc'";
|
|
|
+ $this->sqlArray[] = $sql1;
|
|
|
+ $this->sqlArray[] = $sql2;
|
|
|
$ids[] = $order;
|
|
|
}
|
|
|
|
|
|
@@ -505,9 +545,10 @@ trait SettelementLogic
|
|
|
return "'.$i.'";
|
|
|
}, $ids);
|
|
|
$ids_array = implode(",", $ids);
|
|
|
- $sql = "update settlement_middle_detail set money=0 where order_id in($ids_array) and bet_type=$this->orderType ";
|
|
|
+ $sql = "update settlement_middle_detail set money=0 where order_id in($ids_array) and bet_type=$bet_type ";
|
|
|
$this->sqlArray[] = $sql;
|
|
|
|
|
|
+ unset($nowArray, $bet_type, $ids, $ids_array, $sql);
|
|
|
return true;
|
|
|
}
|
|
|
|