EventsController.class.php 20 KB

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