objLottery = new Lottery (); $this->operatorData = $this->getUser (); $this->setOutput('action', Request::g('action')); } public function doDefault() { } /** * 获取当前互动的互动数据 * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageList&events_id=n * 参数:events_id 活动ID 必填 * 参数:groupByUid 是否用户排重  * */ public function doPageList() { $events_id = Request::varGetInt ( 'events_id' ); $groupByUid = Request::g ( 'groupByUid' ); // 用户是否排重 $objMLotteryLog = new LotteryLog ( null, $events_id ); $eventData = $this->objLottery->getOneLotteryEvents ( $events_id ); $this->setOutput ( 'eventData', $eventData ); $page = Request::varGetInt ( 'page', 1 ); $size = 10; $offset = ($page - 1) * $size; $limit = "{$offset},{$size}"; $order = ' id desc'; $total_user_num = $objMLotteryLog->getUserParticipateLogNumGroupByUid (); if ($groupByUid) { $logData = $objMLotteryLog->findUserParticipateDataGroupByUid ( $limit, $order ); $total_num = $total_user_num; } else { $condition = array ( 'events_id' => $events_id ); $logData = $objMLotteryLog->findUserParticipateData ( $condition, $limit, $order ); $total_num = $objMLotteryLog->getUserParticipateLogNum ( $condition ); } // 分页 $url_tpl = Request::url(); $url_tpl .= "&page={page}"; $objPage = new Page ( $total_num, $url_tpl, $page, $size ); $page_html = $objPage->html (); $uids = array (); foreach ( $logData as $key => $data ) { $uids [$data ['uid']] = $data ['uid']; } # 通过UIDs 获取用户信息 $objMUser = new User(); $userData = $objMUser -> gets($uids); $this->tpl = 'admin/activity/user_participate_log'; $title = '互动数据'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单 $this->addNavMenu('活动列表'); $this->addNavMenu($title); // 获取所有活动类型 $typeData = LotteryEvents::getType (); // 转换格式 if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY && $_GET['action'] == 'all'){ $logData =$this->setData($eventData,$logData); } $navConfig = $this->getUpPageNav($events_id, 'UserLog'); $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示 $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus ); $this->setOutput ( 'groupByUid', $groupByUid ); $this->setOutput ( 'navConfig', $navConfig ); //公用内部导航信息 $this->setOutput ( 'page_html', $page_html ); //分页HTML $this->setOutput ( 'logData', $logData ); // i日志 $this->setOutput ( 'total_user_num', $total_user_num ); // 参与人数 $this->setOutput ( 'userData', $userData ); // 当前列表用户信息 $this->setOutput ( 'eventData', $eventData ); // 当前活动信息 $this->setOutput ( 'typeData', $typeData ); $this->setOutput('displayDesc', LotteryEvents::getDisplay()); $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据 $isPrizes = in_array($eventData['type'], array(LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH)); $this->setOutput('isPrizes', $isPrizes); if ($groupByUid) { $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&groupByUid=true&events_id={$events_id}"; } else { $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&events_id={$events_id}"; } $this->setOutput('download_url', $download_url); } /** * 显示 用户调查问卷 选择的结果集 */ public function doShowResultSet(){ $events_id = Request::varGetInt ( 'events_id' ); $objMLotteryLog = new LotteryLog ( null, $events_id ); $condition = array ( 'events_id' => $events_id ); $logData = $objMLotteryLog->findUserParticipateData ( $condition); $eventData = $this->objLottery->getOneLotteryEvents ( $events_id ); if($eventData['type'] != LotteryEvents:: TYPE_EVENTS_SURVEY){ exit('end'); } $return_data = array(); $survery_question = $eventData['survery_question']; foreach($survery_question as $key => $data){ $survery_question[$key]['choice'] = $data['choice']==0?'单选':'多选'; $survery_question[$key]['num'] = 0; foreach($survery_question[$key]['answer'] as $k =>$d){ $survery_question[$key]['answer'][$k]['num'] = 0; } } $log = array(); foreach($logData as $key =>$data){ $xznr = $data['other']['选择内容:']; if($xznr){ $wtData = explode('|', $xznr); foreach($wtData as $key=> $wt){ $survery_question[$key+1]['num'] ++; if($wt){ $xz = explode(',', $wt); foreach($xz as $xzkey){ $xzkey = (int)$xzkey; $survery_question[$key+1]['answer'][$xzkey]['num'] ++ ; } } } } } $mp= $survery_question[1]['num']; echo "此次活动共计: {$mp}次 完成问卷


"; foreach( $survery_question as $key=>$data){ echo "问题[{$key}]:".$data['question'].'
'; echo "选择类型:[".$data['choice'].']
'; echo '选择:
'; foreach($data['answer'] as $k => $d){ $hhl=round(($d['num']/$data['num'])*100); echo "  ({$k}) ;  {$d['answer']};   [ {$hhl} %]
"; } echo '


