EventsController.class.php 18 KB

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