Esempio n. 1
0
 function update()
 {
     $this->load->helper('html2text');
     $id = $this->input->post('id');
     $subject = $this->input->post('subject');
     $htmlbody = $this->input->post('htmlbody');
     $textbody = html_to_plaintext($htmlbody);
     $attachments = $this->input->post('attachment');
     $db = new DbConn();
     if (!$id) {
         // New template
         $db->exec('insert into mail_templates () values ()');
         $id = $db->last_insert_id();
     }
     $rows = $db->exec('insert into mail_template_versions (templateid, subject, html, plaintext, datecreated, creator)
                    values (?, ?, ?, ?, ?, ?)', (int) $id, $subject, $htmlbody, $textbody, date_create(), $this->admin->id());
     if ($rows != 1) {
         throw new RuntimeException("Insertion failed!");
     }
     $newId = $db->last_insert_id();
     // process attachments
     if ($attachments) {
         foreach ($attachments as $attachId) {
             $attachId = (int) $attachId;
             $db->exec('insert into templatevers_to_attachments (templateverid, attachmentid) values (?, ?)', $newId, $attachId);
         }
     }
     $template = get_mail_template($id);
     $role = $template ? $template->role : '(unknown)';
     log_event(LOG_MAIL_TEMPLATE_EDITED, NULL, $role);
     redirect("admin/emails/index/{$id}");
 }
Esempio n. 2
0
/**
 * @param  $user_id
 * @param  $mail_id
 * @param DateTime $when The approximate date/time the e-mail should be sent
 * @param bool $allow_duplicates If false, won't schedule this e-mail if it has already been sent
 *    in the past, or if it's currently scheduled to be sent. If true, will schedule the e-mail
 *    no matter what. If NULL (or omitted) then the mail template's preferred setting will be used
 * @return void
 */
function schedule_mail($user_id, $mail_id, $when = FALSE, $allow_duplicates = NULL)
{
    $db = new DbConn();
    $template = get_mail_template($mail_id, TRUE);
    if ($allow_duplicates === FALSE || is_null($allow_duplicates) && !$template->allowdupes) {
        $results = $db->query('select *
                           from mails_sent as ms, mail_template_versions as mtv
                           where ms.templateverid = mtv.id
                             and mtv.templateid = ?
                             and userid = ?', $mail_id, $user_id);
        if ($results->length > 0) {
            return FALSE;
        }
        $results = $db->query('select * from mails_scheduled where userid = ? and mailid = ?', $user_id, $mail_id);
        if ($results->length > 0) {
            return FALSE;
        }
    }
    if (!$when) {
        send_user_mail($template, $user_id);
        return TRUE;
    } else {
        $db->exec('insert into mails_scheduled (userid, mailid, due) values (?, ?, ?)', $user_id, $mail_id, $when);
        return TRUE;
    }
}
Esempio n. 3
0
/**
* useful templating functions from an older project of mine, hacked for Moodle
* @param template the template's file name from $CFG->sitedir
* @param infomap a hash containing pairs of parm => data to replace in template
* @return a fully resolved template where all data has been injected
*/
function compile_mail_template($template, $infomap, $module = 'tracker')
{
    $notification = implode('', get_mail_template($template, $module));
    foreach ($infomap as $aKey => $aValue) {
        $notification = str_replace("<%%{$aKey}%%>", $aValue, $notification);
    }
    return $notification;
}
Esempio n. 4
0
/**
 * 发送邮箱验证所需的验证码
 */
function action_send_email_code()
{
    $_LANG = $GLOBALS['_LANG'];
    $_CFG = $GLOBALS['_CFG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    require_once ROOT_PATH . 'includes/lib_validate_record.php';
    $email = trim($_SESSION[VT_EMAIL_VALIDATE]);
    if (empty($email)) {
        exit("邮箱不能为空");
        return;
    } else {
        if (!is_email($email)) {
            exit("邮箱格式不正确");
            return;
        } else {
            if (check_validate_record_exist($email)) {
                $record = get_validate_record($email);
                /**
                 * 检查是过了限制发送邮件的时间
                 */
                if (time() - $record['last_send_time'] < 60) {
                    echo "每60秒内只能发送一次注册邮箱验证码,请稍候重试";
                    return;
                }
            }
        }
    }
    require_once ROOT_PATH . 'includes/lib_passport.php';
    /* 设置验证邮件模板所需要的内容信息 */
    $template = get_mail_template('email_validate');
    // 生成邮箱验证码
    $email_code = rand_number(6);
    $GLOBALS['smarty']->assign('email_code', $email_code);
    $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
    $GLOBALS['smarty']->assign('send_date', date($GLOBALS['_CFG']['date_format']));
    $content = $GLOBALS['smarty']->fetch('str:' . $template['template_content']);
    /* 发送激活验证邮件 */
    $result = send_mail($email, $email, $template['template_subject'], $content, $template['is_html']);
    if ($result) {
        // 保存验证码到Session中
        $_SESSION[VT_EMAIL_VALIDATE] = $email;
        // 保存验证记录
        save_validate_record($email, $email_code, VT_EMAIL_VALIDATE, time(), time() + 30 * 60);
        echo 'ok';
    } else {
        echo '邮箱验证码发送失败';
    }
}
Esempio n. 5
0
 function index()
 {
     $this->load->helper('mail');
     $db = new DbConn();
     $mails = $db->query('select * from mails_scheduled where due <= NOW()');
     while ($mail = $mails->next()) {
         $user_id = $mail->userid;
         $mail_id = $mail->mailid;
         $template = get_mail_template($mail_id, false);
         if (!$template) {
             continue;
         }
         send_user_mail($template, $user_id);
         $db->exec('delete from mails_scheduled where id = ?', $mail->id);
     }
 }
Esempio n. 6
0
function action_act_update_email()
{
    // 获取全局变量
    $user = $GLOBALS['user'];
    $_CFG = $GLOBALS['_CFG'];
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    $user_id = $_SESSION['user_id'];
    include_once ROOT_PATH . 'includes/lib_passport.php';
    if (empty($_POST['v_captcha'])) {
        show_message('验证码不能为空!', '返回', 'user.php?act=update_email', 'error');
    }
    /* 检查验证码 */
    include_once 'includes/cls_captcha.php';
    $validator = new captcha();
    $validator->session_word = 'captcha_login';
    if (!$validator->check_word($_POST['v_captcha'])) {
        show_message($_LANG['invalid_captcha'], '返回', 'user.php?act=update_email', 'error');
    } else {
        $sql = "select email,user_name from " . $GLOBALS['ecs']->table('users') . " where user_id = '" . $_SESSION['user_id'] . "'";
        $rows = $GLOBALS['db']->getRow($sql);
        $tpl = get_mail_template('verify_mail');
        $run = "0123456789abcdefghijklmnopqrstuvwxyz";
        $hash = mc_random(16, $run);
        $email = $GLOBALS['ecs']->url() . 'user.php?act=valid_email&hash=' . $hash;
        $smarty->assign('shop_name', $_CFG['shop_name']);
        $smarty->assign('send_date', date($_CFG['time_format']));
        $smarty->assign('user_name', $rows['user_name']);
        $smarty->assign('email', $email);
        $smarty->assign('v_email', $rows['email']);
        $content = $smarty->fetch('str:' . $tpl['template_content']);
        $result = send_mail($_CFG['shop_name'], $rows['email'], $tpl['template_subject'], $content, $tpl['is_html']);
        if ($result == true) {
            $add_time = time();
            $sql = "insert into " . $GLOBALS['ecs']->table('email') . "(`email`,`hash`,`add_time`,`user_id`) values('" . $rows['email'] . "','{$hash}','{$add_time}','" . $_SESSION['user_id'] . "')";
            $GLOBALS['db']->query($sql);
            $smarty->display('user_transaction.dwt');
        } else {
            show_message('邮件发送失败!');
        }
    }
}
Esempio n. 7
0
/**
 * 发红包:发货时发红包
 * @param   int     $order_id   订单号
 * @return  bool
 */
function send_order_bonus($order_id)
{
    /* 取得订单应该发放的红包 */
    $bonus_list = order_bonus($order_id);
    /* 如果有红包,统计并发送 */
    if ($bonus_list) {
        /* 用户信息 */
        $sql = "SELECT u.user_id, u.user_name, u.email " . "FROM " . $GLOBALS['ecs']->table('order_info') . " AS o, " . $GLOBALS['ecs']->table('users') . " AS u " . "WHERE o.order_id = '{$order_id}' " . "AND o.user_id = u.user_id ";
        $user = $GLOBALS['db']->getRow($sql);
        /* 统计 */
        $count = 0;
        $money = '';
        foreach ($bonus_list as $bonus) {
            $count += $bonus['number'];
            $money .= price_format($bonus['type_money']) . ' [' . $bonus['number'] . '], ';
            /* 修改用户红包 */
            $sql = "INSERT INTO " . $GLOBALS['ecs']->table('user_bonus') . " (bonus_type_id, user_id) " . "VALUES('{$bonus['type_id']}', '{$user['user_id']}')";
            for ($i = 0; $i < $bonus['number']; $i++) {
                if (!$GLOBALS['db']->query($sql)) {
                    return $GLOBALS['db']->errorMsg();
                }
            }
        }
        /* 如果有红包,发送邮件 */
        if ($count > 0) {
            $tpl = get_mail_template('send_bonus');
            $GLOBALS['smarty']->assign('user_name', $user['user_name']);
            $GLOBALS['smarty']->assign('count', $count);
            $GLOBALS['smarty']->assign('money', $money);
            $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
            $GLOBALS['smarty']->assign('send_date', local_date($GLOBALS['_CFG']['date_format']));
            $GLOBALS['smarty']->assign('sent_date', local_date($GLOBALS['_CFG']['date_format']));
            $content = $GLOBALS['smarty']->fetch('str:' . $tpl['template_content']);
            send_mail($user['user_name'], $user['email'], $tpl['template_subject'], $content, $tpl['is_html']);
        }
    }
    return true;
}
Esempio n. 8
0
<?php

require_once 'common.inc';
$id = $_REQUEST["id"];
if ($id) {
    $id = (int) $id;
    $mail_template = get_mail_template($id, true);
}
$verb = $mail_template ? "Edit" : "Create New";
vt_header("{$verb} E-mail");
vt_require_yui();
?>
<script type="text/javascript" src="../../javascripts/ckeditor/ckeditor_basic.js"></script>
<script type="text/javascript" src="compose.js"></script>
<style type="text/css">
#subject {
   width: 100%;
}
</style>

<form name="email" method="POST" action="update.php">

<?php 
if ($mail_template) {
    ?>
<input type="hidden" name="id" value="<?php 
    echo (int) $id;
    ?>
" />
<?php 
}
Esempio n. 9
0
     /* 修改团购活动状态为失败,记录失败原因(活动说明) */
     $sql = "UPDATE " . $ecs->table('goods_activity') . " SET is_finished = '" . GBS_FAIL . "', " . "act_desc = '{$_POST['act_desc']}' " . "WHERE act_id = '{$group_buy_id}' LIMIT 1";
     $db->query($sql);
     /* 清除缓存 */
     clear_cache_files();
     /* 提示信息 */
     $links = array(array('href' => 'group_buy.php?act=list', 'text' => $_LANG['back_list']));
     sys_msg($_LANG['edit_success'], 0, $links);
 } elseif (isset($_POST['mail'])) {
     /* 发送通知邮件 */
     /* 判断订单状态 */
     if ($group_buy['status'] != GBS_SUCCEED) {
         sys_msg($_LANG['error_status'], 1);
     }
     /* 取得邮件模板 */
     $tpl = get_mail_template('group_buy');
     /* 初始化订单数和成功发送邮件数 */
     $count = 0;
     $send_count = 0;
     /* 取得有效订单 */
     $sql = "SELECT o.consignee, o.add_time, g.goods_number, o.order_sn, " . "o.order_amount, o.order_id, o.email " . "FROM " . $ecs->table('order_info') . " AS o, " . $ecs->table('order_goods') . " AS g " . "WHERE o.order_id = g.order_id " . "AND o.extension_code = 'group_buy' " . "AND o.extension_id = '{$group_buy_id}' " . "AND o.order_status = '" . OS_CONFIRMED . "'";
     $res = $db->query($sql);
     while ($order = $db->fetchRow($res)) {
         /* 邮件模板赋值 */
         $smarty->assign('consignee', $order['consignee']);
         $smarty->assign('add_time', local_date($_CFG['time_format'], $order['add_time']));
         $smarty->assign('goods_name', $group_buy['goods_name']);
         $smarty->assign('goods_number', $order['goods_number']);
         $smarty->assign('order_sn', $order['order_sn']);
         $smarty->assign('order_amount', price_format($order['order_amount']));
         $smarty->assign('shop_url', $ecs->url() . 'user.php?act=order_detail&order_id=' . $order['order_id']);
/**
 *  发送激活验证邮件
 *
 * @access  public
 * @param   int     $user_id        用户ID
 *
 * @return boolen
 */
function send_regiter_hash($user_id)
{
    /* 设置验证邮件模板所需要的内容信息 */
    $template = get_mail_template('register_validate');
    $hash = register_hash('encode', $user_id);
    $validate_email = $GLOBALS['ecs']->url() . 'user.php?act=validate_email&hash=' . $hash;
    $sql = "SELECT user_name, email FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '{$user_id}'";
    $row = $GLOBALS['db']->getRow($sql);
    $GLOBALS['smarty']->assign('user_name', $row['user_name']);
    $GLOBALS['smarty']->assign('validate_email', $validate_email);
    $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
    $GLOBALS['smarty']->assign('send_date', date($GLOBALS['_CFG']['date_format']));
    $content = $GLOBALS['smarty']->fetch('str:' . $template['template_content']);
    /* 发送激活验证邮件 */
    if (send_mail($row['user_name'], $row['email'], $template['template_subject'], $content, $template['is_html'])) {
        return true;
    } else {
        return false;
    }
}
Esempio n. 11
0
 if (!empty($_POST['action']) && $_POST['action'] == 'get_pwd') {
     $admin_username = !empty($_POST['user_name']) ? trim($_POST['user_name']) : '';
     $admin_email = !empty($_POST['email']) ? trim($_POST['email']) : '';
     if (empty($admin_username) || empty($admin_email)) {
         ecs_header("Location: privilege.php?act=login\n");
         exit;
     }
     /* 管理员用户名和邮件地址是否匹配,并取得原密码 */
     $sql = 'SELECT user_id, password FROM ' . $ecs->table('admin_user') . " WHERE user_name = '{$admin_username}' AND email = '{$admin_email}'";
     $admin_info = $db->getRow($sql);
     if (!empty($admin_info)) {
         /* 生成验证的code */
         $admin_id = $admin_info['user_id'];
         $code = md5($admin_id . $admin_info['password']);
         /* 设置重置邮件模板所需要的内容信息 */
         $template = get_mail_template('send_password');
         $reset_email = $ecs->url() . ADMIN_PATH . '/get_password.php?act=reset_pwd&uid=' . $admin_id . '&code=' . $code;
         $smarty->assign('user_name', $admin_username);
         $smarty->assign('reset_email', $reset_email);
         $smarty->assign('shop_name', $_CFG['shop_name']);
         $smarty->assign('send_date', local_date($_CFG['date_format']));
         $smarty->assign('sent_date', local_date($_CFG['date_format']));
         $content = $smarty->fetch('str:' . $template['template_content']);
         /* 发送确认重置密码的确认邮件 */
         if (send_mail($admin_username, $admin_email, $template['template_subject'], $content, $template['is_html'])) {
             //提示信息
             $link[0]['text'] = $_LANG['back'];
             $link[0]['href'] = 'privilege.php?act=login';
             sys_msg($_LANG['send_success'] . $admin_email, 0, $link);
         } else {
             sys_msg($_LANG['send_mail_error'], 1);
function set_user_on_env_nbm(&$nbm_user, $is_action_send)
{
    global $user, $lang, $lang_info, $env_nbm;
    $user = build_user($nbm_user['user_id'], true);
    switch_lang_to($user['language']);
    if ($is_action_send) {
        $env_nbm['mail_template'] = get_mail_template($env_nbm['email_format']);
        $env_nbm['mail_template']->set_filename('notification_by_mail', 'notification_by_mail.tpl');
    }
}
Esempio n. 13
0
	public function done () {
		global $ecs,$db,$_CFG;
		include_once(RPC_ROOT.'includes/lib_clips_ec.php');
	    include_once(RPC_ROOT.'includes/lib_payment.php');
	
	    /* 取得购物类型 */
	    $flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
	
	    /* 检查购物车中是否有商品 */
	    $sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') ." WHERE session_id = '" . SESS_ID . "' " .
	           "AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'";
	    
		if ($db->getOne($sql) == 0)
	    {
			$msg = rpcLang('flow.php', 'no_goods_in_cart');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    /* 检查商品库存,如果使用库存,且下订单时减库存,则减少库存 */
	    if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
	    {
	        $cart_goods_stock = get_cart_goods();       
	        $_cart_goods_stock = array();        
	        foreach ($cart_goods_stock['goods_list'] as $value)
	        {
	            $_cart_goods_stock[$value['rec_id']] = $value['goods_number'];
	        }       
	        zy_flow_cart_stock($_cart_goods_stock);        
	        unset($cart_goods_stock, $_cart_goods_stock);
	    }
	
	    /*
	     * 检查用户是否已经登录
	     * 如果用户已经登录了则检查是否有默认的收货地址
	     * 如果没有登录则跳转到登录和注册页面
	     */
	    if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0)
	    {
	        /* 用户没有登录且没有选定匿名购物,转向到登录页面 */
	        $msg = rpcLang('user.php', 'nologin');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    $consignee = get_consignee($_SESSION['user_id']);
	
	    /* 检查收货人信息是否完整 */
	    if (!check_consignee_info($consignee, $flow_type))
	    {
	        $msg = rpcLang('flow.php', 'user_address_not_full');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	
	    $_GET['how_oos']	  = isset($_GET['how_oos']) ? intval($_GET['how_oos']) : 0;
	    $_GET['card_message'] = isset($_GET['card_message']) ? htmlspecialchars($_GET['card_message']) : '';
	    $_GET['inv_type']     = !empty($_GET['inv_type']) ? htmlspecialchars($_GET['inv_type']) : '';
	    $_GET['inv_payee']    = isset($_GET['inv_payee']) ? htmlspecialchars($_GET['inv_payee']) : '';
	    $_GET['inv_content']  = isset($_GET['inv_content']) ? htmlspecialchars($_GET['inv_content']) : '';
	    $_GET['postscript']   = isset($_GET['postscript']) ? htmlspecialchars($_GET['postscript']) : '';
	
	    $referer = empty($_GET['referer']) ? 'Android':trim($_GET['referer']);
	    $order = array(
	        //'shipping_id'     => intval($_POST['shipping']),
	    	'shipping_id'     => intval($_GET['shipping']),//快递id
	        'pay_id'          => intval($_GET['payment']),//支付方式id
	        'pack_id'         => isset($_GET['pack']) ? intval($_GET['pack']) : 0,//包装
	        'card_id'         => isset($_GET['card']) ? intval($_GET['card']) : 0,//贺卡
	        'card_message'    => trim($_GET['card_message']),
	        'surplus'         => isset($_POST['surplus']) ? floatval($_POST['surplus']) : 0.00,
	        'integral'        => isset($_POST['integral']) ? intval($_POST['integral']) : 0,
	        'bonus_id'        => isset($_GET['bonus']) ? intval($_GET['bonus']) : 0,
	        'need_inv'        => empty($_POST['need_inv']) ? 0 : 1,
	        'postscript'      => trim($_POST['postscript']),
	        'how_oos'         => isset($_LANG['oos'][$_POST['how_oos']]) ? addslashes($_LANG['oos'][$_POST['how_oos']]) : '',
	        'need_insure'     => isset($_POST['need_insure']) ? intval($_POST['need_insure']) : 0,
	        'user_id'         => $_SESSION['user_id'],
	        'add_time'        => gmtime(),
	        'order_status'    => OS_UNCONFIRMED,
	        'shipping_status' => SS_UNSHIPPED,
	        'pay_status'      => PS_UNPAYED,
	        'agency_id'       => get_agency_by_regions(array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']))
	        );
		if(EC_CHARSET == 'utf-8'){
			$order['inv_type'] = gbktoutf8($_GET['inv_type']);
			$order['inv_payee'] = gbktoutf8(trim($_GET['inv_payee']));
			$order['inv_content'] = gbktoutf8($_GET['inv_content']);
		}else{
			$order['inv_type'] = utf8togbk($_GET['inv_type']);
			$order['inv_payee'] = utf8togbk(trim($_GET['inv_payee']));
			$order['inv_content'] = utf8togbk($_GET['inv_content']);
		}
	
	    /* 扩展信息 */
	    if (isset($_SESSION['flow_type']) && intval($_SESSION['flow_type']) != CART_GENERAL_GOODS)
	    {
	        $order['extension_code'] = $_SESSION['extension_code'];
	        $order['extension_id'] = $_SESSION['extension_id'];
	    }
	    else
	    {
	        $order['extension_code'] = '';
	        $order['extension_id'] = 0;
	    }
	    $user_id = $_SESSION['user_id'];
		/*
	    #检查积分余额是否合法
	    $user_id = $_SESSION['user_id'];
	    if ($user_id > 0)
	    {
	        $user_info = user_info($user_id);
	
	        $order['surplus'] = min($order['surplus'], $user_info['user_money'] + $user_info['credit_line']);
	        if ($order['surplus'] < 0)
	        {
	            $order['surplus'] = 0;
	        }
	
	        // 查询用户有多少积分
	        $flow_points = flow_available_points();  // 该订单允许使用的积分
	        $user_points = $user_info['pay_points']; // 用户的积分总数
	
	        $order['integral'] = min($order['integral'], $user_points, $flow_points);
	        if ($order['integral'] < 0)
	        {
	            $order['integral'] = 0;
	        }
	    }
	    else
	    {
	        $order['surplus']  = 0;
	        $order['integral'] = 0;
	    }*/
	
	    #检查红包是否存在
	    if ($order['bonus_id'] > 0)
	    {
	        $bonus = bonus_info($order['bonus_id']);
	
	        if (empty($bonus) || $bonus['user_id'] != $user_id || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type))
	        {
	            $order['bonus_id'] = 0;
	        }
	        
	    }
	    elseif (isset($_POST['bonus_sn']))
	    {
	        $bonus_sn = trim($_POST['bonus_sn']);
	        $bonus = bonus_info(0, $bonus_sn);
	        $now = gmtime();
	        if (empty($bonus) || $bonus['user_id'] > 0 || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type) || $now > $bonus['use_end_date'])
	        {
	        }
	        else
	        {
	            if ($user_id > 0)
	            {
	                $sql = "UPDATE " . $ecs->table('user_bonus') . " SET user_id = '$user_id' WHERE bonus_id = '$bonus[bonus_id]' LIMIT 1";
	                $db->query($sql);
	            }
	            $order['bonus_id'] = $bonus['bonus_id'];
	            $order['bonus_sn'] = $bonus_sn;
	        }
	    }
		
	
	    /* 订单中的商品 */
	    $cart_goods = cart_goods($flow_type);
	
	    if (empty($cart_goods))
	    {
	        $msg = rpcLang('flow.php', 'no_goods_in_cart');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    /* 检查商品总额是否达到最低限购金额 */
	    if ($flow_type == CART_GENERAL_GOODS && cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount'])
	    {
			$msg = rpcLang('flow.php', 'goods_amount_not_enough');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    /* 收货人信息 */
	    foreach ($consignee as $key => $value)
	    {
	        $order[$key] = addslashes($value);
	    }
	
	    /* 订单中的总额 */
	    $total = order_fee($order, $cart_goods, $consignee);
	
	    $order['bonus']        = $total['bonus'];
	    $order['goods_amount'] = $total['goods_price'];
	    $order['discount']     = $total['discount'];
	    $order['surplus']      = $total['surplus'];
	    $order['tax']          = $total['tax'];
	    #购物车中的商品能享受红包支付的总额
	    $discount_amout = compute_discount_amount();
		#红包和积分最多能支付的金额为商品总额
	    $temp_amout = $order['goods_amount'] - $discount_amout;
		if ($temp_amout <= 0)
	    {
	        $order['bonus_id'] = 0;
	    }
	
	    /* 配送方式 */
	    if ($order['shipping_id'] > 0)
	    {
	        $shipping = shipping_info($order['shipping_id']);
	        $order['shipping_name'] = addslashes($shipping['shipping_name']);
	    }
	    $order['shipping_fee'] = $total['shipping_fee'];
	    $order['insure_fee']   = $total['shipping_insure'];
	
	    /* 支付方式 */
	    if ($order['pay_id'] > 0)
	    {
	        $payment = payment_info($order['pay_id']);
	        $order['pay_name'] = addslashes($payment['pay_name']);
	    }
	    $order['pay_fee'] = $total['pay_fee'];
	    $order['cod_fee'] = $total['cod_fee'];
	
	    /* 商品包装 */
	    if ($order['pack_id'] > 0)
	    {
	        $pack               = pack_info($order['pack_id']);
	        $order['pack_name'] = addslashes($pack['pack_name']);
	    }
	    $order['pack_fee'] = $total['pack_fee'];
	
	
	    /* 祝福贺卡 */
	    if ($order['card_id'] > 0)
	    {
	        $card               = card_info($order['card_id']);
	        $order['card_name'] = addslashes($card['card_name']);
	    }
	    $order['card_fee']      = $total['card_fee'];
	
	    $order['order_amount']  = number_format($total['amount'], 2, '.', '');
	
	    /* 如果全部使用余额支付,检查余额是否足够 */
	    if ($payment['pay_code'] == 'balance' && $order['order_amount'] > 0)
	    {
	        if($order['surplus'] >0) //余额支付里如果输入了一个金额
	        {
	            $order['order_amount'] = $order['order_amount'] + $order['surplus'];
	            $order['surplus'] = 0;
	        }
	        if ($order['order_amount'] > ($user_info['user_money'] + $user_info['credit_line']))
	        {
	            show_message($_LANG['balance_not_enough']);
	        }
	        else
	        {
	            $order['surplus'] = $order['order_amount'];
	            $order['order_amount'] = 0;
	        }
	    }
	
	    /* 如果订单金额为0(使用余额或积分或红包支付),修改订单状态为已确认、已付款 */
	    if ($order['order_amount'] <= 0)
	    {
	        $order['order_status'] = OS_CONFIRMED;
	        $order['confirm_time'] = gmtime();
	        $order['pay_status']   = PS_PAYED;
	        $order['pay_time']     = gmtime();
	        $order['order_amount'] = 0;
	    }
	
	    $order['integral_money']   = $total['integral_money'];
	    $order['integral']         = $total['integral'];
	
	    if ($order['extension_code'] == 'exchange_goods')
	    {
	        $order['integral_money']   = 0;
	        $order['integral']         = $total['exchange_integral'];
	    }
	
	    $order['from_ad']          = !empty($_SESSION['from_ad']) ? $_SESSION['from_ad'] : '0';
	    $order['referer']          = !empty($_SESSION['referer']) ? addslashes($_SESSION['referer']) : '';
	
	    /* 记录扩展信息 */
	    if ($flow_type != CART_GENERAL_GOODS)
	    {
	        $order['extension_code'] = $_SESSION['extension_code'];
	        $order['extension_id'] = $_SESSION['extension_id'];
	    }
	
	    $affiliate = unserialize($_CFG['affiliate']);
	    if(isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 1)
	    {
	        //推荐订单分成
	        $parent_id = get_affiliate();
	        if($user_id == $parent_id)
	        {
	            $parent_id = 0;
	        }
	    }
	    elseif(isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 0)
	    {
	        //推荐注册分成
	        $parent_id = 0;
	    }
	    else
	    {
	        //分成功能关闭
	        $parent_id = 0;
	    }
	    $order['parent_id'] = $parent_id;
	
	    /* 插入订单表 */
	    $error_no = 0;
	    do
	    {
	        $order['order_sn'] = get_order_sn(); //获取新订单号
			
	        $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT');
	
	        $error_no = $GLOBALS['db']->errno();
	
	        if ($error_no > 0 && $error_no != 1062)
	        {
	            die($GLOBALS['db']->errorMsg());
	        }
	    }
	    while ($error_no == 1062); //如果是订单号重复则重新提交数据
	
	    $new_order_id = $db->insert_id();
	    $order['order_id'] = $new_order_id;
	
	    /* 插入订单商品 */
	    $sql = "INSERT INTO " . $ecs->table('order_goods') . "( " .
	                "order_id, goods_id, goods_name, goods_sn, goods_number, market_price, ".
	                "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) ".
	            " SELECT '$new_order_id', goods_id, goods_name, goods_sn, goods_number, market_price, ".
	                "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id".
	            " FROM " .$ecs->table('cart') .
	            " WHERE session_id = '".SESS_ID."' AND rec_type = '$flow_type'";
	    $db->query($sql);
	    /* 修改拍卖活动状态 */
	    if ($order['extension_code']=='auction')
	    {
	        $sql = "UPDATE ". $ecs->table('goods_activity') ." SET is_finished='2' WHERE act_id=".$order['extension_id'];
	        $db->query($sql);
	    }
	
	    /* 处理余额、积分、红包 */
	    if ($order['user_id'] > 0 && $order['surplus'] > 0)
	    {
	        log_account_change($order['user_id'], $order['surplus'] * (-1), 0, 0, 0, sprintf($_LANG['pay_order'], $order['order_sn']));
	    }
	    if ($order['user_id'] > 0 && $order['integral'] > 0)
	    {
	        log_account_change($order['user_id'], 0, 0, 0, $order['integral'] * (-1), sprintf($_LANG['pay_order'], $order['order_sn']));
	    }
	
	    if ($order['bonus_id'] > 0 && $temp_amout > 0)
	    {
	        use_bonus($order['bonus_id'], $new_order_id);
	    }
	
	    /* 如果使用库存,且下订单时减库存,则减少库存 */
	    if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
	    {
	        //change_order_goods_storage($order['order_id'], true, SDT_PLACE);
	    }
	error_log('1',3,'flow.log');
	    /* 给商家发邮件 */
	    /* 增加是否给客服发送邮件选项 */
	    if ($_CFG['send_service_email'] && $_CFG['service_email'] != '')
	    {
	    	error_log('2',3,'flow.log');
	        $tpl = get_mail_template('remind_of_new_order');
			/*
			$smarty->assign('order', $order);
	        $smarty->assign('goods_list', $cart_goods);
	        $smarty->assign('shop_name', $_CFG['shop_name']);
	        $smarty->assign('send_date', date($_CFG['time_format']));
	        $content = $smarty->fetch('str:' . $tpl['template_content']);
	        */
			send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl['template_subject'], $content, $tpl['is_html']);
	    }
	error_log('2',3,'flow.log');
	    /* 如果需要,发短信 */
	    if ($_CFG['sms_order_placed'] == '1' && $_CFG['sms_shop_mobile'] != '')
	    {
	        include_once(RPC_ROOT.'includes/cls_sms.php');
	        $sms = new sms();
	        $msg = $order['pay_status'] == PS_UNPAYED ?
	            $_LANG['order_placed_sms'] : $_LANG['order_placed_sms'] . '[' . $_LANG['sms_paid'] . ']';
	        $sms->send($_CFG['sms_shop_mobile'], sprintf($msg, $order['consignee'], $order['tel']), 0);
	    }
	error_log('3',3,'flow.log');
	    /* 如果订单金额为0 处理虚拟卡 */
	    if ($order['order_amount'] <= 0)
	    {
	        $sql = " SELECT goods_id, goods_name, goods_number AS num FROM ".$GLOBALS['ecs']->table('cart') .
	               " WHERE is_real = 0 AND extension_code = 'virtual_card'".
	               " AND session_id = '".SESS_ID."' AND rec_type = '$flow_type'";
	
	        $res = $GLOBALS['db']->getAll($sql);
	error_log('4',3,'flow.log');
	        $virtual_goods = array();
	        foreach ($res AS $row)
	        {
	            $virtual_goods['virtual_card'][] = array('goods_id' => $row['goods_id'], 'goods_name' => $row['goods_name'], 'num' => $row['num']);
	        }
	
	        if ($virtual_goods AND $flow_type != CART_GROUP_BUY_GOODS)
	        {
	            /* 虚拟卡发货 */
	            if (virtual_goods_ship($virtual_goods,$msg, $order['order_sn'], true))
	            {
	                /* 如果没有实体商品,修改发货状态,送积分和红包 */
	                $sql = "SELECT COUNT(*)" .
	                        " FROM " . $ecs->table('order_goods') .
	                        " WHERE order_id = '$order[order_id]' " .
	                        " AND is_real = 1";
	                if ($db->getOne($sql) <= 0)
	                {
	                    /* 修改订单状态 */
	                    update_order($order['order_id'], array('shipping_status' => SS_SHIPPED, 'shipping_time' => gmtime()));
	error_log('5',3,'flow.log');
	                    /* 如果订单用户不为空,计算积分,并发给用户;发红包 */
	                    if ($order['user_id'] > 0)
	                    {
	                        /* 取得用户信息 */
	                        $user = user_info($order['user_id']);
	
	                        /* 计算并发放积分 */
	                        $integral = integral_to_give($order);
	                        log_account_change($order['user_id'], 0, 0, intval($integral['rank_points']), intval($integral['custom_points']), sprintf($_LANG['order_gift_integral'], $order['order_sn']));
	error_log('6',3,'flow.log');
	                        /* 发放红包 */
	                        send_order_bonus($order['order_id']);
	                    }
	                }
	            }
	        }
	
	    }
	
	    /* 清空购物车 */
	    clear_cart($flow_type);
	error_log('7',3,'flow.log');
	    /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */
	    clear_all_files();
	
	    /* 插入支付日志 */
	    //$order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER);
	
	   error_log('8',3,'flow.log'); 
		
		/*取得支付代码
	
		#取得支付信息,生成支付代码 
	    if ($order['order_amount'] > 0)
	    {
	        $payment = payment_info($order['pay_id']);
	
	        include_once('includes/modules/payment/' . $payment['pay_code'] . '.php');
	
	        $pay_obj    = new $payment['pay_code'];
	
	        $pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config']));
	
	        $order['pay_desc'] = $payment['pay_desc'];
	
	        $smarty->assign('pay_online', $pay_online);
	    }
		*/
	
	    if(!empty($order['shipping_name']))
	    {
	        $order['shipping_name']=trim(stripcslashes($order['shipping_name']));
	    }
	error_log('9',3,'flow.log');
	    /*
		#订单信息
	    $smarty->assign('order',      $order);
	    $smarty->assign('total',      $total);
	    $smarty->assign('goods_list', $cart_goods);
	    $smarty->assign('order_submit_back', sprintf($_LANG['order_submit_back'], $_LANG['back_home'], $_LANG['goto_user_center'])); // 返回提示
		*/
	    //user_uc_call('add_feed', array($order['order_id'], BUY_GOODS)); //推送feed到uc
	    unset($_SESSION['flow_consignee']); // 清除session中保存的收货人信息
	    unset($_SESSION['flow_order']);
	    unset($_SESSION['direct_shopping']);
	
	
		$order_done = array('order'=>$order,'total'=>$total,'cart_goods'=>$cart_goods);
		//var_dump($order_done);exit;
	error_log('10',3,'flow.log');	
		$order_id = $order['order_id'];
		$price = $order['order_amount'];
		$order = array ('order_id'=>$order_id,'order_number'=>$order['order_sn'],'price'=>$price) ;
		error_log('11',3,'flow.log');
		//print_r($order);die;
		jsonExit($order);
		
	}
Esempio n. 14
0
/**
 *  虚拟商品
 * @param type $goods
 * @param type $order_sn
 * @param type $msg
 * @param type $process
 * @return boolean
 */
function virtual_goods_shipping($goods, $order_sn, &$msg, $process = 'other')
{
    /* 代码增加_虚拟团购_START  www.68ecshop.com */
    for ($i = 0; $i < $goods['num']; $i++) {
        $coded_card_sn = rand(1000, 9999) . $i . gmtime();
        $add_date = gmtime();
        $end_date = $goods['valid_date'];
        $supplier_id = $goods['supplier_id'];
        $goods_attr_id = $goods['goods_attr_id'];
        $sql = "INSERT INTO " . $GLOBALS['ecs']->table('virtual_goods_card') . " (goods_id, card_sn, end_date, add_date, supplier_id, is_verification) " . "VALUES ('{$goods['goods_id']}', '{$coded_card_sn}', '{$end_date}', '{$add_date}', '{$supplier_id}', '0')";
        $GLOBALS['db']->query($sql);
    }
    /* 代码增加_虚拟团购_END  www.68ecshop.com */
    /* 取出卡片信息 */
    $sql = "SELECT card_id, card_sn, end_date,buy_date,supplier_id,is_verification  FROM " . $GLOBALS['ecs']->table('virtual_goods_card') . " WHERE goods_id = '{$goods['goods_id']}' AND is_saled = 0  LIMIT " . $goods['num'];
    $arr = $GLOBALS['db']->getAll($sql);
    $card_ids = array();
    $cards = array();
    foreach ($arr as $virtual_card) {
        $card_info = array();
        $card_info['end_date'] = date($GLOBALS['_CFG']['date_format'], $virtual_card['end_date']);
        $card_ids[] = $virtual_card['card_id'];
        $cards[] = $card_info;
    }
    /* 标记已经取出的卡片 */
    $sql = "UPDATE " . $GLOBALS['ecs']->table('virtual_goods_card') . " SET " . "is_saled = 1 ," . "order_sn = '{$order_sn}' " . "WHERE " . db_create_in($card_ids, 'card_id');
    if (!$GLOBALS['db']->query($sql, 'SILENT')) {
        $msg .= $GLOBALS['db']->error();
        return false;
    }
    /* 更新库存 */
    if (empty($goods_attr_id)) {
        $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET goods_number = goods_number - '{$goods['num']}' WHERE goods_id = '{$goods['goods_id']}'";
    } else {
        $goods_attr_id = str_replace(",", "|", $goods_attr_id);
        $sql = "UPDATE " . $GLOBALS['ecs']->table('products') . "set product_number = product_number - '{$goods['num']}'  where goods_id = '{$goods['goods_id']}' and goods_attr='{$goods_attr_id}'";
    }
    $GLOBALS['db']->query($sql);
    if (true) {
        /* 获取订单信息 */
        $sql = "SELECT order_id, order_sn, consignee, email FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_sn = '{$order_sn}'";
        $order = $GLOBALS['db']->GetRow($sql);
        /* 更新订单信息 */
        if ($process == 'split') {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('order_goods') . "\n                    SET send_number = send_number + '" . $goods['num'] . "'\n                    WHERE order_id = '" . $order['order_id'] . "'\n                    AND goods_id = '" . $goods['goods_id'] . "' ";
        } else {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('order_goods') . "\n                    SET send_number = '" . $goods['num'] . "'\n                    WHERE order_id = '" . $order['order_id'] . "'\n                    AND goods_id = '" . $goods['goods_id'] . "' ";
        }
        if (!$GLOBALS['db']->query($sql, 'SILENT')) {
            $msg .= $GLOBALS['db']->error();
            return false;
        }
    }
    /*发送手机验证码*/
    //    require('lib_sms.php');
    //    $mobile_phone = $goods['mobile_phone'];
    //    foreach($arr as $v){
    //        $content = '您的验证码:'.$v['card_sn'].', 请在 '.local_date('Y-m-d',$v['end_date']).' 之前使用';
    //        sendsms($mobile_phone,$content);
    //    }
    /* 发送邮件 */
    $GLOBALS['smarty']->assign('virtual_card', $cards);
    $GLOBALS['smarty']->assign('order', $order);
    $GLOBALS['smarty']->assign('goods', $goods);
    $GLOBALS['smarty']->assign('send_time', date('Y-m-d H:i:s'));
    $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
    $GLOBALS['smarty']->assign('send_date', date('Y-m-d'));
    $GLOBALS['smarty']->assign('sent_date', date('Y-m-d'));
    $tpl = get_mail_template('virtual_card');
    $content = $GLOBALS['smarty']->fetch('str:' . $tpl['template_content']);
    send_mail($order['consignee'], $order['email'], $tpl['template_subject'], $content, $tpl['is_html']);
    return true;
}
Esempio n. 15
0
function action_act_forget_surplus_password()
{
    $user = $GLOBALS['user'];
    $_CFG = $GLOBALS['_CFG'];
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    $user_id = $GLOBALS['user_id'];
    if (empty($_POST['verify_method'])) {
        show_message('未知错误!', '返回', 'user.php?act=forget_surplus_password', 'error');
    } else {
        $verify_method = $_REQUEST['verify_method'];
        if ($verify_method == 'phone') {
            if (empty($_REQUEST['v_code'])) {
                show_message('请输入手机验证码!', '返回', 'user.php?act=forget_surplus_password', 'error');
            }
            if (empty($_REQUEST['v_phone'])) {
                show_message('请输入手机号!', '返回', 'user.php?act=forget_surplus_password', 'error');
            }
            $v_code = $_REQUEST['v_code'];
            $v_phone = $_REQUEST['v_phone'];
            $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('verifycode') . ' WHERE `mobile` = \'' . $v_phone . '\' AND `verifycode` = \'' . $v_code . '\' AND `status` = 1' . ' AND dateline + 86400 > \'' . gmtime() . '\'';
            if ($GLOBALS['db']->getOne($sql) == 0) {
                show_message('手机号和验证码不匹配,请重新输入!');
            } else {
                $smarty->assign('verify_method', 'phone');
                $smarty->assign('v_code', $v_code);
                $smarty->assign('action', 'reset_surplus_password');
                $smarty->assign('validated', 1);
                $smarty->display('user_transaction.dwt');
            }
        } elseif ($verify_method == 'email') {
            if (empty($_REQUEST['v_captcha'])) {
                show_message('请输入验证码!', '返回', 'user.php?act=forget_surplus_password', 'error');
            }
            if (empty($_REQUEST['v_email'])) {
                show_message('请输入邮箱!', '返回', 'user.php?act=forget_surplus_password', 'error');
            }
            $v_captcha = trim($_REQUEST['v_captcha']);
            $v_email = trim($_REQUEST['v_email']);
            include_once 'includes/cls_captcha.php';
            $validator = new captcha();
            $validator->session_word = 'captcha_login';
            if (!$validator->check_word($v_captcha)) {
                show_message($_LANG['invalid_captcha'], $_LANG['back_up_page'], 'user.php?act=forget_surplus_password', 'error');
            } else {
                $sql = 'SELECT `user_name`,`email` ' . ' FROM ' . $GLOBALS['ecs']->table('users') . ' WHERE `user_id` = \'' . $user_id . '\'';
                $row = $GLOBALS['db']->getRow($sql);
                if ($row['email'] != $v_email) {
                    show_message('邮箱输入错误!', '返回', 'user.php?act=forget_surplus_password', 'error');
                }
                $template = get_mail_template('reset_surplus_password');
                $scope = '02456789abdefghjknoqrstwyz13u';
                $hash = mc_random(16, $scope);
                $reset_link = $GLOBALS['ecs']->url() . 'user.php?act=verify_reset_surplus_email' . '&hash=' . $hash;
                $user_name = $row['user_name'];
                $smarty->assign('user_name', $user_name);
                $smarty->assign('reset_link', $reset_link);
                $smarty->assign('shop_name', $_CFG['shop_name']);
                $smarty->assign('send_date', date($_CFG['time_format']));
                $content = $smarty->fetch('str:' . $template['template_content']);
                $result = send_mail($_CFG['shop_name'], $v_email, $template['template_subject'], $content, $template['is_html']);
                if ($result == true) {
                    $add_time = gmtime();
                    $sql = 'INSERT INTO ' . $GLOBALS['ecs']->table('email') . '(`email`,`hash`,`add_time`,`user_id`)' . 'VALUES(\'' . $v_email . '\',\'' . $hash . '\',\'' . $add_time . '\',\'' . $user_id . '\')';
                    $GLOBALS['db']->query($sql);
                    if ($GLOBALS['db']->affected_rows() == 1) {
                        show_message('已发送邮件,请前往邮箱点击链接完成密码重置!', '返回', 'user.php?act=account_security', 'success');
                    } else {
                        show_message('发送邮件失败!');
                    }
                } else {
                    show_message('发送邮件失败!');
                }
            }
        } else {
            show_message('未知错误!', '返回', 'user.php?act=forget_surplus_password', 'error');
        }
    }
}
Esempio n. 16
0
/**
 * Send referral email
 * @param   string      $referral_id referral record id
 * @return  boolean
 */
function send_referral_email($referral_id)
{
    $sql = "SELECT referral_email, user_id FROM " . $GLOBALS['ecs']->table('user_referral') . " WHERE id = '$referral_id'";
    $referral = $GLOBALS['db']->getRow($sql);

    $sql = "SELECT user_name, email FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '" . $referral['user_id'] . "'";
    $row = $GLOBALS['db']->getRow($sql);

    $email = $referral['referral_email'];

    $hash = register_hash('encode', $referral_id);
    $referral_comfirm_url = $GLOBALS['ecs']->url() . 'user.php?act=register_referral&hash=' . $hash;


    $name = '';
    $template    = get_mail_template('referral_email_confirm');
    $subject = $template['template_subject'];
    $type = $template['is_html'];

    $GLOBALS['smarty']->assign('user_name',            $row['email']);
    $GLOBALS['smarty']->assign('referral_comfirm_url', $referral_comfirm_url);
    $GLOBALS['smarty']->assign('shop_name',            $GLOBALS['_CFG']['shop_name']);
    $GLOBALS['smarty']->assign('send_date',            date($GLOBALS['_CFG']['date_format']));

    $content = $GLOBALS['smarty']->fetch('str:' . $template['template_content']);

    if(send_mail($name, $email, $subject, $content, $type))
    {
        return true;
    }
    else
    {
        return false;
    }
}
Esempio n. 17
0
     $sql = "UPDATE " . $ecs->table('comment') . " SET " . "email     = '{$_POST['email']}', " . "user_name = '{$_POST['user_name']}', " . "content   = '{$_POST['content']}', " . "add_time  =  '" . gmtime() . "', " . "ip_address= '{$ip}', " . "status    = 0" . " WHERE comment_id = '" . $reply_info['comment_id'] . "'";
 } else {
     /* 插入回复的评论内容 */
     $sql = "INSERT INTO " . $ecs->table('comment') . " (comment_type, id_value, email, user_name , " . "content, add_time, ip_address, status, parent_id) " . "VALUES('{$_POST['comment_type']}', '{$_POST['id_value']}','{$_POST['email']}', " . "'{$_SESSION['admin_name']}','{$_POST['content']}','" . gmtime() . "', '{$ip}', '0', '{$_POST['comment_id']}')";
 }
 $db->query($sql);
 /* 更新当前的评论状态为已回复并且可以显示此条评论 */
 $sql = "UPDATE " . $ecs->table('comment') . " SET status = 1 WHERE comment_id = '{$_POST['comment_id']}'";
 $db->query($sql);
 /* 邮件通知处理流程 */
 if (!empty($_POST['send_email_notice']) or isset($_POST['remail'])) {
     //获取邮件中的必要内容
     $sql = 'SELECT user_name, email, content ' . 'FROM ' . $ecs->table('comment') . " WHERE comment_id ='{$_REQUEST['comment_id']}'";
     $comment_info = $db->getRow($sql);
     /* 设置留言回复模板所需要的内容信息 */
     $template = get_mail_template('recomment');
     $smarty->assign('user_name', $comment_info['user_name']);
     $smarty->assign('recomment', $_POST['content']);
     $smarty->assign('comment', $comment_info['content']);
     $smarty->assign('shop_name', "<a href='" . $ecs->url() . "'>" . $_CFG['shop_name'] . '</a>');
     $smarty->assign('send_date', date('Y-m-d'));
     $content = $smarty->fetch('str:' . $template['template_content']);
     /* 发送邮件 */
     if (send_mail($comment_info['user_name'], $comment_info['email'], $template['template_subject'], $content, $template['is_html'])) {
         $send_ok = 0;
     } else {
         $send_ok = 1;
     }
 }
 /* 清除缓存 */
 clear_cache_files();
Esempio n. 18
0
/**
 * 发送注册邮箱验证码
 *
 * @access public
 * @param string $email        	
 *
 * @return boolen
 */
function send_reg_email_code($email)
{
    /* 设置验证邮件模板所需要的内容信息 */
    $template = get_mail_template('reg_email_code');
    // 生成邮箱验证码
    $email_code = generate_email_code(6);
    $GLOBALS['smarty']->assign('email_code', $email_code);
    $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
    $GLOBALS['smarty']->assign('send_date', date($GLOBALS['_CFG']['date_format']));
    $content = $GLOBALS['smarty']->fetch('str:' . $template['template_content']);
    /* 发送激活验证邮件 */
    if (send_mail($email, $email, $template['template_subject'], $content, $template['is_html'])) {
        return true;
    } else {
        return false;
    }
}
Esempio n. 19
0
function delivery($order_id, $deliery_id, $express_no)
{
    /* 定义当前时间 */
    define('GMTIME_UTC', gmtime());
    // 获取 UTC 时间戳
    /* 取得参数 */
    $delivery = array();
    $delivery['invoice_no'] = $express_no;
    $action_note = isset($_REQUEST['action_note']) ? trim($_REQUEST['action_note']) : '';
    /* 根据发货单id查询发货单信息 */
    if (!empty($delivery_id)) {
        $delivery_order = delivery_order_info($delivery_id);
    } else {
        die('order does not exist');
    }
    /* 查询订单信息 */
    $order = order_info($order_id);
    /* 检查此单发货商品库存缺货情况 */
    $virtual_goods = array();
    $delivery_stock_sql = "SELECT DG.goods_id, DG.is_real, DG.product_id, SUM(DG.send_number) AS sums, IF(DG.product_id > 0, P.product_number, G.goods_number) AS storage, G.goods_name, DG.send_number\r\n        FROM " . $GLOBALS['ecs']->table('delivery_goods') . " AS DG, " . $GLOBALS['ecs']->table('goods') . " AS G, " . $GLOBALS['ecs']->table('products') . " AS P\r\n        WHERE DG.goods_id = G.goods_id\r\n        AND DG.delivery_id = '{$delivery_id}'\r\n        AND DG.product_id = P.product_id\r\n        GROUP BY DG.product_id ";
    $delivery_stock_result = $GLOBALS['db']->getAll($delivery_stock_sql);
    /* 如果商品存在规格就查询规格,如果不存在规格按商品库存查询 */
    if (!empty($delivery_stock_result)) {
        foreach ($delivery_stock_result as $value) {
            if (($value['sums'] > $value['storage'] || $value['storage'] <= 0) && ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_SHIP || $_CFG['use_storage'] == '0' && $value['is_real'] == 0)) {
                /* 操作失败 */
                $links[] = array('text' => $GLOBALS['_LANG']['order_info'], 'href' => 'order.php?act=delivery_info&delivery_id=' . $delivery_id);
                sys_msg(sprintf($GLOBALS['_LANG']['act_good_vacancy'], $value['goods_name']), 1, $links);
                break;
            }
            /* 虚拟商品列表 virtual_card*/
            if ($value['is_real'] == 0) {
                $virtual_goods[] = array('goods_id' => $value['goods_id'], 'goods_name' => $value['goods_name'], 'num' => $value['send_number']);
            }
        }
    } else {
        $delivery_stock_sql = "SELECT DG.goods_id, DG.is_real, SUM(DG.send_number) AS sums, G.goods_number, G.goods_name, DG.send_number\r\n        FROM " . $GLOBALS['ecs']->table('delivery_goods') . " AS DG, " . $GLOBALS['ecs']->table('goods') . " AS G\r\n        WHERE DG.goods_id = G.goods_id\r\n        AND DG.delivery_id = '{$delivery_id}'\r\n        GROUP BY DG.goods_id ";
        $delivery_stock_result = $GLOBALS['db']->getAll($delivery_stock_sql);
        foreach ($delivery_stock_result as $value) {
            if (($value['sums'] > $value['goods_number'] || $value['goods_number'] <= 0) && ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_SHIP || $_CFG['use_storage'] == '0' && $value['is_real'] == 0)) {
                /* 操作失败 */
                $links[] = array('text' => $GLOBALS['_LANG']['order_info'], 'href' => 'order.php?act=delivery_info&delivery_id=' . $delivery_id);
                sys_msg(sprintf($GLOBALS['_LANG']['act_good_vacancy'], $value['goods_name']), 1, $links);
                break;
            }
            /* 虚拟商品列表 virtual_card*/
            if ($value['is_real'] == 0) {
                $virtual_goods[] = array('goods_id' => $value['goods_id'], 'goods_name' => $value['goods_name'], 'num' => $value['send_number']);
            }
        }
    }
    /* 发货 */
    /* 处理虚拟卡 商品(虚货) */
    if (is_array($virtual_goods) && count($virtual_goods) > 0) {
        foreach ($virtual_goods as $virtual_value) {
            virtual_card_shipping($virtual_value, $order['order_sn'], $msg, 'split');
        }
    }
    /* 如果使用库存,且发货时减库存,则修改库存 */
    if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_SHIP) {
        foreach ($delivery_stock_result as $value) {
            /* 商品(实货)、超级礼包(实货) */
            if ($value['is_real'] != 0) {
                //(货品)
                if (!empty($value['product_id'])) {
                    $minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('products') . "\r\n                                        SET product_number = product_number - " . $value['sums'] . "\r\n                                        WHERE product_id = " . $value['product_id'];
                    $GLOBALS['db']->query($minus_stock_sql, 'SILENT');
                }
                $minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . "\r\n                                    SET goods_number = goods_number - " . $value['sums'] . "\r\n                                    WHERE goods_id = " . $value['goods_id'];
                $GLOBALS['db']->query($minus_stock_sql, 'SILENT');
            }
        }
    }
    /* 修改发货单信息 */
    $invoice_no = str_replace(',', '<br>', $delivery['invoice_no']);
    $invoice_no = trim($invoice_no, '<br>');
    $_delivery['invoice_no'] = $invoice_no;
    $_delivery['status'] = 0;
    // 0,为已发货
    $query = $db->autoExecute($ecs->table('delivery_order'), $_delivery, 'UPDATE', "delivery_id = {$delivery_id}", 'SILENT');
    if (!$query) {
        /* 操作失败 */
        $links[] = array('text' => $GLOBALS['_LANG']['delivery_sn'] . $GLOBALS['_LANG']['detail'], 'href' => 'order.php?act=delivery_info&delivery_id=' . $delivery_id);
        sys_msg($GLOBALS['_LANG']['act_false'], 1, $links);
    }
    /* 标记订单为已确认 “已发货” */
    /* 更新发货时间 */
    $order_finish = get_all_delivery_finish($order_id);
    $shipping_status = $order_finish == 1 ? SS_SHIPPED : SS_SHIPPED_PART;
    $arr['shipping_status'] = $shipping_status;
    $arr['shipping_time'] = GMTIME_UTC;
    // 发货时间
    $arr['invoice_no'] = trim($order['invoice_no'] . '<br>' . $invoice_no, '<br>');
    update_order($order_id, $arr);
    /* 发货单发货记录log */
    order_action($order['order_sn'], OS_CONFIRMED, $shipping_status, $order['pay_status'], $action_note, null, 1);
    /* 如果当前订单已经全部发货 */
    if ($order_finish) {
        /* 如果订单用户不为空,计算积分,并发给用户;发红包 */
        if ($order['user_id'] > 0) {
            /* 取得用户信息 */
            $user = user_info($order['user_id']);
            /* 计算并发放积分 */
            $integral = integral_to_give($order);
            log_account_change($order['user_id'], 0, 0, intval($integral['rank_points']), intval($integral['custom_points']), sprintf($GLOBALS['_LANG']['order_gift_integral'], $order['order_sn']));
            /* 发放红包 */
            send_order_bonus($order_id, $order['supplier_id']);
        }
        /* 发送邮件 */
        $cfg = $_CFG['send_ship_email'];
        if ($cfg == '1') {
            $order['invoice_no'] = $invoice_no;
            $tpl = get_mail_template('deliver_notice');
            $smarty->assign('order', $order);
            $smarty->assign('send_time', local_date($_CFG['time_format']));
            $smarty->assign('shop_name', $_CFG['shop_name']);
            $smarty->assign('send_date', local_date($_CFG['date_format']));
            $smarty->assign('sent_date', local_date($_CFG['date_format']));
            $smarty->assign('confirm_url', $ecs->url() . 'receive.php?id=' . $order['order_id'] . '&con=' . rawurlencode($order['consignee']));
            $smarty->assign('send_msg_url', $ecs->url() . 'user.php?act=message_list&order_id=' . $order['order_id']);
            $content = $smarty->fetch('str:' . $tpl['template_content']);
            if (!send_mail($order['consignee'], $order['email'], $tpl['template_subject'], $content, $tpl['is_html'])) {
                $msg = $GLOBALS['_LANG']['send_mail_fail'];
            }
        }
        /* 如果需要,发短信 */
        if ($GLOBALS['_CFG']['sms_order_shipped'] == '1' && $order['mobile'] != '') {
            include_once '../send.php';
            $content = '您的订单已发货,订单号为' . $order['order_sn'] . '收货人为' . $order['consignee'] . '收货地址为' . $order['address'] . ',请注意查收【' . $GLOBALS['_CFG']['shop_name'] . '】';
            sendSMS($order['mobile'], $content);
        }
    }
    /* 清除缓存 */
    clear_cache_files();
    /* 操作成功 */
    $links[] = array('text' => $GLOBALS['_LANG']['09_delivery_order'], 'href' => 'order.php?act=delivery_list');
    $links[] = array('text' => $GLOBALS['_LANG']['delivery_sn'] . $GLOBALS['_LANG']['detail'], 'href' => 'order.php?act=delivery_info&delivery_id=' . $delivery_id);
    sys_msg($GLOBALS['_LANG']['act_ok'], 0, $links);
}
Esempio n. 20
0
/**
 * 添加/编辑预售活动的提交
 */
function action_insert_update()
{
    $user = $GLOBALS['user'];
    $_CFG = $GLOBALS['_CFG'];
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    $user_id = $_SESSION['user_id'];
    /* 取得预售活动id */
    $pre_sale_id = intval($_POST['act_id']);
    if (isset($_POST['finish']) || isset($_POST['succeed']) || isset($_POST['fail']) || isset($_POST['mail'])) {
        if ($pre_sale_id <= 0) {
            sys_msg($_LANG['error_pre_sale'], 1);
        }
        $pre_sale = pre_sale_info($pre_sale_id);
        if (empty($pre_sale)) {
            sys_msg($_LANG['error_pre_sale'], 1);
        }
    }
    if (isset($_POST['finish'])) {
        /* 设置活动结束 */
        /* 判断活动状态 */
        if ($pre_sale['status'] != PSS_UNDER_WAY) {
            sys_msg($_LANG['error_status'], 1);
            // 此处怀疑是如果活动进行中突然要结束掉,应该抛出禁止的页面,貌似去掉了,所以程序继续执行
        }
        /* 结束预售活动,修改结束时间为当前时间 */
        $sql = "UPDATE " . $ecs->table('goods_activity') . " SET end_time = '" . gmtime() . "' " . "WHERE act_id = '{$pre_sale_id}' LIMIT 1";
        $db->query($sql);
        /* 清除缓存 */
        clear_cache_files();
        /* 提示信息 */
        $links = array(array('href' => 'pre_sale.php?act=list', 'text' => $_LANG['back_list']));
        sys_msg($_LANG['edit_success'], 0, $links);
    } elseif (isset($_POST['succeed'])) {
        /* 设置活动成功 */
        /* 判断订单状态 */
        if ($pre_sale['status'] != PSS_FINISHED) {
            sys_msg($_LANG['error_status'], 1);
        }
        /* 如果有订单,更新订单信息 */
        if ($pre_sale['total_order'] > 0) {
            /* 查找该预售活动的已确认或未确认订单(已取消的就不管了) */
            $sql = "SELECT order_id " . "FROM " . $ecs->table('order_info') . " WHERE extension_code = '" . PRE_SALE_CODE . "' " . "AND extension_id = '{$pre_sale_id}' " . "AND (order_status = '" . OS_CONFIRMED . "' or order_status = '" . OS_UNCONFIRMED . "')";
            $order_id_list = $db->getCol($sql);
            /* 更新订单商品价 */
            $final_price = $pre_sale['trans_price'];
            $sql = "UPDATE " . $ecs->table('order_goods') . " SET goods_price = '{$final_price}' " . "WHERE order_id " . db_create_in($order_id_list);
            $db->query($sql);
            /* 查询订单商品总额 */
            $sql = "SELECT order_id, SUM(goods_number * goods_price) AS goods_amount " . "FROM " . $ecs->table('order_goods') . " WHERE order_id " . db_create_in($order_id_list) . " GROUP BY order_id";
            $res = $db->query($sql);
            while ($row = $db->fetchRow($res)) {
                $order_id = $row['order_id'];
                $goods_amount = floatval($row['goods_amount']);
                /* 取得订单信息 */
                $order = order_info($order_id);
                /* 判断订单是否有效:余额支付金额 + 已付款金额 >= 保证金 */
                if ($order['surplus'] + $order['money_paid'] >= $pre_sale['deposit']) {
                    /* 有效,设为已确认,更新订单 */
                    // 更新商品总额
                    $order['goods_amount'] = $goods_amount;
                    // 如果保价,重新计算保价费用
                    if ($order['insure_fee'] > 0) {
                        $shipping = shipping_info($order['shipping_id']);
                        $order['insure_fee'] = shipping_insure_fee($shipping['shipping_code'], $goods_amount, $shipping['insure']);
                    }
                    // 重算支付费用
                    $order['order_amount'] = $order['goods_amount'] + $order['shipping_fee'] + $order['insure_fee'] + $order['pack_fee'] + $order['card_fee'] - $order['money_paid'] - $order['surplus'];
                    if ($order['order_amount'] > 0) {
                        $order['pay_fee'] = pay_fee($order['pay_id'], $order['order_amount']);
                    } else {
                        $order['pay_fee'] = 0;
                    }
                    // 计算应付款金额
                    $order['order_amount'] += $order['pay_fee'];
                    // 计算付款状态
                    if ($order['order_amount'] > 0) {
                        $order['pay_status'] = PS_UNPAYED;
                        $order['pay_time'] = 0;
                    } else {
                        $order['pay_status'] = PS_PAYED;
                        $order['pay_time'] = gmtime();
                    }
                    // 如果需要退款,退到帐户余额
                    if ($order['order_amount'] < 0) {
                        // todo (现在手工退款)
                    }
                    // 订单状态
                    $order['order_status'] = OS_CONFIRMED;
                    $order['confirm_time'] = gmtime();
                    // 更新订单
                    $order = addslashes_deep($order);
                    update_order($order_id, $order);
                } else {
                    /* 无效,取消订单,退回已付款 */
                    // 修改订单状态为已取消,付款状态为未付款
                    $order['order_status'] = OS_CANCELED;
                    $order['to_buyer'] = $_LANG['cancel_order_reason'];
                    $order['pay_status'] = PS_UNPAYED;
                    $order['pay_time'] = 0;
                    /* 如果使用余额或有已付款金额,退回帐户余额 */
                    $money = $order['surplus'] + $order['money_paid'];
                    if ($money > 0) {
                        $order['surplus'] = 0;
                        $order['money_paid'] = 0;
                        $order['order_amount'] = $money;
                        // 退款到帐户余额
                        order_refund($order, 1, $_LANG['cancel_order_reason'] . ':' . $order['order_sn']);
                    }
                    /* 更新订单 */
                    $order = addslashes_deep($order);
                    update_order($order['order_id'], $order);
                }
            }
        }
        /* 修改预售活动状态为成功 */
        $sql = "UPDATE " . $ecs->table('goods_activity') . " SET is_finished = '" . PSS_SUCCEED . "' " . "WHERE act_id = '{$pre_sale_id}' LIMIT 1";
        $db->query($sql);
        /* 清除缓存 */
        clear_cache_files();
        /* 提示信息 */
        $links = array(array('href' => 'pre_sale.php?act=list', 'text' => $_LANG['back_list']));
        sys_msg($_LANG['edit_success'], 0, $links);
    } elseif (isset($_POST['fail'])) {
        /* 设置活动失败 */
        /* 判断订单状态 */
        if ($pre_sale['status'] != PSS_FINISHED) {
            sys_msg($_LANG['error_status'], 1);
        }
        /* 如果有有效订单,取消订单 */
        if ($pre_sale['valid_order'] > 0) {
            /* 查找未确认或已确认的订单 */
            $sql = "SELECT * " . "FROM " . $ecs->table('order_info') . " WHERE extension_code = '" . PRE_SALE_CODE . "' " . "AND extension_id = '{$pre_sale_id}' " . "AND (order_status = '" . OS_CONFIRMED . "' OR order_status = '" . OS_UNCONFIRMED . "') ";
            $res = $db->query($sql);
            while ($order = $db->fetchRow($res)) {
                // 修改订单状态为已取消,付款状态为未付款
                $order['order_status'] = OS_CANCELED;
                $order['to_buyer'] = $_LANG['cancel_order_reason'];
                $order['pay_status'] = PS_UNPAYED;
                $order['pay_time'] = 0;
                /* 如果使用余额或有已付款金额,退回帐户余额 */
                $money = $order['surplus'] + $order['money_paid'];
                if ($money > 0) {
                    $order['surplus'] = 0;
                    $order['money_paid'] = 0;
                    $order['order_amount'] = $money;
                    // 退款到帐户余额
                    order_refund($order, 1, $_LANG['cancel_order_reason'] . ':' . $order['order_sn'], $money);
                }
                /* 更新订单 */
                $order = addslashes_deep($order);
                update_order($order['order_id'], $order);
            }
        }
        /* 修改预售活动状态为失败,记录失败原因(活动说明) */
        $sql = "UPDATE " . $ecs->table('goods_activity') . " SET is_finished = '" . PSS_FAIL . "', " . "act_desc = '{$_POST['act_desc']}' " . "WHERE act_id = '{$pre_sale_id}' LIMIT 1";
        $db->query($sql);
        /* 清除缓存 */
        clear_cache_files();
        /* 提示信息 */
        $links = array(array('href' => 'pre_sale.php?act=list', 'text' => $_LANG['back_list']));
        sys_msg($_LANG['edit_success'], 0, $links);
    } elseif (isset($_POST['mail'])) {
        /* 发送通知邮件 */
        /* 判断订单状态 */
        if ($pre_sale['status'] != PSS_SUCCEED) {
            sys_msg($_LANG['error_status'], 1);
        }
        /* 取得邮件模板 */
        $tpl = get_mail_template('pre_sale');
        /* 初始化订单数和成功发送邮件数 */
        $count = 0;
        $send_count = 0;
        /* 取得有效订单 */
        $sql = "SELECT o.consignee, o.add_time, g.goods_number, o.order_sn, " . "o.order_amount, o.order_id, o.email " . "FROM " . $ecs->table('order_info') . " AS o, " . $ecs->table('order_goods') . " AS g " . "WHERE o.order_id = g.order_id " . "AND o.extension_code = '" . PRE_SALE_CODE . "' " . "AND o.extension_id = '{$pre_sale_id}' " . "AND o.order_status = '" . OS_CONFIRMED . "'";
        $res = $db->query($sql);
        while ($order = $db->fetchRow($res)) {
            /* 邮件模板赋值 */
            $smarty->assign('consignee', $order['consignee']);
            $smarty->assign('add_time', local_date($_CFG['time_format'], $order['add_time']));
            $smarty->assign('goods_name', $pre_sale['goods_name']);
            $smarty->assign('goods_number', $order['goods_number']);
            $smarty->assign('order_sn', $order['order_sn']);
            $smarty->assign('order_amount', price_format($order['order_amount']));
            $smarty->assign('shop_url', $ecs->url() . 'user.php?act=order_detail&order_id=' . $order['order_id']);
            $smarty->assign('shop_name', $_CFG['shop_name']);
            $smarty->assign('send_date', local_date($_CFG['date_format']));
            /* 取得模板内容,发邮件 */
            $content = $smarty->fetch('str:' . $tpl['template_content']);
            if (send_mail($order['consignee'], $order['email'], $tpl['template_subject'], $content, $tpl['is_html'])) {
                $send_count++;
            }
            $count++;
        }
        /* 提示信息 */
        sys_msg(sprintf($_LANG['mail_result'], $count, $send_count));
    } else {
        /* 保存预售信息 */
        $goods_id = intval($_POST['goods_id']);
        if ($goods_id <= 0) {
            sys_msg($_LANG['error_goods_null']);
        }
        $info = goods_pre_sale($goods_id);
        if ($info && $info['act_id'] != $pre_sale_id) {
            sys_msg($_LANG['error_goods_exist']);
        }
        $goods_name = $db->getOne("SELECT goods_name FROM " . $ecs->table('goods') . " WHERE goods_id = '{$goods_id}'");
        $act_name = empty($_POST['act_name']) ? $goods_name : sub_str($_POST['act_name'], 0, 255, false);
        // 预售价格
        $sale_price = floatval($_POST['sale_price']);
        if ($sale_price < 0) {
            $sale_price = 0;
        }
        // 定金
        $deposit = floatval($_POST['deposit']);
        if ($deposit < 0) {
            $deposit = 0;
        }
        // 限购数量
        $restrict_amount = intval($_POST['restrict_amount']);
        if ($restrict_amount < 0) {
            $restrict_amount = 0;
        }
        // 赠送积分
        $gift_integral = intval($_POST['gift_integral']);
        if ($gift_integral < 0) {
            $gift_integral = 0;
        }
        $price_ladder = array();
        $count = count($_POST['ladder_amount']);
        for ($i = $count - 1; $i >= 0; $i--) {
            /* 如果数量小于等于0,不要 */
            $amount = intval($_POST['ladder_amount'][$i]);
            if ($amount <= 0) {
                continue;
            }
            /* 如果价格小于等于0,不要 */
            $price = round(floatval($_POST['ladder_price'][$i]), 2);
            if ($price <= 0) {
                continue;
            }
            /* 加入价格阶梯 */
            $price_ladder[$amount] = array('amount' => $amount, 'price' => $price);
        }
        if (count($price_ladder) < 1) {
            sys_msg($_LANG['error_price_ladder']);
        }
        /* 限购数量不能小于价格阶梯中的最大数量 */
        $amount_list = array_keys($price_ladder);
        if ($restrict_amount > 0 && max($amount_list) > $restrict_amount) {
            sys_msg($_LANG['error_restrict_amount']);
        }
        ksort($price_ladder);
        $price_ladder = array_values($price_ladder);
        /* 检查开始时间和结束时间是否合理 */
        $start_time = local_strtotime($_POST['start_time']);
        $end_time = local_strtotime($_POST['end_time']);
        if ($start_time >= $end_time) {
            // $_LANG['invalid_time']
            sys_msg('您输入了一个无效的时间,活动结束时间不能早于活动开始时间!');
        }
        if ($deposit > 0) {
            $retainage_start = local_strtotime($_POST['retainage_start']);
            $retainage_end = local_strtotime($_POST['retainage_end']);
            /* 检查活动结束时间和尾款开始支付时间是否合理 */
            if ($end_time >= $retainage_start) {
                // $_LANG['invalid_time']
                sys_msg('您输入了一个无效的时间,尾款开始支付时间不能早于活动结束时间!');
            }
            /* 检查尾款支付开始时间和结束时间是否合理 */
            if ($retainage_start >= $retainage_end) {
                // $_LANG['invalid_time']
                sys_msg('您输入了一个无效的时间,尾款结束支付时间不能早于尾款开始支付时间!');
            }
        } else {
            $retainage_start = '';
            $retainage_end = '';
        }
        // 预计发货时间描述
        $deliver_goods = $_POST['deliver_goods'];
        $pre_sale = array('act_name' => $act_name, 'act_desc' => $_POST['act_desc'], 'act_type' => GAT_PRE_SALE, 'goods_id' => $goods_id, 'goods_name' => $goods_name, 'start_time' => $start_time, 'end_time' => $end_time, 'ext_info' => serialize(array('sale_price' => $sale_price, 'retainage_start' => $retainage_start, 'retainage_end' => $retainage_end, 'price_ladder' => $price_ladder, 'restrict_amount' => $restrict_amount, 'gift_integral' => $gift_integral, 'deposit' => $deposit, 'deliver_goods' => $deliver_goods)));
        // 开始发货时间描述
        /* 清除缓存 */
        clear_cache_files();
        /* 保存数据 */
        if ($pre_sale_id > 0) {
            /* update */
            $db->autoExecute($ecs->table('goods_activity'), $pre_sale, 'UPDATE', "act_id = '{$pre_sale_id}'");
            /* log */
            admin_log(addslashes($goods_name) . '[' . $pre_sale_id . ']', 'edit', 'pre_sale');
            /* todo 更新活动表 */
            /* 提示信息 */
            $links = array(array('href' => 'pre_sale.php?act=list&' . list_link_postfix(), 'text' => $_LANG['back_list']));
            sys_msg($_LANG['edit_success'], 0, $links);
        } else {
            /* insert */
            $db->autoExecute($ecs->table('goods_activity'), $pre_sale, 'INSERT');
            /* log */
            admin_log(addslashes($goods_name), 'add', 'pre_sale');
            /* 提示信息 */
            $links = array(array('href' => 'pre_sale.php?act=add', 'text' => $_LANG['continue_add']), array('href' => 'pre_sale.php?act=list', 'text' => $_LANG['back_list']));
            sys_msg($_LANG['add_success'], 0, $links);
        }
    }
}
Esempio n. 21
0
     log_account_change($order['user_id'], $order['surplus'] * -1, 0, 0, 0, sprintf($_LANG['pay_order'], $order['order_sn']));
 }
 if ($order['user_id'] > 0 && $order['integral'] > 0) {
     log_account_change($order['user_id'], 0, 0, 0, $order['integral'] * -1, sprintf($_LANG['pay_order'], $order['order_sn']));
 }
 if ($order['bonus_id'] > 0 && $temp_amout > 0) {
     use_bonus($order['bonus_id'], $new_order_id);
 }
 /* 如果使用库存,且下订单时减库存,则减少库存 */
 if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE) {
     change_order_goods_storage($order['order_id'], true, SDT_PLACE);
 }
 /* 给商家发邮件 */
 /* 增加是否给客服发送邮件选项 */
 if ($_CFG['send_service_email'] && $_CFG['service_email'] != '') {
     $tpl = get_mail_template('remind_of_new_order');
     $smarty->assign('order', $order);
     $smarty->assign('goods_list', $cart_goods);
     $smarty->assign('shop_name', $_CFG['shop_name']);
     $smarty->assign('send_date', date($_CFG['time_format']));
     $content = $smarty->fetch('str:' . $tpl['template_content']);
     send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl['template_subject'], $content, $tpl['is_html']);
 }
 /* 如果需要,发短信 */
 if ($_CFG['sms_order_placed'] == '1' && $_CFG['sms_shop_mobile'] != '') {
     include_once 'includes/cls_sms.php';
     $sms = new sms();
     $msg = $order['pay_status'] == PS_UNPAYED ? $_LANG['order_placed_sms'] : $_LANG['order_placed_sms'] . '[' . $_LANG['sms_paid'] . ']';
     $sms->send($_CFG['sms_shop_mobile'], sprintf($msg, $order['consignee'], $order['tel']), 0);
 }
 /* 如果订单金额为0 处理虚拟卡 */
 /**
  * 提交订单
  */
 public function submit_order()
 {
     /* 检查购物车中是否有商品 */
     if (count($_SESSION['wholesale_goods']) == 0) {
         show_message(L('no_goods_in_cart'));
     }
     /* 检查备注信息 */
     if (empty($_POST['remark'])) {
         show_message(L('ws_remark'));
     }
     /* 计算商品总额 */
     $goods_amount = 0;
     foreach ($_SESSION['wholesale_goods'] as $goods) {
         $goods_amount += $goods['subtotal'];
     }
     $order = array('postscript' => htmlspecialchars($_POST['remark']), 'user_id' => $_SESSION['user_id'], 'add_time' => gmtime(), 'order_status' => OS_UNCONFIRMED, 'shipping_status' => SS_UNSHIPPED, 'pay_status' => PS_UNPAYED, 'goods_amount' => $goods_amount, 'order_amount' => $goods_amount);
     /* 插入订单表 */
     $error_no = 0;
     do {
         $order['order_sn'] = get_order_sn();
         //获取新订单号
         $this->model->table('order_info')->data($order)->insert();
         $error_no = $this->model->errno();
         if ($error_no > 0 && $error_no != 1062) {
             die($this->model->errorMsg());
         }
     } while ($error_no == 1062);
     //如果是订单号重复则重新提交数据
     $new_order_id = $this->model->insert_id();
     $order['order_id'] = $new_order_id;
     /* 插入订单商品 */
     foreach ($_SESSION['wholesale_goods'] as $goods) {
         //如果存在货品
         $product_id = 0;
         if (!empty($goods['goods_attr_id'])) {
             $goods_attr_id = array();
             foreach ($goods['goods_attr_id'] as $value) {
                 $goods_attr_id[$value['attr_id']] = $value['attr_val_id'];
             }
             ksort($goods_attr_id);
             $goods_attr = implode('|', $goods_attr_id);
             $res = $this->model->table('products')->field('product_id')->where("goods_attr = '{$goods_attr}' AND goods_id = '" . $goods['goods_id'] . "'")->find();
             $product_id = $res['product_id'];
         }
         $sql = "INSERT INTO " . $this->model->pre . "order_goods( " . "order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, " . "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift) " . " SELECT '{$new_order_id}', goods_id, goods_name, goods_sn, '{$product_id}','{$goods['goods_number']}', market_price, " . "'{$goods['goods_price']}', '{$goods['goods_attr']}', is_real, extension_code, 0, 0 " . " FROM " . $this->model->pre . "goods WHERE goods_id = '{$goods['goods_id']}'";
         $this->model->query($sql);
     }
     /* 给商家发邮件 */
     if (C('service_email') != '') {
         $tpl = get_mail_template('remind_of_new_order');
         $this->assign('order', $order);
         $this->assign('shop_name', C('shop_name'));
         $this->assign('send_date', date(C('time_format')));
         $content = ECTouch::view()->fetch('str:' . $tpl['template_content']);
         send_mail(C('shop_name'), C('service_email'), $tpl['template_subject'], $content, $tpl['is_html']);
     }
     /* 如果需要,发短信 */
     if (C('sms_order_placed') == '1' && C('sms_shop_mobile') != '') {
         $sms = new EcsSms();
         $msg = L('order_placed_sms');
         $sms->send(C('sms_shop_mobile'), sprintf($msg, $order['consignee'], $order['mobile']), '', 13, 1);
     }
     /* 清空购物车 */
     unset($_SESSION['wholesale_goods']);
     /* 提示 */
     show_message(sprintf(L('ws_order_submitted'), $order['order_sn']), L('ws_return_home'), url('index'));
 }
Esempio n. 23
0
    $smarty->display('msg_info.htm');
} elseif ($_REQUEST['act'] == 'action') {
    if (empty($_REQUEST['parent_id'])) {
        $sql = "INSERT INTO " . $ecs->table('feedback') . " (msg_title, msg_time, user_id, user_name , " . "user_email, parent_id, msg_content) " . "VALUES ('reply', '" . gmtime() . "', '" . $_SESSION['admin_id'] . "', " . "'" . $_SESSION['admin_name'] . "', '" . $_POST['user_email'] . "', " . "'" . $_REQUEST['msg_id'] . "', '" . $_POST['msg_content'] . "') ";
        $db->query($sql);
    } else {
        $sql = "UPDATE " . $ecs->table('feedback') . " SET user_email = '" . $_POST['user_email'] . "', msg_content='" . $_POST['msg_content'] . "', msg_time = '" . gmtime() . "' WHERE msg_id = '" . $_REQUEST['parent_id'] . "'";
        $db->query($sql);
    }
    /* 邮件通知处理流程 */
    if (!empty($_POST['send_email_notice']) or isset($_POST['remail'])) {
        //获取邮件中的必要内容
        $sql = 'SELECT user_name, user_email, msg_title, msg_content ' . 'FROM ' . $ecs->table('feedback') . " WHERE msg_id ='{$_REQUEST['msg_id']}'";
        $message_info = $db->getRow($sql);
        /* 设置留言回复模板所需要的内容信息 */
        $template = get_mail_template('user_message');
        $message_content = $message_info['msg_title'] . "\r\n" . $message_info['msg_content'];
        $smarty->assign('user_name', $message_info['user_name']);
        $smarty->assign('message_note', $_POST['msg_content']);
        $smarty->assign('message_content', $message_content);
        $smarty->assign('shop_name', "<a href='" . $ecs->url() . "'>" . $_CFG['shop_name'] . '</a>');
        $smarty->assign('send_date', date('Y-m-d'));
        $content = $smarty->fetch('str:' . $template['template_content']);
        /* 发送邮件 */
        if (send_mail($message_info['user_name'], $message_info['user_email'], $template['template_subject'], $content, $template['is_html'])) {
            $send_ok = 0;
        } else {
            $send_ok = 1;
        }
    }
    ecs_header("Location: ?act=view&id=" . $_REQUEST['msg_id'] . "&send_ok={$send_ok}\n");
Esempio n. 24
0
/**
 * Sends an email, using Piwigo specific informations.
 *
 * @param string|array $to
 * @param array $args
 *       o from: sender [default value webmaster email]
 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
 *       o subject [default value 'Piwigo']
 *       o content: content of mail [default value '']
 *       o content_format: format of mail content [default value 'text/plain']
 *       o email_format: global mail format [default value $conf_mail['default_email_format']]
 *       o theme: theme to use [default value $conf_mail['mail_theme']]
 *       o mail_title: main title of the mail [default value $conf['gallery_title']]
 *       o mail_subtitle: subtitle of the mail [default value subject]
 * @param array $tpl - use these options to define a custom content template file
 *       o filename
 *       o dirname (optional)
 *       o assign (optional)
 *
 * @return boolean
 */
function pwg_mail($to, $args = array(), $tpl = array())
{
    global $conf, $conf_mail, $lang_info, $page;
    if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
        return true;
    }
    if (!isset($conf_mail)) {
        $conf_mail = get_mail_configuration();
    }
    include_once PHPWG_ROOT_PATH . 'include/phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    foreach (get_clean_recipients_list($to) as $recipient) {
        $mail->addAddress($recipient['email'], $recipient['name']);
    }
    $mail->WordWrap = 76;
    $mail->CharSet = 'UTF-8';
    // Compute root_path in order have complete path
    set_make_full_url();
    if (empty($args['from'])) {
        $from = array('email' => $conf_mail['email_webmaster'], 'name' => $conf_mail['name_webmaster']);
    } else {
        $from = unformat_email($args['from']);
    }
    $mail->setFrom($from['email'], $from['name']);
    $mail->addReplyTo($from['email'], $from['name']);
    // Subject
    if (empty($args['subject'])) {
        $args['subject'] = 'Piwigo';
    }
    $args['subject'] = trim(preg_replace('#[\\n\\r]+#s', '', $args['subject']));
    $mail->Subject = $args['subject'];
    // Cc
    if (!empty($args['Cc'])) {
        foreach (get_clean_recipients_list($args['Cc']) as $recipient) {
            $mail->addCC($recipient['email'], $recipient['name']);
        }
    }
    // Bcc
    $Bcc = get_clean_recipients_list(@$args['Bcc']);
    if ($conf_mail['send_bcc_mail_webmaster']) {
        $Bcc[] = array('email' => get_webmaster_mail_address(), 'name' => '');
    }
    if (!empty($Bcc)) {
        foreach ($Bcc as $recipient) {
            $mail->addBCC($recipient['email'], $recipient['name']);
        }
    }
    // theme
    if (empty($args['theme']) or !in_array($args['theme'], array('clear', 'dark'))) {
        $args['theme'] = $conf_mail['mail_theme'];
    }
    // content
    if (!isset($args['content'])) {
        $args['content'] = '';
    }
    // try to decompose subject like "[....] ...."
    if (!isset($args['mail_title']) and !isset($args['mail_subtitle'])) {
        if (preg_match('#^\\[(.*)\\](.*)$#', $args['subject'], $matches)) {
            $args['mail_title'] = $matches[1];
            $args['mail_subtitle'] = $matches[2];
        }
    }
    if (!isset($args['mail_title'])) {
        $args['mail_title'] = $conf['gallery_title'];
    }
    if (!isset($args['mail_subtitle'])) {
        $args['mail_subtitle'] = $args['subject'];
    }
    // content type
    if (empty($args['content_format'])) {
        $args['content_format'] = 'text/plain';
    }
    $content_type_list = array();
    if ($conf_mail['mail_allow_html'] and @$args['email_format'] != 'text/plain') {
        $content_type_list[] = 'text/html';
    }
    $content_type_list[] = 'text/plain';
    $contents = array();
    foreach ($content_type_list as $content_type) {
        // key compose of indexes witch allow to cache mail data
        $cache_key = $content_type . '-' . $lang_info['code'];
        if (!isset($conf_mail[$cache_key])) {
            // instanciate a new Template
            if (!isset($conf_mail[$cache_key]['theme'])) {
                $conf_mail[$cache_key]['theme'] = get_mail_template($content_type);
                trigger_notify('before_parse_mail_template', $cache_key, $content_type);
            }
            $template =& $conf_mail[$cache_key]['theme'];
            $template->set_filename('mail_header', 'header.tpl');
            $template->set_filename('mail_footer', 'footer.tpl');
            $template->assign(array('GALLERY_URL' => get_gallery_home_url(), 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : '', 'CONTENT_ENCODING' => get_pwg_charset(), 'CONTACT_MAIL' => $conf_mail['email_webmaster']));
            if ($content_type == 'text/html') {
                if ($template->smarty->templateExists('global-mail-css.tpl')) {
                    $template->set_filename('global-css', 'global-mail-css.tpl');
                    $template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'global-css');
                }
                if ($template->smarty->templateExists('mail-css-' . $args['theme'] . '.tpl')) {
                    $template->set_filename('css', 'mail-css-' . $args['theme'] . '.tpl');
                    $template->assign_var_from_handle('MAIL_CSS', 'css');
                }
            }
        }
        $template =& $conf_mail[$cache_key]['theme'];
        $template->assign(array('MAIL_TITLE' => $args['mail_title'], 'MAIL_SUBTITLE' => $args['mail_subtitle']));
        // Header
        $contents[$content_type] = $template->parse('mail_header', true);
        // Content
        // Stored in a temp variable, if a content template is used it will be assigned
        // to the $CONTENT template variable, otherwise it will be appened to the mail
        if ($args['content_format'] == 'text/plain' and $content_type == 'text/html') {
            // convert plain text to html
            $mail_content = '<p>' . nl2br(preg_replace('/(https?:\\/\\/([-\\w\\.]+[-\\w])+(:\\d+)?(\\/([\\w\\/_\\.\\#-]*(\\?\\S+)?[^\\.\\s])?)?)/i', '<a href="$1">$1</a>', htmlspecialchars($args['content']))) . '</p>';
        } else {
            if ($args['content_format'] == 'text/html' and $content_type == 'text/plain') {
                // convert html text to plain text
                $mail_content = strip_tags($args['content']);
            } else {
                $mail_content = $args['content'];
            }
        }
        // Runtime template
        if (isset($tpl['filename'])) {
            if (isset($tpl['dirname'])) {
                $template->set_template_dir($tpl['dirname'] . '/' . $content_type);
            }
            if ($template->smarty->templateExists($tpl['filename'] . '.tpl')) {
                $template->set_filename($tpl['filename'], $tpl['filename'] . '.tpl');
                if (!empty($tpl['assign'])) {
                    $template->assign($tpl['assign']);
                }
                $template->assign('CONTENT', $mail_content);
                $contents[$content_type] .= $template->parse($tpl['filename'], true);
            } else {
                $contents[$content_type] .= $mail_content;
            }
        } else {
            $contents[$content_type] .= $mail_content;
        }
        // Footer
        $contents[$content_type] .= $template->parse('mail_footer', true);
    }
    // Undo Compute root_path in order have complete path
    unset_make_full_url();
    // Send content to PHPMailer
    if (isset($contents['text/html'])) {
        $mail->isHTML(true);
        $mail->Body = move_css_to_body($contents['text/html']);
        if (isset($contents['text/plain'])) {
            $mail->AltBody = $contents['text/plain'];
        }
    } else {
        $mail->isHTML(false);
        $mail->Body = $contents['text/plain'];
    }
    if ($conf_mail['use_smtp']) {
        // now we need to split port number
        if (strpos($conf_mail['smtp_host'], ':') !== false) {
            list($smtp_host, $smtp_port) = explode(':', $conf_mail['smtp_host']);
        } else {
            $smtp_host = $conf_mail['smtp_host'];
            $smtp_port = 25;
        }
        $mail->IsSMTP();
        // enables SMTP debug information (for testing) 2 - debug, 0 - no message
        $mail->SMTPDebug = 0;
        $mail->Host = $smtp_host;
        $mail->Port = $smtp_port;
        if (!empty($conf_mail['smtp_secure']) and in_array($conf_mail['smtp_secure'], array('ssl', 'tls'))) {
            $mail->SMTPSecure = $conf_mail['smtp_secure'];
        }
        if (!empty($conf_mail['smtp_user'])) {
            $mail->SMTPAuth = true;
            $mail->Username = $conf_mail['smtp_user'];
            $mail->Password = $conf_mail['smtp_password'];
        }
    }
    $ret = true;
    $pre_result = trigger_change('before_send_mail', true, $to, $args, $mail);
    if ($pre_result) {
        $ret = $mail->send();
        if (!$ret and (!ini_get('display_errors') or is_admin())) {
            trigger_error('Mailer Error: ' . $mail->ErrorInfo, E_USER_WARNING);
        }
        if ($conf['debug_mail']) {
            pwg_send_mail_test($ret, $mail, $args);
        }
    }
    return $ret;
}
Esempio n. 25
0
/**
 *  超值礼包虚拟卡发货、跳过修改订单商品发货数的虚拟卡发货
 *
 * @access  public
 * @param   array      $goods      超值礼包虚拟商品列表数组
 * @param   string      $order_sn   本次操作的订单
 *
 * @return  boolen
 */
