UserHelp.class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. $ids = $this->objLotteryUserHelp->findIdsBy ( $condition, $limit, $order );
  67. $helpData = $this->objLotteryUserHelp->gets ( $ids );
  68. // 分页
  69. $this->objLotteryUserHelpLog = new LotteryUserHelpLog ();
  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 ( $helpData as $key => $data ) {
  76. $uids [$data ['uid']] = $data ['uid'];
  77. //$helpData[$key]['num'] = $this->objLotteryUserHelpLog->totals(array('help_id' => $data['id']));
  78. }
  79. # 通过UIDs 获取用户信息
  80. $objMUser = new User();
  81. $userData = $objMUser -> gets($uids);
  82. $this->tpl = 'admin/activity/user_help';
  83. $title = '助力排行';
  84. $this->setOutput('title', $title);
  85. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  86. $this->addNavMenu('活动列表');
  87. $this->addNavMenu($title);
  88. // 获取所有活动类型
  89. $typeData = LotteryEvents::getType ();
  90. // 转换格式
  91. if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY && $_GET['action'] == 'all'){
  92. $helpData =$this->setData($eventData,$helpData);
  93. }
  94. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  95. $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示
  96. $isPrizes = in_array($eventData['type'], array(LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH, LotteryEvents::TYPE_EVENTS_TRY, LotteryEvents::TYPE_EVENTS_INVITATION));
  97. $this->setOutput('isPrizes', $isPrizes);
  98. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  99. $this->setOutput ( 'groupByUid', $groupByUid );
  100. $this->setOutput ( 'navConfig', $navConfig ); //公用内部导航信息
  101. $this->setOutput ( 'page_html', $page_html ); //分页HTML
  102. $this->setOutput ( 'helpData', $helpData ); // i日志
  103. $this->setOutput ( 'total_num', $total_num ); // 参与人数
  104. $this->setOutput ( 'userData', $userData ); // 当前列表用户信息
  105. $this->setOutput ( 'eventData', $eventData ); // 当前活动信息
  106. $this->setOutput ( 'typeData', $typeData );
  107. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  108. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  109. if ($groupByUid) {
  110. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserHelp&a=ExportData&groupByUid=true&events_id={$events_id}";
  111. } else {
  112. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserHelp&a=ExportData&events_id={$events_id}";
  113. }
  114. $this->setOutput('download_url', $download_url);
  115. }
  116. /**
  117. * 导出:获取用户参与活动日志
  118. * ?c=Admin_Activity_UserParticipateLog&a=doExportData&events_id=x
  119. * ?c=Admin_Activity_UserParticipateLog&a=doExportData&groupByUid=true&events_id=x
  120. */
  121. public function doExportData() {
  122. $events_id = Request::varGetInt ( 'events_id' );
  123. $groupByUid = Request::g ( 'groupByUid' );
  124. $datalist = array ();
  125. $objMLotteryLog = new LotteryLog ( null, $events_id );
  126. $allData = array ();
  127. $condition = array (
  128. 'events_id' => $events_id
  129. );
  130. $ids = $this->objLotteryUserHelp->findIdsBy ( $condition);
  131. $allData = $this->objLotteryUserHelp->gets ( $ids );
  132. $uids = array ();
  133. foreach ( $allData as $key => $data ) {
  134. $uids [$data ['uid']] = $data ['uid'];
  135. }
  136. // 转换格式
  137. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  138. /*
  139. if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY ){
  140. $allData =$this->setData($eventData,$allData);
  141. foreach($allData as $key => $data){
  142. $allData[$key]['other']['选择内容:'] = str_replace("<br>",",", $allData[$key]['other']['选择内容:']);
  143. }
  144. }
  145. */
  146. # 通过UIDs 获取用户信息
  147. $objMUser = new User();
  148. $userData = $objMUser -> gets($uids);
  149. $filename = '' . date ( 'YmdHis' ) . '.csv';
  150. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  151. header ( "Pragma: public" );
  152. header ( "Expires: 0" );
  153. header ( 'Content-Disposition: attachment; filename=' . $filename );
  154. $titleTag = '用户ID,昵称,时间,邀请人次数量' . "\n";
  155. foreach ( $allData as $data ) {
  156. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',' . $data['num'] . "\n";
  157. }
  158. $titleTag = Convert::u82gb ( $titleTag );
  159. exit ( $titleTag );
  160. }
  161. public function display() {
  162. return $this->render ();
  163. }
  164. }