EventsController.class.php 18 KB

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