EventsController.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. }
  212. $this->setOutput('type', $type);
  213. $ajax = Request::g('ajax');
  214. if ($ajax == 'ajax') {
  215. $this->tpl = 'ajax_events';
  216. $this->ajax_success_exit($this->render(true));
  217. die;
  218. }
  219. }
  220. public function share($eventsData, $plat_form_id, $uid)
  221. {
  222. $events_id = $eventsData['id'];
  223. $condition = array (
  224. 'events_id' => $events_id,
  225. 'uid' => $uid,
  226. );
  227. $objLotteryUserHelp = new LotteryUserHelp();
  228. $info = $objLotteryUserHelp->fetchOne ( $condition);
  229. if (!$info) {
  230. $id = $objLotteryUserHelp->add ( $condition);
  231. } else {
  232. $id = $info['id'];
  233. }
  234. if ($id) {
  235. $objLotteryUserHelpLog = new LotteryUserHelpLog();
  236. $condition = array (
  237. 'events_id' => $events_id,
  238. 'help_id' => $id,
  239. );
  240. $total_num = $objLotteryUserHelpLog->totals ( $condition );
  241. $ids = $objLotteryUserHelpLog->findIdsBy ( $condition, '0,50', 'id desc' );
  242. $helpData = $objLotteryUserHelpLog->gets ( $ids );
  243. if ($helpData) {
  244. foreach ($helpData as $k => $v) {
  245. $helpData[$k]['headimgurl'] = $this->getUserHead($v['uid']);
  246. }
  247. }
  248. $session = $this->shareSession($id, $uid);
  249. $this->setOutput('help_session', $session);
  250. $this->setOutput('help_id', $id);
  251. $this->setOutput('helpData', $helpData);
  252. $this->setOutput('helpDataTotal', $total_num);
  253. # 获取登录地址
  254. $thisUrl = $this->thisUrl . '/share?events_id='.$events_id.'&help_id='.$id.'&help_session='.$session.'&source_user=' . $uid;
  255. $loginUrl = $this -> getLoginUrl($thisUrl);
  256. $this->setOutput('loginUrl', $loginUrl);
  257. }
  258. }
  259. public function shareSession($id, $uid, $source_session = false)
  260. {
  261. $key = 'onepage2999';
  262. $session = md5($id . '_' . $key . '_' . $uid);
  263. if ($source_session) {
  264. if ($source_session == $session) {
  265. return true;
  266. } else {
  267. return false;
  268. }
  269. } else {
  270. return $session;
  271. }
  272. }
  273. public function help($eventsData, $plat_form_id, $limit = 10, $uid = false)
  274. {
  275. $objUserHelp = new LotteryUserHelp ();
  276. $page = Request::varGetInt ( 'page', 1 );
  277. $size = $limit;
  278. $offset = ($page - 1) * $size;
  279. $limit = "{$offset},{$size}";
  280. $order = ' num desc, id desc';
  281. $condition = array (
  282. 'events_id' => $eventsData['id'],
  283. );
  284. $data = $objUserHelp->fetchAll ( $condition, $limit, $order );
  285. $total_num = $objUserHelp->totals ( $condition );
  286. $uids = array();
  287. if ($data) {
  288. foreach ($data as $k => $v) {
  289. $uids[] = $v['uid'];
  290. $data[$k]['num'] = $v['num'] + $eventsData['zhuli_num'];
  291. }
  292. # 通过UIDs 获取用户信息
  293. $objMUser = new User();
  294. $users = $objMUser -> gets($uids);
  295. $this->setOutput('userDatas', $users);
  296. }
  297. $this->setOutput('helpData', $data);
  298. $this->setOutput('helpDataTotals', ceil($total_num / $size));
  299. }
  300. public function feedback($eventsData, $plat_form_id, $limit = 10, $uid = false)
  301. {
  302. $objFeedBack = new LotteryUserFeedback ();
  303. $page = Request::varGetInt ( 'page', 1 );
  304. $size = $limit;
  305. $offset = ($page - 1) * $size;
  306. $limit = "{$offset},{$size}";
  307. $order = ' id desc';
  308. $condition = array (
  309. 'events_id' => $eventsData['id'],
  310. 'status' => 1,
  311. );
  312. $ids = $objFeedBack->findIdsBy ( $condition, $limit, $order );
  313. $data = $objFeedBack->gets ( $ids );
  314. $total_num = $objFeedBack->totals ( $condition );
  315. $uids = array();
  316. if ($data) {
  317. foreach ($data as $k => $v) {
  318. $uids[] = $v['uid'];
  319. }
  320. # 通过UIDs 获取用户信息
  321. $objMUser = new User();
  322. $users = $objMUser -> gets($uids);
  323. }
  324. if ($data) {
  325. $data = $this->userData($data, $eventsData);
  326. }
  327. $this->setOutput('fdData', $data);
  328. $this->setOutput('fdDataTotals', ceil($total_num / $size));
  329. }
  330. public function prize($eventsData, $plat_form_id, $limit = 10, $uid = false)
  331. {
  332. $condition = array('audit' => 2, 'platform_id' => SqlHelper::addCompareOperator('&', $plat_form_id), 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  333. if (isset($eventsData['id'])) {
  334. $condition['events_id'] = $eventsData['id'];
  335. unset($condition['platform_id']);
  336. unset($condition['scratch_receive']);
  337. }
  338. if ($uid) {
  339. $condition['uid'] = $uid;
  340. }
  341. $totals = $this->objMLottery -> getLotteryDataListNum($condition);
  342. $page = Request::varGetInt ( 'page', 1 );
  343. $size = $limit;
  344. $offset = ($page - 1) * $size;
  345. $order = 'id desc';
  346. $data = $this->objMLottery->getLotteryDataList($condition, "{$offset},{$size}", $order);
  347. if ($data) {
  348. $data = $this->userData($data, $eventsData);
  349. $this->setOutput('userEventsData', $data);
  350. $this->setOutput('userEventsDataTotals', ceil($totals / $size));
  351. }
  352. }
  353. public function userData($data, $eventsData)
  354. {
  355. $t = Request::g('a');
  356. if ($t == 1) {
  357. print_r($data);
  358. }
  359. $uids = array();
  360. foreach ($data as $k => $v) {
  361. $uids[] = $v['uid'];
  362. }
  363. # 通过UIDs 获取用户信息
  364. $objMUser = new User();
  365. $users = $objMUser -> gets($uids);
  366. $objLotteryUserExpress = new LotteryUserExpress();
  367. $condition = array(
  368. 'uid' => $uids
  369. );
  370. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  371. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  372. $newUserExpData = array();
  373. foreach($userExpData as $k => $v){
  374. $newUserExpData[$v['uid']] = $v;
  375. }
  376. if ($t == 1) {
  377. print_r($newUserExpData);
  378. }
  379. $objLotteryEventsForms = new LotteryEventsForms();
  380. $ids = $objLotteryEventsForms->findIdsBy($condition);
  381. $formData = $objLotteryEventsForms->gets($ids);
  382. $userFormData = array();
  383. foreach($formData as $k => $v){
  384. $userFormData[$v['uid']] = $v;
  385. }
  386. $this->setOutput('newUserExpData', $newUserExpData);
  387. //138****1234 的用户 2018.4.20 15:10 获得 某某某某活动 奖品。
  388. $objEvents = new LotteryEvents ();
  389. foreach ($data as $k => $v) {
  390. if (isset($v['pic'])) {
  391. $data[$k]['pic'] = explode(',', $v['pic']);
  392. }
  393. $data[$k]['user'] = array();
  394. $data[$k]['user']['nickname'] = $users[$v['uid']]['nickname'];
  395. $key = $v['run_time_data']['events']['forms'][1]['name'];
  396. if ($key) {
  397. $data[$k]['user']['nickname'] = $userFormData[$v['uid']][$key];
  398. }
  399. if ($v['events_id']) {
  400. $d = $objEvents->findIdsBy(array('id' => $v['events_id']));
  401. $t = $objEvents -> gets($d);
  402. $eventsData = array_pop($t);
  403. }
  404. $type = isset($eventsData['type']) ? $eventsData['type'] : $eventsData[$v['events_id']]['type'];
  405. $data[$k]['user']['cdate'] = date('Y.m.d H:i', isset($v['create_time']) ? $v['create_time'] : $v['create_time']);
  406. $data[$k]['user']['events'] = isset($eventsData['events_name']) ? $eventsData['events_name'] : $eventsData[$v['events_id']]['events_name'];
  407. $data[$k]['user']['headimgurl'] = $this->getUserHead($users[$v['uid']]);
  408. $data[$k]['user']['ext'] = '';
  409. if ($type == 6) {
  410. $data[$k]['user']['ext'] = '邀请';
  411. } elseif ($type == 4) {
  412. $data[$k]['user']['ext'] = '试用资格';
  413. } elseif ($type == 7) {
  414. $data[$k]['user']['ext'] = '优惠券';
  415. } elseif ($type == 1) {
  416. $data[$k]['user']['ext'] = '奖品';
  417. }
  418. if ($type == 4) {
  419. $data[$k]['user']['mobile'] = $data[$k]['user']['nickname'];
  420. } elseif (isset($v['express']['phone']) && $v['express']['phone']) {
  421. $data[$k]['user']['mobile'] = substr_replace($v['express']['phone'],'****',3,4);
  422. } elseif (isset($newUserExpData[$v['uid']]['phone']) && $newUserExpData[$v['uid']]['phone']) {
  423. $data[$k]['user']['mobile'] = substr_replace($newUserExpData[$v['uid']]['phone'],'****',3,4);
  424. } else {
  425. //unset($data[$k]);
  426. $data[$k]['user']['mobile'] = $data[$k]['user']['nickname'];
  427. }
  428. if (!$data[$k]['user']['mobile']) {
  429. $data[$k]['user']['mobile'] = '游客';
  430. }
  431. }
  432. return $data;
  433. }
  434. /**
  435. * 获取头像
  436. */
  437. public function getUserHead($user)
  438. {
  439. if (!is_array($user)) {
  440. $objUserData = new UserInfo();
  441. $user = $objUserData -> get($user);
  442. }
  443. if (isset($user['headimgurl']) && $user['headimgurl']) {
  444. $result = $user['headimgurl'];
  445. } else {
  446. $result = 'http://news.mydrivers.com/Img/20110518/04481549.png';
  447. }
  448. return $result;
  449. }
  450. /**
  451. * 判断当前用户是否已经登录
  452. * true 需要
  453. * false 不需要
  454. */
  455. public function ckLogin() {
  456. $cookieInfo = Cookie::get ( $this->userCookieName );
  457. $cookieInfo = html_entity_decode ( $cookieInfo );
  458. $userInfo = json_decode ( $cookieInfo, true );
  459. /*
  460. * if(!$this->checkSign($userInfo['sign'] , $userInfo)){ return true; }
  461. */
  462. if ($userInfo ['is_new'] == 0) {
  463. return true;
  464. }
  465. return false;
  466. }
  467. /**
  468. * 获取登录地址
  469. * $thisUrl : 活动URL地址
  470. */
  471. public function getLoginUrl($thisUrl) {
  472. $type = Request::g('type');
  473. if ($type == 'share' && !strstr($thisUrl, 'share')) {
  474. $thisUrl .= '/share';
  475. }
  476. // 1.拼接一个 referer 地址 
  477. $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) );
  478. $cookieInfo = json_decode ( $cookieInfo, true );
  479. $uid = $cookieInfo ['id'];
  480. $args = array (
  481. 'cas_uid' => $uid,
  482. 'cas_return_url' => urlencode ( $thisUrl ) // 绑定用户后的跳转地址
  483. );
  484. $args ['sign'] = $this->createSign ( $args );
  485. $refererUrl = urlencode ( String::jointUrl ( Request::schemeDomain () . '/SetUser/', $args ) ); // passport 返回统一着陆页
  486. // 2. 拼接passport请求地址
  487. $passport_url = Config::getInstance ()->get ( 'passport_url' );
  488. $passport_third_url = Config::getInstance ()->get ( 'passport_third_url' );
  489. $weixin = $this->checkIsFromWeixin();
  490. if ($passport_third_url && !$weixin) {
  491. $passport_url = $passport_third_url;
  492. }
  493. $passport_url .= '&referer=' . $refererUrl;
  494. $arr = $this->convertUrlQuery ( $passport_url );
  495. $arr ['sign'] = $this->createSign ( $arr );
  496. $passport_url .= '&sign=' . $arr ['sign'];
  497. $passport_url .= '&cas_uid=' . $uid;
  498. $this->setOutput('applogin', 2);
  499. $this->applogin = 2;
  500. if (!$weixin) {
  501. $tokenid = Request::g('tokenid');
  502. if (!$tokenid) {
  503. $tokenid = Request::g('tokenId');
  504. }
  505. if ($tokenid) {
  506. Cookie::set ( 'tokenid', $tokenid, 60 * 60 * 24 * 20 ,'.'.$_SERVER['HTTP_HOST']);
  507. }
  508. if (isset($_COOKIE['tokenid'])) {
  509. $tokenid = $_COOKIE['tokenid'];
  510. }
  511. if ($tokenid) {
  512. # 先检查有没有过期吧
  513. /*
  514. $config = Config::getInstance()->get('passport');
  515. $param['authorizedCode'] = 'fulishe';
  516. $param['tokenId'] = $tokenid;
  517. $data = $this->httpPost($config['url'], $param);
  518. $data = json_decode($data, true);
  519. if (isset($data['data']) && isset($data['data']['tokenId']) && $data['data']['tokenId']) {
  520. } else {
  521. # 已过期
  522. $this->setOutput('applogin', 1);
  523. $this->applogin = 1;
  524. return $passport_url;
  525. }
  526. */
  527. # app中已登陆
  528. $passport_url .= '&tokenid=' . $tokenid;
  529. } else {
  530. # app中未登陆
  531. $this->setOutput('applogin', 1);
  532. $this->applogin = 1;
  533. }
  534. #
  535. }
  536. return $passport_url;
  537. }
  538. private function httpPost($url, $param) {
  539. $curl = curl_init();
  540. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  541. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  542. curl_setopt($curl, CURLOPT_URL, $url);
  543. curl_setopt($curl, CURLOPT_POST, 1);
  544. curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
  545. $res = curl_exec($curl);
  546. curl_close($curl);
  547. return $res;
  548. }
  549. public function convertUrlQuery($url) {
  550. $arr = parse_url ( $url );
  551. $query = $arr ['query'];
  552. $queryParts = explode ( '&', $query );
  553. $params = array ();
  554. foreach ( $queryParts as $param ) {
  555. $item = explode ( '=', $param );
  556. $params [$item [0]] = $item [1];
  557. }
  558. return $params;
  559. }
  560. /**
  561. * 通过活动创建时间,返回活动ID
  562. */
  563. public function getEventsCreateTimeToId() {
  564. $create_time = Request::g ( 'create_time' );
  565. $create_time = strtotime ( $create_time );
  566. $objEvents = new LotteryEvents ();
  567. $ids = $objEvents->findIdsBy ( array (
  568. 'create_time' => $create_time
  569. ) );
  570. return array_pop ( $ids );
  571. }
  572. /**
  573. * 活动相关页面获取 plat_form_id 方法
  574. */
  575. public function getPlatFormId() {
  576. $url = Request::g ( 'url' );
  577. $objDPlatform = new Platform ();
  578. $data = $objDPlatform->getsAll ();
  579. foreach ( $data as $key => $d ) {
  580. if ($d ['url'] == $url) {
  581. $plat_form_id = $key;
  582. $this->platform = $d;
  583. }
  584. }
  585. if (empty ( $plat_form_id )) {
  586. $plat_form_id = Cookie::get ( 'plat_form_id' );
  587. } else {
  588. Cookie::set ( 'plat_form_id', $plat_form_id, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] );
  589. }
  590. return $plat_form_id;
  591. }
  592. /**
  593. * 生成请求参数的sign
  594. *
  595. * @param array $params
  596. * @return String
  597. */
  598. public function createSign(array $params) {
  599. if ($params && is_array ( $params )) {
  600. ksort ( $params );
  601. $str = $this->key;
  602. foreach ( $params as $key => $value ) {
  603. if ($key != 'sign') {
  604. $str .= $key . $value;
  605. }
  606. }
  607. return strtoupper ( md5 ( $str ) );
  608. }
  609. return '';
  610. }
  611. /**
  612. * 指定的sign值是否正确
  613. *
  614. * @param String $sign
  615. * 给定需要验证的sign值
  616. * @param Array $params
  617. * 用来计算sign值的参数集合
  618. * @return Boolean
  619. */
  620. public function checkSign($sign, $params = null) {
  621. $sign2 = $this->createSign ( $params );
  622. return ($sign2 == $sign);
  623. }
  624. public function checkIsFromWeixin($title) {
  625. $state = false;
  626. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  627. if (preg_match ( '/MicroMessenger/i', $user_agent )) {
  628. $state = true;
  629. }
  630. return $state;
  631. }
  632. /**
  633. *
  634. * @param string $title
  635. */
  636. public function checkIsFromMobile($title) {
  637. //return true;
  638. if (Request::get ( 'debugs' ) == 'rabin') {
  639. return true;
  640. }
  641. // PC 端显示二维码页
  642. $isMobile = false;
  643. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  644. /*
  645. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  646. $isMobile = true;
  647. }
  648. */
  649. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  650. $isMobile = true;
  651. }
  652. if (! $isMobile) {
  653. include_once Config::getInstance ()->get ( 'App_Path' ) . DS . 'include/phpqrcode/phpqrcode.php';
  654. $IMG_UPLOAD_PATH = Config::getInstance ()->get ( 'upload.path' ) . DS . 'qrcode';
  655. $IMG_UPLOAD_URL = Config::getInstance ()->get ( 'upload.url' ) . DS . 'qrcode';
  656. if (! file_exists ( $IMG_UPLOAD_PATH )) {
  657. if (! mkdir ( $IMG_UPLOAD_PATH, 0775, true )) {
  658. self::fail_exit ( '创建二维码失败,原因:图片目录不存在' );
  659. }
  660. }
  661. $url = Request::url ();
  662. $fileName = Math::md5_16 ( $url ) . '.png';
  663. $save_path = $IMG_UPLOAD_PATH . DS . $fileName;
  664. $save_url = $IMG_UPLOAD_URL . DS . $fileName;
  665. if (! file_exists ( $save_path )) {
  666. \QRcode::png ( $url, $save_path, 3, 6 );
  667. }
  668. $this->tpl = 'pc_qrcode';
  669. $this->setOutput ( 'qrcode', $save_url );
  670. $this->setOutput ( 'title', $title );
  671. $this->setOutput('user_agent', $user_agent);
  672. exit ( $this->render () );
  673. }
  674. }
  675. }