UserHelp.class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. use Cas\Dao\LotteryUserParticipateLog;
  21. use Cas\Dao\LotteryUserHelp;
  22. use Cas\Dao\LotteryUserHelpLog;
  23. /**
  24. * "活动相关" - "互动数据"
  25. *
  26. * @author lihuanchun 
  27. *  
  28. */
  29. class UserHelp extends Controller {
  30. private $objLottery; // 活动后端
  31. private $peratorData;
  32. /**
  33. *  初始化
  34. */
  35. public function __construct() {
  36. header ( "Content-Type: text/html; charset=utf-8" );
  37. $this->objLottery = new Lottery ();
  38. $this->objLotteryUserHelp = new LotteryUserHelp ();
  39. $this->operatorData = $this->getUser ();
  40. $this->setOutput('action', Request::g('action'));
  41. }
  42. public function doDefault() {
  43. }
  44. /**
  45. * 获取当前互动的互动数据
  46. * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserHelp&a=PageList&events_id=n
  47. * 参数:events_id 活动ID 必填
  48. * 参数:groupByUid 是否用户排重 
  49. *
  50. */
  51. public function doPageList() {
  52. $events_id = Request::varGetInt ( 'events_id' );
  53. $groupByUid = Request::g ( 'groupByUid' ); // 用户是否排重
  54. $objMLotteryLog = new LotteryLog ( null, $events_id );
  55. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  56. $this->setOutput ( 'eventData', $eventData );
  57. $page = Request::varGetInt ( 'page', 1 );
  58. $size = 10;
  59. $offset = ($page - 1) * $size;
  60. $limit = "{$offset},{$size}";
  61. $order = ' num desc, id desc';
  62. $condition = array (
  63. 'events_id' => $events_id
  64. );
  65. $total_num = $this->objLotteryUserHelp->totals ( $condition );
  66. $helpData = $this->objLotteryUserHelp->fetchAll ($condition, $limit, $order );
  67. // 分页
  68. $this->objLotteryUserHelpLog = new LotteryUserHelpLog ();
  69. $url_tpl = Request::url();
  70. $url_tpl .= "&page={page}";
  71. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  72. $page_html = $objPage->html ();
  73. $uids = array ();
  74. foreach ( $helpData as $key => $data ) {
  75. $uids [$data ['uid']] = $data ['uid'];
  76. //$helpData[$key]['num'] = $this->objLotteryUserHelpLog->totals(array('help_id' => $data['id']));
  77. }
  78. # 通过UIDs 获取用户信息
  79. $objMUser = new User();
  80. $userData = $objMUser -> gets($uids);
  81. $this->tpl = 'admin/activity/user_help';
  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. $helpData =$this->setData($eventData,$helpData);
  92. }
  93. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  94. $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示
  95. $isPrizes = in_array($eventData['type'], array(LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH, LotteryEvents::TYPE_EVENTS_TRY, LotteryEvents::TYPE_EVENTS_INVITATION));
  96. $this->setOutput('isPrizes', $isPrizes);
  97. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  98. $this->setOutput ( 'groupByUid', $groupByUid );
  99. $this->setOutput ( 'navConfig', $navConfig ); //公用内部导航信息
  100. $this->setOutput ( 'page_html', $page_html ); //分页HTML
  101. $this->setOutput ( 'helpData', $helpData ); // i日志
  102. $this->setOutput ( 'total_num', $total_num ); // 参与人数
  103. $this->setOutput ( 'userData', $userData ); // 当前列表用户信息
  104. $this->setOutput ( 'eventData', $eventData ); // 当前活动信息
  105. $this->setOutput ( 'typeData', $typeData );
  106. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  107. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  108. if ($groupByUid) {
  109. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserHelp&a=ExportData&groupByUid=true&events_id={$events_id}";
  110. } else {
  111. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserHelp&a=ExportData&events_id={$events_id}";
  112. }
  113. $this->setOutput('download_url', $download_url);
  114. }
  115. /**
  116. * 导出:获取用户参与活动日志
  117. * ?c=Admin_Activity_UserParticipateLog&a=doExportData&events_id=x
  118. * ?c=Admin_Activity_UserParticipateLog&a=doExportData&groupByUid=true&events_id=x
  119. */
  120. public function doExportData() {
  121. $events_id = Request::varGetInt ( 'events_id' );
  122. $groupByUid = Request::g ( 'groupByUid' );
  123. $datalist = array ();
  124. $objMLotteryLog = new LotteryLog ( null, $events_id );
  125. $allData = array ();
  126. $condition = array (
  127. 'events_id' => $events_id
  128. );
  129. $order = ' num desc, id desc';
  130. $helpData = $this->objLotteryUserHelp->fetchAll ($condition, 10000, $order );
  131. $uids = array ();
  132. foreach ( $allData as $key => $data ) {
  133. $uids [$data ['uid']] = $data ['uid'];
  134. }
  135. // 转换格式
  136. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  137. /*
  138. if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY ){
  139. $allData =$this->setData($eventData,$allData);
  140. foreach($allData as $key => $data){
  141. $allData[$key]['other']['选择内容:'] = str_replace("<br>",",", $allData[$key]['other']['选择内容:']);
  142. }
  143. }
  144. */
  145. # 通过UIDs 获取用户信息
  146. $objMUser = new User();
  147. $userData = $objMUser -> gets($uids);
  148. $filename = '' . date ( 'YmdHis' ) . '.csv';
  149. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  150. header ( "Pragma: public" );
  151. header ( "Expires: 0" );
  152. header ( 'Content-Disposition: attachment; filename=' . $filename );
  153. $titleTag = '用户ID,昵称,时间,邀请人次数量' . "\n";
  154. foreach ( $allData as $data ) {
  155. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',' . $data['num'] . "\n";
  156. }
  157. $titleTag = Convert::u82gb ( $titleTag );
  158. exit ( $titleTag );
  159. }
  160. public function display() {
  161. return $this->render ();
  162. }
  163. }