230320a303 1 year ago
parent
commit
b2c8968bba
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/components/chat/com.jsx

+ 13 - 1
src/components/chat/com.jsx

@@ -31,6 +31,8 @@ export default class Comment extends Component {
     }
   }
 
+
+
   getList (otherObj) {
     let params = {
       show_status: 1,
@@ -40,7 +42,17 @@ export default class Comment extends Component {
     if (referrer) params.referrer = referrer
     Taro.api.room.apisalelist(params).then(res => {
       const list = res.list || []
-      const arrIndex = Math.floor(Math.random() * list.length)
+      let tempArr = [] // 概率池
+      const total = res.month_num || 1 // 总分数
+      list.forEach((prob, i) => { // 遍历每一个人
+         // 四舍五入获取每个人的概率,比如张三占总分是的30%,就插入30个张三到概率池
+        const n = Math.round(prob.month_integral / total * 100)
+        if (n > 0) {
+          tempArr.splice(tempArr.length, n, ...Array(n).fill(i))
+        }
+      })
+      // 每次用户进入相关页面,随机从概率池中抽取一个人
+      const arrIndex = tempArr[Math.floor(Math.random() * tempArr.length)]
       this.setState({
         curObj: list[arrIndex],
         otherObj,