/** * 保存得分 */ public function commit() { //$score = $this->session->userdata ( 'score' ); $openid = $this->session->userdata ( 'openid' ); $score = $this->input->post('score') ? : 0; $cmp_score = $this->input->post('cmp_score') ? : 0; if (1) { if(($fopenid = $this->input->post('fopenid')) != false) {//挑战记录 log_message ( 'error', "挑战提交", 1 ); $friend = $this->account->getInfoByOpenid ( $fopenid, 1 ); $cmp = $score; if ($score > $cmp_score) $score = 600; else $score = -250; $this->challenge->save ( $openid, $friend, $score, 'fight', 0 , $cmp); //保存未同步记录 $this->account->addScore ( $openid, $score ); //保存本地 $this->session->unset_userdata ( 'fopenid' ); delete_cookie ('fopenid'); } //执行同步 $ids = array(); $if_sync = 0; $challengeLists = $this->challenge->getAllByOpenid($openid, $if_sync); $sync_score = 0; foreach ($challengeLists as $challenge) { $sync_score += $challenge->result; $ids[] = $challenge->id; } if ($sync_score) { $post = array ( 'accessToken' => $this->session->userdata ( 'accesstoken' ), 'score' => abs( $sync_score ), 'flag' => $sync_score > 0 ? 1 : 0, ); $ret = hersbit_api ( $this->config->item ( 'hersbit_api' ), $post ); //同步记录到helloan if ($ret ['returnCode'] == '000') { $this->challenge->update($ids, array('if_sync'=>1)); } else { log_message ( 'error', "code:{$ret['returnCode']} msg:{$ret['returnMsg']}", 1 ); //$this->format ( '同步失败' ); } } //同步完成 if ($fopenid){ if ($score >= 0) { $this->format ( '<i>小样儿,不错呦!再接再厉!<br /><strong>+' . $score . '</strong>合氏币</i>', array ( 'score' => $score, 'play_title' => '挑战成功', ), 3 ); } else { $this->format ( '<i>小样儿,裤衩都没了吧?<br /><strong>' . $score . '</strong>合氏币</i>', array ( 'score' => $score, 'play_title' => '挑战失败', ) , 3); } } } if ($score) { //个人玩,提交游戏分数 $post = array ( 'accessToken' => $this->session->userdata ( 'accesstoken' ), 'score' => abs($score), 'flag' => $score > 0 ? 1 : 0, ); $ret = hersbit_api ( $this->config->item ( 'hersbit_api' ), $post ); if ($ret ['returnCode'] == '000') { $this->account->addScore ( $openid, $score ); $this->challenge->save ( $openid, null, $score, 'fight', 1 ); //保存同步记录 $this->session->unset_userdata ( 'score' ); $this->format ( '完成', null, 0 ); } else if ($ret ['returnCode'] == '004') { //登录失效 delete_cookie ('openid'); } else { log_message ( 'error', "code:{$ret['returnCode']} msg:{$ret['returnMsg']}", 1 ); } $this->challenge->save ( $openid, null, $score, 'fight', 0 ); //保存未同步记录 $this->account->addScore ( $openid, $score ); //保存本地 $this->format ( '完成', null, 0 ); } log_message ( 'error', "提交完成", 1 ); }
/** * 分享获得 */ public function shareHelloan() { $openid = $this->session->userdata ( 'openid' ); $score = 300; $post = array ( 'accessToken' => $this->session->userdata ( 'accesstoken' ), 'score' => $score, 'flag' => 1 ); $ret = hersbit_api ( $this->config->item ( 'hersbit_api' ), $post ); // 提交到helloan $this->account->addScore ( $openid, $score ); if ($ret ['returnCode'] == '000') { $this->challenge->save ( $openid, null, $score, 'share' ); } else { log_message ( 'error', "code:{$ret['returnCode']} msg:{$ret['returnMsg']}", 1 ); $this->challenge->save ( $openid, null, $score, 'share', 0 ); } $this->format ( '恭喜,分享获得' . $score . '合氏币' ); }