EventsController.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. <?php
  2. namespace Cas\Controller;
  3. use KIF\Core\Request;
  4. use KIF\Cookie;
  5. use Cas\Module\User;
  6. use KIF\Core\Config;
  7. use KIF\String\String;
  8. use Cas\Dao\Platform;
  9. use Cas\Dao\LotteryEvents;
  10. use KIF\Math\Math;
  11. use Cas\Module\Lottery;
  12. use Cas\Module\LotteryLog;
  13. use Cas\Dao\LotteryUserFeedback;
  14. use Cas\Dao\LotteryData;
  15. use Cas\Dao\UserInfo;
  16. use KIF\Dao\SqlHelper;
  17. use Cas\Dao\Focus;
  18. use Cas\Dao\LotteryUserExpress;
  19. use Cas\Dao\LotteryUserHelp;
  20. use Cas\Dao\LotteryUserHelpLog;
  21. use Cas\Dao\LotteryEventsForms;
  22. /**
  23. * 活动页面的控制器
  24. *
  25. * @author lihuanchun
  26. *
  27. */
  28. class EventsController extends Controller {
  29. private $userCookieName = "USER_INFO_4";
  30. private $key;
  31. public function __construct() {
  32. $this->key = Config::getInstance ()->get ( 'passport_sign_key' );
  33. // 初始化一个本站用户
  34. $cookieInfo = Cookie::get ( $this->userCookieName );
  35. if (! $cookieInfo) {
  36. $objMUser = new User ();
  37. $uid = $objMUser->initUser ();
  38. $userinfo = $objMUser->get ( $uid );
  39. $userinfo ['sign'] = $this->createSign ( $userinfo );
  40. $json_data = json_encode ( $userinfo, true );
  41. Cookie::set ( $this->userCookieName, $json_data, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] );
  42. }
  43. // 平台信息
  44. $objPlatform = new Platform ();
  45. $plat_form_id = $this->getPlatFormId ();
  46. $platform = $objPlatform->get ( $plat_form_id );
  47. $this->setOutput ( 'platform', $platform );
  48. // 列表页URL
  49. $this->setOutput ( 'listUrl', Request::schemeDomain () . '/list/' . $platform ['url'] );
  50. // 我的礼品URL
  51. $this->setOutput ( 'giftsUrl', Request::schemeDomain () . '/list/' . $platform ['url'] . '/member/my' );
  52. $this->setOutput ( 'memberUrl', Request::schemeDomain () . '/list/' . $platform ['url'] . '/member/' );
  53. }
  54. /**
  55. * 获取当前用户
  56. */
  57. public function getRunTimeUid() {
  58. $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) );
  59. $cookieInfo = json_decode ( $cookieInfo, true );
  60. return $cookieInfo ['id'];
  61. }
  62. /**
  63. * 获取活动基本信息
  64. */
  65. public function info($info) {
  66. $this->objMLottery = new Lottery();
  67. # 剩余天数
  68. $TIME = time();
  69. $rday = ($info['end_time'] - $TIME) / (24 * 60 * 60);
  70. $info['rday'] = ceil($rday);
  71. # 参与人数
  72. $objMLotteryLog = new LotteryLog ( null, $info['id'] );
  73. $info['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  74. if (isset($info['base_num']) && $info['base_num']) {
  75. $info['user_total'] += $info['base_num'];
  76. }
  77. # 获取登录地址
  78. $url = Request::g('url');
  79. $plat_form_id = $this->getPlatFormId();
  80. $thisUrl = $this->objMLottery -> getEventsUrl($info['type'],$info['create_time'],$url);
  81. $loginUrl = $this -> getLoginUrl($thisUrl);
  82. $info['thisUrl'] = $thisUrl;
  83. $this->thisUrl = $thisUrl;
  84. $this->setOutput('thisUrl', $thisUrl);
  85. $this->setOutput('loginUrl', $loginUrl);
  86. # 判断是否需要登录
  87. $ckLogin = $this->ckLogin();
  88. $this->setOutput('ckLogin', $ckLogin);
  89. # 获取用户信息
  90. $objUserData = new UserInfo();
  91. $uid = $this->getRunTimeUid();
  92. $userData = $objUserData -> get($uid);
  93. $userData['headimgurl'] = $this->getUserHead($userData);
  94. $this->setOutput('uid', $uid);
  95. $this->setOutput('userInfo', $userData);
  96. $source_user = Request::g('source_user');
  97. if (!$source_user) {
  98. $source_user = $uid;
  99. }
  100. $this->setOutput('source_user', $source_user);
  101. if ($source_user != $uid) {
  102. $userData = $objUserData -> get($source_user);
  103. $userData['headimgurl'] = $this->getUserHead($userData);
  104. }
  105. if (!$userData['nickname']) {
  106. $userData['nickname'] = '福利社网友';
  107. }
  108. $this->setOutput('userSourceInfo', $userData);
  109. $info['end'] = 1; //未过期
  110. if ($TIME > $info['end_time']) {
  111. $info['end'] = 2;//已过期
  112. }
  113. # 抽奖、优惠券、邀请、试用
  114. $type = array(1,4,6,7);
  115. if (in_array($info['type'], $type)) {
  116. $info['prize'] = 1;
  117. //$info['authorize'] = true; //强制登录
  118. } else {
  119. $info['top_data'] = 1;
  120. }
  121. # 检查当前活动是否需要登录
  122. $info['login'] = 1;
  123. $authorize = $info['authorize'];
  124. if ($authorize) {
  125. if($ckLogin==true){
  126. $info['login'] = 2;//需要登录
  127. $weixin = $this->checkIsFromWeixin();
  128. if (!$weixin && $this->applogin == 2) {
  129. self::redirect($loginUrl);
  130. }
  131. //self::redirect($loginUrl);
  132. }
  133. }
  134. # 如果是试用,判断评价
  135. $condition = array('events_id' => $info['id'],'audit' => 2, 'uid' => $uid,'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  136. $offset = 0;
  137. $size = 1;
  138. $order = 'id desc';
  139. $userData = $this->objMLottery->getOnesLotteryData($condition);
  140. if ($userData) {
  141. $userData['feedback'] = 1;//不需要填写反馈
  142. $userData['url'] = base64_encode($info['thisUrl']);
  143. }
  144. if ($info['type'] == 4) {
  145. $info['feedback'] = 1;
  146. if ($userData) {
  147. $objLotteryUserFeedback = new LotteryUserFeedback();
  148. $userData['feedback'] = 2;//未填写反馈
  149. $where = array();
  150. $where['uid'] = $userData['uid'];
  151. $where['events_id'] = $userData['run_time_data']['events']['id'];
  152. $where['status'] = 1;
  153. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  154. if ($ids) {
  155. $userData['feedback'] = 3;//已填写反馈
  156. }
  157. /*
  158. if (isset($userData['express']) && $userData['express']) {
  159. $userData['feedback'] = 2;//未填写反馈
  160. $where = array();
  161. $where['uid'] = $userData['uid'];
  162. $where['events_id'] = $userData['run_time_data']['events']['id'];
  163. $where['status'] = 1;
  164. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  165. if ($ids) {
  166. $userData['feedback'] = 3;//已填写反馈
  167. }
  168. } else {
  169. $userData['feedback'] = 4;//未填写收货地址
  170. }
  171. */
  172. }
  173. }
  174. if ($info['type'] == 1) {
  175. $info['feedback'] = 1;
  176. if ($userData) {
  177. $objLotteryUserFeedback = new LotteryUserFeedback();
  178. if (isset($userData['express']) && $userData['express']) {
  179. } else {
  180. $userData['feedback'] = 4;//未填写收货地址
  181. }
  182. }
  183. }
  184. $order = '`index` desc, id desc';
  185. $limit = '0,5';
  186. $condition = array ('platform_id' => $plat_form_id);
  187. $objFocus = new Focus ();
  188. $ids = $objFocus->findIdsBy ( $condition, $limit, $order );
  189. $focusData = $objFocus->gets ( $ids );
  190. $ad = false;
  191. if (isset($this->platform['ad'])) {
  192. $ad = $this->platform['ad'];
  193. }
  194. $this->setOutput('ad', $ad);
  195. $this->setOutput('focusData', $focusData);
  196. $this->setOutput('userData', $userData);
  197. $this->setOutput('info', $info);
  198. $type = Request::g('type');
  199. if ($type == 'share') {
  200. # 分享
  201. $this->share($info, $plat_form_id, $source_user);
  202. } elseif ($type == 'prize') {
  203. # 获得福利
  204. $this->prize($info, $plat_form_id, 10, false);
  205. } elseif ($type == 'feedback') {
  206. # 获得评价信息
  207. $this->feedback($info, $plat_form_id, 10, false);
  208. } elseif ($type == 'help') {
  209. # 获得助力排行
  210. $this->help($info, $plat_form_id, 10, false);
  211. } else {
  212. $this->help($info, $plat_form_id, 10, false);
  213. }
  214. $this->setOutput('type', $type);
  215. $ajax = Request::g('ajax');
  216. if ($ajax == 'ajax') {
  217. $this->tpl = 'ajax_events';
  218. $this->ajax_success_exit($this->render(true));
  219. die;
  220. }
  221. }
  222. public function share($eventsData, $plat_form_id, $uid)
  223. {
  224. $events_id = $eventsData['id'];
  225. $condition = array (
  226. 'events_id' => $events_id,
  227. 'uid' => $uid,
  228. );
  229. $objLotteryUserHelp = new LotteryUserHelp();
  230. $info = $objLotteryUserHelp->fetchOne ( $condition);
  231. if (!$info) {
  232. $id = $objLotteryUserHelp->add ( $condition);
  233. } else {
  234. $id = $info['id'];
  235. }
  236. if ($id) {
  237. $objLotteryUserHelpLog = new LotteryUserHelpLog();
  238. $condition = array (
  239. 'events_id' => $events_id,
  240. 'help_id' => $id,
  241. );
  242. $total_num = $objLotteryUserHelpLog->totals ( $condition );
  243. $ids = $objLotteryUserHelpLog->findIdsBy ( $condition, '0,50', 'id desc' );
  244. $helpData = $objLotteryUserHelpLog->gets ( $ids );
  245. if ($helpData) {
  246. foreach ($helpData as $k => $v) {
  247. $helpData[$k]['headimgurl'] = $this->getUserHead($v['uid']);
  248. }
  249. }
  250. $session = $this->shareSession($id, $uid);
  251. $this->setOutput('help_session', $session);
  252. $this->setOutput('help_id', $id);
  253. $this->setOutput('helpData', $helpData);
  254. $this->setOutput('helpDataTotal', $total_num);
  255. # 获取登录地址
  256. $thisUrl = $this->thisUrl . '/share?events_id='.$events_id.'&help_id='.$id.'&help_session='.$session.'&source_user=' . $uid;
  257. $loginUrl = $this -> getLoginUrl($thisUrl);
  258. $this->setOutput('loginUrl', $loginUrl);
  259. }
  260. }
  261. public function shareSession($id, $uid, $source_session = false)
  262. {
  263. $key = 'onepage2999';
  264. $session = md5($id . '_' . $key . '_' . $uid);
  265. if ($source_session) {
  266. if ($source_session == $session) {
  267. return true;
  268. } else {
  269. return false;
  270. }
  271. } else {
  272. return $session;
  273. }
  274. }
  275. public function help($eventsData, $plat_form_id, $limit = 10, $uid = false)
  276. {
  277. $objUserHelp = new LotteryUserHelp ();
  278. $page = Request::varGetInt ( 'page', 1 );
  279. $size = $limit;
  280. $offset = ($page - 1) * $size;
  281. $limit = "{$offset},{$size}";
  282. $order = ' num desc, id desc';
  283. $condition = array (
  284. 'events_id' => $eventsData['id'],
  285. );
  286. $data = $objUserHelp->fetchAll ( $condition, $limit, $order );
  287. $total_num = $objUserHelp->totals ( $condition );
  288. $uids = array();
  289. if ($data) {
  290. foreach ($data as $k => $v) {
  291. $uids[] = $v['uid'];
  292. $data[$k]['num'] = $v['num'] + $eventsData['zhuli_num'];
  293. }
  294. # 通过UIDs 获取用户信息
  295. $objMUser = new User();
  296. $users = $objMUser -> gets($uids);
  297. $this->setOutput('userData', $users);
  298. }
  299. $this->setOutput('helpData', $data);
  300. $this->setOutput('helpDataTotals', ceil($total_num / $size));
  301. }
  302. public function feedback($eventsData, $plat_form_id, $limit = 10, $uid = false)
  303. {
  304. $objFeedBack = new LotteryUserFeedback ();
  305. $page = Request::varGetInt ( 'page', 1 );
  306. $size = $limit;
  307. $offset = ($page - 1) * $size;
  308. $limit = "{$offset},{$size}";
  309. $order = ' id desc';
  310. $condition = array (
  311. 'events_id' => $eventsData['id'],
  312. 'status' => 1,
  313. );
  314. $ids = $objFeedBack->findIdsBy ( $condition, $limit, $order );
  315. $data = $objFeedBack->gets ( $ids );
  316. $total_num = $objFeedBack->totals ( $condition );
  317. $uids = array();
  318. if ($data) {
  319. foreach ($data as $k => $v) {
  320. $uids[] = $v['uid'];
  321. }
  322. # 通过UIDs 获取用户信息
  323. $objMUser = new User();
  324. $users = $objMUser -> gets($uids);
  325. }
  326. if ($data) {
  327. $data = $this->userData($data, $eventsData);
  328. }
  329. $this->setOutput('fdData', $data);
  330. $this->setOutput('fdDataTotals', ceil($total_num / $size));
  331. }
  332. public function prize($eventsData, $plat_form_id, $limit = 10, $uid = false)
  333. {
  334. $condition = array('audit' => 2, 'platform_id' => SqlHelper::addCompareOperator('&', $plat_form_id), 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  335. if (isset($eventsData['id'])) {
  336. $condition['events_id'] = $eventsData['id'];
  337. unset($condition['platform_id']);
  338. unset($condition['scratch_receive']);
  339. }
  340. if ($uid) {
  341. $condition['uid'] = $uid;
  342. }
  343. $totals = $this->objMLottery -> getLotteryDataListNum($condition);
  344. $page = Request::varGetInt ( 'page', 1 );
  345. $size = $limit;
  346. $offset = ($page - 1) * $size;
  347. $order = 'id desc';
  348. $data = $this->objMLottery->getLotteryDataList($condition, "{$offset},{$size}", $order);
  349. if ($data) {
  350. $data = $this->userData($data, $eventsData);
  351. $this->setOutput('userEventsData', $data);
  352. $this->setOutput('userEventsDataTotals', ceil($totals / $size));
  353. }
  354. }
  355. public function userData($data, $eventsData)
  356. {
  357. $t = Request::g('a');
  358. if ($t == 1) {
  359. print_r($data);
  360. }
  361. $uids = array();
  362. foreach ($data as $k => $v) {
  363. $uids[] = $v['uid'];
  364. }
  365. # 通过UIDs 获取用户信息
  366. $objMUser = new User();
  367. $users = $objMUser -> gets($uids);
  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 $k => $v){
  376. $newUserExpData[$v['uid']] = $v;
  377. }
  378. if ($t == 1) {
  379. print_r($newUserExpData);
  380. }
  381. $objLotteryEventsForms = new LotteryEventsForms();
  382. $ids = $objLotteryEventsForms->findIdsBy($condition);
  383. $formData = $objLotteryEventsForms->gets($ids);
  384. $userFormData = array();
  385. foreach($formData as $k => $v){
  386. $userFormData[$v['uid']] = $v;
  387. }
  388. $this->setOutput('newUserExpData', $newUserExpData);
  389. //138****1234 的用户 2018.4.20 15:10 获得 某某某某活动 奖品。
  390. $objEvents = new LotteryEvents ();
  391. foreach ($data as $k => $v) {
  392. if (isset($v['pic'])) {
  393. $data[$k]['pic'] = explode(',', $v['pic']);
  394. }
  395. $data[$k]['user'] = array();
  396. $data[$k]['user']['nickname'] = $users[$v['uid']]['nickname'];
  397. $key = $v['run_time_data']['events']['forms'][1]['name'];
  398. if ($key) {
  399. $data[$k]['user']['nickname'] = $userFormData[$v['uid']][$key];
  400. }
  401. if ($v['events_id']) {
  402. $d = $objEvents->findIdsBy(array('id' => $v['events_id']));
  403. $t = $objEvents -> gets($d);
  404. $eventsData = array_pop($t);
  405. }
  406. $type = isset($eventsData['type']) ? $eventsData['type'] : $eventsData[$v['events_id']]['type'];
  407. $data[$k]['user']['cdate'] = date('Y.m.d H:i', isset($v['create_time']) ? $v['create_time'] : $v['create_time']);
  408. $data[$k]['user']['events'] = isset($eventsData['events_name']) ? $eventsData['events_name'] : $eventsData[$v['events_id']]['events_name'];
  409. $data[$k]['user']['headimgurl'] = $this->getUserHead($users[$v['uid']]);
  410. $data[$k]['user']['ext'] = '';
  411. if ($type == 6) {
  412. $data[$k]['user']['ext'] = '邀请';
  413. } elseif ($type == 4) {
  414. $data[$k]['user']['ext'] = '试用资格';
  415. } elseif ($type == 7) {
  416. $data[$k]['user']['ext'] = '优惠券';
  417. } elseif ($type == 1) {
  418. $data[$k]['user']['ext'] = '奖品';
  419. }
  420. if ($type == 4) {
  421. $data[$k]['user']['mobile'] = $data[$k]['user']['nickname'];
  422. } elseif (isset($v['express']['phone']) && $v['express']['phone']) {
  423. $data[$k]['user']['mobile'] = substr_replace($v['express']['phone'],'****',3,4);
  424. } elseif (isset($newUserExpData[$v['uid']]['phone']) && $newUserExpData[$v['uid']]['phone']) {
  425. $data[$k]['user']['mobile'] = substr_replace($newUserExpData[$v['uid']]['phone'],'****',3,4);
  426. } else {
  427. //unset($data[$k]);
  428. $data[$k]['user']['mobile'] = $data[$k]['user']['nickname'];
  429. }
  430. if (!$data[$k]['user']['mobile']) {
  431. $data[$k]['user']['mobile'] = '游客';
  432. }
  433. }
  434. return $data;
  435. }
  436. /**
  437. * 获取头像
  438. */
  439. public function getUserHead($user)
  440. {
  441. if (!is_array($user)) {
  442. $objUserData = new UserInfo();
  443. $user = $objUserData -> get($user);
  444. }
  445. if (isset($user['headimgurl']) && $user['headimgurl']) {
  446. $result = $user['headimgurl'];
  447. } else {
  448. $result = 'http://news.mydrivers.com/Img/20110518/04481549.png';
  449. }
  450. return $result;
  451. }
  452. /**
  453. * 判断当前用户是否已经登录
  454. * true 需要
  455. * false 不需要
  456. */
  457. public function ckLogin() {
  458. $cookieInfo = Cookie::get ( $this->userCookieName );
  459. $cookieInfo = html_entity_decode ( $cookieInfo );
  460. $userInfo = json_decode ( $cookieInfo, true );
  461. /*
  462. * if(!$this->checkSign($userInfo['sign'] , $userInfo)){ return true; }
  463. */
  464. if ($userInfo ['is_new'] == 0) {
  465. return true;
  466. }
  467. return false;
  468. }
  469. /**
  470. * 获取登录地址
  471. * $thisUrl : 活动URL地址
  472. */
  473. public function getLoginUrl($thisUrl) {
  474. $type = Request::g('type');
  475. if ($type == 'share' && !strstr($thisUrl, 'share')) {
  476. $thisUrl .= '/share';
  477. }
  478. // 1.拼接一个 referer 地址 
  479. $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) );
  480. $cookieInfo = json_decode ( $cookieInfo, true );
  481. $uid = $cookieInfo ['id'];
  482. $args = array (
  483. 'cas_uid' => $uid,
  484. 'cas_return_url' => urlencode ( $thisUrl ) // 绑定用户后的跳转地址
  485. );
  486. $args ['sign'] = $this->createSign ( $args );
  487. $refererUrl = urlencode ( String::jointUrl ( Request::schemeDomain () . '/SetUser/', $args ) ); // passport 返回统一着陆页
  488. // 2. 拼接passport请求地址
  489. $passport_url = Config::getInstance ()->get ( 'passport_url' );
  490. $passport_third_url = Config::getInstance ()->get ( 'passport_third_url' );
  491. $weixin = $this->checkIsFromWeixin();
  492. if ($passport_third_url && !$weixin) {
  493. $passport_url = $passport_third_url;
  494. }
  495. $passport_url .= '&referer=' . $refererUrl;
  496. $arr = $this->convertUrlQuery ( $passport_url );
  497. $arr ['sign'] = $this->createSign ( $arr );
  498. $passport_url .= '&sign=' . $arr ['sign'];
  499. $passport_url .= '&cas_uid=' . $uid;
  500. $this->setOutput('applogin', 2);
  501. $this->applogin = 2;
  502. if (!$weixin) {
  503. $tokenid = Request::g('tokenid');
  504. if (!$tokenid) {
  505. $tokenid = Request::g('tokenId');
  506. }
  507. if ($tokenid) {
  508. Cookie::set ( 'tokenid', $tokenid, 60 * 60 * 24 * 20 ,'.'.$_SERVER['HTTP_HOST']);
  509. }
  510. if (isset($_COOKIE['tokenid'])) {
  511. $tokenid = $_COOKIE['tokenid'];
  512. }
  513. if ($tokenid) {
  514. # 先检查有没有过期吧
  515. /*
  516. $config = Config::getInstance()->get('passport');
  517. $param['authorizedCode'] = 'fulishe';
  518. $param['tokenId'] = $tokenid;
  519. $data = $this->httpPost($config['url'], $param);
  520. $data = json_decode($data, true);
  521. if (isset($data['data']) && isset($data['data']['tokenId']) && $data['data']['tokenId']) {
  522. } else {
  523. # 已过期
  524. $this->setOutput('applogin', 1);
  525. $this->applogin = 1;
  526. return $passport_url;
  527. }
  528. */
  529. # app中已登陆
  530. $passport_url .= '&tokenid=' . $tokenid;
  531. } else {
  532. # app中未登陆
  533. $this->setOutput('applogin', 1);
  534. $this->applogin = 1;
  535. }
  536. #
  537. }
  538. return $passport_url;
  539. }
  540. private function httpPost($url, $param) {
  541. $curl = curl_init();
  542. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  543. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  544. curl_setopt($curl, CURLOPT_URL, $url);
  545. curl_setopt($curl, CURLOPT_POST, 1);
  546. curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
  547. $res = curl_exec($curl);
  548. curl_close($curl);
  549. return $res;
  550. }
  551. public function convertUrlQuery($url) {
  552. $arr = parse_url ( $url );
  553. $query = $arr ['query'];
  554. $queryParts = explode ( '&', $query );
  555. $params = array ();
  556. foreach ( $queryParts as $param ) {
  557. $item = explode ( '=', $param );
  558. $params [$item [0]] = $item [1];
  559. }
  560. return $params;
  561. }
  562. /**
  563. * 通过活动创建时间,返回活动ID
  564. */
  565. public function getEventsCreateTimeToId() {
  566. $create_time = Request::g ( 'create_time' );
  567. $create_time = strtotime ( $create_time );
  568. $objEvents = new LotteryEvents ();
  569. $ids = $objEvents->findIdsBy ( array (
  570. 'create_time' => $create_time
  571. ) );
  572. return array_pop ( $ids );
  573. }
  574. /**
  575. * 活动相关页面获取 plat_form_id 方法
  576. */
  577. public function getPlatFormId() {
  578. $url = Request::g ( 'url' );
  579. $objDPlatform = new Platform ();
  580. $data = $objDPlatform->getsAll ();
  581. foreach ( $data as $key => $d ) {
  582. if ($d ['url'] == $url) {
  583. $plat_form_id = $key;
  584. $this->platform = $d;
  585. }
  586. }
  587. if (empty ( $plat_form_id )) {
  588. $plat_form_id = Cookie::get ( 'plat_form_id' );
  589. } else {
  590. Cookie::set ( 'plat_form_id', $plat_form_id, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] );
  591. }
  592. return $plat_form_id;
  593. }
  594. /**
  595. * 生成请求参数的sign
  596. *
  597. * @param array $params
  598. * @return String
  599. */
  600. public function createSign(array $params) {
  601. if ($params && is_array ( $params )) {
  602. ksort ( $params );
  603. $str = $this->key;
  604. foreach ( $params as $key => $value ) {
  605. if ($key != 'sign') {
  606. $str .= $key . $value;
  607. }
  608. }
  609. return strtoupper ( md5 ( $str ) );
  610. }
  611. return '';
  612. }
  613. /**
  614. * 指定的sign值是否正确
  615. *
  616. * @param String $sign
  617. * 给定需要验证的sign值
  618. * @param Array $params
  619. * 用来计算sign值的参数集合
  620. * @return Boolean
  621. */
  622. public function checkSign($sign, $params = null) {
  623. $sign2 = $this->createSign ( $params );
  624. return ($sign2 == $sign);
  625. }
  626. public function checkIsFromWeixin($title) {
  627. $state = false;
  628. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  629. if (preg_match ( '/MicroMessenger/i', $user_agent )) {
  630. $state = true;
  631. }
  632. return $state;
  633. }
  634. /**
  635. *
  636. * @param string $title
  637. */
  638. public function checkIsFromMobile($title) {
  639. //return true;
  640. if (Request::get ( 'debugs' ) == 'rabin') {
  641. return true;
  642. }
  643. // PC 端显示二维码页
  644. $isMobile = false;
  645. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  646. /*
  647. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  648. $isMobile = true;
  649. }
  650. */
  651. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  652. $isMobile = true;
  653. }
  654. if (! $isMobile) {
  655. include_once Config::getInstance ()->get ( 'App_Path' ) . DS . 'include/phpqrcode/phpqrcode.php';
  656. $IMG_UPLOAD_PATH = Config::getInstance ()->get ( 'upload.path' ) . DS . 'qrcode';
  657. $IMG_UPLOAD_URL = Config::getInstance ()->get ( 'upload.url' ) . DS . 'qrcode';
  658. if (! file_exists ( $IMG_UPLOAD_PATH )) {
  659. if (! mkdir ( $IMG_UPLOAD_PATH, 0775, true )) {
  660. self::fail_exit ( '创建二维码失败,原因:图片目录不存在' );
  661. }
  662. }
  663. $url = Request::url ();
  664. $fileName = Math::md5_16 ( $url ) . '.png';
  665. $save_path = $IMG_UPLOAD_PATH . DS . $fileName;
  666. $save_url = $IMG_UPLOAD_URL . DS . $fileName;
  667. if (! file_exists ( $save_path )) {
  668. \QRcode::png ( $url, $save_path, 3, 6 );
  669. }
  670. $this->tpl = 'pc_qrcode';
  671. $this->setOutput ( 'qrcode', $save_url );
  672. $this->setOutput ( 'title', $title );
  673. $this->setOutput('user_agent', $user_agent);
  674. exit ( $this->render () );
  675. }
  676. }
  677. }