'; } } /** * 转换数据格式 */ public function setData($eventData,$logData){ foreach($logData as $key => $data){ $txt = ''; $tmpLog = $data['other']['选择内容:'] ; $tmpData = explode('|', $tmpLog) ; foreach($tmpData as $k =>$d){ $txt .= "

题目 :".$eventData['survery_question'][$k+1]['question']."
用户选择: "; $ttdd = explode(',', $d); foreach($ttdd as $tt){ $tmptt = (int)$tt; $txt = $txt .$eventData['survery_question'][$k+1] ['answer'][$tmptt]['answer']." | "; } } $logData[$key]['other']['tmp'] = $txt; } foreach($logData as $key => $data){ if(isset($logData[$key]['other']['tmp'])){ $logData[$key]['other']['选择内容:'] = $logData[$key]['other']['tmp']."

" ; unset($logData[$key]['other']['tmp']); }else{ $logData[$key]['other']['选择内容:'] = "用户未选择"."

" ; } } return $logData; } /** * 导出:获取用户参与活动日志 * ?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&events_id=x * ?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&groupByUid=true&events_id=x */ public function doShowUserParticipateLogExportData() { $events_id = Request::varGetInt ( 'events_id' ); $groupByUid = Request::g ( 'groupByUid' ); $datalist = array (); $objMLotteryLog = new LotteryLog ( null, $events_id ); $allData = array (); if ($groupByUid) { $allData = $objMLotteryLog->findUserParticipateDataGroupByUid (null,null); } else { $condition = array ( 'events_id' => $events_id ); $allData = $objMLotteryLog->findUserParticipateData ( $condition,null,null ); } $uids = array (); foreach ( $allData as $key => $data ) { $uids [$data ['uid']] = $data ['uid']; } // 转换格式 $eventData = $this->objLottery->getOneLotteryEvents ( $events_id ); /* if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY ){ $allData =$this->setData($eventData,$allData); foreach($allData as $key => $data){ $allData[$key]['other']['选择内容:'] = str_replace("
",",", $allData[$key]['other']['选择内容:']); } } */ # 通过UIDs 获取用户信息 $objMUser = new User(); $userData = $objMUser -> gets($uids); $filename = '' . date ( 'YmdHis' ) . '.csv'; header ( "Content-Type: application/vnd.ms-excel; charset=GBK" ); header ( "Pragma: public" ); header ( "Expires: 0" ); header ( 'Content-Disposition: attachment; filename=' . $filename ); $titleTag = '用户ID,昵称,时间,其他' . "\n"; foreach ( $allData as $data ) { if (isset ( $data ['other'] )) { $otherStr = ''; foreach ( $data ['other'] as $k => $d ) { $otherStr = $otherStr . $k . $d; } $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',' . $otherStr . "\n"; } else { $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',空' . "\n"; } } $titleTag = Convert::u82gb ( $titleTag ); exit ( $titleTag ); } /** * 页面:[查看中奖详情] * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageLotteryDataList&events_id=n * 活动ID:events_id * 筛选条件[奖品ID]:prize_id * 分页:page * 详情:scratch_receive=false */ public function doPageLotteryDataList(){ $events_id = Request::g ( 'events_id' ); $scratch_receive = Request::g ( 'scratch_receive' ); $eventsAndPrizeData =$this->objLottery->getOneLotteryEventsAndPrize($events_id); if($eventsAndPrizeData['events']['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH){ } // 取数据 $page = Request::varGetInt ( 'page', 1 ); $size = 20; $offset = ($page - 1) * $size; $limit = "{$offset},{$size}"; $condition = array ( 'events_id' => $events_id ); // 刮刮卡 跳将特殊处理 $pieze_notreceive_num = array(); if($eventsAndPrizeData['events']['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH){ $condition['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_TRUE; foreach($eventsAndPrizeData['prize'] as $prize){ $for_condition = array( 'events_id' => $events_id, 'prize_id' => $prize['id'], 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_FALSE ); $pieze_notreceive_num[$prize['id']] = $this->objLottery->getLotteryDataListNum($for_condition); } } // 筛选条件 $prize_id = Request::g ( 'prize_id' ); if ($prize_id) { $condition ['prize_id'] = $prize_id; } if($scratch_receive=='false'){ // $condition['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_FALSE; } $total_num = $this->objLottery->getLotteryDataListNum($condition); $url_tpl = Request::url(); if($prize_id){ $url_tpl .= "&prize_id={$prize_id}"; } $url_tpl .= "&page={page}"; // 分页 $objPage = new Page ( $total_num, $url_tpl, $page, $size ); $page_html = $objPage->html (); $order = 'id desc'; $lotteryData = $this->objLottery->getLotteryDataList ( $condition, $limit, $order ); $uids = array(); foreach ($lotteryData as $tmpItem) { $uids[] = $tmpItem['uid']; } # 通过UIDs 获取用户信息 $objMUser = new User(); $users = $objMUser -> gets($uids); # 获取用户收货地址 $objLotteryUserExpress = new LotteryUserExpress(); $condition = array( 'uid' => $uids ); $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition); $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds); $newUserExpData = array(); foreach($userExpData as $key => $data){ $newUserExpData[$data['uid']] = $data; } $objDLotteryPrize = new LotteryPrize(); $prizeType = $objDLotteryPrize -> getType(); $prizeDisplayStatus = $objDLotteryPrize ->getDisplay(); $this->tpl = 'admin/activity/user_participate_win'; $title = '互动数据'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单 $this->addNavMenu('活动列表'); $this->addNavMenu($title); $this->setOutput ( 'newUserExpData', $newUserExpData ); $this->setOutput ( 'page_html', $page_html ); $this->setOutput ( 'eventData', $eventsAndPrizeData['events'] ); $this->setOutput ( 'prizeData', $eventsAndPrizeData['prize'] ); $this->setOutput ( 'pieze_notreceive_num', $pieze_notreceive_num ); $this->setOutput ( 'prizeType', $prizeType ); $this->setOutput ( 'lotteryData', $lotteryData ); $this->setOutput('userData', $users); $navConfig = $this->getUpPageNav($events_id, 'UserLog'); $this->setOutput ( 'navConfig', $navConfig ); $typeData = LotteryEvents::getType (); $this->setOutput ( 'typeData', $typeData ); $this->setOutput('displayDesc', LotteryEvents::getDisplay()); $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据 $this->setOutput('total_num', $total_num); $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ExportWinData&events_id={$events_id}"; $this->setOutput('download_url', $download_url); } public function doExportWinData() { $events_id = Request::g ( 'events_id' ); $condition = array ( 'events_id' => $events_id ); $order = 'id desc'; $lotteryData = $this->objLottery->getLotteryDataList ( $condition, null, $order ); $uids = array(); foreach ($lotteryData as $tmpItem) { $uids[] = $tmpItem['uid']; } $eventsAndPrizeData =$this->objLottery->getOneLotteryEventsAndPrize($events_id); $prizeData = $eventsAndPrizeData['prize']; # 通过UIDs 获取用户信息 $objMUser = new User(); $users = $objMUser -> gets($uids); # 获取用户收货地址 $objLotteryUserExpress = new LotteryUserExpress(); $condition = array( 'uid' => $uids ); $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition); $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds); $newUserExpData = array(); foreach($userExpData as $key => $data){ $newUserExpData[$data['uid']] = $data; } ############发送头部信息############ $fileName = date('YmdHis',time()) .".csv"; # 文件名 $fileName = Convert::u82gb($fileName); header ( "Content-Type: application/vnd.ms-excel; charset=GBK" ); header ( "Pragma: public" ); header ( "Expires: 0" ); header ( 'Content-Disposition: attachment; filename=' . $fileName ); $title = "用户ID,昵称,时间,行为,用户收货信息\r\n"; echo Convert::u82gb($title); foreach ($lotteryData as $tmpData) { $uid = $tmpData['uid']; $date = date('Y-m-d H:i:s', $tmpData['create_time']); $otherInfo = "获得奖品:{$prizeData[$tmpData['prize_id']]['prize_name']} "; if(isset($newUserExpData[$uid]['user_name'])){ $info = "{$uid},{$users[$uid]['nickname']},{$date},{$otherInfo},姓名:{$newUserExpData[$uid]['user_name']} 地址:{$newUserExpData[$uid]['address']} 电话:{$newUserExpData[$uid]['phone']}\r\n"; }else{ $info = "{$uid},{$users[$uid]['nickname']},{$date},{$otherInfo},未填写\r\n"; } echo Convert::u82gb($info); } exit; } /** * 页面: [表单数据] * 地址:http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageEventFormData&events_id=n * 活动ID:events_id * 分页:page */ public function doPageEventFormData(){ $events_id = Request::varGetInt ( 'events_id'); if (!Verify::unsignedInt($events_id)) { self::fail_exit_bs('无效events_id'); } $page = Request::varGetInt ( 'page', 1 ); $size = 10; $offset = ($page - 1) * $size; $limit = "{$offset},{$size}"; $condition = array ( 'events_id' => $events_id ); $objLotteryEventsForms = new LotteryEventsForms(); $ids = $objLotteryEventsForms->findIdsBy($condition,$limit,'id desc'); $formData = $objLotteryEventsForms->gets($ids); $uids = array(); foreach ($formData as $tmpItem) { $uids[] = $tmpItem['uid']; } $objLotteryEvents = new LotteryEvents(); $eventData = $objLotteryEvents->get($events_id); # 表单类型数据 $formType = array(); foreach ($eventData['forms'] as $tmpForms) { $formType[] = $tmpForms['name']; } # 分页 $total_num = $objLotteryEventsForms->totals($condition); $url_tpl = Request::url(); $url_tpl .= "&page={page}"; $objPage = new Page ( $total_num, $url_tpl, $page, $size ); $page_html = $objPage->html (); # 通过UIDs 获取用户信息 $objMUser = new User(); $users = $objMUser -> gets($uids); $this->tpl = 'admin/activity/user_participate_form'; $title = '互动数据'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单 $this->addNavMenu('活动列表'); $this->addNavMenu($title); $this->setOutput('eventData', $eventData); $this->setOutput ( 'page_html', $page_html ); $this->setOutput ( 'formData', $formData ); $this->setOutput('formType', $formType); $this->setOutput('userData', $users); $navConfig = $this->getUpPageNav($events_id, 'UserLog'); $this->setOutput ( 'navConfig', $navConfig ); $typeData = LotteryEvents::getType (); $this->setOutput ( 'typeData', $typeData ); $this->setOutput('displayDesc', LotteryEvents::getDisplay()); $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据 $this->setOutput('total_num', $total_num); $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ExportFormData&events_id={$events_id}"; $this->setOutput('download_url', $download_url); } public function doExportFormData() { $events_id = Request::varGetInt ( 'events_id'); if (!Verify::unsignedInt($events_id)) { self::fail_exit_bs('无效events_id'); } $condition = array ( 'events_id' => $events_id ); $objLotteryEventsForms = new LotteryEventsForms(); $ids = $objLotteryEventsForms->findIdsBy($condition,null,'id desc'); $formData = $objLotteryEventsForms->gets($ids); $uids = array(); foreach ($formData as $tmpItem) { $uids[] = $tmpItem['uid']; } $objLotteryEvents = new LotteryEvents(); $eventData = $objLotteryEvents->get($events_id); # 表单类型数据 $formType = array(); foreach ($eventData['forms'] as $tmpForms) { $formType[] = $tmpForms['name']; } # 通过UIDs 获取用户信息 $objMUser = new User(); $users = $objMUser -> gets($uids); ############发送头部信息############ $fileName = date('YmdHis',time()) .".csv"; # 文件名 $fileName = Convert::u82gb($fileName); header ( "Content-Type: application/vnd.ms-excel; charset=GBK" ); header ( "Pragma: public" ); header ( "Expires: 0" ); header ( 'Content-Disposition: attachment; filename=' . $fileName ); $title = "用户ID,昵称,时间,行为\r\n"; echo Convert::u82gb($title); foreach ($formData as $tmpData) { $uid = $tmpData['uid']; $date = date('Y-m-d H:i:s', $tmpData['create_time']); $formInfo = ''; foreach ($formType as $formName) { $formInfo = "{$formName}:{$tmpData[$formName]} "; } $info = "{$uid},{$users[$uid]['nickname']},{$date},{$formInfo}\r\n"; echo Convert::u82gb($info); } exit; } public function display() { return $this->render (); } }