UserParticipateLog.class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. /**
  22. * "活动相关" - "互动数据"
  23. *
  24. * @author lihuanchun 
  25. *  
  26. */
  27. class UserParticipateLog extends Controller {
  28. private $objLottery; // 活动后端
  29. private $peratorData;
  30. /**
  31. *  初始化
  32. */
  33. public function __construct() {
  34. header ( "Content-Type: text/html; charset=utf-8" );
  35. $this->objLottery = new Lottery ();
  36. $this->operatorData = $this->getUser ();
  37. $this->setOutput('action', Request::g('action'));
  38. }
  39. public function doDefault() {
  40. }
  41. /**
  42. * 获取当前互动的互动数据
  43. * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageList&events_id=n
  44. * 参数:events_id 活动ID 必填
  45. * 参数:groupByUid 是否用户排重 
  46. *
  47. */
  48. public function doPageList() {
  49. $events_id = Request::varGetInt ( 'events_id' );
  50. $groupByUid = Request::g ( 'groupByUid' ); // 用户是否排重
  51. $objMLotteryLog = new LotteryLog ( null, $events_id );
  52. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  53. $this->setOutput ( 'eventData', $eventData );
  54. $page = Request::varGetInt ( 'page', 1 );
  55. $size = 10;
  56. $offset = ($page - 1) * $size;
  57. $limit = "{$offset},{$size}";
  58. $order = ' id desc';
  59. $total_user_num = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  60. if ($groupByUid) {
  61. $logData = $objMLotteryLog->findUserParticipateDataGroupByUid ( $limit, $order );
  62. $total_num = $total_user_num;
  63. } else {
  64. $condition = array (
  65. 'events_id' => $events_id
  66. );
  67. $logData = $objMLotteryLog->findUserParticipateData ( $condition, $limit, $order );
  68. $total_num = $objMLotteryLog->getUserParticipateLogNum ( $condition );
  69. }
  70. // 分页
  71. $url_tpl = Request::url();
  72. $url_tpl .= "&page={page}";
  73. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  74. $page_html = $objPage->html ();
  75. $uids = array ();
  76. foreach ( $logData as $key => $data ) {
  77. $uids [$data ['uid']] = $data ['uid'];
  78. }
  79. # 通过UIDs 获取用户信息
  80. $objMUser = new User();
  81. $userData = $objMUser -> gets($uids);
  82. $this->tpl = 'admin/activity/user_participate_log';
  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. $logData =$this->setData($eventData,$logData);
  93. }
  94. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  95. $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示
  96. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  97. $this->setOutput ( 'groupByUid', $groupByUid );
  98. $this->setOutput ( 'navConfig', $navConfig ); //公用内部导航信息
  99. $this->setOutput ( 'page_html', $page_html ); //分页HTML
  100. $this->setOutput ( 'logData', $logData ); // i日志
  101. $this->setOutput ( 'total_user_num', $total_user_num ); // 参与人数
  102. $this->setOutput ( 'userData', $userData ); // 当前列表用户信息
  103. $this->setOutput ( 'eventData', $eventData ); // 当前活动信息
  104. $this->setOutput ( 'typeData', $typeData );
  105. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  106. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  107. $isPrizes = in_array($eventData['type'], array(LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH, LotteryEvents::TYPE_EVENTS_TRY, LotteryEvents::TYPE_EVENTS_INVITATION));
  108. $this->setOutput('isPrizes', $isPrizes);
  109. if ($groupByUid) {
  110. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&groupByUid=true&events_id={$events_id}";
  111. } else {
  112. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&events_id={$events_id}";
  113. }
  114. $this->setOutput('download_url', $download_url);
  115. }
  116. /**
  117. * 事件:更新审核状态
  118. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=Audit
  119. * 参数:见方法内
  120. */
  121. public function doAudit() {
  122. $tableInfo = $_POST;
  123. $events_id = $tableInfo['id'];
  124. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  125. $this->objDLotteryEventsForms = new LotteryEventsForms();// 用户"参与"活动日志
  126. $this->objDLotteryData = new LotteryData();
  127. if (isset($tableInfo['yes']) && $tableInfo['yes']) {
  128. $tableInfo['yes'] = explode(',', $tableInfo['yes']);
  129. foreach ($tableInfo['yes'] as $k => $v) {
  130. $info = array(
  131. 'audit' => 2,
  132. 'operator_uid' => $operator_uid
  133. );
  134. $this->objDLotteryEventsForms->modify( $info, array (
  135. 'id' => $v
  136. ));
  137. # 审核成功后,要把数据加到中奖表中
  138. $this->updateAuditData(2, $events_id, $eventData, $v, 0);
  139. }
  140. }
  141. if (isset($tableInfo['no']) && $tableInfo['no']) {
  142. $tableInfo['no'] = explode(',', $tableInfo['no']);
  143. foreach ($tableInfo['no'] as $k => $v) {
  144. $info = array(
  145. 'audit' => 3,
  146. 'operator_uid' => $operator_uid
  147. );
  148. $this->objDLotteryEventsForms->modify( $info, array (
  149. 'id' => $v
  150. ));
  151. # 审核失败后,要把数据从中奖表中拿出来
  152. $this->updateAuditData(3, $events_id, $eventData, $v, 0);
  153. }
  154. }
  155. $this->ajax_success_exit();
  156. }
  157. private function updateAuditData($audit, $events_id, $eventData, $formId, $prize_id)
  158. {
  159. $form = $this->objDLotteryEventsForms->get($formId);
  160. if ($eventData['type'] == 4) {
  161. # 试用
  162. $img = $eventData['weixinShare']['imgUrl'];
  163. $img = $img ? $img : $eventData['img_url'];
  164. $prize = array(
  165. 0 => array(
  166. 'events_id' => $events_id,
  167. 'prize_name' =>$eventData['events_name'],
  168. 'img_url' => $img,
  169. 'type' => LotteryPrize::TYPE_VIRTUAL,
  170. )
  171. );
  172. $virtual_data = "/?c=EventsTry&events_id={$events_id}&formsId=" . $form['id'];
  173. } elseif ($eventData['type'] == 6) {
  174. # 邀请函
  175. $prize = array(
  176. 0 => array(
  177. 'events_id' => $events_id,
  178. 'prize_name' =>$eventData['events_name'],
  179. 'img_url' => '/public/static/img/qricon.png',
  180. 'type' => LotteryPrize::TYPE_ENTITY,
  181. )
  182. );
  183. $virtual_data = "/?c=EventsInvitation&a=Qrcode&events_id={$events_id}&formsId=" . $form['id'];
  184. }
  185. $info = array(
  186. 'events_id' => $events_id,
  187. 'form_id' => $form['id'],
  188. 'prize_id' => $prize_id,
  189. 'audit' => $audit,
  190. 'uid' => $form['uid'],
  191. 'winners_time' => $form['update_time'],
  192. 'winning_time' => $form['update_time'],
  193. 'run_time_data' => array(
  194. 'events' => $eventData,
  195. 'prize' => $prize,
  196. ),
  197. 'virtual_data' => $virtual_data,
  198. );
  199. $dataInfo = $this->objDLotteryData->fetchOne(array
  200. (
  201. 'events_id' => $events_id,
  202. 'uid' => $info['uid'],
  203. 'prize_id' => $prize_id,
  204. ));
  205. if (!$dataInfo) {
  206. $this->objDLotteryData -> add($info);
  207. } else {
  208. $this->objDLotteryData -> modify($info, array('id' => $dataInfo['id']));
  209. }
  210. }
  211. /**
  212. * 显示 用户调查问卷 选择的结果集
  213. */
  214. public function doShowResultSet(){
  215. $events_id = Request::varGetInt ( 'events_id' );
  216. $objMLotteryLog = new LotteryLog ( null, $events_id );
  217. $condition = array (
  218. 'events_id' => $events_id
  219. );
  220. $logData = $objMLotteryLog->findUserParticipateData ( $condition);
  221. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  222. if($eventData['type'] != LotteryEvents:: TYPE_EVENTS_SURVEY){
  223. exit('end');
  224. }
  225. $return_data = array();
  226. $survery_question = $eventData['survery_question'];
  227. foreach($survery_question as $key => $data){
  228. $survery_question[$key]['choice'] = $data['choice']==0?'单选':'多选';
  229. $survery_question[$key]['num'] = 0;
  230. foreach($survery_question[$key]['answer'] as $k =>$d){
  231. $survery_question[$key]['answer'][$k]['num'] = 0;
  232. }
  233. }
  234. $log = array();
  235. foreach($logData as $key =>$data){
  236. $xznr = $data['other']['选择内容:'];
  237. if($xznr){
  238. $wtData = explode('|', $xznr);
  239. foreach($wtData as $key=> $wt){
  240. $survery_question[$key+1]['num'] ++;
  241. if($wt){
  242. $xz = explode(',', $wt);
  243. foreach($xz as $xzkey){
  244. $xzkey = (int)$xzkey;
  245. $survery_question[$key+1]['answer'][$xzkey]['num'] ++ ;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. $mp= $survery_question[1]['num'];
  252. echo "此次活动共计: {$mp}次 完成问卷<br><br><br>";
  253. foreach( $survery_question as $key=>$data){
  254. echo "问题[{$key}]:".$data['question'].'<br>';
  255. echo "选择类型:[".$data['choice'].']<br>';
  256. echo '选择:<br>';
  257. foreach($data['answer'] as $k => $d){
  258. $hhl=round(($d['num']/$data['num'])*100);
  259. echo "&nbsp;&nbsp;({$k}) ;&nbsp; {$d['answer']};&nbsp;&nbsp;&nbsp;[ {$hhl} %]<br>";
  260. }
  261. echo '<br><br><br>';
  262. }
  263. }
  264. /**
  265. * 转换数据格式
  266. */
  267. public function setData($eventData,$logData){
  268. foreach($logData as $key => $data){
  269. $txt = '';
  270. $tmpLog = $data['other']['选择内容:'] ;
  271. $tmpData = explode('|', $tmpLog) ;
  272. foreach($tmpData as $k =>$d){
  273. $txt .= "<br><br> 题目 :".$eventData['survery_question'][$k+1]['question']."<br>用户选择: ";
  274. $ttdd = explode(',', $d);
  275. foreach($ttdd as $tt){
  276. $tmptt = (int)$tt;
  277. $txt = $txt .$eventData['survery_question'][$k+1] ['answer'][$tmptt]['answer']." | ";
  278. }
  279. }
  280. $logData[$key]['other']['tmp'] = $txt;
  281. }
  282. foreach($logData as $key => $data){
  283. if(isset($logData[$key]['other']['tmp'])){
  284. $logData[$key]['other']['选择内容:'] = $logData[$key]['other']['tmp']."<br><br>" ;
  285. unset($logData[$key]['other']['tmp']);
  286. }else{
  287. $logData[$key]['other']['选择内容:'] = "用户未选择"."<br><br>" ;
  288. }
  289. }
  290. return $logData;
  291. }
  292. /**
  293. * 导出:获取用户参与活动日志
  294. * ?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&events_id=x
  295. * ?c=Admin_Activity_UserParticipateLog&a=ShowUserParticipateLogExportData&groupByUid=true&events_id=x
  296. */
  297. public function doShowUserParticipateLogExportData() {
  298. $events_id = Request::varGetInt ( 'events_id' );
  299. $groupByUid = Request::g ( 'groupByUid' );
  300. $datalist = array ();
  301. $objMLotteryLog = new LotteryLog ( null, $events_id );
  302. $allData = array ();
  303. if ($groupByUid) {
  304. $allData = $objMLotteryLog->findUserParticipateDataGroupByUid (null,null);
  305. } else {
  306. $condition = array (
  307. 'events_id' => $events_id
  308. );
  309. $allData = $objMLotteryLog->findUserParticipateData ( $condition,null,null );
  310. }
  311. $uids = array ();
  312. foreach ( $allData as $key => $data ) {
  313. $uids [$data ['uid']] = $data ['uid'];
  314. }
  315. // 转换格式
  316. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  317. /*
  318. if($eventData['type'] == LotteryEvents:: TYPE_EVENTS_SURVEY ){
  319. $allData =$this->setData($eventData,$allData);
  320. foreach($allData as $key => $data){
  321. $allData[$key]['other']['选择内容:'] = str_replace("<br>",",", $allData[$key]['other']['选择内容:']);
  322. }
  323. }
  324. */
  325. # 通过UIDs 获取用户信息
  326. $objMUser = new User();
  327. $userData = $objMUser -> gets($uids);
  328. $filename = '' . date ( 'YmdHis' ) . '.csv';
  329. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  330. header ( "Pragma: public" );
  331. header ( "Expires: 0" );
  332. header ( 'Content-Disposition: attachment; filename=' . $filename );
  333. $titleTag = '用户ID,昵称,时间,其他' . "\n";
  334. foreach ( $allData as $data ) {
  335. if (isset ( $data ['other'] )) {
  336. $otherStr = '';
  337. foreach ( $data ['other'] as $k => $d ) {
  338. $otherStr = $otherStr . $k . $d;
  339. }
  340. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',' . $otherStr . "\n";
  341. } else {
  342. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',空' . "\n";
  343. }
  344. }
  345. $titleTag = Convert::u82gb ( $titleTag );
  346. exit ( $titleTag );
  347. }
  348. /**
  349. * 页面:[查看中奖详情]
  350. * 地址:页面: http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageLotteryDataList&events_id=n
  351. * 活动ID:events_id
  352. * 筛选条件[奖品ID]:prize_id
  353. * 分页:page
  354. * 详情:scratch_receive=false
  355. */
  356. public function doPageLotteryDataList(){
  357. $events_id = Request::g ( 'events_id' );
  358. $scratch_receive = Request::g ( 'scratch_receive' );
  359. $eventsAndPrizeData =$this->objLottery->getOneLotteryEventsAndPrize($events_id);
  360. if($eventsAndPrizeData['events']['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH){
  361. }
  362. // 取数据
  363. $page = Request::varGetInt ( 'page', 1 );
  364. $size = 20;
  365. $offset = ($page - 1) * $size;
  366. $limit = "{$offset},{$size}";
  367. $condition = array (
  368. 'events_id' => $events_id,
  369. # 只有审核通过的才显示
  370. 'audit' => 2,
  371. );
  372. // 刮刮卡 跳将特殊处理
  373. $pieze_notreceive_num = array();
  374. if($eventsAndPrizeData['events']['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH){
  375. $condition['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_TRUE;
  376. foreach($eventsAndPrizeData['prize'] as $prize){
  377. $for_condition = array(
  378. 'events_id' => $events_id,
  379. 'prize_id' => $prize['id'],
  380. 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_FALSE
  381. );
  382. $pieze_notreceive_num[$prize['id']] = $this->objLottery->getLotteryDataListNum($for_condition);
  383. }
  384. }
  385. // 筛选条件
  386. $prize_id = Request::g ( 'prize_id' );
  387. if ($prize_id) {
  388. $condition ['prize_id'] = $prize_id;
  389. }
  390. if($scratch_receive=='false'){
  391. // $condition['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_FALSE;
  392. }
  393. $total_num = $this->objLottery->getLotteryDataListNum($condition);
  394. $url_tpl = Request::url();
  395. if($prize_id){
  396. $url_tpl .= "&prize_id={$prize_id}";
  397. }
  398. $url_tpl .= "&page={page}";
  399. // 分页
  400. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  401. $page_html = $objPage->html ();
  402. $order = 'id desc';
  403. $lotteryData = $this->objLottery->getLotteryDataList ( $condition, $limit, $order );
  404. $uids = array();
  405. foreach ($lotteryData as $tmpItem) {
  406. $uids[] = $tmpItem['uid'];
  407. }
  408. # 通过UIDs 获取用户信息
  409. $objMUser = new User();
  410. $users = $objMUser -> gets($uids);
  411. # 获取用户收货地址
  412. $objLotteryUserExpress = new LotteryUserExpress();
  413. $condition = array(
  414. 'uid' => $uids
  415. );
  416. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  417. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  418. $newUserExpData = array();
  419. foreach($userExpData as $key => $data){
  420. $newUserExpData[$data['uid']] = $data;
  421. }
  422. $objLotteryEventsForms = new LotteryEventsForms();
  423. $formCondition = array(
  424. 'events_id' => $events_id,
  425. );
  426. $ids = $objLotteryEventsForms->fetchOne($formCondition);
  427. if ($ids) {
  428. $formData = $objLotteryEventsForms->gets($ids);
  429. if ($formData) {
  430. foreach ($formData as $k => $v) {
  431. $formUserData[$v['uid']] = $v;
  432. }
  433. # 表单类型数据
  434. $formType = array();
  435. foreach ($eventsAndPrizeData['events']['forms'] as $tmpForms) {
  436. $formType[] = $tmpForms['name'];
  437. }
  438. $this->setOutput ( 'formType', $formType );
  439. $this->setOutput ( 'formUserData', $formUserData );
  440. }
  441. }
  442. $objDLotteryPrize = new LotteryPrize();
  443. $prizeType = $objDLotteryPrize -> getType();
  444. $prizeDisplayStatus = $objDLotteryPrize ->getDisplay();
  445. $this->tpl = 'admin/activity/user_participate_win';
  446. $title = '互动数据';
  447. $this->setOutput('title', $title);
  448. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  449. $this->addNavMenu('活动列表');
  450. $this->addNavMenu($title);
  451. $this->setOutput ( 'newUserExpData', $newUserExpData );
  452. $this->setOutput ( 'page_html', $page_html );
  453. $this->setOutput ( 'eventData', $eventsAndPrizeData['events'] );
  454. $this->setOutput ( 'prizeData', $eventsAndPrizeData['prize'] );
  455. $this->setOutput ( 'pieze_notreceive_num', $pieze_notreceive_num );
  456. $this->setOutput ( 'prizeType', $prizeType );
  457. $this->setOutput ( 'lotteryData', $lotteryData );
  458. $this->setOutput('userData', $users);
  459. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  460. $this->setOutput ( 'navConfig', $navConfig );
  461. $typeData = LotteryEvents::getType ();
  462. $this->setOutput ( 'typeData', $typeData );
  463. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  464. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  465. $this->setOutput('total_num', $total_num);
  466. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ExportWinData&events_id={$events_id}";
  467. $this->setOutput('download_url', $download_url);
  468. }
  469. public function doExportWinData() {
  470. $events_id = Request::g ( 'events_id' );
  471. $condition = array (
  472. 'events_id' => $events_id,
  473. # 只有审核通过的才显示
  474. 'audit' => 2,
  475. );
  476. $order = 'id desc';
  477. $lotteryData = $this->objLottery->getLotteryDataList ( $condition, null, $order );
  478. $uids = array();
  479. foreach ($lotteryData as $tmpItem) {
  480. $uids[] = $tmpItem['uid'];
  481. }
  482. $eventsAndPrizeData =$this->objLottery->getOneLotteryEventsAndPrize($events_id);
  483. $prizeData = $eventsAndPrizeData['prize'];
  484. # 通过UIDs 获取用户信息
  485. $objMUser = new User();
  486. $users = $objMUser -> gets($uids);
  487. # 获取用户收货地址
  488. $objLotteryUserExpress = new LotteryUserExpress();
  489. $condition = array(
  490. 'uid' => $uids
  491. );
  492. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  493. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  494. $newUserExpData = array();
  495. foreach($userExpData as $key => $data){
  496. $newUserExpData[$data['uid']] = $data;
  497. }
  498. ############发送头部信息############
  499. $fileName = date('YmdHis',time()) .".csv"; # 文件名
  500. $fileName = Convert::u82gb($fileName);
  501. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  502. header ( "Pragma: public" );
  503. header ( "Expires: 0" );
  504. header ( 'Content-Disposition: attachment; filename=' . $fileName );
  505. $title = "用户ID,昵称,时间,行为,用户收货信息\r\n";
  506. echo Convert::u82gb($title);
  507. foreach ($lotteryData as $tmpData) {
  508. $uid = $tmpData['uid'];
  509. $date = date('Y-m-d H:i:s', $tmpData['create_time']);
  510. $otherInfo = "获得奖品:{$prizeData[$tmpData['prize_id']]['prize_name']} ";
  511. if(isset($newUserExpData[$uid]['user_name'])){
  512. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$otherInfo},姓名:{$newUserExpData[$uid]['user_name']} 地址:{$newUserExpData[$uid]['address']} 电话:{$newUserExpData[$uid]['phone']}\r\n";
  513. }else{
  514. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$otherInfo},未填写\r\n";
  515. }
  516. echo Convert::u82gb($info);
  517. }
  518. exit;
  519. }
  520. /**
  521. * 页面: [表单数据]
  522. * 地址:http://cas.lishuy.com/?c=Admin_Activity_UserParticipateLog&a=PageEventFormData&events_id=n
  523. * 活动ID:events_id
  524. * 分页:page
  525. */
  526. public function doPageEventFormData(){
  527. $events_id = Request::varGetInt ( 'events_id');
  528. if (!Verify::unsignedInt($events_id)) {
  529. self::fail_exit_bs('无效events_id');
  530. }
  531. $page = Request::varGetInt ( 'page', 1 );
  532. $size = 10;
  533. $offset = ($page - 1) * $size;
  534. $limit = "{$offset},{$size}";
  535. $condition = array (
  536. 'events_id' => $events_id
  537. );
  538. $objLotteryEventsForms = new LotteryEventsForms();
  539. $ids = $objLotteryEventsForms->findIdsBy($condition,$limit,'id desc');
  540. $formData = $objLotteryEventsForms->gets($ids);
  541. $uids = array();
  542. foreach ($formData as $tmpItem) {
  543. $uids[] = $tmpItem['uid'];
  544. }
  545. $objLotteryEvents = new LotteryEvents();
  546. $eventData = $objLotteryEvents->get($events_id);
  547. # 审核状态只有在邀请函和试用才有,type=6&4
  548. $audit = false;
  549. if (in_array($eventData['type'], array(4,6))) {
  550. $audit = true;
  551. }
  552. $this->setOutput ( 'audit', $audit );
  553. # 表单类型数据
  554. $formType = array();
  555. foreach ($eventData['forms'] as $tmpForms) {
  556. $formType[] = $tmpForms['name'];
  557. }
  558. # 分页
  559. $total_num = $objLotteryEventsForms->totals($condition);
  560. $url_tpl = Request::url();
  561. $url_tpl .= "&page={page}";
  562. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  563. $page_html = $objPage->html ();
  564. # 通过UIDs 获取用户信息
  565. $objMUser = new User();
  566. $users = $objMUser -> gets($uids);
  567. $this->tpl = 'admin/activity/user_participate_form';
  568. $title = '互动数据';
  569. $this->setOutput('title', $title);
  570. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  571. $this->addNavMenu('活动列表');
  572. $this->addNavMenu($title);
  573. $isPrizes = in_array($eventData['type'], array(LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH, LotteryEvents::TYPE_EVENTS_TRY, LotteryEvents::TYPE_EVENTS_INVITATION));
  574. $this->setOutput('isPrizes', $isPrizes);
  575. $this->setOutput('eventData', $eventData);
  576. $this->setOutput ( 'page_html', $page_html );
  577. $this->setOutput ( 'formData', $formData );
  578. $this->setOutput('formType', $formType);
  579. $this->setOutput('userData', $users);
  580. $navConfig = $this->getUpPageNav($events_id, 'UserLog');
  581. $this->setOutput ( 'navConfig', $navConfig );
  582. $typeData = LotteryEvents::getType ();
  583. $this->setOutput ( 'typeData', $typeData );
  584. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  585. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  586. $this->setOutput('total_num', $total_num);
  587. $download_url = Request::schemeDomain() . "/?c=Admin_Activity_UserParticipateLog&a=ExportFormData&events_id={$events_id}";
  588. $this->setOutput('download_url', $download_url);
  589. }
  590. public function doExportFormData() {
  591. $events_id = Request::varGetInt ( 'events_id');
  592. if (!Verify::unsignedInt($events_id)) {
  593. self::fail_exit_bs('无效events_id');
  594. }
  595. $condition = array (
  596. 'events_id' => $events_id
  597. );
  598. $objLotteryEventsForms = new LotteryEventsForms();
  599. $ids = $objLotteryEventsForms->findIdsBy($condition,null,'id desc');
  600. $formData = $objLotteryEventsForms->gets($ids);
  601. $uids = array();
  602. foreach ($formData as $tmpItem) {
  603. $uids[] = $tmpItem['uid'];
  604. }
  605. $objLotteryEvents = new LotteryEvents();
  606. $eventData = $objLotteryEvents->get($events_id);
  607. # 表单类型数据
  608. $formType = array();
  609. foreach ($eventData['forms'] as $tmpForms) {
  610. $formType[] = $tmpForms['name'];
  611. }
  612. # 通过UIDs 获取用户信息
  613. $objMUser = new User();
  614. $users = $objMUser -> gets($uids);
  615. ############发送头部信息############
  616. $fileName = date('YmdHis',time()) .".csv"; # 文件名
  617. $fileName = Convert::u82gb($fileName);
  618. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  619. header ( "Pragma: public" );
  620. header ( "Expires: 0" );
  621. header ( 'Content-Disposition: attachment; filename=' . $fileName );
  622. # 审核状态只有在邀请函和试用才有,type=6&4
  623. $audit = false;
  624. if (in_array($eventData['type'], array(4,6))) {
  625. $audit = true;
  626. }
  627. $this->setOutput ( 'audit', $audit );
  628. $title = "用户ID,昵称,时间,行为\r\n";
  629. if ($audit) {
  630. $title = "用户ID,昵称,时间,行为,审核状态\r\n";
  631. }
  632. echo Convert::u82gb($title);
  633. foreach ($formData as $tmpData) {
  634. $uid = $tmpData['uid'];
  635. $date = date('Y-m-d H:i:s', $tmpData['create_time']);
  636. $formInfo = '';
  637. foreach ($formType as $formName) {
  638. $formInfo = "{$formName}:{$tmpData[$formName]} ";
  639. }
  640. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$formInfo}\r\n";
  641. if ($audit) {
  642. $status = $tmpData['audit'];
  643. if ($status == 1) {
  644. $status = '未审核';
  645. } elseif ($status == 2) {
  646. $status = '审核通过';
  647. } elseif ($status == 3) {
  648. $status = '审核未通过';
  649. }
  650. $info = "{$uid},{$users[$uid]['nickname']},{$date},{$formInfo},{$status}\r\n";
  651. }
  652. echo Convert::u82gb($info);
  653. }
  654. exit;
  655. }
  656. public function display() {
  657. return $this->render ();
  658. }
  659. }