/** * 保存用户收货地址 * * @access public * @param array $address array_keys(consignee string, email string, address string, zipcode string, tel string, mobile stirng, sign_building string, best_time string, order_id int) * @param int $user_id 用户ID * * @return boolen $bool */ function save_order_address($address, $user_id) { ECTouch::err()->clean(); /* 数据验证 */ empty($address['consignee']) and ECTouch::err()->add(L('consigness_empty')); empty($address['address']) and ECTouch::err()->add(L('address_empty')); $address['order_id'] == 0 and ECTouch::err()->add(L('order_id_empty')); if (empty($address['email'])) { ECTouch::err()->add($GLOBALS['email_empty']); } else { if (!is_email($address['email'])) { ECTouch::err()->add(sprintf(L('email_invalid'), $address['email'])); } } if (ECTouch::err()->error_no > 0) { return false; } /* 检查订单状态 */ $sql = "SELECT user_id, order_status FROM " . $this->pre . "order_info WHERE order_id = '" . $address['order_id'] . "'"; $row = $this->row($sql); if ($row) { if ($user_id > 0 && $user_id != $row['user_id']) { ECTouch::err()->add(L('no_priv')); return false; } if ($row['order_status'] != OS_UNCONFIRMED) { ECTouch::err()->add(L('require_unconfirmed')); return false; } $this->table = 'order_info'; $condition['order_id'] = $address['order_id']; $this->update($condition, $address); return true; } else { /* 订单不存在 */ ECTouch::err()->add(L('order_exist')); return false; } }
/** * 注册 */ public function register() { // 注册处理 if (IS_POST) { $enabled_sms = isset($_POST['enabled_sms']) ? intval($_POST['enabled_sms']) : 0; $this->back_act = isset($_POST['back_act']) ? in($_POST['back_act']) : ''; // 邮箱注册处理 if (0 == $enabled_sms) { // 数据处理 $username = isset($_POST['username']) ? in($_POST['username']) : ''; $email = isset($_POST['email']) ? in($_POST['email']) : ''; $password = isset($_POST['password']) ? in($_POST['password']) : ''; $other = array(); // 验证码检查 if (intval(C('captcha')) & CAPTCHA_REGISTER) { if (empty($_POST['captcha'])) { show_message(L('invalid_captcha'), L('sign_up'), url('register'), 'error'); } // 检查验证码 if ($_SESSION['ectouch_verify'] !== strtoupper($_POST['captcha'])) { show_message(L('invalid_captcha'), L('sign_up'), url('register'), 'error'); } } if (empty($_POST['agreement'])) { show_message(L('passport_js.agreement')); } if (strlen($username) < 3) { show_message(L('passport_js.username_shorter')); } if (strlen($username) > 15) { show_message(L('passport_js.username_longer')); } if (strlen($password) < 6) { show_message(L('passport_js.password_shorter')); } if (strpos($password, ' ') > 0) { show_message(L('passwd_balnk')); } } elseif (1 == $enabled_sms) { $username = isset($_POST['mobile']) ? in($_POST['mobile']) : ''; $password = isset($_POST['mobile_code']) ? in($_POST['mobile_code']) : ''; $sms_code = isset($_POST['sms_code']) ? in($_POST['sms_code']) : ''; $other['mobile_phone'] = $username; if (empty($username)) { show_message(L('msg_mobile_blank'), L('register_back'), url('register'), 'error'); } if ($sms_code != $_SESSION['sms_code']) { show_message(L('sms_code_error'), L('register_back'), url('register'), 'error'); } if ($password != $_SESSION['sms_mobile_code']) { show_message(L('mobile_code_error'), L('register_back'), url('register'), 'error'); } // 验证手机号重复 $where['mobile_phone'] = $username; $user_id = $this->model->table('users')->field('user_id')->where($where)->getOne(); if ($user_id) { show_message(L('msg_mobile_exists'), L('register_back'), url('register'), 'error'); } // 设置一个默认的邮箱 $email = $username . '@qq.com'; } else { ECTouch::err()->show(L('sign_up'), url('register')); } /*把新注册用户的扩展信息插入数据库*/ $sql = 'SELECT id,is_need,reg_field_name FROM ' . M()->pre . 'reg_fields' . ' WHERE display = 1 ORDER BY dis_order, id'; //读出所有自定义扩展字段的id $fields_arr = M()->query($sql); $extend_field_str = ''; //生成扩展字段的内容字符串 foreach ($fields_arr as $val) { $extend_field_index = 'extend_field' . $val['id']; if (empty($_POST[$extend_field_index])) { if ($val['is_need'] == 1) { show_message($val['reg_field_name'] . L('can_not_empty'), L('register_back'), url('register'), 'error'); } } } if (model('Users')->register($username, $password, $email, $other) !== false) { $sel_question = I('post.sel_question'); $passwd_answer = I('post.passwd_answer'); // 写入密码提示问题和答案 if (!empty($passwd_answer) && !empty($sel_question)) { $where_up['user_id'] = $_SESSION['user_id']; $data_up['passwd_question'] = $sel_question; $data_up['passwd_answer'] = $passwd_answer; $this->model->table('users')->data($data_up)->where($where_up)->update(); } /*把新注册用户的扩展信息插入数据库*/ $sql = 'SELECT id,is_need,reg_field_name FROM ' . M()->pre . 'reg_fields' . ' WHERE display = 1 ORDER BY dis_order, id'; //读出所有自定义扩展字段的id $fields_arr = M()->query($sql); $extend_field_str = ''; //生成扩展字段的内容字符串 foreach ($fields_arr as $val) { $extend_field_index = 'extend_field' . $val['id']; if (!empty($_POST[$extend_field_index])) { $temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? mb_substr($_POST[$extend_field_index], 0, 99) : $_POST[$extend_field_index]; $extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . $temp_field_content . "'),"; } else { if ($val['is_need'] == 1) { show_message($val['reg_field_name'] . L('can_not_empty'), L('register_back'), url('register'), 'error'); } } } $extend_field_str = substr($extend_field_str, 0, -1); if ($extend_field_str) { $sql = 'INSERT INTO ' . M()->pre . 'reg_extend_info' . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str; M()->query($sql); } /* 写入密码提示问题和答案 */ if (!empty($passwd_answer) && !empty($sel_question)) { $sql = 'UPDATE ' . M()->pre . 'users' . " SET `passwd_question`='{$sel_question}', `passwd_answer`='{$passwd_answer}' WHERE `user_id`='" . $_SESSION['user_id'] . "'"; M()->query($sql); } // 判断是否需要自动发送注册邮件 if (C('member_email_validate') && C('send_verify_email')) { model('Users')->send_regiter_hash($_SESSION['user_id']); } $ucdata = empty(self::$user->ucdata) ? "" : self::$user->ucdata; show_message(sprintf(L('register_success'), $username . $ucdata), array(L('back_up_page'), L('profile_lnk')), array($this->back_act, url('index')), 'info'); } else { ECTouch::err()->show(L('sign_up'), url('register')); } exit; } /* 取出注册扩展字段 */ $sql = 'SELECT * FROM ' . M()->pre . 'reg_fields' . ' WHERE type < 2 AND display = 1 ORDER BY dis_order, id'; $extend_info_list = M()->query($sql); foreach ($extend_info_list as $key => $val) { if ($val['id'] >= 100) { unset($extend_info_list[$key]); } } $this->assign('extend_info_list', $extend_info_list); // 密码提示问题 $this->assign('password_question', L('passwd_questions')); // 注册页面显示 if (empty($this->back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) { $this->back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'c=user') ? url('index/index') : $GLOBALS['_SERVER']['HTTP_REFERER']; } // 验证码相关设置 if (intval(C('captcha')) & CAPTCHA_REGISTER) { $this->assign('enabled_captcha', 1); $this->assign('rand', mt_rand()); } // 短信开启 if (intval(C('sms_signin')) > 0) { $this->assign('enabled_sms_signin', C('sms_signin')); // 随机code $_SESSION['sms_code'] = $sms_code = md5(mt_rand(1000, 9999)); $this->assign('sms_code', $sms_code); } $this->assign('title', L('register')); $this->assign('back_act', $this->back_act); /* 是否关闭注册 */ $this->assign('shop_reg_closed', C('shop_reg_closed')); $this->display('user_register.dwt'); }
/** * 获取分销指订单的详情 * * @access public * @param int $order_id 订单ID * @param int $user_id 用户ID * * @return arr $order 订单所有信息的数组 */ function get_order_detail($order_id, $user_id = 0) { $order_id = intval($order_id); if ($order_id <= 0) { ECTouch::err()->add(L('invalid_order_id')); return false; } $order = model('Order')->order_info($order_id); //检查订单是否属于该用户 if ($user_id > 0 && $user_id != $order['parent_id']) { ECTouch::err()->add(L('no_priv')); return false; } /* 对发货号处理 */ if (!empty($order['invoice_no'])) { $sql = "SELECT shipping_code FROM " . $this->pre . "shipping WHERE shipping_id = '{$order['shipping_id']}'"; $res = $this->row($sql); $shipping_code = $res['shipping_code']; $plugin = ROOT_PATH . 'includes/modules/shipping/' . $shipping_code . '.php'; if (file_exists($plugin)) { include_once $plugin; $shipping = new $shipping_code(); $order['invoice_no'] = $shipping->query($order['invoice_no']); } } $order['allow_update_address'] = 0; /* 获取订单中实体商品数量 */ $order['exist_real_goods'] = model('Order')->exist_real_goods($order_id); /* 无配送时的处理 */ $order['shipping_id'] == -1 and $order['shipping_name'] = L('shipping_not_need'); /* 其他信息初始化 */ $order['how_oos_name'] = $order['how_oos']; $order['how_surplus_name'] = $order['how_surplus']; /* 确认时间 支付时间 发货时间 */ if ($order['confirm_time'] > 0 && ($order['order_status'] == OS_CONFIRMED || $order['order_status'] == OS_SPLITED || $order['order_status'] == OS_SPLITING_PART)) { $order['confirm_time'] = sprintf(L('confirm_time'), local_date(C('time_format'), $order['confirm_time'])); } else { $order['confirm_time'] = ''; } if ($order['pay_time'] > 0 && $order['pay_status'] != PS_UNPAYED) { $order['pay_time'] = sprintf(L('pay_time'), local_date(C('time_format'), $order['pay_time'])); } else { $order['pay_time'] = ''; } if ($order['shipping_time'] > 0 && in_array($order['shipping_status'], array(SS_SHIPPED, SS_RECEIVED))) { $order['shipping_time'] = sprintf(L('shipping_time'), local_date(C('time_format'), $order['shipping_time'])); } else { $order['shipping_time'] = ''; } return $order; }
/** * 将指定user_id的密码修改为new_password。可以通过旧密码和验证字串验证修改。 * * @access public * @param int $user_id 用户ID * @param string $new_password 用户新密码 * @param string $old_password 用户旧密码 * @param string $code 验证码(md5($user_id . md5($password))) * * @return boolen $bool */ function edit_password($user_id, $old_password, $new_password = '', $code = '') { if (empty($user_id)) { ECTouch::err()->add(L('not_login')); } if (ECTouch::user()->edit_password($user_id, $old_password, $new_password, $code)) { return true; } else { ECTouch::err()->add(L('edit_password_failure')); return false; } }
/** * 分销订单详情 */ public function order_detail() { $order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0; // 订单详情 $order = model('Sale')->get_order_detail($order_id, $this->user_id); if ($order === false) { ECTouch::err()->show(L('back_home_lnk'), './'); exit; } // 订单商品 $goods_list = model('Order')->order_goods($order_id); foreach ($goods_list as $key => $value) { $goods_list[$key]['market_price'] = price_format($value['market_price'], false); $goods_list[$key]['goods_price'] = price_format($value['goods_price'], false); $goods_list[$key]['subtotal'] = price_format($value['subtotal'], false); $goods_list[$key]['tags'] = model('ClipsBase')->get_tags($value['goods_id']); $goods_list[$key]['goods_thumb'] = get_image_path($order_id, $value['goods_thumb']); } // 订单 支付 配送 状态语言项 $order['order_status'] = L('os.' . $order['order_status']); $order['pay_status'] = L('ps.' . $order['pay_status']); $order['shipping_status'] = L('ss.' . $order['shipping_status']); $this->assign('title', L('order_detail')); $this->assign('order', $order); $this->assign('goods_list', $goods_list); $this->display('sale_order_detail.dwt'); }
/** * 登录信息 */ public function login() { //用户登录注册 if ($_SERVER['REQUEST_METHOD'] == 'GET') { $this->assign('anonymous_buy', C('anonymous_buy')); /* 检查是否有赠品,如果有提示登录后重新选择赠品 */ $count = $this->model->table('cart')->field('count(*)')->where("session_id = '" . SESS_ID . "' AND is_gift > 0")->getOne(); if ($count > 0) { $this->assign('need_rechoose_gift', 1); } /* 检查是否需要注册码 */ $captcha = intval(C('captcha')); if ($captcha & CAPTCHA_LOGIN && (!($captcha & CAPTCHA_LOGIN_FAIL) || $captcha & CAPTCHA_LOGIN_FAIL && $_SESSION['login_fail'] > 2) && gd_version() > 0) { $this->assign('enabled_login_captcha', 1); $this->assign('rand', mt_rand()); } if ($captcha & CAPTCHA_REGISTER) { $this->assign('enabled_register_captcha', 1); $this->assign('rand', mt_rand()); } } else { $act = in($_POST['act']); $username = in($_POST['username']); $password = in($_POST['password']); $remember = in($_POST['remember']); $email = in($_POST['email']); $post_captcha = in($_POST['captcha']); if ($act == 'signin') { $captcha = intval(C('captcha')); if ($captcha & CAPTCHA_LOGIN && (!($captcha & CAPTCHA_LOGIN_FAIL) || $captcha & CAPTCHA_LOGIN_FAIL && $_SESSION['login_fail'] > 2) && gd_version() > 0) { if (empty($post_captcha)) { show_message(L('invalid_captcha')); } if ($_SESSION['ectouch_verify'] !== $_POST['captcha']) { show_message(L('invalid_captcha')); } } if (self::$user->login($username, $password, isset($remember))) { model('Users')->update_user_info(); // 更新用户信息 model('Users')->recalculate_price(); // 重新计算购物车中的商品价格 /* 检查购物车中是否有商品 没有商品则跳转到首页 */ $count = $this->model->table('cart')->field('count(*)')->where("session_id = '" . SESS_ID . "'")->getOne(); if ($count > 0) { ecs_header("Location: " . url('flow/checkout') . "\n"); } else { ecs_header("Location:index.php\n"); } } else { $_SESSION['login_fail']++; show_message(L('signin_failed'), '', url('flow/index', array('step' => 'login'))); } } elseif ($act == 'signup') { if (intval(C('captcha')) & CAPTCHA_REGISTER && gd_version() > 0) { if (empty($post_captcha)) { show_message(L('invalid_captcha')); } if ($_SESSION['ectouch_verify'] !== $_POST['captcha']) { show_message(L('invalid_captcha')); } } if (model('Users')->register(trim($username), trim($password), trim($email))) { /* 用户注册成功 */ ecs_header("Location: " . url('flow/consignee') . "\n"); } else { ECTouch::err()->show(); } } else { // TODO: 非法访问的处理 } } $this->assign('currency_format', C('currency_format')); $this->assign('integral_scale', C('integral_scale')); $this->assign('step', ACTION_NAME); $this->assign('action', 'login'); /* 验证码相关设置 */ if (intval(C('captcha')) & CAPTCHA_REGISTER && gd_version() > 0) { $this->assign('enabled_captcha', 1); $this->assign('rand', mt_rand()); } $this->display('flow.dwt'); }
public function add_to_gift() { //对goods处理 $_POST['goods'] = strip_tags(urldecode($_POST['goods'])); $_POST['goods'] = json_str_iconv($_POST['goods']); if (!empty($_REQUEST['goods_id']) && empty($_POST['goods'])) { if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0) { ecs_header("Location:./\n"); } exit; } // 初始化返回数组 $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => ''); if (empty($_POST['goods'])) { $result['error'] = 1; die(json_encode($result)); } $json = new EcsJson(); $goods = $json->decode($_POST['goods']); $result['goods_id'] = $goods->goods_id; $result['product_spec'] = $goods->spec; // 检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台 if (empty($goods->spec) and empty($goods->quick)) { $sql = "SELECT a.attr_id, a.attr_name, a.attr_type, " . "g.goods_attr_id, g.attr_value, g.attr_price " . 'FROM ' . $this->model->pre . 'goods_attr AS g ' . 'LEFT JOIN ' . $this->model->pre . 'attribute AS a ON a.attr_id = g.attr_id ' . "WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " . 'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id'; $res = $this->model->query($sql); if (!empty($res)) { $spe_arr = array(); foreach ($res as $row) { $spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type']; $spe_arr[$row['attr_id']]['name'] = $row['attr_name']; $spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id']; $spe_arr[$row['attr_id']]['values'][] = array('label' => $row['attr_value'], 'price' => $row['attr_price'], 'format_price' => price_format($row['attr_price'], false), 'id' => $row['goods_attr_id']); } $i = 0; $spe_array = array(); foreach ($spe_arr as $row) { $spe_array[] = $row; } $result['error'] = ERR_NEED_SELECT_ATTR; $result['goods_id'] = $goods->goods_id; $result['parent'] = $goods->parent; $result['message'] = $spe_array; die(json_encode($result)); } } // 购买礼包商品清空购物车 model('Order')->clear_cart(CART_GIFT_GOODS); // 查询:系统启用了库存,检查输入的商品数量是否有效 // 查询 $arrGoods = $this->model->table('goods')->field('goods_name,goods_number,extension_code')->where('goods_id =' . $goods->goods_id)->find(); $goodsnmber = model('Users')->get_goods_number($goods->goods_id); $goodsnmber += $goods->number; if (intval(C('use_storage')) > 0) { if ($arrGoods['goods_number'] < $goodsnmber) { $result['error'] = 1; $result['message'] = sprintf(L('stock_insufficiency'), $arrGoods['goods_name'], $arrGoods['goods_number'], $arrGoods['goods_number']); if (C('use_how_oos') == 1) { $result['message'] = L('oos_tips'); } die(json_encode($result)); } } // 检查:商品数量是否合法 if (!is_numeric($goods->number) || intval($goods->number) <= 0) { $result['error'] = 1; $result['message'] = L('invalid_number'); } else { // 更新:添加到购物车 $_SESSION['flow_type'] = CART_GIFT_GOODS; $_SESSION['extension_code'] = "gift_goods"; $_SESSION['extension_id'] = CART_GIFT_GOODS; if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent, CART_GIFT_GOODS)) { if (C('cart_confirm') > 2) { $result['message'] = ''; } else { $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2'); } $result['content'] = insert_cart_info(); $result['one_step_buy'] = C('one_step_buy'); } else { $result['message'] = ECTouch::err()->last_message(); $result['error'] = ECTouch::err()->error_no; $result['goods_id'] = stripslashes($goods->goods_id); if (is_array($goods->spec)) { $result['product_spec'] = implode(',', $goods->spec); } else { $result['product_spec'] = $goods->spec; } } } $cart_confirm = C('cart_confirm'); $result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2; // 返回购物车商品总数量 $result['cart_number'] = insert_cart_info_number(); die(json_encode($result)); }
/** * 注册 */ public function register() { /*添加导航15-04-01*/ // 自定义导航栏 $navigator = model('Common')->get_navigator(); $this->assign('navigator', $navigator['middle']); /*end--*/ // 注册处理 if (IS_POST) { $enabled_sms = isset($_POST['enabled_sms']) ? intval($_POST['enabled_sms']) : 0; $this->back_act = isset($_POST['back_act']) ? in($_POST['back_act']) : ''; // 邮箱注册处理 if (0 == $enabled_sms) { // 数据处理 $username = isset($_POST['username']) ? in($_POST['username']) : ''; $email = isset($_POST['email']) ? in($_POST['email']) : ''; $password = isset($_POST['password']) ? in($_POST['password']) : ''; $other = array(); // 验证码检查 if (intval(C('captcha')) & CAPTCHA_REGISTER) { if (empty($_POST['captcha'])) { show_message(L('invalid_captcha'), L('sign_up'), url('register'), 'error'); } // 检查验证码 if ($_SESSION['ectouch_verify'] !== strtoupper($_POST['captcha'])) { show_message(L('invalid_captcha'), L('sign_up'), url('register'), 'error'); } } if (empty($_POST['agreement'])) { show_message(L('passport_js.agreement')); } if (strlen($username) < 3) { show_message(L('passport_js.username_shorter')); } if (strlen($username) > 15) { show_message(L('passport_js.username_longer')); } if (strlen($password) < 6) { show_message(L('passport_js.password_shorter')); } if (strpos($password, ' ') > 0) { show_message(L('passwd_balnk')); } } elseif (1 == $enabled_sms) { $username = isset($_POST['mobile']) ? in($_POST['mobile']) : ''; $password = isset($_POST['mobile_code']) ? in($_POST['mobile_code']) : ''; $sms_code = isset($_POST['sms_code']) ? in($_POST['sms_code']) : ''; $other['mobile_phone'] = $username; if (empty($username)) { show_message(L('msg_mobile_blank'), L('register_back'), url('register'), 'error'); } if ($sms_code != $_SESSION['sms_code']) { show_message(L('sms_code_error'), L('register_back'), url('register'), 'error'); } if ($password != $_SESSION['sms_mobile_code']) { show_message(L('mobile_code_error'), L('register_back'), url('register'), 'error'); } // 验证手机号重复 $where['mobile_phone'] = $username; $user_id = $this->model->table('users')->field('user_id')->where($where)->getOne(); if ($user_id) { show_message(L('msg_mobile_exists'), L('register_back'), url('register'), 'error'); } // 设置一个默认的邮箱 $email = $username . '@qq.com'; } else { ECTouch::err()->show(L('sign_up'), url('register')); } if (model('Users')->register($username, $password, $email, $other) !== false) { // 判断是否需要自动发送注册邮件 if (C('member_email_validate') && C('send_verify_email')) { model('Users')->send_regiter_hash($_SESSION['user_id']); } $ucdata = empty(self::$user->ucdata) ? "" : self::$user->ucdata; show_message(sprintf(L('register_success'), $username . $ucdata), array(L('back_up_page'), L('profile_lnk')), array($this->back_act, url('index')), 'info'); } else { ECTouch::err()->show(L('sign_up'), url('register')); } exit; } // 注册页面显示 if (empty($this->back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) { $this->back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'c=user') ? url('index/index') : $GLOBALS['_SERVER']['HTTP_REFERER']; } // 验证码相关设置 if (intval(C('captcha')) & CAPTCHA_REGISTER) { $this->assign('enabled_captcha', 1); $this->assign('rand', mt_rand()); } // 短信开启 if (intval(C('sms_signin')) > 0) { $this->assign('enabled_sms_signin', C('sms_signin')); // 随机code $_SESSION['sms_code'] = $sms_code = md5(mt_rand(1000, 9999)); $this->assign('sms_code', $sms_code); } $this->assign('title', L('register')); $this->assign('back_act', $this->back_act); /* 是否关闭注册 */ $this->assign('shop_reg_closed', C('shop_reg_closed')); $this->display('user_register.dwt'); }
/** * 添加留言函数 * @access public * @param array $message * @return boolen $bool */ public function add_message($message) { $upload_size_limit = C('upload_size_limit') == '-1' ? ini_get('upload_max_filesize') : C('upload_size_limit'); $status = 1 - C('message_check'); $last_char = strtolower($upload_size_limit[strlen($upload_size_limit) - 1]); switch ($last_char) { case 'm': $upload_size_limit *= 1024 * 1024; break; case 'k': $upload_size_limit *= 1024; break; } if ($message['upload']) { if ($_FILES['message_img']['size'] / 1024 > $upload_size_limit) { ECTouch::err()->add(sprintf(L('upload_file_limit'), $upload_size_limit)); return false; } $img_name = upload_file($_FILES['message_img'], 'feedbackimg'); if ($img_name === false) { return false; } } else { $img_name = ''; } if (empty($message['msg_title'])) { ECTouch::err()->add(L('msg_title_empty')); return false; } $message['msg_area'] = isset($message['msg_area']) ? intval($message['msg_area']) : 0; $data['msg_id'] = NULL; $data['parent_id'] = 0; $data['user_id'] = $message['user_id']; $data['user_name'] = $message['user_name']; $data['user_email'] = $message['user_email']; $data['msg_title'] = $message['msg_title']; $data['msg_type'] = $message['msg_type']; $data['msg_status'] = $status; $data['msg_content'] = $message['msg_content']; $data['msg_time'] = gmtime(); $data['message_img'] = $img_name; $data['order_id'] = $message['order_id']; $data['msg_area'] = $message['msg_area']; $this->table = 'feedback'; $this->insert($data); return true; }
/** * 添加礼包到购物车 */ public function add_package_to_cart() { $_POST['package_info'] = json_str_iconv($_POST['package_info']); $result = array('error' => 0, 'message' => '', 'content' => '', 'package_id' => ''); if (empty($_POST['package_info'])) { $result['error'] = 1; die(json_encode($result)); } $json = new EcsJson(); $package = $json->decode($_POST['package_info']); /* 如果是一步购物,先清空购物车 */ if (C('one_step_buy') == '1') { model('Order')->clear_cart(); } /* 商品数量是否合法 */ if (!is_numeric($package->number) || intval($package->number) <= 0) { $result['error'] = 1; $result['message'] = L('invalid_number'); } else { /* 添加到购物车 */ if (model('Order')->add_package_to_cart($package->package_id, $package->number)) { if (C('cart_confirm') > 2) { $result['message'] = ''; } else { $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2'); } $result['content'] = insert_cart_info(); $result['one_step_buy'] = C('one_step_buy'); } else { $result['message'] = ECTouch::err()->last_message(); $result['error'] = ECTouch::err()->error_no; $result['package_id'] = stripslashes($package->package_id); } } $cart_confirm = C('cart_confirm'); $result['confirm_type'] = !empty($cart_confirm) ? $cart_confirm : 2; die(json_encode($result)); }
/** * 添加商品到购物车 * * @access public * @param integer $goods_id 商品编号 * @param integer $num 商品数量 * @param array $spec 规格值对应的id数组 * @param integer $parent 基本件 * @return boolean */ function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0, $rec_type = 0) { ECTouch::err()->clean(); $_parent_id = $parent; /* 取得商品信息 */ $sql = "SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, " . "g.market_price, g.shop_price AS org_price, g.promote_price, g.promote_start_date, " . "g.promote_end_date, g.goods_weight, g.integral, g.extension_code, " . "g.goods_number, g.is_alone_sale, g.is_shipping," . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . " FROM " . $this->pre . "goods AS g " . " LEFT JOIN " . $this->pre . "member_price AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE g.goods_id = '{$goods_id}'" . " AND g.is_delete = 0"; $goods = $this->row($sql); if (empty($goods)) { ECTouch::err()->add(L('goods_not_exists'), ERR_NOT_EXISTS); return false; } /* 如果是作为配件添加到购物车的,需要先检查购物车里面是否已经有基本件 */ if ($parent > 0) { $sql = "SELECT COUNT(*) as count FROM " . $this->pre . "cart WHERE goods_id='{$parent}' AND session_id='" . SESS_ID . "'"; $res = $this->row($sql); if ($res['count'] == 0) { ECTouch::err()->add(L('no_basic_goods'), ERR_NO_BASIC_GOODS); return false; } } /* 是否正在销售 */ if ($goods['is_on_sale'] == 0) { ECTouch::err()->add(L('not_on_sale'), ERR_NOT_ON_SALE); return false; } /* 不是配件时检查是否允许单独销售 */ if (empty($parent) && $goods['is_alone_sale'] == 0) { ECTouch::err()->add(L('cannt_alone_sale'), ERR_CANNT_ALONE_SALE); return false; } /* 如果商品有规格则取规格商品信息 配件除外 */ $sql = "SELECT * FROM " . $this->pre . "products WHERE goods_id = '{$goods_id}' LIMIT 0, 1"; $prod = $this->row($sql); if (model('GoodsBase')->is_spec($spec) && !empty($prod)) { $product_info = model('ProductsBase')->get_products_info($goods_id, $spec); } if (empty($product_info)) { $product_info = array('product_number' => '', 'product_id' => 0); } /* 检查:库存 */ if (C('use_storage') == 1) { //检查:商品购买数量是否大于总库存 if ($num > $goods['goods_number']) { ECTouch::err()->add(sprintf(L('shortage'), $goods['goods_number']), ERR_OUT_OF_STOCK); return false; } //商品存在规格 是货品 检查该货品库存 if (model('GoodsBase')->is_spec($spec) && !empty($prod)) { if (!empty($spec)) { /* 取规格的货品库存 */ if ($num > $product_info['product_number']) { ECTouch::err()->add(sprintf(L('shortage'), $product_info['product_number']), ERR_OUT_OF_STOCK); return false; } } } } /* 计算商品的促销价格 */ $spec_price = model('Goods')->spec_price($spec); $goods_price = model('GoodsBase')->get_final_price($goods_id, $num, true, $spec); $goods['market_price'] += $spec_price; $goods_attr = $this->get_goods_attr_info($spec); $goods_attr_id = join(',', $spec); /* 初始化要插入购物车的基本件数据 */ $parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods_id, 'goods_sn' => addslashes($goods['goods_sn']), 'product_id' => $product_info['product_id'], 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $goods_attr_id, 'is_real' => $goods['is_real'], 'extension_code' => $goods['extension_code'], 'is_gift' => 0, 'is_shipping' => $goods['is_shipping'], 'rec_type' => CART_GENERAL_GOODS); if ($rec_type) { $parent['rec_type'] = $rec_type; } /* 如果该配件在添加为基本件的配件时,所设置的“配件价格”比原价低,即此配件在价格上提供了优惠, */ /* 则按照该配件的优惠价格卖,但是每一个基本件只能购买一个优惠价格的“该配件”,多买的“该配件”不享 */ /* 受此优惠 */ $basic_list = array(); $sql = "SELECT parent_id, goods_price " . "FROM " . $this->pre . "group_goods WHERE goods_id = '{$goods_id}'" . " AND goods_price < '{$goods_price}'" . " AND parent_id = '{$_parent_id}'" . " ORDER BY goods_price"; $res = $this->query($sql); foreach ($res as $row) { $basic_list[$row['parent_id']] = $row['goods_price']; } /* 取得购物车中该商品每个基本件的数量 */ $basic_count_list = array(); if ($basic_list) { $sql = "SELECT goods_id, SUM(goods_number) AS count " . "FROM " . $this->pre . "cart WHERE session_id = '" . SESS_ID . "'" . " AND parent_id = 0" . " AND goods_id " . db_create_in(array_keys($basic_list)) . " GROUP BY goods_id"; $res = $this->query($sql); foreach ($res as $row) { $basic_count_list[$row['goods_id']] = $row['count']; } } /* 取得购物车中该商品每个基本件已有该商品配件数量,计算出每个基本件还能有几个该商品配件 */ /* 一个基本件对应一个该商品配件 */ if ($basic_count_list) { $sql = "SELECT parent_id, SUM(goods_number) AS count " . "FROM " . $this->pre . "cart WHERE session_id = '" . SESS_ID . "'" . " AND goods_id = '{$goods_id}'" . " AND parent_id " . db_create_in(array_keys($basic_count_list)) . " GROUP BY parent_id"; $res = $this->query($sql); foreach ($res as $row) { $basic_count_list[$row['parent_id']] -= $row['count']; } } /* 循环插入配件 如果是配件则用其添加数量依次为购物车中所有属于其的基本件添加足够数量的该配件 */ foreach ($basic_list as $parent_id => $fitting_price) { /* 如果已全部插入,退出 */ if ($num <= 0) { break; } /* 如果该基本件不再购物车中,执行下一个 */ if (!isset($basic_count_list[$parent_id])) { continue; } /* 如果该基本件的配件数量已满,执行下一个基本件 */ if ($basic_count_list[$parent_id] <= 0) { continue; } /* 作为该基本件的配件插入 */ $parent['goods_price'] = max($fitting_price, 0) + $spec_price; //允许该配件优惠价格为0 $parent['goods_number'] = min($num, $basic_count_list[$parent_id]); $parent['parent_id'] = $parent_id; /* 添加 */ $this->table = 'cart'; $this->insert($parent); /* 改变数量 */ $num -= $parent['goods_number']; } /* 如果数量不为0,作为基本件插入 */ if ($num > 0) { /* 检查该商品是否已经存在在购物车中 */ $sql = "SELECT goods_number FROM " . $this->pre . "cart WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$goods_id}' " . " AND parent_id = 0 AND goods_attr = '" . $this->get_goods_attr_info($spec) . "' " . " AND rec_type = '{$rec_type}'"; $row = $this->row($sql); if ($row) { //如果购物车已经有此物品,则更新 $num += $row['goods_number']; if (model('GoodsBase')->is_spec($spec) && !empty($prod)) { $goods_storage = $product_info['product_number']; } else { $goods_storage = $goods['goods_number']; } if (C('use_storage') == 0 || $num <= $goods_storage) { $goods_price = model('GoodsBase')->get_final_price($goods_id, $num, true, $spec); $sql = "UPDATE " . $this->pre . "cart SET goods_number = '{$num}'" . " , goods_price = '{$goods_price}'" . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$goods_id}' " . " AND parent_id = 0 AND goods_attr = '" . $this->get_goods_attr_info($spec) . "' " . "AND rec_type = 'CART_GENERAL_GOODS'"; $this->query($sql); } else { ECTouch::err()->add(sprintf(L('shortage'), $num), ERR_OUT_OF_STOCK); return false; } } else { //购物车没有此物品,则插入 $goods_price = model('GoodsBase')->get_final_price($goods_id, $num, true, $spec); $parent['goods_price'] = max($goods_price, 0); $parent['goods_number'] = $num; $parent['parent_id'] = 0; $this->table = 'cart'; $this->insert($parent); } } /* 把赠品删除 */ $sql = "DELETE FROM " . $this->pre . "cart WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0"; $this->query($sql); return true; }
/** * 邮件发送 * * @param: $name[string] 接收人姓名 * @param: $email[string] 接收人邮件地址 * @param: $subject[string] 邮件标题 * @param: $content[string] 邮件内容 * @param: $type[int] 0 普通邮件, 1 HTML邮件 * @param: $notification[bool] true 要求回执, false 不用回执 * * @return boolean */ function send_mail($name, $email, $subject, $content, $type = 0, $notification = false) { /* 如果邮件编码不是EC_CHARSET,创建字符集转换对象,转换编码 */ if (C('mail_charset') != EC_CHARSET) { $name = ecs_iconv(EC_CHARSET, C('mail_charset'), $name); $subject = ecs_iconv(EC_CHARSET, C('mail_charset'), $subject); $content = ecs_iconv(EC_CHARSET, C('mail_charset'), $content); $shop_name = ecs_iconv(EC_CHARSET, C('mail_charset'), C('shop_name')); } $charset = C('mail_charset'); /** * 使用mail函数发送邮件 */ if (C('mail_service') == 0 && function_exists('mail')) { /* 邮件的头部信息 */ $content_type = ($type == 0) ? 'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset; $headers = array(); $headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . C('smtp_mail') . '>'; $headers[] = $content_type . '; format=flowed'; if ($notification) { $headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . C('smtp_mail') . '>'; } $res = @mail($email, '=?' . $charset . '?B?' . base64_encode($subject) . '?=', $content, implode("\r\n", $headers)); if (!$res) { ECTouch::err()->add(L('sendemail_false')); return false; } else { return true; } } /** * 使用smtp服务发送邮件 */ else { /* 邮件的头部信息 */ $content_type = ($type == 0) ? 'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset; $content = base64_encode($content); $headers = array(); $headers[] = 'Date: ' . gmdate('D, j M Y H:i:s') . ' +0000'; $headers[] = 'To: "' . '=?' . $charset . '?B?' . base64_encode($name) . '?=' . '" <' . $email . '>'; $headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . C('smtp_mail') . '>'; $headers[] = 'Subject: ' . '=?' . $charset . '?B?' . base64_encode($subject) . '?='; $headers[] = $content_type . '; format=flowed'; $headers[] = 'Content-Transfer-Encoding: base64'; $headers[] = 'Content-Disposition: inline'; if ($notification) { $headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . C('smtp_mail') . '>'; } /* 获得邮件服务器的参数设置 */ $params['host'] = C('smtp_host'); $params['port'] = C('smtp_port'); $params['user'] = C('smtp_user'); $params['pass'] = C('smtp_pass'); if (empty($params['host']) || empty($params['port'])) { // 如果没有设置主机和端口直接返回 false ECTouch::err()->add(L('smtp_setting_error')); return false; } else { // 发送邮件 if (!function_exists('fsockopen')) { //如果fsockopen被禁用,直接返回 ECTouch::err()->add(L('disabled_fsockopen')); return false; } static $smtp; $send_params['recipients'] = $email; $send_params['headers'] = $headers; $send_params['from'] = C('smtp_mail'); $send_params['body'] = $content; if (!isset($smtp)) { $smtp = new EcsSmtp($params); } if ($smtp->connect() && $smtp->send($send_params)) { return true; } else { $err_msg = $smtp->error_msg(); if (empty($err_msg)) { ECTouch::err()->add('Unknown Error'); } else { if (strpos($err_msg, 'Failed to connect to server') !== false) { ECTouch::err()->add(sprintf(L('smtp_connect_failure'), $params['host'] . ':' . $params['port'])); } else if (strpos($err_msg, 'AUTH command failed') !== false) { ECTouch::err()->add(L('smtp_login_failure')); } elseif (strpos($err_msg, 'bad sequence of commands') !== false) { ECTouch::err()->add(L('smtp_refuse')); } else { ECTouch::err()->add($err_msg); } } return false; } } } }
/** * 添加礼包到购物车 * * @access public * @param integer $package_id 礼包编号 * @param integer $num 礼包数量 * @return boolean */ function add_package_to_cart($package_id, $num = 1) { ECTouch::err()->clean(); /* 取得礼包信息 */ $package = get_package_info($package_id); if (empty($package)) { ECTouch::err()->add(L('goods_not_exists'), ERR_NOT_EXISTS); return false; } /* 是否正在销售 */ if ($package['is_on_sale'] == 0) { ECTouch::err()->add(L('not_on_sale'), ERR_NOT_ON_SALE); return false; } /* 现有库存是否还能凑齐一个礼包 */ if (C('use_storage') == '1' && model('Order')->judge_package_stock($package_id)) { ECTouch::err()->add(sprintf(L('shortage'), 1), ERR_OUT_OF_STOCK); return false; } /* 检查库存 */ // if (C('use_storage') == 1 && $num > $package['goods_number']) // { // $num = $goods['goods_number']; // ECTouch::err()->add(sprintf(L('shortage'), $num), ERR_OUT_OF_STOCK); // // return false; // } /* 初始化要插入购物车的基本件数据 */ $parent = array( 'user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $package_id, 'goods_sn' => '', 'goods_name' => addslashes($package['package_name']), 'market_price' => $package['market_package'], 'goods_price' => $package['package_price'], 'goods_number' => $num, 'goods_attr' => '', 'goods_attr_id' => '', 'is_real' => $package['is_real'], 'extension_code' => 'package_buy', 'is_gift' => 0, 'rec_type' => CART_GENERAL_GOODS ); /* 如果数量不为0,作为基本件插入 */ if ($num > 0) { /* 检查该商品是否已经存在在购物车中 */ $sql = "SELECT goods_number FROM " . $this->pre . "cart WHERE session_id = '" . SESS_ID . "' AND goods_id = '" . $package_id . "' " . " AND parent_id = 0 AND extension_code = 'package_buy' " . " AND rec_type = '" . CART_GENERAL_GOODS . "'"; $row = $this->row($sql); if ($row) { //如果购物车已经有此物品,则更新 $num += $row['goods_number']; if (C('use_storage') == 0 || $num > 0) { $sql = "UPDATE " . $this->pre . "cart SET goods_number = '" . $num . "'" . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '$package_id' " . " AND parent_id = 0 AND extension_code = 'package_buy' " . " AND rec_type = '" . CART_GENERAL_GOODS . "'"; $this->query($sql); } else { ECTouch::err()->add(sprintf(L('shortage'), $num), ERR_OUT_OF_STOCK); return false; } } else { //购物车没有此物品,则插入 $this->table = 'cart'; $this->insert($parent); } } /* 把赠品删除 */ $sql = "DELETE FROM " . $this->pre . "cart WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0"; $this->query($sql); return true; }
public function receive_gift() { //对goods处理 $_POST['goods'] = strip_tags(urldecode($_POST['gift'])); $_POST['goods'] = json_str_iconv($_POST['gift']); // 初始化返回数组 $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => ''); if (empty($_POST['goods'])) { $result['error'] = 1; die(json_encode($result)); } $json = new EcsJson(); $gift = $json->decode($_POST['gift']); $result['sn'] = $gift->sn; $result['product_spec'] = $gift->spec; // 购买礼包商品清空购物车 model('Order')->clear_cart(CART_RECEIVE_GIFTS); // 查询:系统启用了库存,检查输入的商品数量是否有效 // 查询 $Gift = $this->model->table('gift_sn')->field('goods_name,amount,sn_id,goods_id')->where("sn_id='" . $gift->sn . "'")->find(); if ($gift->number > $Gift['amount']) { $result['error'] = 1; $result['message'] = sprintf(L('stock_insufficiency'), $Gift['goods_name'], $Gift['goods_number'], $Gift['goods_number']); if (C('use_how_oos') == 1) { $result['message'] = L('oos_tips'); } die(json_encode($result)); } // 检查:商品数量是否合法 if (!is_numeric($gift->number) || intval($gift->number) <= 0) { $result['error'] = 1; $result['message'] = L('invalid_number'); } else { // 更新:添加到购物车 $_SESSION['flow_type'] = CART_RECEIVE_GIFTS; $_SESSION['extension_code'] = "receive_gift"; $_SESSION['extension_id'] = CART_RECEIVE_GIFTS; if (model('Order')->addto_cart($Gift['goods_id'], $gift->number, $gift->spec, $gift->parent, CART_RECEIVE_GIFTS)) { if (C('cart_confirm') > 2) { $result['message'] = ''; } else { $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2'); } $result['content'] = insert_cart_info(); $result['one_step_buy'] = C('one_step_buy'); } else { $result['message'] = ECTouch::err()->last_message(); $result['error'] = ECTouch::err()->error_no; $result['goods_id'] = stripslashes($Gift['goods_id']); if (is_array($goods->spec)) { $result['product_spec'] = implode(',', $gift->spec); } else { $result['product_spec'] = $gift->spec; } } } $cart_confirm = C('cart_confirm'); $result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2; // 返回购物车商品总数量 $result['cart_number'] = insert_cart_info_number(); die(json_encode($result)); }
public function add_to_cart_cf() { //对goods处理 $_POST['goods'] = strip_tags(urldecode($_POST['goods'])); $_POST['goods'] = json_str_iconv($_POST['goods']); if (!empty($_REQUEST['goods_id']) && empty($_POST['goods'])) { if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0) { ecs_header("Location:./\n"); } exit; } // 初始化返回数组 $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => ''); if (empty($_POST['goods'])) { $result['error'] = 1; die(json_encode($result)); } $json = new EcsJson(); $goods = $json->decode($_POST['goods']); $result['goods_id'] = $goods->goods_id; $result['product_spec'] = $goods->spec; // 清空众筹购物车 model('Order')->clear_cart(CART_CF_GOODS); //TODO 查询众筹库存 /* $arrGoods = $this->model->table('goods')->field('goods_name,goods_number,extension_code')->where('goods_id =' . $goods->goods_id)->find(); $goodsnmber = model('Users')->get_goods_number($goods->goods_id); $goodsnmber+=$goods->number; if ($arrGoods ['goods_number'] < $goodsnmber) { $result['error'] = 1; $result['message'] = sprintf(L('stock_insufficiency'), $arrGoods ['goods_name'], $arrGoods ['goods_number'], $arrGoods ['goods_number']); if (C('use_how_oos') == 1){ $result['message'] =L('oos_tips'); } die(json_encode($result)); } */ // 检查:商品数量是否合法 if (!is_numeric($goods->number) || intval($goods->number) <= 0) { $result['error'] = 1; $result['message'] = L('invalid_number'); } else { // 更新:添加到购物车 $_SESSION['flow_type'] = CART_CF_GOODS; $_SESSION['extension_code'] = "Crowdfunding"; $_SESSION['extension_id'] = CART_CF_GOODS; if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent, CART_CF_GOODS)) { if (C('cart_confirm') > 2) { $result['message'] = ''; } else { $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2'); } $result['content'] = insert_cart_info(); $result['one_step_buy'] = C('one_step_buy'); } else { $result['message'] = ECTouch::err()->last_message(); $result['error'] = ECTouch::err()->error_no; $result['goods_id'] = stripslashes($goods->goods_id); if (is_array($goods->spec)) { $result['product_spec'] = implode(',', $goods->spec); } else { $result['product_spec'] = $goods->spec; } } } $cart_confirm = C('cart_confirm'); $result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2; // 返回购物车商品总数量 $result['cart_number'] = insert_cart_info_number(); die(json_encode($result)); }