flyzto 6 mesiacov pred
rodič
commit
bf472f2ed5

+ 7 - 1
server/models/Games.js

@@ -359,6 +359,12 @@ const solutionsCleanup = () => {
   });
 }
 
+const getTotalProfit = (sid1, sid2, gold_side_jc) => {
+  const sol1 = GAMES.Solutions[sid1];
+  const sol2 = GAMES.Solutions[sid2];
+  return calcTotalProfit(sol1, sol2, gold_side_jc);
+}
+
 const getDataFromChild = (type, callback) => {
   const id = ++Request.count;
   Request.callbacks[id] = callback;
@@ -401,5 +407,5 @@ setInterval(() => {
 module.exports = {
   updateGamesList, updateGamesEvents, getGamesList,
   updateGamesRelation, getGamesRelation, removeGamesRelation,
-  getGamesEvents, getSolutions, calcTotalProfit,
+  getGamesEvents, getSolutions, getTotalProfit,
 }

+ 2 - 2
server/routes/triangle.js

@@ -89,8 +89,8 @@ router.get('/get_solutions', authMiddleware, (req, res) => {
 
 // 计算总利润
 router.post('/calc_total_profit', authMiddleware, (req, res) => {
-  const { sol1, sol2, gold_side_jc } = req.body;
-  const totalProfit = Games.calcTotalProfit(sol1, sol2, gold_side_jc);
+  const { sid1, sid2, gold_side_jc } = req.body;
+  const totalProfit = Games.getTotalProfit(sid1, sid2, gold_side_jc);
   res.sendSuccess(totalProfit);
 });
 

+ 13 - 0
web/apps/web-antd/src/views/match/solutions/index.vue

@@ -33,6 +33,19 @@ const getSolutions = async () => {
   }
 }
 
+const calcTotalProfit = async () => {
+  const [sid1, sid2] = selectedSolutions.map(item => item.sid);
+  try {
+    const totalProfit = await requestClient.post('/triangle/calc_total_profit', { sid1, sid2, gold_side_jc: 10000 });
+    return totalProfit;
+  }
+  catch (error) {
+    console.error('Failed to calc total profit:', error);
+    message.error('计算综合利润失败');
+    return {};
+  }
+}
+
 const parseIorKey = (iorKey) => {
   const [, type, accept, side, , ratioString] = iorKey.match(/^ior_(r|ou|m|wm|t)(a?)(h|c|n)?(_(\d+))?$/);
   const ratio = ratioString ? `${ratioString[0]}.${ratioString.slice(1)}` * (accept ? 1 : -1) : 0;