function package_virtual_card_shipping($goods, $order_sn)
{
    if (!is_array($goods)) {
        return false;
    }
    /* 包含加密解密函数所在文件 */
    include_once ROOT_PATH . 'includes/lib_code.php';
    // 取出超值礼包中的虚拟商品信息
    foreach ($goods as $virtual_goods_key => $virtual_goods_value) {
        /* 取出卡片信息 */
        $sql = "SELECT card_id, card_sn, card_password, end_date, crc32\n                FROM " . $GLOBALS['ecs']->table('virtual_card') . "\n                WHERE goods_id = '" . $virtual_goods_value['goods_id'] . "'\n                AND is_saled = 0\n                LIMIT " . $virtual_goods_value['num'];
        $arr = $GLOBALS['db']->getAll($sql);
        /* 判断是否有库存 没有则推出循环 */
        if (count($arr) == 0) {
            continue;
        }
        $card_ids = array();
        $cards = array();
        foreach ($arr as $virtual_card) {
            $card_info = array();
            /* 卡号和密码解密 */
            if ($virtual_card['crc32'] == 0 || $virtual_card['crc32'] == crc32(AUTH_KEY)) {
                $card_info['card_sn'] = decrypt($virtual_card['card_sn']);
                $card_info['card_password'] = decrypt($virtual_card['card_password']);
            } elseif ($virtual_card['crc32'] == crc32(OLD_AUTH_KEY)) {
                $card_info['card_sn'] = decrypt($virtual_card['card_sn'], OLD_AUTH_KEY);
                $card_info['card_password'] = decrypt($virtual_card['card_password'], OLD_AUTH_KEY);
            } else {
                return false;
            }
            $card_info['end_date'] = date($GLOBALS['_CFG']['date_format'], $virtual_card['end_date']);
            $card_ids[] = $virtual_card['card_id'];
            $cards[] = $card_info;
        }
        /* 标记已经取出的卡片 */
        $sql = "UPDATE " . $GLOBALS['ecs']->table('virtual_card') . " SET " . "is_saled = 1 ," . "order_sn = '{$order_sn}' " . "WHERE " . db_create_in($card_ids, 'card_id');
        if (!$GLOBALS['db']->query($sql)) {
            return false;
        }
        /* 获取订单信息 */
        $sql = "SELECT order_id, order_sn, consignee, email FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_sn = '{$order_sn}'";
        $order = $GLOBALS['db']->GetRow($sql);
        $cfg = $GLOBALS['_CFG']['send_ship_email'];
        if ($cfg == '1') {
            /* 发送邮件 */
            $GLOBALS['smarty']->assign('virtual_card', $cards);
            $GLOBALS['smarty']->assign('order', $order);
            $GLOBALS['smarty']->assign('goods', $virtual_goods_value);
            $GLOBALS['smarty']->assign('send_time', date('Y-m-d H:i:s'));
            $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
            $GLOBALS['smarty']->assign('send_date', date('Y-m-d'));
            $GLOBALS['smarty']->assign('sent_date', date('Y-m-d'));
            $tpl = get_mail_template('virtual_card');
            $content = $GLOBALS['smarty']->fetch('str:' . $tpl['template_content']);
            send_mail($order['consignee'], $order['email'], $tpl['template_subject'], $content, $tpl['is_html']);
        }
    }
    return true;
}
Esempio n. 26
0
<?php

