/** * 获得指定页面的动态内容 * * @access public * @param string $tmp 模板名称 * @return void */ function assign_dynamic($tmp) { $sql = 'SELECT id, number, type FROM ' . $this->pre . "template WHERE filename = '{$tmp}' AND type > 0 AND remarks ='' AND theme='" . C('template') . "'"; $res = $this->query($sql); foreach ($res as $row) { switch ($row['type']) { case 1: /* 分类下的商品 */ ECTouch::view()->assign('goods_cat_' . $row['id'], model('Goods')->assign_cat_goods($row['id'], $row['number'])); break; case 2: /* 品牌的商品 */ $brand_goods = model('Goods')->assign_brand_goods($row['id'], $row['number']); ECTouch::view()->assign('brand_goods_' . $row['id'], $brand_goods['goods']); ECTouch::view()->assign('goods_brand_' . $row['id'], $brand_goods['brand']); break; case 3: /* 文章列表 */ $cat_articles = model('Article')->assign_articles($row['id'], $row['number']); ECTouch::view()->assign('articles_cat_' . $row['id'], $cat_articles['cat']); ECTouch::view()->assign('articles_' . $row['id'], $cat_articles['arr']); break; } } }
public function asynclist() { $this->parameter(); $asyn_last = intval(I('post.last')) + 1; $this->size = I('post.amount'); $this->page = $asyn_last > 0 ? ceil($asyn_last / $this->size) : 1; $gb_list = model('Groupbuy')->group_buy_list($this->size, $this->page, $this->sort, $this->order); foreach ($gb_list as $key => $value) { $this->assign('groupbuy', $value); $sayList[] = array('single_item' => ECTouch::view()->fetch('library/asynclist_info.lbi')); } die(json_encode($sayList)); exit; }
public function asynclist_list() { $this->parameter(); $asyn_last = intval(I('post.last')) + 1; $this->size = I('post.amount'); $this->page = $asyn_last > 0 ? ceil($asyn_last / $this->size) : 1; $list = model('Exchange')->exchange_get_goods($this->children, $this->integral_min, $this->integral_max, $this->ext, $this->size, $this->page, $this->sort, $this->order); foreach ($list as $key => $value) { $this->assign('exchange', $value); $sayList[] = array('single_item' => ECTouch::view()->fetch('library/asynclist_info.lbi')); } die(json_encode($sayList)); exit; }
/** * 文章列表异步加载 */ public function asynclist() { $this->parameter(); $asyn_last = intval(I('post.last')) + 1; $this->size = I('post.amount'); $this->page = $asyn_last > 0 ? ceil($asyn_last / $this->size) : 1; $list = model('ArticleBase')->get_cat_articles($this->cat_id, $this->page, $this->size, $this->keywords); foreach ($list as $key => $value) { $this->assign('article', $value); $sayList[] = array('single_item' => ECTouch::view()->fetch('library/asynclist_info.lbi')); } die(json_encode($sayList)); exit; }
/** * ajax获取商品 */ public function ajax_goods() { if (IS_AJAX) { $type = I('get.type'); $start = $_POST['last']; $limit = $_POST['amount']; $hot_goods = model('Index')->goods_list($type, $limit, $start); $list = array(); // 热卖商品 if ($hot_goods) { foreach ($hot_goods as $key => $value) { $this->assign('hot_goods', $value); $list[] = array('single_item' => ECTouch::view()->fetch('library/asynclist_index.lbi')); } } echo json_encode($list); exit; } else { $this->redirect(url('index')); } }
/** * 提交订单 */ 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')); }
/** * 获取分类信息 * 只获取二级分类当没有参数时获取最高的二级分类 */ public function all() { $cat_id = I('get.id'); /* 页面的缓存ID */ $cache_id = sprintf('%X', crc32($_SERVER['REQUEST_URI'] . C('lang'))); if (!ECTouch::view()->is_cached('category_all.dwt', $cache_id)) { // 获得请求的分类 ID if ($cat_id > 0) { $category = model('CategoryBase')->get_child_tree($cat_id); } else { //顶级分类 ecs_header("Location: " . url('category/top_all') . "\n"); } $this->assign('title', L('catalog')); $this->assign('category', $category); /* 页面标题 */ $page_info = get_page_title($cat_id); $this->assign('ur_here', $page_info['ur_here']); $this->assign('page_title', $cat_id > 0 ? $page_info['title'] : L('catalog') . '_' . $page_info['title']); } $this->display('category_all.dwt', $cache_id); }
/** * 调用在线调查信息 * * @access public * @return string */ function insert_vote() { $vote = get_vote(); if (!empty($vote)) { ECTouch::view()->assign('vote_id', $vote['id']); ECTouch::view()->assign('vote', $vote['content']); } $val = ECTouch::view()->fetch('library/vote.lbi'); return $val; }
/** * 分销订单详情 */ 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'); }
/** * 功能:license 注册 * * @param array $certi_added 配置信息补充数组 array_key 登录信息的key;array_key => array_value; * @return array $return_array['flag'] = reg_succ、reg_fail、reg_ping_fail; * $return_array['request']; */ function license_reg($certi_added = '') { // 登录信息配置 $certi['certi_app'] = ''; // 证书方法 $certi['app_id'] = 'ectouch_free'; // 说明客户端来源 $certi['app_instance_id'] = ''; // 应用服务ID $certi['version'] = LICENSE_VERSION; // license接口版本号 $certi['shop_version'] = VERSION . '#' . RELEASE; // 网店软件版本号 $certi['certi_url'] = sprintf(__URL__); // 网店URL $certi['certi_session'] = ECTouch::sess()->get_session_id(); // 网店SESSION标识 $certi['certi_validate_url'] = sprintf(__URL__ . url('api/certi')); // 网店提供于官方反查接口 $certi['format'] = 'json'; // 官方返回数据格式 $certi['certificate_id'] = ''; // 网店证书ID // 标识 $certi_back['succ'] = 'succ'; $certi_back['fail'] = 'fail'; // return 返回数组 $return_array = array(); if (is_array($certi_added)) { foreach ($certi_added as $key => $value) { $certi[$key] = $value; } } // 取出网店 license $license = model('LicenseBase')->get_shop_license(); // 注册 $certi['certi_app'] = 'certi.reg'; // 证书方法 $certi['certi_ac'] = make_shopex_ac($certi, ''); // 网店验证字符串 unset($certi['certificate_id']); $request_arr = exchange_shop_license($certi, $license); if (is_array($request_arr) && $request_arr['res'] == $certi_back['succ']) { // 注册信息入库 $data['value'] = $request_arr['info']['certificate_id']; $condition['code'] = 'certificate_id'; model('Base')->table('touch_shop_config')->data($data)->where($condition)->update(); $data['value'] = $request_arr['info']['token']; $condition['code'] = 'certificate_id'; model('Base')->table('touch_shop_config')->data($data)->where($condition)->update(); $return_array['flag'] = 'reg_succ'; $return_array['request'] = $request_arr; clear_cache_files(); } elseif (is_array($request_arr) && $request_arr['res'] == $certi_back['fail']) { $return_array['flag'] = 'reg_fail'; $return_array['request'] = $request_arr; } else { $return_array['flag'] = 'reg_ping_fail'; $return_array['request'] = array('res' => 'fail'); } return $return_array; }
/** * ajax获取推荐列表 * 最新团拼 热门品牌 护肤 彩妆 个人护理 香氛 男士专区 家庭护理 母婴专区 */ public function ajax_recommend() { if (IS_AJAX) { $list = array(); // 获得首页推荐的团拼 $groupbuy_list = model('Groupbuy')->group_buy_list(2, 1, 'act_id', 'DESC'); if ($groupbuy_list) { $this->assign('cate', ['name' => 'group_buy_last', 'url' => '/default/group_buy/index']); $list[] = ['single_item' => ECTouch::view()->fetch('library/cate_header.lbi')]; foreach ($groupbuy_list as $key => $value) { $value['url'] = '/index.php?m=default&c=goods&a=index&id=' . $value['goods_id']; $value['group_remain'] = $value['end_time'] - time(); $this->assign('groupbuy', $value); $list[] = array('single_item' => ECTouch::view()->fetch('library/async_groupbuy_index.lbi')); } } // 获取热门品牌列表 $brand_list = model('Brand')->get_brands('brand', 6, 1); if ($brand_list) { $this->assign('cate', ['name' => 'hot_brand', 'url' => '/default/brand/index']); $list[] = ['single_item' => ECTouch::view()->fetch('library/cate_header.lbi')]; $this->assign('brand_list', $brand_list); $list[] = array('single_item' => ECTouch::view()->fetch('library/brand_index.lbi')); } // 获取分类下最热的商品,暂不设价格区间 $category_list = model('Category')->get_cat_list(0); if ($category_list) { foreach ($category_list as $category) { $subcate_list = model('Category')->get_cat_list($category['cat_id']); if ($category['style'] && $subcate_list) { // 分类的banner $position_id = model('Adposition')->getPositionId($category['style']); if ($position_id) { $ads = model('Ad')->getAds($position_id); if ($ads) { $this->assign('ads', $ads); $this->assign('id', $category['style'] . '-banner'); $list[] = ['single_item' => ECTouch::view()->fetch('library/cate_banner.lbi')]; } } // 分类名称 $this->assign('cate', ['name' => 'cate_' . $category['style'], 'style' => $category['style'], 'url' => '/index.php?m=default&c=category&a=index&id=' . $category['cat_id']]); $list[] = ['single_item' => ECTouch::view()->fetch('library/cate_header.lbi')]; $this->assign('subcate_list', $subcate_list); $this->assign('valid_count', count($subcate_list)); $list[] = array('single_item' => ECTouch::view()->fetch('library/async_catelist_index.lbi')); } } } echo json_encode($list); exit; } else { $this->redirect(url('index')); } }
/** * 获取分销指订单的详情 * * @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; }
/** * 获取配送地址列表 */ public function consignee_list() { if (IS_AJAX) { $start = $_POST['last']; $limit = $_POST['amount']; // 获得用户所有的收货人信息 $consignee_list = model('Users')->get_consignee_list($_SESSION['user_id'], 0, $limit, $start); if ($consignee_list) { foreach ($consignee_list as $k => $v) { $address = ''; if ($v['province']) { $address .= model('RegionBase')->get_region_name($v['province']); } if ($v['city']) { $address .= model('RegionBase')->get_region_name($v['city']); } if ($v['district']) { $address .= model('RegionBase')->get_region_name($v['district']); } $v['address'] = $address . ' ' . $v['address']; $v['url'] = url('flow/consignee', array('id' => $v['address_id'])); $this->assign('consignee', $v); $sayList[] = array('single_item' => ECTouch::view()->fetch('library/asynclist_info.lbi')); } } die(json_encode($sayList)); exit; } // 赋值于模板 $this->assign('title', L('consignee_info')); // 加载user语言包 require APP_PATH . C('_APP_NAME') . '/language/' . C('LANG') . '/user.php'; $_LANG = array_merge(L(), $_LANG); $this->assign('lang', $_LANG); $this->display('flow_consignee_list.dwt'); }
/** * 获得指定分类下的商品 * * @access public * @param integer $cat_id 分类ID * @param integer $num 数量 * @param string $from 来自web/wap的调用 * @param string $order_rule 指定商品排序规则 * @return array */ function assign_cat_goods($cat_id, $num = 0, $from = 'web', $order_rule = '') { $children = get_children($cat_id); $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . "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.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . 'g.is_delete = 0 AND (' . $children . 'OR ' . model('Goods')->get_extension_goods($children) . ') '; $order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule; $sql .= $order_rule; if ($num > 0) { $sql .= ' LIMIT ' . $num; } $res = $this->query($sql); $goods = array(); foreach ($res as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['short_name'] = C('goods_name_length') > 0 ? sub_str($row['goods_name'], C('goods_name_length')) : $row['goods_name']; $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = url('goods/index', array('id' => $row['goods_id'])); } if ($from == 'web') { ECTouch::view()->assign('cat_goods_' . $cat_id, $goods); } elseif ($from == 'wap') { $cat['goods'] = $goods; } /* 分类信息 */ $sql = 'SELECT cat_name FROM ' . $this->pre . "category WHERE cat_id = '{$cat_id}'"; $result = $this->row($sql); $cat['name'] = $result['cat_name']; $cat['url'] = url('category/index', array('id' => $cat_id)); $cat['id'] = $cat_id; return $cat; }
/** * 添加留言函数 * @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 info() { /* 取得参数:拍卖活动id */ $id = isset($_REQUEST['id']) ? intval(I('request.id')) : 0; if ($id <= 0) { $this->redirect(url('Auction/index')); exit; } /* 取得拍卖活动信息 */ $auction = model('Auction')->auction_info($id); if (empty($auction)) { $this->redirect(url('Auction/index')); exit; } /* 缓存id:语言,拍卖活动id,状态,如果是进行中,还要最后出价的时间(如果有的话) */ $cache_id = C('lang') . '-' . $id . '-' . $auction['status_no']; if ($auction['status_no'] == UNDER_WAY) { if (isset($auction['last_bid'])) { $cache_id = $cache_id . '-' . $auction['last_bid']['bid_time']; } } elseif ($auction['status_no'] == FINISHED && $auction['last_bid']['bid_user'] == $_SESSION['user_id'] && $auction['order_count'] == 0) { $auction['is_winner'] = 1; $cache_id = $cache_id . '-' . $auction['last_bid']['bid_time'] . '-1'; } $cache_id = sprintf('%X', crc32($cache_id)); /* 如果没有缓存,生成缓存 */ if (!ECTouch::view()->is_cached('auction.dwt', $cache_id)) { //取货品信息 if ($auction['product_id'] > 0) { $goods_specifications = model('goodsBase')->get_specifications_list($auction['goods_id']); $good_products = model('ProductsBase')->get_good_products($auction['goods_id'], 'AND product_id = ' . $auction['product_id']); $_good_products = explode('|', $good_products[0]['goods_attr']); $products_info = ''; foreach ($_good_products as $value) { $products_info .= ' ' . $goods_specifications[$value]['attr_name'] . ':' . $goods_specifications[$value]['attr_value']; } $this->assign('products_info', $products_info); unset($goods_specifications, $good_products, $_good_products, $products_info); } $auction['gmt_end_time'] = local_strtotime($auction['end_time']); $this->assign('auction', $auction); //print_r($auction ); /* 取得拍卖商品信息 */ $goods_id = $auction['goods_id']; $goods = model('Goods')->goods_info($goods_id); if (empty($goods)) { $this->redirect(url('Auction/index')); exit; } $goods['url'] = url('goods/index', array('id' => $goods_id)); $this->assign('auction_goods', $goods); // 商品相册 $this->assign('pictures', model('GoodsBase')->get_goods_gallery($goods_id)); // print_r($goods ); } //更新商品点击次数 $sql = 'UPDATE ' . $this->model->pre . 'goods SET click_count = click_count + 1 ' . "WHERE goods_id = '" . $auction['goods_id'] . "'"; $this->model->query($sql); $this->assign('now_time', gmtime()); // 当前系统时间 $this->assign('title', L('auction_goods_info')); $this->display('aution.dwt'); }
/** * 显示错误信息 * * @access public * @param string $link * @param string $href * @return void */ function show($link = '', $href = '') { if ($this->error_no > 0) { $message = array(); $link = empty($link) ? L('back_up_page') : $link; $href = empty($href) ? 'javascript:history.back();' : $href; $message['url_info'][$link] = $href; $message['back_url'] = $href; foreach ($this->_message as $msg) { $message['content'] = htmlspecialchars($msg); } $view = ECTouch::view(); if (isset($view)) { assign_template(); ECTouch::view()->assign('title', L('tips_message')); ECTouch::view()->assign('auto_redirect', true); ECTouch::view()->assign('message', $message); ECTouch::view()->display($this->_template); } else { die($message['content']); } exit; } }
/** * 添加商品到购物车 * * @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; }
<?php /** * 微信支付告警通知 */ define('IN_ECTOUCH', true); // require(dirname(__FILE__) . '/../include/init.php'); //接收数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; if (!empty($postStr)) { //转换数据 $postData = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); //插入留言表 $sql = "INSERT INTO " . ECTouch::ecs()->table('feedback') . "(msg_title, msg_content, msg_time)" . " VALUES ('告警通知', 'ErrorType:{$postData['ErrorType']} " . "\n\r" . " 错误描述:{$postData['Description']} " . "\n\r" . " 错误详情:{$postData['AlarmContent']}', '" . gmtime() . "')"; ECTouch::db()->query($sql); echo 'success'; } else { echo ''; }
/** * 异步加载品牌列表 */ public function list_asynclist() { $this->parameter(); $this->assign('show_marketprice', C('show_marketprice')); $brand_id = I('request.brand'); $brand_info = model('BrandBase')->get_brand_info($brand_id); if (empty($brand_info)) { ecs_header("Location: ./\n"); exit; } $asyn_last = intval(I('post.last')) + 1; $this->size = I('post.amount'); $this->page = $asyn_last > 0 ? ceil($asyn_last / $this->size) : 1; $list = model('Brand')->brand_get_goods($brand_id, '', $this->sort, $this->order, $this->size, $this->page); foreach ($list as $key => $value) { $this->assign('brand_goods', $value); $sayList[] = array('single_item' => ECTouch::view()->fetch('library/asynclist_info.lbi')); } die(json_encode($sayList)); exit; }
/** * 设置指定用户SESSION * * @access public * @param * * @return void */ function set_session($username = '') { if (empty($username)) { ECTouch::sess()->destroy_session(); } else { $sql = "SELECT user_id, password, email FROM " . $this->db->pre . 'users ' . " WHERE user_name='{$username}' LIMIT 1"; $row = $this->db->getRow($sql); if ($row) { $_SESSION['user_id'] = $row['user_id']; $_SESSION['user_name'] = $username; $_SESSION['email'] = $row['email']; } } }
/** * 更新微信用户信息 * * @param unknown $userinfo * @param unknown $wechat_id * @param unknown $weObj */ static function update_weixin_user($userinfo, $wechat_id, $weObj) { $time = time(); $ret = model('Base')->model->table('wechat_user')->field('openid, ect_uid')->where('openid = "' . $userinfo['openid'] . '"')->find(); if (empty($ret)) { // 获取用户所在分组ID $group_id = $weObj->getUserGroup($userinfo['openid']); $group_id = $group_id ? $group_id : 0; //微信用户绑定会员id $ect_uid = 0; //查看公众号是否绑定 if ($userinfo['unionid']) { $ect_uid = model('Base')->model->table('wechat_user')->field('ect_uid')->where(array('unionid' => $userinfo['unionid']))->getOne(); } //未绑定 if (empty($ect_uid)) { // 设置的用户注册信息 $register = model('Base')->model->table('wechat_extend')->field('config')->where('enable = 1 and command = "register_remind" and wechat_id = ' . $wechat_id)->find(); if (!empty($register)) { $reg_config = unserialize($register['config']); $username = msubstr($reg_config['user_pre'], 3, 0, 'utf-8', false) . time() . mt_rand(1, 99); // 密码随机数 $rs = array(); $arr = range(0, 9); $reg_config['pwd_rand'] = $reg_config['pwd_rand'] ? $reg_config['pwd_rand'] : 3; for ($i = 0; $i < $reg_config['pwd_rand']; $i++) { $rs[] = array_rand($arr); } $pwd_rand = implode('', $rs); // 密码 $password = $reg_config['pwd_pre'] . $pwd_rand; // 通知模版 $template = str_replace(array('[$username]', '[$password]'), array($username, $password), $reg_config['template']); } else { $username = '******' . time() . mt_rand(1, 99); $password = '******'; // 通知模版 $template = '默认用户名:' . $username . "\r\n" . '默认密码:' . $password; } // 会员注册 $domain = get_top_domain(); if (model('Users')->register($username, $password, $username . '@' . $domain) !== false) { $data['user_rank'] = 99; if (session('sale_id')) { $data['parent_id'] = session('sale_id'); } model('Base')->model->table('users')->data($data)->where('user_name = "' . $username . '"')->update(); } else { die('授权失败,如重试一次还未解决问题请联系管理员'); } $data1['ect_uid'] = $_SESSION['user_id']; } else { //已绑定 $username = model('Base')->model->table('users')->field('user_name')->where(array('user_id' => $ect_uid))->getOne(); $template = '您已拥有帐号,用户名为' . $username; $data1['ect_uid'] = $ect_uid; } $data1['wechat_id'] = $wechat_id; $data1['subscribe'] = 1; $data1['openid'] = $userinfo['openid']; $data1['nickname'] = $userinfo['nickname']; $data1['sex'] = $userinfo['sex']; $data1['city'] = $userinfo['city']; $data1['country'] = $userinfo['country']; $data1['province'] = $userinfo['province']; $data1['language'] = $userinfo['country']; $data1['headimgurl'] = $userinfo['headimgurl']; $data1['subscribe_time'] = $time; $data1['group_id'] = $group_id; $data1['unionid'] = $userinfo['unionid']; model('Base')->model->table('wechat_user')->data($data1)->insert(); // 微信端发送消息 $msg = array('touser' => $userinfo['openid'], 'msgtype' => 'text', 'text' => array('content' => $template)); $weObj->sendCustomMessage($msg); } else { //开放平台有privilege字段,公众平台没有 unset($userinfo['privilege']); $userinfo['subscribe'] = 1; model('Base')->model->table('wechat_user')->data($userinfo)->where('openid = "' . $userinfo['openid'] . '"')->update(); $new_user_name = model('Base')->model->table('users')->field('user_name')->where('user_id = "' . $ret['ect_uid'] . '"')->getOne(); ECTouch::user()->set_session($new_user_name); ECTouch::user()->set_cookie($new_user_name); model('Users')->update_user_info(); } // 推送量 model('Base')->model->table('wechat')->data('oauth_count = oauth_count + 1')->where('default_wx = 1 and status = 1')->update(); session('openid', $userinfo['openid']); }
/** * 取得跟商品关联的礼包列表 * * @param string $goods_id * 商品编号 * * @return 礼包列表 */ function get_package_goods_list($goods_id) { $now = gmtime(); $sql = "SELECT pg.goods_id, ga.act_id, ga.act_name, ga.act_desc, ga.goods_name, ga.start_time,\n\t\t\t\t\t ga.end_time, ga.is_finished, ga.ext_info\n\t\t\t\tFROM " . $this->pre . "goods_activity AS ga, " . $this->pre . "package_goods AS pg\n\t\t\t\tWHERE pg.package_id = ga.act_id\n\t\t\t\tAND ga.start_time <= '" . $now . "'\n\t\t\t\tAND ga.end_time >= '" . $now . "'\n\t\t\t\tAND pg.goods_id = " . $goods_id . "\n\t\t\t\tGROUP BY ga.act_id\n\t\t\t\tORDER BY ga.act_id "; $res = $this->query($sql); foreach ($res as $tempkey => $value) { $subtotal = 0; $row = unserialize($value['ext_info']); unset($value['ext_info']); if ($row) { foreach ($row as $key => $val) { $res[$tempkey][$key] = $val; } } $sql = "SELECT pg.package_id, pg.goods_id, pg.goods_number, pg.admin_id, p.goods_attr, g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS rank_price\n\t\t\t\t\tFROM " . $this->pre . "package_goods AS pg\n\t\t\t\t\t\tLEFT JOIN " . $this->pre . "goods AS g\n\t\t\t\t\t\t\tON g.goods_id = pg.goods_id\n\t\t\t\t\t\tLEFT JOIN " . $this->pre . "products AS p\n\t\t\t\t\t\t\tON p.product_id = pg.product_id\n\t\t\t\t\t\tLEFT JOIN " . $this->pre . "member_price AS mp\n\t\t\t\t\t\t\tON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}'\n\t\t\t\t\tWHERE pg.package_id = " . $value['act_id'] . "\n\t\t\t\t\tORDER BY pg.package_id, pg.goods_id"; $goods_res = $this->query($sql); foreach ($goods_res as $key => $val) { $goods_id_array[] = $val['goods_id']; $goods_res[$key]['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true); $goods_res[$key]['market_price'] = price_format($val['market_price']); $goods_res[$key]['rank_price'] = price_format($val['rank_price']); $subtotal += $val['rank_price'] * $val['goods_number']; } /* 取商品属性 */ $sql = "SELECT ga.goods_attr_id, ga.attr_value\n\t\t\t\t\tFROM " . $this->pre . "goods_attr AS ga, " . ECTouch::ecs()->table('attribute') . " AS a\n\t\t\t\t\tWHERE a.attr_id = ga.attr_id\n\t\t\t\t\tAND a.attr_type = 1\n\t\t\t\t\tAND " . db_create_in($goods_id_array, 'goods_id'); $result_goods_attr = $this->query($sql); $_goods_attr = array(); foreach ($result_goods_attr as $value) { $_goods_attr[$value['goods_attr_id']] = $value['attr_value']; } /* 处理货品 */ $format = '[%s]'; foreach ($goods_res as $key => $val) { if ($val['goods_attr'] != '') { $goods_attr_array = explode('|', $val['goods_attr']); $goods_attr = array(); foreach ($goods_attr_array as $_attr) { $goods_attr[] = $_goods_attr[$_attr]; } $goods_res[$key]['goods_attr_str'] = sprintf($format, implode(',', $goods_attr)); } } $res[$tempkey]['goods_list'] = $goods_res; $res[$tempkey]['subtotal'] = price_format($subtotal); $res[$tempkey]['saving'] = price_format($subtotal - $res[$tempkey]['package_price']); $res[$tempkey]['package_price'] = price_format($res[$tempkey]['package_price']); } return $res; }
/** * 功能:license 登录 * * @param array $certi_added 配置信息补充数组 array_key 登录信息的key;array_key => array_value; * @return array $return_array['flag'] = login_succ、login_fail、login_ping_fail、login_param_fail; * $return_array['request']; */ function license_login($certi_added = '') { // 登录信息配置 $certi['certi_app'] = ''; // 证书方法 $certi['app_id'] = 'ectouch_free'; // 说明客户端来源 $certi['app_instance_id'] = ''; // 应用服务ID $certi['version'] = LICENSE_VERSION; // license接口版本号 $certi['shop_version'] = VERSION . '#' . RELEASE; // 网店软件版本号 $certi['certi_url'] = sprintf(__URL__); // 网店URL $certi['certi_session'] = ECTouch::sess()->get_session_id(); // 网店SESSION标识 $certi['certi_validate_url'] = sprintf(__URL__ . url('api/certi')); // 网店提供于官方反查接口 $certi['format'] = 'json'; // 官方返回数据格式 $certi['certificate_id'] = ''; // 网店证书ID // 标识 $certi_back['succ'] = 'succ'; $certi_back['fail'] = 'fail'; // return 返回数组 $return_array = array(); if (is_array($certi_added)) { foreach ($certi_added as $key => $value) { $certi[$key] = $value; } } // 取出网店 license $license = model('LicenseBase')->get_shop_license(); // 检测网店 license if (!empty($license['certificate_id']) && !empty($license['token']) && !empty($license['certi'])) { // 登录 $certi['certi_app'] = 'certi.login'; // 证书方法 $certi['app_instance_id'] = 'cert_auth'; // 应用服务ID $certi['certificate_id'] = $license['certificate_id']; // 网店证书ID $certi['certi_ac'] = make_shopex_ac($certi, $license['token']); // 网店验证字符串 $request_arr = exchange_shop_license($certi, $license); if (is_array($request_arr) && $request_arr['res'] == $certi_back['succ']) { $return_array['flag'] = 'login_succ'; $return_array['request'] = $request_arr; } elseif (is_array($request_arr) && $request_arr['res'] == $certi_back['fail']) { $return_array['flag'] = 'login_fail'; $return_array['request'] = $request_arr; } else { $return_array['flag'] = 'login_ping_fail'; $return_array['request'] = array('res' => 'fail'); } } else { $return_array['flag'] = 'login_param_fail'; $return_array['request'] = array('res' => 'fail'); } return $return_array; }
/** * 用户进行密码找回操作时,发送一封确认邮件 * * @access public * @param string $uid 用户ID * @param string $user_name 用户帐号 * @param string $email 用户Email * @param string $code key * * @return boolen $result; */ function send_pwd_email($uid, $user_name, $email, $code) { if (empty($uid) || empty($user_name) || empty($email) || empty($code)) { ecs_header("Location: " . url('user/get_password_phone') . "\n"); exit; } /* 设置重置邮件模板所需要的内容信息 */ $template = model('Base')->get_mail_template('send_password'); $reset_email = __HOST__ . url('user/get_password_email', array('uid' => $uid, 'code' => $code)); ECTouch::view()->assign('user_name', $user_name); ECTouch::view()->assign('reset_email', $reset_email); ECTouch::view()->assign('shop_name', C('shop_name')); ECTouch::view()->assign('send_date', date('Y-m-d')); ECTouch::view()->assign('sent_date', date('Y-m-d')); $content = ECTouch::view()->fetch('str:' . $template['template_content']); /* 发送确认重置密码的确认邮件 */ if (send_mail($user_name, $email, $template['template_subject'], $content, $template['is_html'])) { return true; } else { return false; } }
/** * 设置指定用户SESSION * * @access public * @param * * * * @return void */ function set_session($username = '') { if (empty($username)) { ECTouch::sess()->destroy_session(); } else { $sql = "SELECT user_id, password, email FROM " . model('Base')->model->pre . "users WHERE user_name='{$username}' LIMIT 1"; $row = model('Base')->model->query($sql); $row = reset($row); if ($row) { $_SESSION['user_id'] = $row['user_id']; $_SESSION['user_name'] = $username; $_SESSION['email'] = $row['email']; } } }
/** * 保存用户收货地址 * * @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 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() { // 注册处理 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'); }
/** * 注册 */ 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'); }