EventsController.class.php 18 KB

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