Exemple #1
0
 public function getDataSplit()
 {
     $limit = 10;
     $gameRecord = $this->getlink('game_record');
     $where = ['share_wechat_id' => 'oiyNFuOoe4NMhX-Hvi5OmyR0yltg'];
     $gameRecord->setWhere($where);
     $helperRs = $this->getlink('game_record')->get();
     //php计算总得分
     $arrHelper = [];
     $arrWechatId = [];
     foreach ($helperRs as $v) {
         $arrWechatId[$v['wechat_id']] = $v['wechat_id'];
         //记录下助攻者的id, 用于查询用户信息 nickname, image...
         if (!empty($arrHelper[$v['wechat_id']])) {
             $arrHelper[$v['wechat_id']]['score'] += $v['score'];
         } else {
             $arrHelper[$v['wechat_id']] = $v;
         }
     }
     //附加信息, 头像, 昵称
     $gameUsers = $this->getlink('game_users');
     $gameUsers->setWhereIn('wechat_id', $arrWechatId);
     $arrExtra = $gameUsers->get('wechat_id');
     //排序
     //usort($arrHelper, array($this, 'mysort'));
     $arrHelper = Fun::sort2DArray($arrHelper, 'score', '1');
     $arrHelper = array_slice($arrHelper, 0, $limit);
     foreach ($arrHelper as &$v) {
         $v['wechat_name'] = $arrExtra[$v['wechat_id']]['wechat_name'];
         $v['wechat_image'] = $arrExtra[$v['wechat_id']]['wechat_image'];
     }
     return $arrHelper;
 }