public function _getAll() { $res = M('FriendLink')->select(); $links = array('all' => array()); foreach ($res as $link) { if ($link['link_type'] == 2) { if (is_file(FixedUploadedFileUrl($link['link_code']))) { $link['link_code'] = FixedUploadedFileUrl($link['link_code']); } } $links['all'][$link['link_id']] = $link; if (!isset($links[$link['position_id']])) { $links[$link['position_id']] = array(); } $links[$link['position_id']][] = $link['link_id']; } return $links; }
public function show() { $id = intval($_REQUEST['id']); $advS = service('Adv'); $ad_info = $advS->info($id); $ad_pos_info = $advS->position($ad_info['position_id']); $str = ''; header('Content-type: application/x-javascript; charset=' . YF_CHARSET); $url = 'http://' . $_SERVER['HTTP_HOST']; $nowtime = LocalTime::getInstance()->gmtime(); if (!empty($ad_info)) { if ($ad_info['end_time'] < $nowtime || $ad_info['enabled'] == 0) { exit("document.writeln('The adv is timeout');"); } switch ($ad_info['media_type']) { case 101: /* 图片广告 */ $src = strpos($ad_info['ad_code'], 'http://') === false && strpos($ad_info['ad_code'], 'https://') === false ? $url . FixedUploadedFileUrl($ad_info[ad_code]) : $ad_info['ad_code']; $str = '<a href="' . $url . __ROOT__ . '/index.php?m=Adv&a=click&ad_id=' . $ad_info['ad_id'] . '" target="_blank">' . '<img src="' . $src . '" border="0" alt="' . $ad_info['ad_name'] . '" height="' . $ad_pos_info['ad_height'] . '" width="' . $ad_pos_info['ad_width'] . '" /></a>'; break; case 102: /* Falsh广告 */ $src = strpos($ad_info['ad_code'], 'http://') === false && strpos($ad_info['ad_code'], 'https://') === false ? $url . FixedUploadedFileUrl($ad_info[ad_code]) : $ad_info['ad_code']; $str = '<object width="' . $ad_pos_info['ad_width'] . '" height="' . $ad_pos_info['ad_height'] . '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"> <param name="movie" value="' . $src . '"><param name="quality" value="high"><embed width="' . $ad_pos_info['ad_width'] . '" height="' . $ad_pos_info['ad_height'] . '" src="' . $src . '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>'; break; case 103: /* 代码广告 */ $str = $ad_info['ad_code']; break; case 104: /* 文字广告 */ $str = '<a href="' . $url . __ROOT__ . '/index.php?m=Adv&a=click&ad_id=' . $ad_info['ad_id'] . '" target="_blank">' . nl2br(htmlspecialchars(addslashes($ad_info['ad_code']))) . '</a>'; break; } } echo "document.writeln('{$str}');"; }
/** * 删除 * */ public function del() { if ($this->isAjax()) { if (C('TOKEN_ON') && !checkFormToken($_REQUEST)) { die('hack attemp.'); } $link_id = intval($_REQUEST['id']); $flModel = D('FriendLink'); $link = $flModel->info($link_id); if ($flModel->del($link_id)) { if (is_file(FixedUploadedFileUrl($link['link_code']))) { @unlink(FixedUploadedFileUrl($link['link_code'])); } $params = null; B('FriendLinks', $params); $this->ajaxReturn('', buildFormToken(), 1); } else { $this->ajaxReturn('', '', 0); } } }
/** * Smarty count_paragraphs modifier plugin * * Type: modifier<br> * Name: fixed_uploadfile_url<br> * Purpose: fixed the url of uploaded file * @author anqiu xiao * @param string * @return string */ function smarty_modifier_fixed_uploadfile_url($string) { return FixedUploadedFileUrl($string); }
/** * 编辑 * */ public function edit() { $adModel = D('Ad'); $ad_id = intval($_REQUEST['ad_id']); if ($this->isPost()) { if (C('TOKEN_ON') && !checkFormToken($_REQUEST)) { die('hack attemp.'); } if (!$_REQUEST['ad_name'] || !$_REQUEST['start_time'] || !$_REQUEST['end_time']) { die('data invalid.'); } $media_type = intval($_REQUEST['media_type']); $localTimeObj = LocalTime::getInstance(); $start_time = $localTimeObj->local_strtotime($_REQUEST['start_time']); $end_time = $localTimeObj->local_strtotime($_REQUEST['end_time']); $upload_path = get_upload_path(); $file_prefix = 'http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/' . $upload_path; $adModel = D('Ad'); $data = array('ad_name' => $_REQUEST['ad_name'], 'media_type' => $media_type, 'position_id' => intval($_REQUEST['position_id']), 'enabled' => intval($_REQUEST['enabled']), 'start_time' => $start_time, 'end_time' => $end_time); //图片广告 if ($media_type == 101) { if (!$_REQUEST['ad_link'] || !$_REQUEST['img_url'] && (!$_FILES['ad_img'] || $_FILES['ad_img']['size'] == 0 || $_FILES['ad_img']['error'] != 0)) { die('data invalid.'); } $data['ad_link'] = $_REQUEST['ad_link']; if ($_REQUEST['img_url']) { $data['ad_code'] = str_replace($file_prefix, '', $_REQUEST['img_url']); } if ($_FILES['ad_img'] && $_FILES['ad_img']['size'] > 0 && $_FILES['ad_img']['error'] == 0) { $upfile = array(); $upfile = upload_one_file($_FILES['ad_img']); if ($upfile['error']) { $this->error($upfile['error']); } $data['ad_code'] = $upfile['file_name']; } } elseif ($media_type == 102) { if (!$_REQUEST['flash_url'] && (!$_FILES['upfile_flash'] || $_FILES['upfile_flash']['size'] == 0 || $_FILES['upfile_flash']['error'] != 0)) { die('data invalid.'); } if ($_REQUEST['flash_url']) { $data['ad_code'] = str_replace($file_prefix, '', $_REQUEST['flash_url']); } if ($_FILES['upfile_flash'] && $_FILES['upfile_flash']['size'] > 0 && $_FILES['upfile_flash']['error'] == 0) { $upfile = array(); $upfile = upload_one_file($_FILES['upfile_flash']); if ($upfile['error']) { $this->error($upfile['error']); } $data['ad_code'] = $upfile['file_name']; } } elseif ($media_type == 103) { if (!$_REQUEST['ad_code']) { die('data invalid.'); } $data['ad_code'] = htmlentities($_REQUEST['ad_code']); } elseif ($media_type == 104) { if (!$_REQUEST['ad_link2'] || !$_REQUEST['ad_text']) { die('data invalid.'); } $data['ad_link'] = $_REQUEST['ad_link2']; $data['ad_code'] = $_REQUEST['ad_text']; } if ($adModel->editAd($ad_id, $data)) { //更新缓存 $params = array('ad_id' => $ad_id); B('Adv', $params); $this->assign('jumpUrl', '?g=' . GROUP_NAME . '&m=' . MODULE_NAME); $this->success('编辑成功'); } else { $this->error('编辑失败'); } } $localTimeObj = LocalTime::getInstance(); $ad = $adModel->info($ad_id); $ad['start_time'] = $localTimeObj->local_date($this->_CFG['time_format'], $ad['start_time']); $ad['end_time'] = $localTimeObj->local_date($this->_CFG['time_format'], $ad['end_time']); $upload_path = get_upload_path(); if (is_file(DOC_ROOT_PATH . $upload_path . $ad['ad_code'])) { //$upload_path = str_replace('./','/',$upload_path); $ad['ad_code'] = 'http://' . $_SERVER['HTTP_HOST'] . FixedUploadedFileUrl($ad['ad_code']); } $this->assign('ad', $ad); $apModel = D('AdPosition'); $res = $apModel->getPositions(); $positions = array(); foreach ($res as $rs) { $position = $apModel->info($rs['position_id']); $positions[] = $position; } $this->assign('positions', $positions); $this->assign('ad_media_type_conf', $this->_ad_media_type_conf); $this->assign('ur_href', '广告管理 > 编辑广告'); $this->assign('_hash_', buildFormToken()); $this->display('post'); }
/** * 领取优惠券 * */ public function pull() { if ($this->isAjax()) { $this->_check_login(); $localTimeObj = LocalTime::getInstance(); $nowtime = $localTimeObj->gmtime(); $today = $localTimeObj->local_strtotime(date('Y-m-d 23:59:59')); $cccModel = D('CouponCodeCodes'); $ip = get_client_ip(); //同一IP领取数量限制 $begin_time = $localTimeObj->local_strtotime(date('Y-m-d 00:00:00')); if ($this->_CFG['ip_fetch_limit'] && $cccModel->where("fetch_time>='{$begin_time}' AND fetch_time<='{$today}' AND ip='{$ip}'")->count() >= intval($this->_CFG['ip_fetch_limit'])) { $this->ajaxReturn('', '您今天领取的优惠券数量已超过限制,请明天再来', 0); } $c_id = intval($_REQUEST['c_id']); $c_id or die('id invalid.'); $ccModel = D('CouponCode'); $detail = $ccModel->info($c_id); $detail or die('id invalid.'); if ($detail['is_active'] == 0) { $this->ajaxReturn('', '该优惠券已下架,请选择商家其他的优惠券', 0); } //是否过期 if ($detail['expiry_type'] == 1 && $detail['expiry'] < $today) { $this->ajaxReturn('', '该优惠券已过期,请选择商家其他的优惠券', 0); } //剩余数量 if ($detail['fetched_amount'] >= $detail['amount']) { $this->ajaxReturn('', '该优惠券已发放完毕,请选择其他的优惠券', 0); } //领取帐号限制 if ($detail['data']['fetch_account_limit'] != 200 && intval($_SESSION['login_type']) != $detail['data']['fetch_account_limit']) { $fetch_account_limit_conf = CouponCodeConf::fetch_account_limit_conf(); $this->ajaxReturn('', $fetch_account_limit_conf[$detail['data']['fetch_account_limit']], 0); } //领取数量限制 //每个账户一张 if ($detail['data']['fetch_limit'] == 101) { if ($cccModel->getOneByUid($this->_user['user_id'], $c_id)) { $this->ajaxReturn('', '您已领取过该优惠券,请选择其他的优惠券', 0); } } else { if ($detail['data']['fetch_limit'] == 102) { $b_time = $localTimeObj->local_strtotime(date('Y-m-d 00:00:00')); $e_time = $today; $params = array('b_time' => $b_time, 'e_time' => $e_time); if ($cccModel->getOneByUid($this->_user['user_id'], $c_id, $params)) { $this->ajaxReturn('', '您今天已领取过该优惠券,请选择其他的优惠券', 0); } } } //付费情况 if ($detail['price_type'] != 1) { $userModel = D('User'); $user = $userModel->info($this->_user['user_id'], array('money', 'credit')); //付费 if ($detail['price_type'] == 2) { if ($user['money'] < $detail['price']) { $this->ajaxReturn('', '您的账户金额不足,请先到帐号中心充值再来购买。请点击<a href="' . reUrl('Payment/pay') . '" target="_blank">在线充值</a>', 0); } $spend = Consume::spend($this->_user['user_id'], $detail['price'], Consume::TYPE_MONEY); } else { if ($detail['price_type'] == 3) { if ($user['credit'] < $detail['price']) { $this->ajaxReturn('', '您的账户积分不足,请选择其他的优惠券', 0); } $spend = Consume::spend($this->_user['user_id'], $detail['price'], Consume::TYPE_CREDIT); } } if ($spend !== 1) { $this->ajaxReturn('', '支付失败,请重试', 0); } } $code = $cccModel->pull($c_id, $this->_user['user_id'], $this->_user['nick'], $nowtime, $ip); if ($code) { //更新领取数量 $ccModel->update($c_id, array('fetched_amount' => $detail['fetched_amount'] + 1)); //更新昨日、今日、本周、本月等领取数量 $yestoday = $nowtime - 24 * 3600; $ccdModel = D('CouponCodeData'); $r = $ccdModel->info($c_id, array('yesterdayfetched', 'dayfetched', 'weekfetched', 'monthfetched', 'updatetime')); $yesterdayfetched = date('Ymd', $r['updatetime']) == date('Ymd', $yestoday) ? $r['dayfetched'] : $r['yesterdayfetched']; $dayfetched = date('Ymd', $r['updatetime']) == date('Ymd', $nowtime) ? $r['dayfetched'] + 1 : 1; $weekfetched = date('YW', $r['updatetime']) == date('YW', $nowtime) ? $r['weekfetched'] + 1 : 1; $monthfetched = date('Ym', $r['updatetime']) == date('Ym', $nowtime) ? $r['monthfetched'] + 1 : 1; $data = array('yesterdayfetched' => $yesterdayfetched, 'dayfetched' => $dayfetched, 'weekfetched' => $weekfetched, 'monthfetched' => $monthfetched, 'updatetime' => $nowtime); $ccdModel->update($c_id, $data); //发表一条微博 if ($this->_CFG['sina_wb_open'] && $_SESSION['sina']['token']['access_token'] || $this->_CFG['qq_open'] && $_SESSION['qq']["access_token"]) { $ccmService = service('CouponCodeMall'); $mall = $ccmService->info($detail['m_id']); $title = ''; if ($detail['title']) { $title .= $detail['title']; } else { $title .= $mall['name']; if ($detail['c_type'] == 1) { $title .= '满' . $detail['money_max'] . '减' . $detail['money_reduce'] . '元优惠券'; } else { $title .= $detail['money_amount'] . '元代金券'; } } $url = 'http://' . $_SERVER['HTTP_HOST'] . reUrl('Code/view?id=' . $c_id); $pic_path = 'http://' . $_SERVER['HTTP_HOST'] . FixedUploadedFileUrl($mall['figure_image']); $text = '我刚刚在#' . $this->_CFG['site_name'] . '#领取了一张【' . $title . '】,数量有限,抢完为止,一般人我不告诉!' . $url; if ($this->_CFG['sina_wb_open'] && $_SESSION['sina']['token']['access_token']) { include_once DOC_ROOT_PATH . 'Addons/plugins/login/sina.class.php'; $sina = new sina(); $sina->upload($text, $pic_path); } else { if ($this->_CFG['qq_open'] && $_SESSION['qq']["access_token"]) { include_once DOC_ROOT_PATH . 'Addons/plugins/login/qq.class.php'; $qq = new qq(); //发送微博 $qq->add_t($text); //发送空间分享 $title = '我刚刚在' . $this->_CFG['site_name'] . '领取了一张【' . $title . '】,数量有限,抢完为止,一般人我不告诉!'; $site = $_SERVER['HTTP_HOST']; $qq->add_share($title, $url, $site, $pic_path); } } } $this->ajaxReturn($code, '领取成功', 1); } else { $this->ajaxReturn('', '领取失败', 0); } } }