define('IN_ECS', true);
require dirname(__FILE__) . '/includes/init.php';
// 获得所有有效会员清单
$sql_memeber = "select u.user_id, u.email, u.user_name,u.user_money,u.rank_points, u.msn, u.to_date from " . $ecs->table("users") . " u  where u.member_novalid ='0' and (u.msn is not null or u.msn <> '') ";
$member_list = $db->getAll($sql_memeber);
if ($member_list) {
    foreach ($member_list as $user) {
        if (!empty($user['to_date']) and $user['to_date'] < gmtime()) {
            //判断合同期限
            //if ($GLOBALS['_CFG']['send_service_email'] == '1' && $GLOBALS['_CFG']['kf'] != '')
            if ($GLOBALS['_CFG']['send_service_email'] == '1') {
                $tpl = get_mail_template('member_novalid');
                $smarty->assign('user', $user);
                $smarty->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
                $smarty->assign('send_date', date($GLOBALS['_CFG']['time_format']));
                $content = $smarty->fetch('str:' . $tpl['template_content']);
                send_mail($_CFG['shop_name'], "*****@*****.**", $tpl['template_subject'], $content, $tpl['is_html']);
            }
            $db->query("update " . $ecs->table("users") . " set member_novalid='1' and rank_points='0' where user_id=" . $user['user_id']);
            log_account_change($user['user_id'], 0, 0, -$user['rank_points'], 0, '会员过期自动清理', ACT_OTHER);
        }
    }
    exit;
}
?>
 
