🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
:-: 商品详情 文件路径:shop/controllers/Goods/GoodsCtl.php; ##### 后台数据: 商品信息(商品活动信息,评论数,销售数,咨询数): $goods_detail = $Goods_BaseModel->getGoodsDetailInfoByGoodId($goods_id); 计算商品的销售数量: 1.直接显示本件商品的销售数量,2.显示本类common商品的销售数量 $common_goods = $Goods_BaseModel->getByWhere(array('common_id' => $goods_detail['goods_base']['common_id'])); $count_sale = 0; foreach ($common_goods as $comkey => $comval) { $count_sale += $comval['goods_salenum']; } $goods_detail['goods_base']['count_sale'] = $count_sale; 获取商品所在地: $goods_location_row = $Base_DistrictModel->getByWhere(array('district_id:IN' => $goods_detail['common_base']['common_location'])); 店铺信息: $shop_detail = $Shop_BaseModel->getShopDetail($goods_detail['goods_base']['shop_id']); 查找店铺下的实体店铺 $entity_shop = $Shop_EntityModel->getByWhere(array("shop_id" => $goods_detail['goods_base']['shop_id'])); 推荐商品 $data_foot_recommon = $Goods_CommonModel->listByWhere(array( 'shop_id' => $shop_id ), array('common_is_recommend' => 'DESC'), 0, 5); $data_foot_recommon_goods = $Goods_CommonModel->getRecommonRow($data_foot_recommon); 热门销售 $data_hot_salle = $Goods_CommonModel->getHotSalle($shop_id, $is_wap); $data_salle = $Goods_CommonModel->getRecommonRow($data_hot_salle); 热门收藏 $data_hot_collect = $Goods_CommonModel->getHotCollect($shop_id); $data_collect = $Goods_CommonModel->getRecommonRow($data_hot_collect); 商品咨询数量 $Consult_BaseModel = new Consult_BaseModel(); $data_consult = $Consult_BaseModel->getByWhere(array( 'goods_id' => $goods_id, 'shop_id' => $shop_id )); $consult_num = count($data_consult); 首页名 $title = Web_ConfigModel::value("product_title"); 关键字 $this->keyword = Web_ConfigModel::value("product_keyword"); 描述 $this->description = Web_ConfigModel::value("product_description"); QQ: $service[$key]["tool"] = "<a target='_blank' href='http://wpa.qq.com/msgrd?v=3&uin=".$val['number']."&site=qq&menu=yes'><img border='0' src='http://wpa.qq.com/pa?p=2:".$val['number'].":41 &amp;r=0.22914223582483828' alt='点击这里'></a>"; 旺旺: $service[$key]["tool"] = "<a target='_blank' href='http://www.taobao.com/webww/ww.php?ver=3&amp;touid=".$val['number']."&amp;siteid=cntaobao&amp;status=1&amp;charset=utf-8' ><img border='0' src='http://amos.alicdn.com/online.aw?v=2&amp;uid=".$val['number']."&amp;site=cntaobao&s=1&amp;charset=utf-8' alt='点击这里' /></a>"; IM: $service[$key]["tool"] = '<a href="javascript:;" class="chat-enter" onclick="return chat(\''.$val['number'].'\');"><img src="'.$this->view->img.'/icon-im.gif" alt=""></a>'; 物流和运费信息: $cookie_area = $this->getCookieArea(); if($cookie_area['city']['id']){ $transportInfo = $this->getTramsportData($cookie_area['city']['id'], $goods_detail['goods_base']['common_id']); $transportInfo['area'] = $cookie_area['area']; $transportInfo['area_id'] = $cookie_area['city']['id']; }else{ $transportInfo = array(); } $goods_detail['transport'] = $transportInfo; wap端: //商品规格描述 $show_goods_spec_value = array_values($goods_detail['goods_base']['goods_spec']); //商品详情 $goods_info = array_merge($goods_detail['common_base'], $goods_detail['goods_base']); //好评率 $all_count = $Goods_EvaluationModel->countEvaluation($common_id, 'all'); $good_count = $Goods_EvaluationModel->countEvaluation($goods_detail['common_base']['common_id'], 'good'); //配送信息 $goods_hair_info['content'] = $goods_detail['shop_base']['shipping']; $goods_hair_info['store'] = $goods_detail['goods_base']['goods_stock']; //定位 $user_lbs_geo = $subSiteModel->getLbsGeo($lbs_geo,$level); //获取默认配送区域运费 $transportInfo = $Goods_BaseModel->getTransportInfo($user_lbs_geo['district_id'], $goods_detail['common_base']['common_id']); //图片信息 if ( isset($goods_detail['goods_base']['image_row']) && !empty($goods_detail['goods_base']['image_row']) ) { $images_list = array_column($goods_detail['goods_base']['image_row'], 'images_image'); $images_list = array_map(function ($img) { return image_thumb($img, 360, 360); }, $images_list); $goods_image = implode(',', $images_list); } else { $goods_image = $goods_detail['goods_base']['goods_image']; } //满送 $mansong_info = $goods_detail['mansong_info']; //商品规格 $spec_list = $Goods_BaseModel->createSGIdByWap($goods_detail['common_base']['common_id']); //商品规格颜色图 if ( !empty($goods_detail['common_base']['common_spec_value_color']) ) { $spec_image = $goods_detail['common_base']['common_spec_value_color']; } $data['goods_id'] = $goods_id; $data['goods_info'] = $goods_info; //商品详情 $data['goods_commend_list'] = $data_salle; //推荐商品(销量) $data['goods_eval_list'] = $goods_eval_list; //商品评论 $data['goods_evaluate_info'] = $goods_evaluate_info; //商品评论 $data['goods_hair_info'] = $goods_hair_info; //售卖区域 $data['goods_image'] = $goods_image; //商品图片 $data['mansong_info'] = $mansong_info; //商品满送 $data['spec_list'] = $spec_list; //商品规格 $data['stock_list'] = $stock_list; //规格库存 $data['spec_image'] = $spec_image; //商品颜色 $data['store_info'] = $store_info; //店铺信息 $data['buyer_limit'] = $goods_detail['buy_limit']; //限购数量 $data['is_favorate'] = $isFavoritesGoods; //是否收藏过商品 $data['shop_owner'] = $shop_owner; //是否为店主 $data['isBuyHave'] = $IsHaveBuy; //是否已达限购数量 $data['good_pre'] = $good_pre; //好评率 if(Web_ConfigModel::value('Plugin_Directseller')) { $data['rec_images'] = $goods_detail['recImages'];//推荐者上传图片 } //获取商品的促销信息 $promotion_info = $this->getPromotionInfo($goods_id); $data['promotion_info'] = $promotion_info; ##### 前台显示: 面包屑导航: <?php if($parent_cat){?> <?php foreach($parent_cat as $catkey => $catval):?> <a href="<?= Yf_Registry::get('url') ?>?ctl=Goods_Goods&met=goodslist&cat_id=<?=($catval['cat_id'])?>"><?=($catval['cat_name'])?></a><?php if(!isset($catval['ext'])){ ?><i class="iconfont icon-iconjiantouyou"></i><?php }?> <?php endforeach;?> <?php }?> 二维码: function lazyload(){ $("img.lazy").lazyload({ effect: "fadeIn" }); $('img.lazy').on('load',function(){ $(window).trigger('scroll') }); } 商品数量加减: g.bind("click",function(l){ if(!$(this).hasClass("no_reduce")){ var j=parseInt(h.val(),10)||1; if($(this).hasClass("add")&&!$(this).hasClass("no_add")){ $(this).prev().prev().attr("class","reduce"); if(f>=i&&j>=f){ $(this).attr("class","no_add") } else { j++; } }else{ if($(this).hasClass("reduce")&&!$(this).hasClass("no_reduce")){ j--; $(this).next().next().attr("class","add"); j<=i&&$(this).attr("class","no_reduce") } } h.val(j).trigger("propertychange") } }) 加入购物车: $.ajax({ url: SITE_URL + '?ctl=Buyer_Cart&met=addCart&typ=json', data: {goods_id:goods_id, goods_num: goods_num}, dataType: "json", contentType: "application/json;charset=utf-8", async: false, success: function (a) { if (a.status == 250) { Public.tips.error(a.msg); } else { //加入购物车成功后,修改购物车数量 $.ajax({ type: "GET", url: SITE_URL + "?ctl=Buyer_Cart&met=getCartGoodsNum&typ=json", data: {}, dataType: "json", success: function(data){ getCartList(); $('#cart_num').html(data.data.cart_count); $('.cart_num_toolbar').html(data.data.cart_count); } }); $.dialog({ title: "<?=__('加入购物车')?>", height: 100, width: 250, lock: true, drag: false, content: 'url: '+SITE_URL + '?ctl=Buyer_Cart&met=add&typ=e' }); } }, failure: function (a) { Public.tips.error('<?=__('操作失败!')?>'); } }); //判断商品是否满足限购条件,如果限时折扣设置最低购买数量大于商品本身限购数,按照限时折扣最低数量计算 if($goods_xianshi && $goods_num < $goods_xianshi['goods_lower_limit'] && strtotime($goods_xianshi['goods_start_time']) <= time() && strtotime($goods_xianshi['goods_end_time']) >= time()) { return $this->data->setError("添加失败,低于最低购买数量"); } //如果该商品限购,查出用户之前购买过的商品数量,当前添加购物车数量与之前购买数量相加不能超过限购数 if($goods_num_sum + $goods_num> $goods_limit_num) { return $this->data->setError("添加失败,超出限购数量"); } //如果是供货商的商品 //分销商申请是否通过 if(!$shopDistributorBase['distributor_enable']) { return $this->data->setError("分销申请未通过!"); } if(!array_intersect($common_shopcat_id, $allow_shop_cat) ) { return $this->data->setError("该分类未授权"); } //判断购物车中是否存在该商品 if(is_array($cart_row) && $cart_row){ $cart_row = array_shift($cart_row); //如果购物车中存在该商品 //购物车内的商品与立即购买的商品数不累加所以如果购物车存在此商品就将购物车商品数量修改为现在购买的数量 $flag = $this->cartModel->editCart($cart_row['cart_id'], $edit_cond_rows, false); //如果不存在 $flag = $this->cartModel->addCart($add_row, true); 立即购买虚拟商品: $.ajax({ type : 'POST', url : SITE_URL + "?ctl=Goods_Goods&met=checkVirtual&typ=json", data : {goods_id:goods_id,goods_num:$('#nums').val()}, dataType : 'JSON', success : function(a) { if(a.status == 250) { Public.tips.warning('<?=__('您已达购买上限!')?>'); return false; }else{ window.location.href = SITE_URL + '?ctl=Buyer_Cart&met=buyVirtual&goods_id=' + goods_id +'&goods_num='+$("#nums").val(); } } }); //检测当前商品是否参加团购活动 $info = $Groupbuy_BaseModel->getByWhere($con_row); if($info){ $limit = 0; foreach($info as $k=>$v){ $limit = $v['groupbuy_upper_limit']; } $goods_max_sale = $limit; }else{ $goods_max_sale = $goods_detail['goods_max_sale']; } 立即购买实物商品: $.ajax({ url: SITE_URL + '?ctl=Buyer_Cart&met=addCart&typ=json', data: {goods_id:goods_id, goods_num:$("#nums").val()}, dataType: "json", contentType: "application/json;charset=utf-8", async: false, success: function (a) { if (a.status == 250) { Public.tips.error(a.msg); } else { if(a.data.cart_id) { window.location.href = SITE_URL + '?ctl=Buyer_Cart&met=confirm&product_id=' + a.data.cart_id; } } }, failure: function (a) { Public.tips.error('<?=__('操作失败!')?>'); } }); 收藏商品: $.post(SITE_URL + '?ctl=Goods_Goods&met=collectGoods&typ=json',{goods_id:e},function(data) { if(data.status == 200) { Public.tips.success(data.data.msg); $(".icon-icoheart").addClass("icon-taoxinshi").removeClass('icon-icoheart'); //toolbar显示收藏效果 $("#collect_lable").removeClass('icon-icoheart'); $("#collect_lable").addClass('icon-taoxinshi').addClass('bbc_color'); } else { Public.tips.error(data.data.msg); } }); //插入用户收藏商品表 //如果用户未收藏过 //商品详情中收藏数量增加 $edit_row['goods_collect'] = '1'; $flag = $Goods_BaseModel->editBase($goods_id, $edit_row, true); //商品common中 $edit_common_row['common_collect'] = '1'; $Goods_CommonModel = $Goods_CommonModel->editCommonTrue($goods_base['common_id'],$edit_common_row); 收藏店铺: $.post(SITE_URL + '?ctl=Shop&met=addCollectShop&typ=json',{shop_id:e},function(data) { if(data.status == 200) { Public.tips.success(data.data.msg); } else { Public.tips.error(data.data.msg); } }); //插入用户收藏店铺表 //如果用户未收藏过 $User_FavoritesShopModel->addShop($add_row); //店铺详情中收藏数量增加 $edit_row['shop_collect'] = '1'; $flag = $Shop_BaseModel->editBaseCollectNum($shop_id, $edit_row, true); //店铺收藏成功添加数据到统计中心 $analytics_data = array( 'shop_id'=>$shop_id, 'date'=>date('Y-m-d'), ); Yf_Plugin_Manager::getInstance()->trigger('analyticsShopCollect',$analytics_data);