UserParticipateLog.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. namespace Cas\Controller\Admin\Activity;
  3. use Cas\Module\Lottery;
  4. use Cas\Dao\PlatformBulletin;
  5. use KIF\Core\Request;
  6. use Cas\Dao\LotteryEvents;
  7. use Cas\Controller\Admin\Controller;
  8. use Cas\Dao\Platform;
  9. use Cas\Dao\LotteryDeliveryChannels;
  10. use KIF\Core\Config;
  11. use Cas\Module\LotteryLog;
  12. use KIF\Page\Page;
  13. use Cas\Module\User;
  14. use KIF\Data\Convert;
  15. use Cas\Dao\LotteryData;
  16. use Cas\Dao\LotteryPrize;
  17. use Cas\Dao\LotteryEventsForms;
  18. use KIF\Verify;
  19. use Cas\Dao\LotteryUserExpress;
  20. /**
  21. * "活动相关" - "互动数据"
  22. *
  23. * @author lihuanchun 
  24. *  
  25. */
  26. class UserParticipateLog extends Controller {
  27. private $objLottery; // 活动后端
  28. private $peratorData;
  29. /**
  30. *  初始化
  31. */
  32. public function __construct() {
  33. header ( "Content-Type: text/html; charset=utf-8" );
  34. $this->objLottery = new Lottery ();
  35. $this->operatorData = $this->getUser ();
  36. $this->setOutput('action', Request::g('action'));
  37. }
  38. public function doDefault() {
  39. }
  40. /**
  41. * 获取当前互动的互动数据
  42. * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageList&events_id=n
  43. * 参数:events_id 活动ID 必填
  44. * 参数:groupByUid 是否用户排重 
  45. *
  46. */
  47. public function doPageList() {
  48. $events_id = Request::varGetInt ( 'events_id' );
  49. $groupByUid = Request::g ( 'groupByUid' ); // 用户是否排重
  50. $objMLotteryLog = new LotteryLog ( null, $events_id );
  51. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  52. $this->setOutput ( 'eventData', $eventData );
  53. $page = Request::varGetInt ( 'page', 1 );
  54. $size = 10;
  55. $offset = ($page - 1) * $size;
  56. $limit = "{$offset},{$size}";
  57. $order = ' id desc';
  58. $total_user_num = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  59. if ($groupByUid) {
  60. $logData = $objMLotteryLog->findUserParticipateDataGroupByUid ( $limit, $order );
  61. $total_num = $total_user_num;
  62. } else {
  63. $condition = array (
  64. 'events_id' => $events_id
  65. );
  66. $logData = $objMLotteryLog->findUserParticipateData ( $condition, $limit, $order );
  67. $total_num = $objMLotteryLog->getUserParticipateLogNum ( $condition );
  68. }
  69. // 分页
  70. $url_tpl = Request::url();
  71. $url_tpl .= "&page={page}";
  72. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  73. $page_html = $objPage->html ();
  74. $uids = array ();
  75. foreach ( $logData as $key => $data ) {
  76. $uids [$data ['uid']] = $data ['uid'];
  77. }
  78. # 通过UIDs 获取用户信息
  79. $objMUser = new User();
  80. $userData = $objMUser -> gets($uids);
  81. $this->tpl = 'admin/activity/user_participate_log';
  82. $title = '互动数据';
  83. $this->setOutput('title', $title);
  84. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  85. $this->addNavMenu('活动列表');
  86. $this->addNavMenu($title);
  87. // 获取所有活动类型
  88. $typeData = LotteryEvents::getType ();
  89. // 转换格式
  90. if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY && $_GET['action'] == 'all'){
  91. $logData =$this->setData($eventData,$logData);
  92. }
  93. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  94. $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示
  95. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  96. $this->setOutput ( 'groupByUid', $groupByUid );
  97. $this->setOutput ( 'navConfig', $navConfig ); //公用内部导航信息
  98. $this->setOutput ( 'page_html', $page_html ); //分页HTML
  99. $this->setOutput ( 'logData', $logData ); // i日志
  100. $this->setOutput ( 'total_user_num', $total_user_num ); // 参与人数
  101. $this->setOutput ( 'userData', $userData ); // 当前列表用户信息
  102. $this->setOutput ( 'eventData', $eventData ); // 当前活动信息
  103. $this->setOutput ( 'typeData', $typeData );
  104. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  105. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  106. $isPrizes = in_array($eventData['type'], array(LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH));
  107. $this->setOutput('isPrizes', $isPrizes);
  108. if ($groupByUid) {
  109. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&groupByUid=true&events_id={$events_id}";
  110. } else {
  111. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&events_id={$events_id}";
  112. }
  113. $this->setOutput('download_url', $download_url);
  114. }
  115. /**
  116. * 显示 用户调查问卷 选择的结果集
  117. */
  118. public function doShowResultSet(){
  119. $events_id = Request::varGetInt ( 'events_id' );
  120. $objMLotteryLog = new LotteryLog ( null, $events_id );
  121. $condition = array (
  122. 'events_id' => $events_id
  123. );
  124. $logData = $objMLotteryLog->findUserParticipateData ( $condition);
  125. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  126. if($eventData['type'] != LotteryEvents:: TYPE_EVENTS_SURVEY){
  127. exit('end');
  128. }
  129. $return_data = array();
  130. $survery_question = $eventData['survery_question'];
  131. foreach($survery_question as $key => $data){
  132. $survery_question[$key]['choice'] = $data['choice']==0?'单选':'多选';
  133. $survery_question[$key]['num'] = 0;
  134. foreach($survery_question[$key]['answer'] as $k =>$d){
  135. $survery_question[$key]['answer'][$k]['num'] = 0;
  136. }
  137. }
  138. $log = array();
  139. foreach($logData as $key =>$data){
  140. $xznr = $data['other']['选择内容:'];
  141. if($xznr){
  142. $wtData = explode('|', $xznr);
  143. foreach($wtData as $key=> $wt){
  144. $survery_question[$key+1]['num'] ++;
  145. if($wt){
  146. $xz = explode(',', $wt);
  147. foreach($xz as $xzkey){
  148. $xzkey = (int)$xzkey;
  149. $survery_question[$key+1]['answer'][$xzkey]['num'] ++ ;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. $mp= $survery_question[1]['num'];
  156. echo "此次活动共计: {$mp}次 完成问卷<br><br><br>";
  157. foreach( $survery_question as $key=>$data){
  158. echo "问题[{$key}]:".$data['question'].'<br>';
  159. echo "选择类型:[".$data['choice'].']<br>';
  160. echo '选择:<br>';
  161. foreach($data['answer'] as $k => $d){
  162. $hhl=round(($d['num']/$data['num'])*100);
  163. echo "&nbsp;&nbsp;({$k}) ;&nbsp; {$d['answer']};&nbsp;&nbsp;&nbsp;[ {$hhl} %]<br>";
  164. }
  165. echo '<br><br><br>';
  166. }
  167. }
  168. /**
  169. * 转换数据格式
  170. */
  171. public function setData($eventData,$logData){
  172. foreach($logData as $key => $data){
  173. $txt = '';
  174. $tmpLog = $data['other']['选择内容:'] ;
  175. $tmpData = explode('|', $tmpLog) ;
  176. foreach($tmpData as $k =>$d){
  177. $txt .= "<br><br> 题目 :".$eventData['survery_question'][$k+1]['question']."<br>用户选择: ";
  178. $ttdd = explode(',', $d);
  179. foreach($ttdd as $tt){
  180. $tmptt = (int)$tt;
  181. $txt = $txt .$eventData['survery_question'][$k+1] ['answer'][$tmptt]['answer']." | ";
  182. }
  183. }
  184. $logData[$key]['other']['tmp'] = $txt;
  185. }
  186. foreach($logData as $key => $data){
  187. if(isset($logData[$key]['other']['tmp'])){
  188. $logData[$key]['other']['选择内容:'] = $logData[$key]['other']['tmp']."<br><br>" ;
  189. unset($logData[$key]['other']['tmp']);
  190. }else{
  191. $logData[$key]['other']['选择内容:'] = "用户未选择"."<br><br>" ;
  192. }
  193. }
  194. return $logData;
  195. }
  196. /**
  197. * 导出:获取用户参与活动日志
  198. * ?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&events_id=x
  199. * ?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&groupByUid=true&events_id=x
  200. */
  201. public function doShowUserParticipateLogExportData() {
  202. $events_id = Request::varGetInt ( 'events_id' );
  203. $groupByUid = Request::g ( 'groupByUid' );
  204. $datalist = array ();
  205. $objMLotteryLog = new LotteryLog ( null, $events_id );
  206. $allData = array ();
  207. if ($groupByUid) {
  208. $allData = $objMLotteryLog->findUserParticipateDataGroupByUid (null,null);
  209. } else {
  210. $condition = array (
  211. 'events_id' => $events_id
  212. );
  213. $allData = $objMLotteryLog->findUserParticipateData ( $condition,null,null );
  214. }
  215. $uids = array ();
  216. foreach ( $allData as $key => $data ) {
  217. $uids [$data ['uid']] = $data ['uid'];
  218. }
  219. // 转换格式
  220. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  221. /*
  222. if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY ){
  223. $allData =$this->setData($eventData,$allData);
  224. foreach($allData as $key => $data){
  225. $allData[$key]['other']['选择内容:'] = str_replace("<br>",",", $allData[$key]['other']['选择内容:']);
  226. }
  227. }
  228. */
  229. # 通过UIDs 获取用户信息
  230. $objMUser = new User();
  231. $userData = $objMUser -> gets($uids);
  232. $filename = '' . date ( 'YmdHis' ) . '.csv';
  233. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  234. header ( "Pragma: public" );
  235. header ( "Expires: 0" );
  236. header ( 'Content-Disposition: attachment; filename=' . $filename );
  237. $titleTag = '用户ID,昵称,时间,其他' . "\n";
  238. foreach ( $allData as $data ) {
  239. if (isset ( $data ['other'] )) {
  240. $otherStr = '';
  241. foreach ( $data ['other'] as $k => $d ) {
  242. $otherStr = $otherStr . $k . $d;
  243. }
  244. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',' . $otherStr . "\n";
  245. } else {
  246. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',空' . "\n";
  247. }
  248. }
  249. $titleTag = Convert::u82gb ( $titleTag );
  250. exit ( $titleTag );
  251. }
  252. /**
  253. * 页面:[查看中奖详情]
  254. * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageLotteryDataList&events_id=n
  255. * 活动ID:events_id
  256. * 筛选条件[奖品ID]:prize_id
  257. * 分页:page
  258. * 详情:scratch_receive=false
  259. */
  260. public function doPageLotteryDataList(){
  261. $events_id = Request::g ( 'events_id' );
  262. $scratch_receive = Request::g ( 'scratch_receive' );
  263. $eventsAndPrizeData =$this->objLottery->getOneLotteryEventsAndPrize($events_id);
  264. if($eventsAndPrizeData['events']['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH){
  265. }
  266. // 取数据
  267. $page = Request::varGetInt ( 'page', 1 );
  268. $size = 20;
  269. $offset = ($page - 1) * $size;
  270. $limit = "{$offset},{$size}";
  271. $condition = array (
  272. 'events_id' => $events_id
  273. );
  274. // 刮刮卡 跳将特殊处理
  275. $pieze_notreceive_num = array();
  276. if($eventsAndPrizeData['events']['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH){
  277. $condition['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_TRUE;
  278. foreach($eventsAndPrizeData['prize'] as $prize){
  279. $for_condition = array(
  280. 'events_id' => $events_id,
  281. 'prize_id' => $prize['id'],
  282. 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_FALSE
  283. );
  284. $pieze_notreceive_num[$prize['id']] = $this->objLottery->getLotteryDataListNum($for_condition);
  285. }
  286. }
  287. // 筛选条件
  288. $prize_id = Request::g ( 'prize_id' );
  289. if ($prize_id) {
  290. $condition ['prize_id'] = $prize_id;
  291. }
  292. if($scratch_receive=='false'){
  293. // $condition['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_FALSE;
  294. }
  295. $total_num = $this->objLottery->getLotteryDataListNum($condition);
  296. $url_tpl = Request::url();
  297. if($prize_id){
  298. $url_tpl .= "&prize_id={$prize_id}";
  299. }
  300. $url_tpl .= "&page={page}";
  301. // 分页
  302. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  303. $page_html = $objPage->html ();
  304. $order = 'id desc';
  305. $lotteryData = $this->objLottery->getLotteryDataList ( $condition, $limit, $order );
  306. $uids = array();
  307. foreach ($lotteryData as $tmpItem) {
  308. $uids[] = $tmpItem['uid'];
  309. }
  310. # 通过UIDs 获取用户信息
  311. $objMUser = new User();
  312. $users = $objMUser -> gets($uids);
  313. # 获取用户收货地址
  314. $objLotteryUserExpress = new LotteryUserExpress();
  315. $condition = array(
  316. 'uid' => $uids
  317. );
  318. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  319. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  320. $newUserExpData = array();
  321. foreach($userExpData as $key => $data){
  322. $newUserExpData[$data['uid']] = $data;
  323. }
  324. $objDLotteryPrize = new LotteryPrize();
  325. $prizeType = $objDLotteryPrize -> getType();
  326. $prizeDisplayStatus = $objDLotteryPrize ->getDisplay();
  327. $this->tpl = 'admin/activity/user_participate_win';
  328. $title = '互动数据';
  329. $this->setOutput('title', $title);
  330. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  331. $this->addNavMenu('活动列表');
  332. $this->addNavMenu($title);
  333. $this->setOutput ( 'newUserExpData', $newUserExpData );
  334. $this->setOutput ( 'page_html', $page_html );
  335. $this->setOutput ( 'eventData', $eventsAndPrizeData['events'] );
  336. $this->setOutput ( 'prizeData', $eventsAndPrizeData['prize'] );
  337. $this->setOutput ( 'pieze_notreceive_num', $pieze_notreceive_num );
  338. $this->setOutput ( 'prizeType', $prizeType );
  339. $this->setOutput ( 'lotteryData', $lotteryData );
  340. $this->setOutput('userData', $users);
  341. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  342. $this->setOutput ( 'navConfig', $navConfig );
  343. $typeData = LotteryEvents::getType ();
  344. $this->setOutput ( 'typeData', $typeData );
  345. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  346. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  347. $this->setOutput('total_num', $total_num);
  348. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ExportWinData&events_id={$events_id}";
  349. $this->setOutput('download_url', $download_url);
  350. }
  351. public function doExportWinData() {
  352. $events_id = Request::g ( 'events_id' );
  353. $condition = array (
  354. 'events_id' => $events_id
  355. );
  356. $order = 'id desc';
  357. $lotteryData = $this->objLottery->getLotteryDataList ( $condition, null, $order );
  358. $uids = array();
  359. foreach ($lotteryData as $tmpItem) {
  360. $uids[] = $tmpItem['uid'];
  361. }
  362. $eventsAndPrizeData =$this->objLottery->getOneLotteryEventsAndPrize($events_id);
  363. $prizeData = $eventsAndPrizeData['prize'];
  364. # 通过UIDs 获取用户信息
  365. $objMUser = new User();
  366. $users = $objMUser -> gets($uids);
  367. # 获取用户收货地址
  368. $objLotteryUserExpress = new LotteryUserExpress();
  369. $condition = array(
  370. 'uid' => $uids
  371. );
  372. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  373. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  374. $newUserExpData = array();
  375. foreach($userExpData as $key => $data){
  376. $newUserExpData[$data['uid']] = $data;
  377. }
  378. ############发送头部信息############
  379. $fileName = date('YmdHis',time()) .".csv"; # 文件名
  380. $fileName = Convert::u82gb($fileName);
  381. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  382. header ( "Pragma: public" );
  383. header ( "Expires: 0" );
  384. header ( 'Content-Disposition: attachment; filename=' . $fileName );
  385. $title = "用户ID,昵称,时间,行为,用户收货信息\r\n";
  386. echo Convert::u82gb($title);
  387. foreach ($lotteryData as $tmpData) {
  388. $uid = $tmpData['uid'];
  389. $date = date('Y-m-d H:i:s', $tmpData['create_time']);
  390. $otherInfo = "获得奖品:{$prizeData[$tmpData['prize_id']]['prize_name']} ";
  391. if(isset($newUserExpData[$uid]['user_name'])){
  392. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$otherInfo},姓名:{$newUserExpData[$uid]['user_name']} 地址:{$newUserExpData[$uid]['address']} 电话:{$newUserExpData[$uid]['phone']}\r\n";
  393. }else{
  394. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$otherInfo},未填写\r\n";
  395. }
  396. echo Convert::u82gb($info);
  397. }
  398. exit;
  399. }
  400. /**
  401. * 页面: [表单数据]
  402. * 地址:http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageEventFormData&events_id=n
  403. * 活动ID:events_id
  404. * 分页:page
  405. */
  406. public function doPageEventFormData(){
  407. $events_id = Request::varGetInt ( 'events_id');
  408. if (!Verify::unsignedInt($events_id)) {
  409. self::fail_exit_bs('无效events_id');
  410. }
  411. $page = Request::varGetInt ( 'page', 1 );
  412. $size = 10;
  413. $offset = ($page - 1) * $size;
  414. $limit = "{$offset},{$size}";
  415. $condition = array (
  416. 'events_id' => $events_id
  417. );
  418. $objLotteryEventsForms = new LotteryEventsForms();
  419. $ids = $objLotteryEventsForms->findIdsBy($condition,$limit,'id desc');
  420. $formData = $objLotteryEventsForms->gets($ids);
  421. $uids = array();
  422. foreach ($formData as $tmpItem) {
  423. $uids[] = $tmpItem['uid'];
  424. }
  425. $objLotteryEvents = new LotteryEvents();
  426. $eventData = $objLotteryEvents->get($events_id);
  427. # 表单类型数据
  428. $formType = array();
  429. foreach ($eventData['forms'] as $tmpForms) {
  430. $formType[] = $tmpForms['name'];
  431. }
  432. # 分页
  433. $total_num = $objLotteryEventsForms->totals($condition);
  434. $url_tpl = Request::url();
  435. $url_tpl .= "&page={page}";
  436. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  437. $page_html = $objPage->html ();
  438. # 通过UIDs 获取用户信息
  439. $objMUser = new User();
  440. $users = $objMUser -> gets($uids);
  441. $this->tpl = 'admin/activity/user_participate_form';
  442. $title = '互动数据';
  443. $this->setOutput('title', $title);
  444. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  445. $this->addNavMenu('活动列表');
  446. $this->addNavMenu($title);
  447. $this->setOutput('eventData', $eventData);
  448. $this->setOutput ( 'page_html', $page_html );
  449. $this->setOutput ( 'formData', $formData );
  450. $this->setOutput('formType', $formType);
  451. $this->setOutput('userData', $users);
  452. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  453. $this->setOutput ( 'navConfig', $navConfig );
  454. $typeData = LotteryEvents::getType ();
  455. $this->setOutput ( 'typeData', $typeData );
  456. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  457. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  458. $this->setOutput('total_num', $total_num);
  459. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ExportFormData&events_id={$events_id}";
  460. $this->setOutput('download_url', $download_url);
  461. }
  462. public function doExportFormData() {
  463. $events_id = Request::varGetInt ( 'events_id');
  464. if (!Verify::unsignedInt($events_id)) {
  465. self::fail_exit_bs('无效events_id');
  466. }
  467. $condition = array (
  468. 'events_id' => $events_id
  469. );
  470. $objLotteryEventsForms = new LotteryEventsForms();
  471. $ids = $objLotteryEventsForms->findIdsBy($condition,null,'id desc');
  472. $formData = $objLotteryEventsForms->gets($ids);
  473. $uids = array();
  474. foreach ($formData as $tmpItem) {
  475. $uids[] = $tmpItem['uid'];
  476. }
  477. $objLotteryEvents = new LotteryEvents();
  478. $eventData = $objLotteryEvents->get($events_id);
  479. # 表单类型数据
  480. $formType = array();
  481. foreach ($eventData['forms'] as $tmpForms) {
  482. $formType[] = $tmpForms['name'];
  483. }
  484. # 通过UIDs 获取用户信息
  485. $objMUser = new User();
  486. $users = $objMUser -> gets($uids);
  487. ############发送头部信息############
  488. $fileName = date('YmdHis',time()) .".csv"; # 文件名
  489. $fileName = Convert::u82gb($fileName);
  490. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  491. header ( "Pragma: public" );
  492. header ( "Expires: 0" );
  493. header ( 'Content-Disposition: attachment; filename=' . $fileName );
  494. $title = "用户ID,昵称,时间,行为\r\n";
  495. echo Convert::u82gb($title);
  496. foreach ($formData as $tmpData) {
  497. $uid = $tmpData['uid'];
  498. $date = date('Y-m-d H:i:s', $tmpData['create_time']);
  499. $formInfo = '';
  500. foreach ($formType as $formName) {
  501. $formInfo = "{$formName}:{$tmpData[$formName]} ";
  502. }
  503. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$formInfo}\r\n";
  504. echo Convert::u82gb($info);
  505. }
  506. exit;
  507. }
  508. public function display() {
  509. return $this->render ();
  510. }
  511. }