/**
 *  虚拟卡发货
 *
 * @access  public
 * @param   string      $goods      商品详情数组
 * @param   string      $order_sn   本次操作的订单
 * @param   string      $msg        返回信息
 * @param   string      $process    设定当前流程:split,发货分单流程;other,其他,默认。
 *
 * @return  boolen
 */
function virtual_card_shipping($goods, $order_sn, &$msg, $process = 'other')
{
    /* 包含加密解密函数所在文件 */
    include_once ROOT_PATH . 'includes/lib_code.php';
    /* 检查有没有缺货 */
    $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('virtual_card') . " WHERE goods_id = '{$goods['goods_id']}' AND is_saled = 0 ";
    $num = $GLOBALS['db']->GetOne($sql);
    if ($num < $goods['num']) {
        $msg .= sprintf($GLOBALS['_LANG']['virtual_card_oos'], $goods['goods_name']);
        return false;
    }
    /* 取出卡片信息 */
    $sql = "SELECT card_id, card_sn, card_password, end_date, crc32 FROM " . $GLOBALS['ecs']->table('virtual_card') . " WHERE goods_id = '{$goods['goods_id']}' AND is_saled = 0  LIMIT " . $goods['num'];
    $arr = $GLOBALS['db']->getAll($sql);
    $card_ids = array();
    $cards = array();
    foreach ($arr as $virtual_card) {
        $card_info = array();
        /* 卡号和密码解密 */
        if ($virtual_card['crc32'] == 0 || $virtual_card['crc32'] == crc32(AUTH_KEY)) {
            $card_info['card_sn'] = decrypt($virtual_card['card_sn']);
            $card_info['card_password'] = decrypt($virtual_card['card_password']);
        } elseif ($virtual_card['crc32'] == crc32(OLD_AUTH_KEY)) {
            $card_info['card_sn'] = decrypt($virtual_card['card_sn'], OLD_AUTH_KEY);
            $card_info['card_password'] = decrypt($virtual_card['card_password'], OLD_AUTH_KEY);
        } else {
            $msg .= 'error key';
            return false;
        }
        $card_info['end_date'] = date($GLOBALS['_CFG']['date_format'], $virtual_card['end_date']);
        $card_ids[] = $virtual_card['card_id'];
        $cards[] = $card_info;
    }
    /* 标记已经取出的卡片 */
    $sql = "UPDATE " . $GLOBALS['ecs']->table('virtual_card') . " SET " . "is_saled = 1 ," . "order_sn = '{$order_sn}' " . "WHERE " . db_create_in($card_ids, 'card_id');
    if (!$GLOBALS['db']->query($sql, 'SILENT')) {
        $msg .= $GLOBALS['db']->error();
        return false;
    }
    /* 更新库存 */
    $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET goods_number = goods_number - '{$goods['num']}' WHERE goods_id = '{$goods['goods_id']}'";
    $GLOBALS['db']->query($sql);
    if (true) {
        /* 获取订单信息 */
        $sql = "SELECT order_id, order_sn, consignee, email FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_sn = '{$order_sn}'";
        $order = $GLOBALS['db']->GetRow($sql);
        /* 更新订单信息 */
        if ($process == 'split') {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('order_goods') . "\n                    SET send_number = send_number + '" . $goods['num'] . "'\n                    WHERE order_id = '" . $order['order_id'] . "'\n                    AND goods_id = '" . $goods['goods_id'] . "' ";
        } else {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('order_goods') . "\n                    SET send_number = '" . $goods['num'] . "'\n                    WHERE order_id = '" . $order['order_id'] . "'\n                    AND goods_id = '" . $goods['goods_id'] . "' ";
        }
        if (!$GLOBALS['db']->query($sql, 'SILENT')) {
            $msg .= $GLOBALS['db']->error();
            return false;
        }
    }
    /* 发送邮件 */
    $GLOBALS['smarty']->assign('virtual_card', $cards);
    $GLOBALS['smarty']->assign('order', $order);
    $GLOBALS['smarty']->assign('goods', $goods);
    $GLOBALS['smarty']->assign('send_time', date('Y-m-d H:i:s'));
    $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
    $GLOBALS['smarty']->assign('send_date', date('Y-m-d'));
    $GLOBALS['smarty']->assign('sent_date', date('Y-m-d'));
    $tpl = get_mail_template('virtual_card');
    $content = $GLOBALS['smarty']->fetch('str:' . $tpl['template_content']);
    send_mail($order['consignee'], $order['email'], $tpl['template_subject'], $content, $tpl['is_html']);
    return true;
}
Esempio n. 28
0
 function send_mail_attachment($email, $type_of_member, $yesterday = false)
 {
     $ci =& get_instance();
     $ci->load->model('outgoing_email_model');
     $ci->load->model('outgoing_email_yesterday_model');
     $ci->load->model('user_model');
     if ($yesterday == true) {
         $get_email_con = $ci->outgoing_email_yesterday_model->get_outgoing_email_yesterday_by_field_value_array(array("email", "type_of_member"), array($email, $type_of_member));
     } else {
         $get_email_con = $ci->outgoing_email_model->get_outgoing_email_by_field_value_array(array("email", "type_of_member"), array($email, $type_of_member));
     }
     $ci->load->helper('email');
     //load email library
     $config = array('protocol' => 'smtp', 'smtp_host' => 'ssl://secure146.inmotionhosting.com', 'smtp_port' => 465, 'smtp_user' => '*****@*****.**', 'smtp_pass' => 'G#-(6Z{!d)LJ', 'mailtype' => 'html', 'charset' => 'iso-8859-1');
     $ci->load->library('email', $config);
     $ci->email->set_newline("\r\n");
     if (valid_email($email)) {
         // compose email
         $ci->email->clear(TRUE);
         $get_admin_detail = get_admin_detail();
         //common helper function for admin detail
         //$config['protocol'] = 'sendmail';
         //            $config['mailpath'] = '/usr/sbin/sendmail';
         //            $config['charset'] = 'iso-8859-1';
         //            $config['mailtype'] = 'html';
         //            $config['priority'] = 3;
         //            $ci->email->initialize($config);
         $ci->email->from("*****@*****.**", $get_admin_detail['name']);
         $ci->email->to($email);
         $ci->email->set_mailtype("html");
         //$ci->email->subject("knewdog! newsletter");
         $random_adds = get_random_adds($get_email_con[0]['user_id']);
         $user_data = $ci->user_model->get_user_by_id($get_email_con[0]['user_id']);
         $username = $user_data[0]['username'];
         //$link = site_url() . 'signin/mynewsletter/' . base64url_encode($user_data[0]['primary_email']); //site_url("");
         $link = '<a href="' . site_url() . '">www.knewdog.com</a>';
         if (!empty($type_of_member)) {
             if ($type_of_member == "FREE") {
                 $email_template_id = 10;
                 $replace = array('{random_ads}', '{user_name}', '{link}');
                 $with = array("{$random_adds}", "{$username}", "{$link}");
             } elseif ($type_of_member == "PRE1" || $type_of_member == "PRE2") {
                 if ($user_data[0]['no_ads'] == 'NO') {
                     $email_template_id = 11;
                     $replace = array('{random_ads}', '{user_name}', '{link}');
                     $with = array("{$random_adds}", "{$username}", "{$link}");
                 } else {
                     $email_template_id = 12;
                     $replace = array('{user_name}', '{link}');
                     $with = array("{$username}", "{$link}");
                 }
             }
         } else {
             echo "Type of member is empty";
         }
         $language_interface = $ci->user_model->get_user_by_filed_2("user.user_id", $get_email_con[0]['user_id']);
         //echo '<pre>';print_r($language_interface);
         //die;
         $session_lang = $language_interface[0]['language_shortcode'];
         //$this->session->userdata('language_shortcode');
         $htmlcontent = get_mail_template($replace, $with, $email_template_id, $session_lang);
         //echo $htmlcontent;exit;
         //exit;
         $ci->email->message($htmlcontent);
         //echo "cmming";exit;
         $filename_array = array();
         $sent_attach = 0;
         for ($i = 0; $i < count($get_email_con); $i++) {
             $check_adult_tag = check_adult_content_tag($get_email_con[$i]['newsletter_rand_id'], $get_email_con[$i]['user_id']);
             if ($check_adult_tag == true) {
                 $htmlname = "newsletter_" . rand() . ".html";
                 $filename = FCPATH . "uploads/newsletters/" . $htmlname;
                 $myfile = fopen($filename, "w") or die("Unable to open file!");
                 $txt = $get_email_con[$i]['content'];
                 fwrite($myfile, $txt);
                 fclose($myfile);
                 $filename_array[] = $filename;
                 $ci->email->attach($filename);
                 $sent_attach++;
             }
         }
         if ($sent_attach > 0) {
             //echo "hiii";exit;
             if ($ci->email->send()) {
                 echo "<br>mail sent with attachment " . count($filename_array);
                 $return = true;
             } else {
                 echo "mail not sent";
                 $return = false;
             }
         } else {
             echo "<br>No Attachment";
             $return = false;
         }
         for ($f = 0; $f < count($filename_array); $f++) {
             @unlink($filename_array[$f]);
         }
     }
 }
