load_helper($files);
//ecmoban模板堂 --zhuo start
if(!empty($_SESSION['user_id'])){
$this->sess_id = " user_id = '" . $_SESSION['user_id'] . "' ";
$this->a_sess = " a.user_id = '" . $_SESSION['user_id'] . "' ";
$this->b_sess = " b.user_id = '" . $_SESSION['user_id'] . "' ";
$this->c_sess = " c.user_id = '" . $_SESSION['user_id'] . "' ";
$this->sess_cart = "";
}else{
$this->sess_id = " session_id = '" . real_cart_mac_ip() . "' ";
$this->a_sess = " a.session_id = '" . real_cart_mac_ip() . "' ";
$this->b_sess = " b.session_id = '" . real_cart_mac_ip() . "' ";
$this->c_sess = " c.session_id = '" . real_cart_mac_ip() . "' ";
$this->sess_cart = real_cart_mac_ip();
}
//ecmoban模板堂 --zhuo end
//初始化位置信息
$this->init_params();
$this->assign('area_id',$this->area_info['region_id']);
$this->assign('warehouse_id',$this->region_id);
}
/**
* 购物车列表 连接到index
*/
public function actionIndex()
{
var_dump($_SESSION['appid']);
/* 标记购物流程为普通商品 */
$_SESSION['flow_type'] = CART_GENERAL_GOODS;
/* 如果是一步购物,跳到结算中心 */
if (C('shop.one_step_buy') == '1')
{
ecs_header("Location: ".U('flow/index/index')."\n");
exit;
}
/* 取得优惠活动 */
$favourable_list = favourable_list($_SESSION['user_rank']);
usort($favourable_list, 'cmp_favourable');
/* 取得商品列表,计算合计 */
$cart_goods = get_cart_goods('', 0, $favourable_list);
// 获取每个商品是否有配件
$cart_show = array();
if($cart_goods['goods_list']){
foreach($cart_goods['goods_list'] as $k => $list){
if($list['goods_list']){
$fitting_key = 0;
foreach($list['goods_list'] as $key=>$val){
$num = get_goods_fittings(array($val['goods_id']));
$count = count($num);
if($fitting_key!=1 && !empty($count)) {
$cart_goods['goods_list'][$k]['fitting'] = $count > 0 ? $count : 0;
$fitting_key = 1;
}
$cart_show['cart_goods_number']+= $val['goods_number'];
}
}
}
}
$this->assign('cart_show',$cart_show);//购物车商品数&购物车总价
$this->assign('goods_list', $cart_goods['goods_list']);//商品列表
$this->assign('total', $cart_goods['total']);
$this->assign('relation',$this->relation_goods());//推荐商品
$this->assign('page_title','购物车');
$this->display('flow_cart');
}
/*
* 优惠活动
*/
function actionActivity(){
$act_id = I('act_id');
$sql = "SELECT * FROM {pre}favourable_activity WHERE act_id=".$act_id;
$obj = $this->db->getRow($sql);
$list = unserialize($obj['gift']);
foreach($list as $key => $v){
$sql = "SELECT * FROM {pre}goods WHERE goods_id=".$v['id'].' and is_on_sale=1 and is_delete=0 and goods_number>0';
$info = $this->db->getRow($sql);
if($info) {
//根据商品模式判断当前库存
if ((int)$info['model_attr'] === 1) {
$sql = "SELECT region_number FROM {pre}warehouse_goods WHERE region_id=" . $this->region_id;
$number = $this->db->getRow($sql);
$goods_number = $number['region_number'];
} elseif ((int)$info['model_attr'] === 2) {
$sql = "SELECT region_number FROM {pre}warehouse_area_goods WHERE region_id=" . $this->area_info['region_id'];
$number = $this->db->getRow($sql);
$goods_number = $number['region_number'];
} else {
$goods_number = $info['goods_number'];
}
$list[$key]['goods_id'] = $v['id'];
$list[$key]['goods_img'] = get_image_path($info['goods_thumb']);
$list[$key]['goods_name'] = $v['name'];
$list[$key]['goods_number'] = $goods_number;
$list[$key]['url'] = build_uri('goods', array('gid' => $v['id']));
$list[$key]['act_price'] = $v['price'];
$list[$key]['price'] = price_format($v['price']);
if((int)$goods_number===0){
unset($list[$key]);
}
}else{
unset($list[$key]);
}
}
$this->assign('act_id',$act_id);
$this->assign('list',$list);
$this->display('flow_accessories');
}
/*
*
* 添加优惠活动(赠品)到购物车
* @param int $act_id 优惠活动id
* @param int $id 赠品id
* @param float $price 赠品价格
*/
function actionAddGiftToCart()
{
$act_id = I('act_id');
$id = I('id');
$price = I('price');
//ecmoban模板堂 --zhuo start
$sess = $this->sess_cart;
//ecmoban模板堂 --zhuo end
$sql = 'SELECT act_type_ext FROM {pre}favourable_activity WHERE act_id='.$act_id;
$min = $this->db->getOne($sql);
//是否已近加入
$sql = "SELECT count(goods_id) FROM {pre}cart WHERE session_id='$sess' and goods_id=$id";
$max = $this->db->getOne($sql);
$sql = "SELECT count(is_gift) FROM {pre}cart WHERE session_id='$sess' and is_gift=$act_id";
$act_max = $this->db->getOne($sql);
if($max>0 || $act_max>=intval($min)){
$info['error'] = '已达到数量限制';
die(json_encode($info));
}
$sql = "INSERT INTO {pre}cart (" .
"user_id, session_id, goods_id, goods_sn, goods_name, market_price, goods_price, ".
"goods_number, is_real, extension_code, parent_id, is_gift, rec_type, ru_id ) ".
"SELECT $_SESSION[user_id], '" . $sess . "', goods_id, goods_sn, goods_name, market_price, ".
"'$price', 1, is_real, extension_code, 0, '$act_id', '" . CART_GENERAL_GOODS . "', user_id " .
"FROM {pre}goods" .
" WHERE goods_id = '$id'";
if($this->db->query($sql)){
$info['error'] = '已加入购物车';
die(json_encode($info));
}
}
/**
* 相关配件
*/
public function actionGoodsFittings(){
$goods_list = explode(',',I('goods_list'));
$fittings_list = get_goods_fittings($goods_list);
if(empty($fittings_list)){
show_message(L('no_accessories'));
exit();
}
$this->assign('fittings_list', $fittings_list);
$this->display('flow_accessories');
}
/*
* 商品属性
*/
public function actionGoodsTranslation($id){
$sql = 'SELECT sales_volume, goods_id, goods_name, goods_number, promote_start_date, promote_end_date, is_promote, market_price, promote_price, shop_price, goods_thumb, market_price
FROM {pre}goods WHERE goods_id='.$id;
$get = $this->db->getRow($sql);
$properties = get_goods_properties($id);
$info = $this->good_info_array($get,$properties);
return $info;
}
public function good_info_array($get,$properties){
$info = get_goods_info($get['goods_id'], $this->region_id, $this->area_info['region_id']);
$properties= get_goods_properties($get['goods_id'], $this->region_id, $this->area_info['region_id']);
foreach ($properties['spe'] as $key => $val) {
$checked =1;
if(count($val)>2){
foreach ($val['values'] as $k => $v) {
if($v['checked']==1){
$checked =0;
}
}
if($checked){
foreach ($val['values'] as $k => $v) {
if($k==0){
$properties['spe'][$key]['values'][$k]['checked'] = 1;
}
}
}
}
}
$info['spe'] = $properties['spe'];
return $info;
}
/*
* 推荐商品
*/
public function relation_goods(){
$sql = "SELECT * FROM {pre}goods where is_on_sale=1 and is_alone_sale=1 and is_delete=0 order by click_count desc limit 12";
$data = $this->db->getAll($sql);
$info=array();
foreach ($data as $key) {
$info[] = $this->actionGoodsTranslation($key['goods_id']);
}
foreach ($info as $key => $val){
if(empty($val['promote_price'])){
$info[$key]['promote_price'] = price_format(0);
}
}
return $info;
}
/*
* 购物车商品数量修改
*/
public function actionCartGoodsNumber(){
$rec_id = I('id','');
$goods_number = I('number','');
$none = I('none','');
$arr = I('arr','');
if(!empty($arr)){
$arr = substr($arr,0,strlen($arr)-1);
}
$sql="UPDATE {pre}cart SET goods_number='$goods_number' WHERE rec_id='$rec_id'";
if($this->db->query($sql)){
$sql="SELECT goods_price, goods_number FROM {pre}cart WHERE rec_id in (".$arr.")";
$count=$this->db->getAll($sql);
foreach ($count as $key) {
$count_price += floatval($key['goods_number']) * floatval($key['goods_price']);
}
$result['error'] = 0;
$result['msg'] = '';
$result['content'] = price_format($count_price);
}else{
$result['error'] = 1;
$data['msg'] = '#ADD_NO';
}
$result['none'] = $none;
die(json_encode($result));
}
/*
* label选中价格
*/
public function actionCartLabelCount(){
$rec_id = I('id','');
$rec_id = str_replace('undefined','',$rec_id);
$rec_id = substr($rec_id,0,str_len($rec_id)-1);
if($rec_id) {
$sql = "SELECT rec_id, goods_price, goods_number FROM {pre}cart WHERE rec_id in ($rec_id)";
$count = $this->db->getAll($sql);
}
$num=0;
if(count($count)>0){
foreach($count as $key){
$count_price += floatval($key['goods_number'])*floatval($key['goods_price']);
$num +=$key['goods_number'];
}
}else{
$count_price = '0.00';
}
$result['content'] = price_format($count_price);
$result['cart_number'] = $num;
die(json_encode($result));
}
/*
* 优惠卷
*/
public function actionCartBonus(){
$ru_id = I('ru_id', '', 'intval');
if(IS_INT($ru_id)){
//该店铺是否存在优惠卷
$bonus=$this->db->getAll("SELECT type_id, type_name, type_money, send_start_date,send_end_date, min_goods_amount FROM {pre}bonus_type WHERE user_id=".$ru_id." AND send_end_date>".time() );
$str='
';
foreach($bonus as $key){
$num=1;
if($key['type_money']>=0){
if($key['type_money']>=50){
if($key['type_money']>=100){
$num=1;
}else{
$num=2;
}
}else{
$num=3;
}
}else{
$num=3;
}
$key['type_money'] = round($key['type_money']);
$key['min_goods_amount'] = round($key['min_goods_amount']);
$str.="";
}
$str.='
';
$result['number'] = count($bonus);
$result['data'] = $str;
die(json_encode($result));
}
$result['number'] = 0;
$result['data'] = 0;
die(json_encode($result));
}
/*
* 领取优惠卷
*/
public function actionReceiveBonus(){
$bonus_id=I('bonus_id','');
//不考虑红包编号重复6212261001038699861
if($_SESSION['user_id']>0){
$number = $this->db->getRow("SELECT user_id FROM {pre}user_bonus WHERE bonus_type_id='$bonus_id' and user_id=".$_SESSION['user_id']);
if(count($number)==0){
$error = $this->db->query("INSERT INTO {pre}user_bonus (bonus_type_id, user_id) " .
"VALUES('$bonus_id', '$_SESSION[user_id]')");
if($error){
$result['msg'] = '已把优惠券放入你的账户';
$result['code'] = 0;
}else{
$result['msg'] = '优惠券发完了';
$result['code'] = 0;
}
}else{
$result['msg'] = '已领取过该优惠券';
$result['code'] = 0;
}
}else{
$result['msg'] = '您没有登录';
$result['code'] = 1;
}
die(json_encode($result));
}
/*
* 加入购物车
*/
public function actionAddToCart(){
$goods = strip_tags(urldecode($_REQUEST['goods']));
$goods_id = I('post.goods_id', 0, 'intval');
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'url'=>'');
if (!empty($goods_id) && empty($goods))
{
if (!is_numeric($goods_id) || intval($goods_id) <= 0)
{
//跳转到首页
$result['error'] = 1;
$result['url'] = U('site');
die(json_encode($result));
}
}
if (empty($goods))
{
$result['error'] = 1;
$result['url'] = U('site');
die(json_encode($result));
}
$goods = stripslashes($goods);
$goods = json_decode($goods);
$warehouse_id = intval($goods->warehouse_id);
$area_id = intval($goods->area_id);
/* 检查:该地区是否支持配送 ecmoban模板堂 --zhuo */
if(C('shop.open_area_goods') == 1){
$leftJoin = '';
$leftJoin .= " left join " .$GLOBALS['ecs']->table('warehouse_goods'). " as wg on g.goods_id = wg.goods_id and wg.region_id = '$warehouse_id' ";
$leftJoin .= " left join " .$GLOBALS['ecs']->table('warehouse_area_goods'). " as wag on g.goods_id = wag.goods_id and wag.region_id = '$area_id' ";
$sql = "SELECT g.user_id, g.review_status, g.model_attr, " .
' IF(g.model_price < 1, g.goods_number, IF(g.model_price < 2, wg.region_number, wag.region_number)) AS goods_number ' .
" FROM " .$GLOBALS['ecs']->table('goods') ." as g ".
$leftJoin .
" WHERE g.goods_id = '" .$goods->goods_id. "'";
$goodsInfo = $GLOBALS['db']->getRow($sql);
$area_list = get_goods_link_area_list($goods->goods_id, $goodsInfo['user_id']);
if($area_list['goods_area']){
if(!in_array($area_id, $area_list['goods_area'])){
$no_area = 2;
}
} else {
$no_area = 2;
}
if($goodsInfo['model_attr'] == 1){
$table_products = "products_warehouse";
$type_files = " and warehouse_id = '$warehouse_id'";
}elseif($goodsInfo['model_attr'] == 2){
$table_products = "products_area";
$type_files = " and area_id = '$area_id'";
}else{
$table_products = "products";
$type_files = "";
}
$sql = "SELECT * FROM " .$GLOBALS['ecs']->table($table_products). " WHERE goods_id = '" .$goods->goods_id. "'" .$type_files. " LIMIT 0, 1";
$prod = $GLOBALS['db']->getRow($sql);
if(empty($prod)){ //当商品没有属性库存时
$prod = 1;
}else{
$prod = 0;
}
if($no_area == 2){
$result['error'] = 1;
$result['message'] = '该地区暂不支持配送';
die(json_encode($result));
}elseif($goodsInfo['review_status'] <= 2){
$result['error'] = 1;
$result['message'] = '该商品已下架';
die(json_encode($result));
}
}
/* 检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台 */
if (empty($goods->spec) AND empty($goods->quick))
{
//ecmoban模板堂 --zhuo start
$groupBy = " group by ga.goods_attr_id ";
$leftJoin = '';
$shop_price = "wap.attr_price, wa.attr_price, g.model_attr, ";
$leftJoin .= " left join " .$GLOBALS['ecs']->table('goods'). " as g on g.goods_id = ga.goods_id";
$leftJoin .= " left join " .$GLOBALS['ecs']->table('warehouse_attr'). " as wap on ga.goods_id = wap.goods_id and wap.warehouse_id = '$warehouse_id' and ga.goods_attr_id = wap.goods_attr_id ";
$leftJoin .= " left join " .$GLOBALS['ecs']->table('warehouse_area_attr'). " as wa on ga.goods_id = wa.goods_id and wa.area_id = '$area_id' and ga.goods_attr_id = wa.goods_attr_id ";
//ecmoban模板堂 --zhuo end
$sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
"ga.goods_attr_id, ga.attr_value, IF(g.model_attr < 1, ga.attr_price, IF(g.model_attr < 2, wap.attr_price, wa.attr_price)) as attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS ga ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = ga.attr_id ' .$leftJoin.
"WHERE a.attr_type != 0 AND ga.goods_id = '" . $goods->goods_id . "' " . $groupBy .
'ORDER BY a.sort_order, IF(g.model_attr < 1, ga.attr_price, IF(g.model_attr < 2, wap.attr_price, wa.attr_price)), ga.goods_attr_id';
$res = $this->db->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['warehouse_id'] = $warehouse_id;
$result['area_id'] = $area_id;
$result['parent'] = $goods->parent;
$result['message'] = $spe_array;
$result['goods_number'] = cart_number();
die(json_encode($result));
}
}
/* 更新:如果是一步购物,先清空购物车 */
if (C('shop.one_step_buy') == '1')
{
clear_cart();
}
$goods_number = intval($goods->number);
/* 检查:商品数量是否合法 */
if (!is_numeric($goods_number) || $goods_number <= 0)
{
$result['error'] = 1;
$result['message'] = L('invalid_number');
}
/* 更新:购物车 */
else
{
//ecmoban模板堂 --zhuo start 限购
$xiangouInfo = get_purchasing_goods_info($goods->goods_id);
if($xiangouInfo['is_xiangou'] == 1){
$user_id = !empty($_SESSION['user_id']) ? $_SESSION['user_id'] : 0;
$sql= "SELECT goods_number FROM ". $this->ecs->table('cart') ."WHERE goods_id = ".$goods->goods_id . " and " . $this->sess_id;
$cartGoodsNumInfo=$this->db->getRow($sql);//获取购物车数量
$start_date = $xiangouInfo['xiangou_start_date'];
$end_date = $xiangouInfo['xiangou_end_date'];
$orderGoods = get_for_purchasing_goods($start_date, $end_date, $goods->goods_id, $user_id);
$nowTime = gmtime();
if($nowTime > $start_date && $nowTime < $end_date){
if($orderGoods['goods_number'] >= $xiangouInfo['xiangou_num']){
$result['error'] = 1;
$max_num = $xiangouInfo['xiangou_num'] - $orderGoods['goods_number'];
$result['message'] ="该商品您已购买过,无法再购买";
die(json_encode($result));
}else{
if($xiangouInfo['xiangou_num'] > 0){
if($cartGoodsNumInfo['goods_number'] + $orderGoods['goods_number'] + $goods_number > $xiangouInfo['xiangou_num']){
$result['error'] = 1;
$result['message'] ='该商品已经累计超过限购数量';
die(json_encode($result));
}
}
}
}
}
//ecmoban模板堂 --zhuo end 限购
// 更新:添加到购物车
if (addto_cart($goods->goods_id, $goods_number, $goods->spec, $goods->parent, $warehouse_id, $area_id))
{
if (C('shop.cart_confirm') > 2)
{
$result['message'] = '';
}
else
{
$result['message'] = C('shop.cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
}
$result['content'] = insert_cart_info();
$result['one_step_buy'] = C('shop.one_step_buy');
}
else
{
$result['message'] = $this->err->last_message();
$result['error'] = $this->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;
}
}
}
$result['confirm_type'] = C('shop.cart_confirm') ? C('shop.cart_confirm') : 2;
$result['goods_number'] = cart_number();
die(json_encode($result));
}
// 更新购物车
public function actionUpdate_cart(){
//格式化返回数组
$result = array(
'error' => 0,
'message' => ''
);
// 是否有接收值
if (isset($_POST ['rec_id']) && isset($_POST ['goods_number'])) {
$key = $_POST ['rec_id'];
$val = $_POST ['goods_number'];
$val = intval(make_semiangle($val));
if ($val <= 0 && !is_numeric($key)) {
$result ['error'] = 99;
$result ['message'] = '';
die(json_encode($result));
}
// 查询:
$condition['rec_id'] = $key;
$condition['session_id'] = SESS_ID;
$goods = $this->db->table('cart')->field('goods_id,goods_attr_id,product_id,extension_code')->where($condition)->find();
$sql = "SELECT g.goods_name,g.goods_number " . "FROM {pre}goods AS g, {pre}cart AS c " . "WHERE g.goods_id =c.goods_id AND c.rec_id = '$key'";
$res = $this->db->query($sql);
$row = $res[0];
// 查询:系统启用了库存,检查输入的商品数量是否有效
if (intval(C('shop.use_storage')) > 0 && $goods ['extension_code'] != 'package_buy') {
if ($row ['goods_number'] < $val) {
$result ['error'] = 1;
$result ['message'] = sprintf(L('stock_insufficiency'), $row ['goods_name'], $row ['goods_number'], $row ['goods_number']);
$result ['err_max_number'] = $row ['goods_number'];
die(json_encode($result));
}
/* 是货品 */
$goods ['product_id'] = trim($goods ['product_id']);
if (!empty($goods ['product_id'])) {
$condition = " goods_id = '" . $goods ['goods_id'] . "' AND product_id = '" . $goods ['product_id'] . "'";
$product_number = $this->db->table('products')->field('product_number')->where($condition)->find();
$product_number = $product_number['product_number'];
if ($product_number < $val) {
$result ['error'] = 2;
$result ['message'] = sprintf(L('stock_insufficiency'), $row ['goods_name'], $product_number, $product_number);
die(json_encode($result));
}
}
} elseif (intval(C('shop.use_storage')) > 0 && $goods ['extension_code'] == 'package_buy') {
if (judge_package_stock($goods ['goods_id'], $val)) {
$result ['error'] = 3;
$result ['message'] = L('package_stock_insufficiency');
die(json_encode($result));
}
}
/* 查询:检查该项是否为基本件 以及是否存在配件 */
/* 此处配件是指添加商品时附加的并且是设置了优惠价格的配件 此类配件都有parent_idgoods_number为1 */
$sql = "SELECT b.goods_number,b.rec_id
FROM {pre}cart a, {pre}cart b
WHERE a.rec_id = '$key'
AND a.session_id = '" . SESS_ID . "'
AND a.extension_code <>'package_buy'
AND b.parent_id = a.goods_id
AND b.session_id = '" . SESS_ID . "'";
$offers_accessories_res = $this->db->getAll($sql);
// 订货数量大于0
if ($val > 0) {
/* 判断是否为超出数量的优惠价格的配件 删除 */
$row_num = 1;
foreach ($offers_accessories_res as $offers_accessories_row) {
if ($row_num > $val) {
$where['session_id'] = SESS_ID;
$where['rec_id'] = $offers_accessories_row ['rec_id'];
$this->db->table('cart')->where()->delete();
}
$row_num++;
}
/* 处理超值礼包 */
if ($goods ['extension_code'] == 'package_buy') {
// 更新购物车中的商品数量
$sql = "UPDATE {pre}cart SET goods_number= '$val' WHERE rec_id='$key' AND session_id='" . SESS_ID . "'";
} /* 处理普通商品或非优惠的配件 */ else {
$attr_id = empty($goods ['goods_attr_id']) ? array() : explode(',', $goods ['goods_attr_id']);
$goods_price = get_final_price($goods ['goods_id'], $val, true, $attr_id);
// 更新购物车中的商品数量
$sql = "UPDATE {pre}cart SET goods_number= '$val', goods_price = '$goods_price' WHERE rec_id='$key' AND session_id='" . SESS_ID . "'";
}
} // 订货数量等于0
else {
/* 如果是基本件并且有优惠价格的配件则删除优惠价格的配件 */
foreach ($offers_accessories_res as $offers_accessories_row) {
$where['session_id'] = SESS_ID;
$where['rec_id'] = $offers_accessories_row ['rec_id'];
$this->db->table('cart')->where()->delete();
}
$sql = "DELETE FROM {pre}cart WHERE rec_id='$key' AND session_id='" . SESS_ID . "'";
}
$this->db->query($sql);
/* 删除所有赠品 */
$sql = "DELETE FROM {pre}cart WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0";
$this->db->query($sql);
$result ['rec_id'] = $key;
$result ['goods_number'] = $val;
$result ['goods_subtotal'] = '';
$result ['total_desc'] = '';
$result ['cart_info'] = insert_cart_info();
/* 计算合计 */
$cart_goods = get_cart_goods();
foreach ($cart_goods ['goods_list'] as $goods) {
if ($goods ['rec_id'] == $key) {
$result ['goods_subtotal'] = $goods ['subtotal'];
break;
}
}
$market_price_desc = sprintf(L('than_market_price'), $cart_goods ['total'] ['market_price'], $cart_goods ['total'] ['saving'], $cart_goods ['total'] ['save_rate']);
/* 计算折扣 */
$discount = compute_discount();
$favour_name = empty($discount ['name']) ? '' : join(',', $discount ['name']);
$your_discount = sprintf('', $favour_name, price_format($discount ['discount']));
$result ['total_desc'] = $cart_goods ['total'] ['goods_price'];
$result ['total_number'] = $cart_goods ['total'] ['total_number'];
$result['market_total'] = $cart_goods['total']['market_price'];//市场价格
die(json_encode($result));
} else {
$result ['error'] = 100;
$result ['message'] = '';
die(json_encode($result));
}
}
/*
* 购物车关注
*/
public function actionHeart(){
if($_SESSION['user_id']>0){
$id = I('id','');
$status = I('status');
$id = explode(',',substr($id,0,str_len($id)-1));
foreach($id as $key){
if($key!='undefined'){
$arr[] = $key;
}
}
if(count($arr)>0){
if($status%2) {
foreach ($arr as $key) {
$sql = "SELECT count(rec_id) as a FROM {pre}collect_goods WHERE user_id=" . $_SESSION['user_id'] . ' AND goods_id=' . $key;
$info = $this->db->getOne($sql);
if ($info < 1) {
$sql = 'INSERT INTO {pre}collect_goods (user_id,goods_id,add_time,is_attention) VALUES(' . $_SESSION['user_id'] . ',' . $key . ',' . time() . ',1)';
$this->db->query($sql);
}
}
die(json_encode(array('msg' => '已关注选中商品', 'error' => 1)));
}else{
$sql = "DELETE FROM {pre}collect_goods WHERE user_id=" . $_SESSION['user_id'] . ' AND goods_id in('.implode(',',$arr).')';
$this->db->query($sql);
die(json_encode(array('msg' => '已取消关注', 'error' => 2)));
}
}else{
die(json_encode(array('msg'=>'Attention NO','error'=>0)));
}
}
die(json_encode(array('msg'=>'您还没有登录','error'=>0)));
}
/**
* 删除购物车中的商品
*/
public function actionDropGoods()
{
if(IS_AJAX){
$id = I('id','');
$id = explode(',',substr($id,0,str_len($id)-1));
foreach($id as $key){
if($key!='undefined'){
$arr[] = $key;
}
}
if(count($arr)>0) {
foreach ($arr as $key) {
flow_drop_cart_goods($key);
}
}
die;
}
}
public function actionDeleteCart()
{
if(IS_AJAX){
$rec_id = I('id');
flow_drop_cart_goods($rec_id);
die;
}
}
/**
* 初始化参数
*/
private function init_params(){
#需要查询的IP start
if(!isset($_COOKIE['province'])){
$area_array = get_ip_area_name();
if($area_array['county_level'] == 2){
$date = array('region_id', 'parent_id', 'region_name');
$where = "region_name = '" .$area_array['area_name']. "' AND region_type = 2";
$city_info = get_table_date('region', $where, $date, 1);
$date = array('region_id', 'region_name');
$where = "region_id = '" .$city_info[0]['parent_id']. "'";
$province_info = get_table_date('region', $where, $date);
$where = "parent_id = '" .$city_info[0]['region_id']. "' order by region_id asc limit 0, 1";
$district_info = get_table_date('region', $where, $date, 1);
}elseif($area_array['county_level'] == 1){
$area_name = $area_array['area_name'];
$date = array('region_id', 'region_name');
$where = "region_name = '$area_name'";
$province_info = get_table_date('region', $where, $date);
$where = "parent_id = '" .$province_info['region_id']. "' order by region_id asc limit 0, 1";
$city_info = get_table_date('region', $where, $date, 1);
$where = "parent_id = '" .$city_info[0]['region_id']. "' order by region_id asc limit 0, 1";
$district_info = get_table_date('region', $where, $date, 1);
}
}
#需要查询的IP end
$order_area = get_user_order_area($this->user_id);
$user_area = get_user_area_reg($this->user_id); //2014-02-25
if($order_area['province'] && $this->user_id > 0){
$this->province_id = $order_area['province'];
$this->city_id = $order_area['city'];
$this->district_id = $order_area['district'];
}else{
//省
if($user_area['province'] > 0){
$this->province_id = $user_area['province'];
setcookie('province', $user_area['province'], gmtime() + 3600 * 24 * 30);
$this->region_id = get_province_id_warehouse($this->province_id);
}else{
$sql = "select region_name from " .$this->ecs->table('region_warehouse'). " where regionId = '" .$province_info['region_id']. "'";
$warehouse_name = $this->db->getOne($sql);
$this->province_id = $province_info['region_id'];
$cangku_name = $warehouse_name;
$this->region_id = get_warehouse_name_id(0, $cangku_name);
}
//市
if($user_area['city'] > 0){
$this->city_id = $user_area['city'];
setcookie('city', $user_area['city'], gmtime() + 3600 * 24 * 30);
}else{
$this->city_id = $city_info[0]['region_id'];
}
//区
if($user_area['district'] > 0){
$this->district_id = $user_area['district'];
setcookie('district', $user_area['district'], gmtime() + 3600 * 24 * 30);
}else{
$this->district_id = $district_info[0]['region_id'];
}
}
$this->province_id = isset($_COOKIE['province']) ? $_COOKIE['province'] : $this->province_id;
$child_num = get_region_child_num($this->province_id);
if($child_num > 0){
$this->city_id = isset($_COOKIE['city']) ? $_COOKIE['city'] : $this->city_id;
}else{
$this->city_id = '';
}
$child_num = get_region_child_num($this->city_id);
if($child_num > 0){
$this->district_id = isset($_COOKIE['district']) ? $_COOKIE['district'] : $this->district_id;
}else{
$this->district_id = '';
}
$this->region_id = !isset($_COOKIE['region_id']) ? $this->region_id : $_COOKIE['region_id'];
$goods_warehouse = get_warehouse_goods_region($this->province_id); //查询用户选择的配送地址所属仓库
if($goods_warehouse){
$this->regionId = $goods_warehouse['region_id'];
if($_COOKIE['region_id'] && $_COOKIE['regionId']){
$gw = 0;
}else{
$gw = 1;
}
}
if($gw){
$this->region_id = $this->regionId;
setcookie('area_region', $this->region_id, gmtime() + 3600 * 24 * 30);
}
setcookie('goodsId', $this->goods_id, gmtime() + 3600 * 24 * 30);
$sellerInfo = get_seller_info_area();
if(empty($this->province_id)){
$this->province_id = $sellerInfo['province'];
$this->city_id = $sellerInfo['city'];
$this->district_id = 0;
setcookie('province', $this->province_id, gmtime() + 3600 * 24 * 30);
setcookie('city', $this->city_id, gmtime() + 3600 * 24 * 30);
setcookie('district', $this->district_id, gmtime() + 3600 * 24 * 30);
$this->region_id = get_warehouse_goods_region($this->province_id);
}
//ecmoban模板堂 --zhuo end 仓库
$this->area_info = get_area_info($this->province_id);
}
}