Esempio n. 29
0
/*------------------------------------------------------ */
//-- 处理提交数据
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'update') {
    /* 权限判断 */
    admin_priv('booking');
    $dispose_note = !empty($_POST['dispose_note']) ? trim($_POST['dispose_note']) : '';
    $sql = "UPDATE  " . $ecs->table('booking_goods') . " SET is_dispose='1', dispose_note='{$dispose_note}', " . "dispose_time='" . gmtime() . "', dispose_user='******'admin_name'] . "'" . " WHERE rec_id='{$_REQUEST['rec_id']}'";
    $db->query($sql);
    /* 邮件通知处理流程 */
    if (!empty($_POST['send_email_notice']) or isset($_POST['remail'])) {
        //获取邮件中的必要内容
        $sql = 'SELECT bg.email, bg.link_man, bg.goods_id, g.goods_name ' . 'FROM ' . $ecs->table('booking_goods') . ' AS bg, ' . $ecs->table('goods') . ' AS g ' . "WHERE bg.goods_id = g.goods_id AND bg.rec_id='{$_REQUEST['rec_id']}'";
        $booking_info = $db->getRow($sql);
        /* 设置缺货回复模板所需要的内容信息 */
        $template = get_mail_template('goods_booking');
        $goods_link = $ecs->url() . 'goods.php?id=' . $booking_info['goods_id'];
        $smarty->assign('user_name', $booking_info['link_man']);
        $smarty->assign('goods_link', $goods_link);
        $smarty->assign('goods_name', $booking_info['goods_name']);
        $smarty->assign('dispose_note', $dispose_note);
        $smarty->assign('shop_name', "<a href='" . $ecs->url() . "'>" . $_CFG['shop_name'] . '</a>');
        $smarty->assign('send_date', date('Y-m-d'));
        $content = $smarty->fetch('str:' . $template['template_content']);
        /* 发送邮件 */
        if (send_mail($booking_info['link_man'], $booking_info['email'], $template['template_subject'], $content, $template['is_html'])) {
            $send_ok = 0;
        } else {
            $send_ok = 1;
        }
    }
Esempio n. 30
0
/**
 * 发送红包邮件
 * @param   int     $bonus_type_id  红包类型id
 * @param   array   $bonus_id_list  红包id数组
 * @return  int     成功发送数量
 */
function send_bonus_mail($bonus_type_id, $bonus_id_list)
{
    /* 取得红包类型信息 */
    $bonus_type = bonus_type_info($bonus_type_id);
    if ($bonus_type['send_type'] != SEND_BY_USER) {
        return 0;
    }
    /* 取得属于该类型的红包信息 */
    $sql = "SELECT b.bonus_id, u.user_name, u.email " . "FROM " . $GLOBALS['ecs']->table('user_bonus') . " AS b, " . $GLOBALS['ecs']->table('users') . " AS u " . " WHERE b.user_id = u.user_id " . " AND b.bonus_id " . db_create_in($bonus_id_list) . " AND b.order_id = 0 " . " AND u.email <> ''";
    $bonus_list = $GLOBALS['db']->getAll($sql);
    if (empty($bonus_list)) {
        return 0;
    }
    /* 初始化成功发送数量 */
    $send_count = 0;
    /* 发送邮件 */
    $tpl = get_mail_template('send_bonus');
    $today = local_date($GLOBALS['_CFG']['date_format']);
    foreach ($bonus_list as $bonus) {
        $GLOBALS['smarty']->assign('user_name', $bonus['user_name']);
        $GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
        $GLOBALS['smarty']->assign('send_date', $today);
        $GLOBALS['smarty']->assign('sent_date', $today);
        $GLOBALS['smarty']->assign('count', 1);
        $GLOBALS['smarty']->assign('money', price_format($bonus_type['type_money']));
        $content = $GLOBALS['smarty']->fetch('str:' . $tpl['template_content']);
        if (add_to_maillist($bonus['user_name'], $bonus['email'], $tpl['template_subject'], $content, $tpl['is_html'], false)) {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('user_bonus') . " SET emailed = '" . BONUS_MAIL_SUCCEED . "'" . " WHERE bonus_id = '{$bonus['bonus_id']}'";
            $GLOBALS['db']->query($sql);
            $send_count++;
        } else {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('user_bonus') . " SET emailed = '" . BONUS_MAIL_FAIL . "'" . " WHERE bonus_id = '{$bonus['bonus_id']}'";
            $GLOBALS['db']->query($sql);
        }
    }
    return $send_count;
}