show('

:)

欢迎使用 ThinkPHP


版本 V{$Think.version}
','utf-8'); // $sto=tpCache('shop_info',$stoid); // if($user['erpvipid']) //已绑定线下会员 // { // $where['VIPId']=$user['erpvipid']; // // $cardinfo =getApiData("wxd.mem.vipinfo.list.get",$sto['api_token'],null,$where); // $cardinfo=json_decode($cardinfo,true); // if($cardinfo['code']==1 && $cardinfo['data'][0]['GradeCardID']!='') // { // $user['card_field']=$cardinfo['data'][0]; // $expiredate=$cardinfo['ExpiryDate']; // $expireday=$cardinfo['YExpiryDate']; // $user['card_expiredate']=date("Y-m-d",strtotime("$expiredate +$expireday day")); // } // // } return $this->fetch('', getMobileStoId()); } /** * 分类列表显示 */ public function categoryList() { //tpCache()配置 $bconf=tpCache("basic",getMobileStoId()); /*--手机端三级分类--*/ $getype = I('type/d', 0); $bconf= $bconf['switch_list']; $bconf= json_decode($bconf, true); $is_newgoodstpey =$bconf["is_newsgoodstype"]; //新旧版本的控制器 $this->assign('is_newgoodstpey', $is_newgoodstpey); if ($is_newgoodstpey!=1) { switch ($getype) { case 0: $goods_category_tree = get_goods_category_tree_mobile(); $this->cateTrre = $goods_category_tree; if (empty($goods_category_tree)) { $this->assign('goods_category_tree', '');//类别 } else { $this->assign('goods_category_tree', $goods_category_tree);//类别 } break; case 2: $zmsql = "select zm from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " group by zm"; $brand_zm = DB::query($zmsql); foreach ($brand_zm as $val) { $zmsql1 = "select id,name,logo,imgtype from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " and zm='" . $val['zm'] . "' order by sort asc";// $brand_zm1 = DB::query($zmsql1); $arr[] = ['zm' => $val['zm'], 'tmenu' => $brand_zm1]; } if (empty($arr)) { $this->assign('brand_list', '');//品牌 } else { $this->assign('brand_list', $arr);//品牌 } $this->assign('brand_zm', $brand_zm); break; case 1: $nationlist = M('nation')->where(' is_hot=1 and store_id=' . getMobileStoId())->order('sort')->select(); if (empty($nationlist)) { $this->assign('nation_list', '');//国别 } else { $this->assign('nation_list', $nationlist);//国别 } break; } } else { //国别 $nationlist = M('nation')->where(' is_hot=1 and store_id=' . getMobileStoId())->order('sort')->select(); if (empty($nationlist)) { $this->assign('nation_list', '');//国别 } else { $this->assign('nation_list', $nationlist);//国别 $is_nationlist = 1; $this->assign('is_nationlist', $is_nationlist); } //品牌 $zmsql = "select zm from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " group by zm"; $brand_zm = DB::query($zmsql); foreach ($brand_zm as $val) { $zmsql1 = "select id,name,logo,imgtype from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " and zm='" . $val['zm'] . "' order by sort asc";// $brand_zm1 = DB::query($zmsql1); $brand_img[] = $brand_zm1; //$arr[] = ['zm' => $val['zm'], 'tmenu' => $brand_zm1]; } if (empty($brand_img)) { $this->assign('brand_list', '');//品牌 } else { $brand = 2; $this->assign('brand', $brand); $this->assign('brand_list', $brand_img);//品牌 } $this->assign('brand_zm', $brand_zm); } //一级分类 $goods_category_tree = get_goods_category_tree_mobile(); $this->cateTrre = $goods_category_tree; if (empty($goods_category_tree)) { $this->assign('goods_category_tree', '');//类别 } else { $this->assign('goods_category_tree', $goods_category_tree);//类别 } upload_ylp_log('分类列表'); return $this->fetch("", getMobileStoId()); } //商品分类点击一级的ajax public function ajaxGoodsBrand() { // 点击的分类id $brand_id = I('brand_id'); $goods_category_tree = get_goods_category_tree_mobile(); $this->cateTrre = $goods_category_tree; if (!empty($goods_category_tree)) { $arrs=array(); $kz=1; $arrs["is_three"]=0; foreach ($goods_category_tree as $key => $value) { if (!empty($value["tmenu"])) { $count = count($value["tmenu"]); foreach ($value["tmenu"] as $ke => $val) { if ($brand_id == $val['parent_id']) { if( $kz==1 ) { $arrs[] = $value["tmenu"]; $kz=2; } if(!empty($val["sub_menu"])){ $arrs["is_three"]=1; } if ($ke == $count-1) { return json(['code' => 0, 'msg' => '成功', 'err_data' => $arrs]); } } } }else{ $arrs=[]; return json(['code' => 0, 'msg' => '成功', 'err_data' => $arrs]); } } } } /** * 商品列表页 */ public function goodsList() { $uid = Cookie::get('user_id'); $user = session('user'); $this->assign('uid', $uid); $key = "goodsList"; if ($uid) { $key .= $uid; } $co = Cache::get($key); /*--如果是本页清理--*/ $clearcache = I('clearcache'); if ($clearcache == 1) { Cache::rm($key); Cache::rm($key . '_url'); $co = 0; } else { /*--如果返回的地址不一样--*/ $url1 = Cache::get($key . '_url'); $url2 = curHostURL() . $_SERVER['REQUEST_URI']; if ($url1 != $url2) { Cache::rm($key); Cache::rm($key . '_url'); $co = 0; } } $stoid = I('stoid/d'); if (empty($co)) { $filter_param = array(); // 帅选数组 $id = I('id/d', 0); // 当前分类id $brand_id = I('brand_id/d', 0); //品牌 $nation_id = I('nation_id/d', 0);//国别 $price = I('price', ''); // 价钱 $gid = I('gid/d', 0); //分组 $sort = I('sort', 'sort'); // 排序 $sort_asc = I('sort_asc', 'asc'); // 排序 if($sort=="") $sort_asc="desc"; $start_price = trim(I('start_price', '0')); // 输入框价钱 $end_price = trim(I('end_price', '0')); // 输入框价钱 if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中 $nation_id && ($filter_param['nation_id'] = $nation_id); //加入筛选条件中 $price && ($filter_param['price'] = $price); //加入筛选条件中 $goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类 // 分类菜单显示 $goodsCate = M('GoodsCategory')->where("id", $id)->find();// 当前分类 //($goodsCate['level'] == 1) && header('Location:'.U('Home/Channel/index',array('cat_id'=>$id))); //一级分类跳转至大分类馆 $cateArr = $goodsLogic->get_goods_cate($goodsCate); // 帅选 品牌 规格 属性 价格 $filter_goods_id =$filter_goods_id2= null; $titlename = ''; $whereall=" "; if (!empty($id)) { $rrs = M('goods_category')->where('store_id',getMobileStoId())->where('id', $id)->find(); $titlename = $rrs['name']; $cat_id_arr = getCatGrandson($id); /*--商品修改。store_id筛选条件--*/ $filter_goods_id = M('goods')->where('store_id', getMobileStoId())->where("is_on_sale=1")->where("cat_id", "in", implode(',', $cat_id_arr))->getField("goods_id", true); $whereall.=" and a.cat_id in (".implode(',', $cat_id_arr).")"; } else if (!empty($gid)) { $rrs = M('goods_group')->where('store_id',getMobileStoId())->where('gpid', $gid)->find(); $titlename = $rrs['gpname']; $filter_goods_id2=$filter_goods_id = explode(',', $rrs['gp_goodslist']); } else { if (!empty($brand_id)) { $rrs = M('brand')->where('store_id',getMobileStoId())->where('id', $brand_id)->find(); $titlename = $rrs['name']; } if (!empty($nation_id)) { $rrs = M('nation')->where('store_id',getMobileStoId())->where('id', $nation_id)->find(); $titlename = $rrs['name']; } $filter_goods_id = M('goods')->where('store_id', $stoid)->where("is_on_sale=1")->getField("goods_id", true); } $this->assign('titlename', $titlename); // 过滤帅选的结果集里面找商品 if ($brand_id || $nation_id)// 品牌或者价格 { if($brand_id) $whereall.=" and a.brand_id=".$brand_id; if($nation_id) $whereall.=" and a.nation_id=".$nation_id; $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice2($brand_id, $nation_id); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 //$sel = I('sel'); //if ($sel) { // $goods_id_4 = $goodsLogic->get_filter_selected($sel, $cat_id_arr); // $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4); //} //$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'goodsList'); // 获取显示的帅选菜单 /*--如果有价格条件--*/ $where = ""; if ($price) { $pricearr = explode('-', $price); $where = " having final_price>=" . $pricearr[0] . " and final_price<=" . $pricearr[1]; } $time = time(); $where11 = ""; if ($filter_goods_id2) { $filter_goods_id2_array = implode(",", $filter_goods_id2); if ($filter_goods_id2_array && count($filter_goods_id2) > 0) { $where11 = " and a.goods_id in(" . implode(',', $filter_goods_id2) . ")"; } else { $where11 = " and a.goods_id=0"; } } $str = "select a.market_price,a.goods_name,a.goods_id,a.original_img, a.sales_sum,a.mz_price,a.prom_type,a.prom_id,a.cardprice1,a.cardprice2,a.cardprice3,a.is_mainshow, CAST(case when (a.prom_type>0 and a.prom_type<3 and b.id<>'') or (a.prom_type=4 and b.is_show=1 and b.id<>'') or (a.prom_type=6 and b.id<>'') then b.prom_price else a.shop_price end as decimal(9,2)) as final_price,b.prom_integral from __PREFIX__goods a left join (select id,commission,is_show,prom_price,type,expression,prom_integral,goods_listid,good_object,prom_type from __PREFIX__activitylist where is_end=0 and (s_time<=" . $time . " or (warm_uptime<=" . $time . " and warm_uptime<>0)) and e_time>=" . $time . " and store_id=" . $stoid . ") as b on locate(CONCAT(',',a.goods_id,','),b.goods_listid)>0 and (b.good_object=1 or b.prom_type<>3) where a.store_id=" . $stoid . $where11 .$whereall. " and a.is_on_sale=1 and a.on_time<".$time." and (a.down_time>".$time." or a.down_time=0 ) and a.is_mainshow=1 " . $where . " order by " . $sort . " " . $sort_asc; $arr = Db::query($str); $count = count($arr); $pricearr = get_arr_column($arr, 'final_price'); /*--各种帅选--*/ $filter_price = $goodsLogic->get_filter_price2($pricearr, $filter_param, 'goodsList'); // 帅选的价格期间 $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选品牌 $filter_nation = $goodsLogic->get_filter_nation($filter_goods_id, $filter_param, 'goodsList', 1);// 获取指定分类下的帅选属性 /*--计算分页--*/ $end = I('p/d', 1) * 10; $mshow = 0; if ($count > 0) { $fir = I('p/d', 1) * 10 - 10; if ($count < $end) $end = $count; for ($i = $fir; $i < $end; $i++) { $arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2); // if ($arr[$i]['mz_price'] == 0) // $arr[$i]['mz_price'] =$arr[$i]['final_price']; if ($arr[$i]['is_mainshow'] == 1) $goods_list[] = $arr[$i]; } //$filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); //if ($filter_goods_id2) // $goods_images = M('goods_images')->where("goods_id", "in", implode(',', $filter_goods_id2)) // ->cache("goods_list_goods_images_" . getMobileStoId())->select(); } //$goods_category = M('goods_category')->where('is_show=1') // ->cache("good_list_goods_category_" . getMobileStoId())->getField('id,name,parent_id,level'); // 键值分类数组 //$this->assign('goods_category', $goods_category); //$this->assign('goods_images', $goods_images); // 相册图片 //$this->assign('filter_menu', $filter_menu); // 帅选菜单 //$this->assign('filter_spec', $filter_spec); // 帅选规格 //$this->assign('filter_attr', $filter_attr); // 帅选属性 $this->assign('goods_list', $goods_list); $this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_nation', $filter_nation);// 列表页帅选属性 - 国别 $this->assign('filter_price', $filter_price);// 帅选的价格期间 $this->assign('goodsCate', $goodsCate); $this->assign('cateArr', $cateArr); $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格 $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格 $this->assign('rank_switch', $rank_switch); $this->assign('mz_switch', $mz_switch); if (!empty($rank_switch)){ //$this->assign('rank_field',$user['card_field']); $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']); $card_field=$rand_end>time()?$user['card_field']:0; $this->assign('rank_field',$card_field); //----读取等级卡标签--- $all_card=get_plus_price_arr($stoid); if($all_card) { $this->assign('all_card', $all_card); //--读取卡的分类--- $new_card_dd = null; foreach ($all_card as $kl => $vl) { if ($vl) { switch ($vl['CorrPrice']) { case "Price1": $new_card_dd['cardprice1'] = $vl['CardName']; break; case "Price2": $new_card_dd['cardprice2'] = $vl['CardName']; break; case "Price3": $new_card_dd['cardprice3'] = $vl['CardName']; break; } } } $card_label = $new_card_dd[$card_field]; $len = mb_strlen($card_label, "utf-8"); if ($len > 4) $card_label = mb_substr($card_label, 0, 4, "utf-8"); $this->assign('card_label', $card_label); } } if (!empty($mz_switch)){ $this->assign('mz_vip',$user['is_mzvip']); } if ($count > $end) { $mshow = 1; } $this->assign('mshow', $mshow); $this->assign('filter_param', $filter_param); // 帅选条件 $this->assign('cat_id', $id); //$this->assign('page', $page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON', false); upload_ylp_log('商品列表'); if (input('is_ajax')) return $this->fetch('ajaxGoodsList', $stoid); //return $this->fetch(); else return $this->fetch('', $stoid); //return $this->fetch(); } else { Cache::rm($key); Cache::rm($key . '_url'); $id = I('id/d', 0); // 当前分类id $brand_id = I('brand_id/d', 0); //品牌 $nation_id = I('nation_id/d', 0);//国别 $price = I('price', ''); // 价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中 $nation_id && ($filter_param['nation_id'] = $nation_id); //加入筛选条件中 $price && ($filter_param['price'] = $price); //加入筛选条件中 $this->assign('filter_param', $filter_param); // 帅选条件 return $this->fetch('goodsList_b', $stoid); } } /** * 商品列表页 ajax 翻页请求 搜索 */ public function ajaxGoodsList() { $where = ''; $cat_id = I("id", 0); // 所选择的商品分类id if ($cat_id > 0) { $grandson_ids = getCatGrandson($cat_id); $where .= " WHERE cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件 } /*--商品修改,store_id筛选条件--*/ $where .= ' and store_id=' . getMobileStoId(); $result = DB::query("select count(1) as count from __PREFIX__goods $where "); $count = $result[0]['count']; $page = new AjaxPage($count, 10); $order = " order by goods_id desc"; // 排序 $limit = " limit " . $page->firstRow . ',' . $page->listRows; $list = DB::query("select * from __PREFIX__goods $where $order $limit"); $this->assign('lists', $list); $html = $this->fetch('ajaxGoodsList', getMobileStoId()); //return $this->fetch('ajax_goods_list'); upload_ylp_log('商品列表页'); exit($html); } /** * 商品详情页 */ public function goodsInfo() { C('TOKEN_ON', true); $stoid = getMobileStoId(); //$user = session('user'); $user_id = cookie('user_id'); $user = M("users")->where("user_id",$user_id)->find(); $goodsLogic = new \app\home\logic\GoodsLogic(); $goods_id = I("get.id"); $is_inte_normal=I("is_inte_normal/d",0); $now0 = time(); /*--活动判断--*/ $goods = M('Goods')->where("goods_id", $goods_id)->where('is_on_sale', 1) //->where('is_mainshow', 1) ->where("on_time<" . $now0 . " and (down_time>" . $now0 . " or down_time=0)") ->field('goods_id,goods_name,brand_id,nation_id,cat_id,market_price,store_count,shop_price,sku,original_img,goods_sn,goods_spec,goods_color, sales_sum,on_time,prom_id,prom_type,REPLACE(REPLACE(goods_remark, CHAR(10),""), CHAR(13),"") as goods_remark,viplimited,distr_type,mz_price,cardprice1,cardprice2,cardprice3,spec_img')->find(); // $ylpapp_list=M('store_config')->where('store_id='.getMobileStoId())->find();//app使用 // $ylpapp_list=$ylpapp_list['ylpapp_list']; if (empty($goods)) { $this->error("此商品已经下架", U('Mobile/index/index', array('stoid' => $stoid))); } if($is_inte_normal==1){ $goods['prom_type']=0;} if (empty($goods['spec_img'])) $goods['spec_img'] = $goods['original_img']; //有礼派APP $getylpres=getylapp_res($stoid,'3'); if ($getylpres) { $this->assign('ylpres',$getylpres); } $this->buy_page_assign(); $rank_switch = tpCache('shopping.rank_switch', $stoid);//等级价格 $mz_switch = tpCache('shopping.is_beauty', $stoid);//美妆价格 $this->assign('mz_switch',$mz_switch); $this->assign('rank_switch',$rank_switch); //---关于销售规则--- $switch_list=tpCache('basic.switch_list', $stoid); $switch_list=json_decode($switch_list,true); $is_newsales_rules=$switch_list['is_newsales_rules']; $this->assign('is_newsales_rules',$is_newsales_rules); $mstore=tpCache('basic.sales_rules',$stoid); $this->assign('sales_rules',$mstore); $fid = "," . $goods_id . ','; $where0 = "((warm_uptime<=" . $now0 . " and warm_uptime>0) or s_time<=" . $now0 . ") and " . $now0 . "<=e_time and goods_listid='" . $fid . "' and is_end=0"; $rrs = M('activitylist')->where($where0)->field('is_show')->find(); $rrs_str = M('activitylist')->where($where0)->field('is_show')->fetchSql(true)->find(); mlog("活动不行".$rrs_str,"activitylist/".$stoid); if ($rrs) { mlog("活动不行,类型".$goods['prom_type'],"activitylist/".$stoid); switch ($goods['prom_type']) { case "1"://限时抢购 //$this->redirect(U('Mobile/Activity/seckill_info', array('id' => $goods_id, 'stoid' => $stoid))); $Event = \think\Loader::controller('mobile/Activity'); $Event->seckill_fun(); return $this->fetch('activity/seckill_info', getMobileStoId()); break; case "2"://团购 //$this->redirect(U('Mobile/Activity/group', array('id' => $goods_id, 'stoid' => $stoid))); $Event = \think\Loader::controller('mobile/Activity'); $Event->group_fun(); return $this->fetch('activity/group', getMobileStoId()); break; case "4"://积分购 if ($rrs['is_show'] == 1 && $is_inte_normal!=1) { //$this->redirect(U('Mobile/integral/integral_info', array('id' => $goods_id, 'stoid' => $stoid))); $Event = \think\Loader::controller('mobile/Integral'); $Event->integral_fun(); return $this->fetch('integral/integral_info', getMobileStoId()); } break; case "6"://拼团 //$this->redirect(U('Mobile/Activity/group', array('id' => $goods_id, 'stoid' => $stoid))); mlog("活动不行,类型".$rrs['is_show'],"activitylist/".$stoid); if ($rrs['is_show'] == 1) { mlog("活动不行,类型1212121","activitylist/".$stoid); $Event = \think\Loader::controller('mobile/Team'); $Event->team_fun(); return $this->fetch('team/team_info', getMobileStoId()); break; } } } if (empty($goods)) { $this->error('此商品不存在或者已下架'); return; } $this->assign('stoid', $stoid); //如果商品有活动,要判断改活动是不是结束了 if($goods['prom_id']){ //如果是搭配促销的话 if($goods['prom_type']==5){ $act=M("collocation")->where("store_id",getMobileStoId()) ->where("id",$goods['prom_id'])->find(); //如果是已经结束或者当前时间大于结束时间 if ($act['is_end'] == 1 || $now0 > $act['end_time']) { M('Goods')->where("goods_id", $goods_id)->save(["prom_type" => 0, "prom_id" => 0]); } }else{ //---查找活动--- $wherea=" store_id=".getMobileStoId()." and act_id=".$goods['prom_id']." and prom_type=".$goods['prom_type']." and locate(',$fid,', goods_listid)>0"; $act = M('activitylist') ->where($wherea) ->field('is_end,e_time')->find(); if($act){ //如果是已经结束或者当前时间大于结束时间 if($act['is_end']==1 || $now0>$act['e_time']){ M('Goods')->where("goods_id",$goods_id)->save(["prom_type"=>0,"prom_id"=>0]); } } } } $gconfig=M("giftuser_config")->where('store_id',getMobileStoId())->field('state')->find(); $this->assign('gconfig', $gconfig); // $goods['prom_type']=0; $is_chat = tpCache("basic.is_chat", $stoid); $rs_server = M('storage_recharge_detail') ->where('store_id', $stoid)->where('admin_id<>0') ->where('end_time>' . $now0) ->find(); $this->assign('is_chat', $is_chat && $rs_server); if ($goods['brand_id']) { $brnad = M('brand')->where("id", $goods['brand_id'])->find(); $goods['brand_name'] = $brnad['name']; } if ($goods['nation_id']) { $nation = M('nation')->where("id", $goods['nation_id'])->find(); $goods['nation_name'] = $nation['name']; } if ($goods['cat_id']) { $cat = M('goods_category')->where("id", $goods['cat_id'])->find(); $goods['cat_name'] = $cat['name']; } $goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->order('ismain desc')->select(); // 商品 图册 $goods_videos = M('goods_videos')->where("goods_id", $goods_id) ->order('video_sort asc')->select(); // 商品 图册 if($goods_videos[0]) $this->assign("goods_videos", $goods_videos); /*---规格筛选---*/ $filter_spec = M('goods')->where('sku', $goods['sku'])->where('store_id', $stoid)->where("is_on_sale", 1) ->where("on_time<" . $now0 . " and (down_time>" . $now0 . " or down_time=0 or down_time='' )") ->field('goods_id,erpwareid,goods_name,brand_id,nation_id,cat_id,goods_spec,goods_color,goods_unitname,goods_sn,sku,shop_price, market_price,sales_sum,store_count,original_img,prom_type,REPLACE(REPLACE(goods_remark, CHAR(10),""), CHAR(13),"") as goods_remark,mz_price,distr_type,cardprice1,cardprice2,cardprice3,spec_img,viplimited') ->order("sort") ->select(); foreach ($filter_spec as $k4 => $v4) { $gidarr4[$v4['erpwareid']] = $v4['goods_id']; } /*-----查看销售规则,采用线下规则要计算所有规格的商品在线下的库存 $mstore=tpCache('basic.sales_rules',$stoid); if($mstore==2){ $this->assign('is_bline',1); mlog('获取线下库存','blinestore0'); $blinesto=getblinesto($gidarr4,getMobileStoId()); mlog('获取线下库存','blinestore0'); if($blinesto==-1){ $this->assign('err', 1); mlog('系统获取线下库存失败','getdownkun/'.$stoid.'/'.$goods_id); }else if($blinesto==-2){ $this->assign('err', 1); mlog('系统未设置线下库存','getdownkun/'.$stoid.'/'.$goods_id); }else { $this->assign('sto_data', $blinesto); } }else{ $this->assign('is_bline',0); } ----*/ //查看销售规则,采用线下规则要计算所有规格的商品在线下的库存 $mstore = tpCache('basic.sales_rules', $stoid); if ($mstore == 2) { $this->assign('is_bline', 1); } else { $this->assign('is_bline', 0); } $guige = "规格"; $gorder = 1; $ary = null; foreach ($filter_spec as $k => $v) { /*-----过滤掉活动的商品-----*/ $now = time(); $wh0 = [ 'end_time' => ['>=', $now], 'start_time' => ['<=', $now], 'id' => $v['prom_id'], 'goods_id' => $v['goods_id'], 'is_end' => 0, ]; $rs = M('group_buy')->where($wh0)->find(); if ($rs) { unset($filter_spec[$k]); continue; } $rs = M('integral_buy')->where($wh0)->where('is_show', 1)->find(); if ($rs) { unset($filter_spec[$k]); continue; } $rs = M('flash_sale')->where($wh0)->find(); if ($rs) { unset($filter_spec[$k]); continue; } $sp = trim($v["goods_spec"]); $cn = trim($$v["goods_color"]); if ($sp == "" && $cn == "") { $tgg = $guige . $gorder; $gorder++; } else if ($sp != "" && $cn == "") { $tgg = $sp; } else if ($sp == "" && $cn != "") { $tgg = $cn; } else { $tgg = $sp . "/" . $cn; } if (empty($v['spec_img'])) $filter_spec[$k]['spec_img'] = $v['original_img']; /*--该商品此卖了多少件--*/ $filter_spec[$k]['guige'] = $tgg; $filter_spec[$k]['curprice'] = $v['shop_price']; if($v['goods_id']==$goods_id && $is_inte_normal==1){ $filter_spec[$k]['prom_type'] = 0; }else { if ($v['prom_type'] > 0) { //找出活动的细节 $prom = $filter_spec[$k]['flash_sale'] = get_goods_promotion($v['goods_id']); if ($prom['is_end'] != 1 && $prom['is_end'] != 4 && $prom['is_end'] != 2) { $filter_spec[$k]['curprice'] = $filter_spec[$k]['flash_sale']['price']; } else { $filter_spec[$k]['prom_type'] = 0; } } } //---判断价格,等级价,美妆价---- if ($v['prom_type'] == 0 || $v['prom_type'] == 3 || $v['prom_type'] == 5) { if ($user['is_mzvip'] && $v['mz_price'] > 0 && $mz_switch) { $filter_spec[$k]['curprice'] = $v['mz_price']; } if ($rank_switch) { if ($user['card_field'] && $v[$user['card_field']] > 0 && strtotime($user['card_expiredate']) > time()) { $filter_spec[$k]['curprice'] = $v[$user['card_field']]; } } } /*--规格排序--*/ if ($v["goods_id"] == $goods_id) { //$filter_spec[$k]['viplimited'] = $goods['viplimited']; $ary = $filter_spec[$k]; unset($filter_spec[$k]); } } /*--规格排序--*/ array_unshift($filter_spec, $ary); M('Goods')->where("goods_id=$goods_id")->save(array('click_count' => $goods['click_count'] + 1)); //统计点击数 $commentStatistics = $goodsLogic->commentStatistics($goods_id);// 获取某个商品的评论统计 $goods['guige'] = $ary['guige']; /*-----当前价格-----*/ $curprice = $ary['curprice']; $now = time(); $where = [ 'end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'id' => $goods['prom_id'], 'is_end' => 0, ]; $goods['discount'] = round($curprice / $goods['market_price'], 2) * 10; if ($goods['prom_type'] == 3) { $prom_active = M('prom_goods') ->where('store_id', $stoid) ->where($where)->find(); } else if ($goods['prom_type'] == 5) { $collocation_active = M('collocation') ->where('store_id', $stoid) ->where($where)->field('id,title,img_url,end_time')->find(); if (!empty($collocation_active)) { $collocation_active['max'] = $goods['shop_price'] + M('collocation_list')->where('prom_id', $goods['prom_id'])->order('price desc')->limit(0, 1)->field('price')->find()['price']; $collocation_active['min'] = $goods['shop_price'] + M('collocation_list')->where('prom_id', $goods['prom_id'])->order('price asc')->limit(0, 1)->field('price')->find()['price']; } $this->assign('collocation', $collocation_active); } else { /*---- $prom_active = M('prom_goods') ->where('store_id', $stoid) ->where(['end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'is_end' => 0, 'good_object' => 0])->find(); }---*/ $now=time(); $w1="(b.goods_listid='' or b.goods_listid is null or locate(',".$goods['goods_id'].",',b.goods_listid)=0)"; $prom_active = M('prom_goods')->alias('a')->join('activitylist b','b.act_id=a.id and b.prom_type=3') ->where('a.store_id', $stoid)->where($w1) ->where(['a.end_time' => ['gt', $now], 'a.start_time' => ['lt', $now], 'a.is_end' => 0, 'a.good_object' => 0]) ->field('a.*') ->find(); } if (!empty($prom_active)) { $prom_lists = M('prom_goods_list')->where('prom_id', $prom_active['id'])->order('condition', 'asc')->select(); foreach ($prom_lists as $k => $v) { $prom_list = json_decode($v['preferential_type'], true); $prom_lists[$k]['condition'] = floatval($v['condition']); $prom_lists[$k]['money'] = floatval(($prom_list['money'])); $prom_lists[$k]['sale'] = $prom_list['sale']; $prom_lists[$k]['past'] = $prom_list['is_past']; $prom_lists[$k]['int'] = $prom_list['int']; $id = $prom_list['coupon']; if ($id > 0) { $coupon = M('coupon')->where(['id' => $id, 'send_start_time' => ['lt', $now], 'send_end_time' => ['gt', $now]])->field('id,money')->find(); $prom_lists[$k]['coupon'] = $coupon['money']; $prom_lists[$k]['coupon_id'] = (int)$coupon['id']; } $id = $prom_list['gift']; if ($id > 0) { $gift = M('gift')->where(['id' => $id, 'start_time' => ['lt', $now], 'end_time' => ['gt', $now], 'goods_num' => ['>', 0], 'is_end' => 0])->field('id,goods_name,goods_id')->find(); $prom_lists[$k]['goods_name'] = $gift['goods_name']; $prom_lists[$k]['gift_id'] = (int)$gift['id']; } $liid=$prom_list['libao']; if($liid>0){ $lb = M('libao_form')->where(['id' => $liid, 'startime' => ['lt', $now], 'endtime' => ['gt', $now],'isdel' => 0])->field('id,lbtitle')->find(); $prom_lists[$k]['lbtitle'] = $lb['lbtitle']; $prom_lists[$k]['lb_id'] = (int)$lb['id']; } } $this->assign('prom_list', $prom_lists);// 商品促销 } //修改美妆价 if ($goods['prom_type'] == 0 || $goods['prom_type'] == 3) { //如果有美妆价和启用,大于0 if ($goods['mz_price'] > 0 && $user['is_mzvip'] && $mz_switch) { $curprice = $goods['mz_price']; } //如果有等级价和启用,大于0 if ($rank_switch) { if ($user['card_field'] && strtotime($user['card_expiredate']) > time() && $goods[$user['card_field']] > 0) { $curprice = $goods[$user['card_field']]; //--- 如果卡还没有到期,前30天 -- if(strtotime($user['card_expiredate'])-time()>30*24*3600){ $this->assign("is_no_date",1); } } } } //当前用户收藏 $user_id = cookie('user_id'); $collect = M('goods_collect')->where(array("goods_id" => $goods_id, "user_id" => $user_id))->count(); $goods_collect_count = M('goods_collect')->where(array("goods_id" => $goods_id))->count(); //商品收藏数 $this->assign('collect', $collect); $this->assign('commentStatistics', $commentStatistics);//评论概览 $this->assign('filter_spec', $filter_spec);//规格参数 $this->assign('goods_images_list', $goods_images_list);//商品缩略图 $this->assign('goods', $goods); $this->assign('goods_collect_count', $goods_collect_count); //商品收藏人数 $this->assign('collect', $collect); //是否收藏 $this->assign('curprice', $curprice); //价格 if ($rank_switch) { //$this->assign('rank_field', $user['card_field']); $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']); $card_field=$rand_end>time()?$user['card_field']:0; //30天,要显示等级卡续费 if($rand_end>time() && $rand_end-time()<60*60*24*30 ){ $this->assign('is_near',1); } $this->assign('rank_field',$card_field); $this->assign('card_expiredate',$user['card_expiredate']); $rs_dd=get_plus_price_arr(getMobileStoId()); if($rs_dd) { $new_card_dd = null; foreach ($rs_dd as $kl => $vl) { if ($vl) { switch ($vl['CorrPrice']) { case "Price1": $new_card_dd['cardprice1'] = $vl['CardName']; break; case "Price2": $new_card_dd['cardprice2'] = $vl['CardName']; break; case "Price3": $new_card_dd['cardprice3'] = $vl['CardName']; break; } } } $this->assign('card_data', $rs_dd); $this->assign('new_card_dd', $new_card_dd); } } if ($mz_switch) { $this->assign('mz_vip', $user['is_mzvip']); } $mzprice_list = tpCache('shopping.mzprice_list',$stoid);//美妆条件 $mzprice_list=json_decode($mzprice_list,true); $this->assign('mz_switch',$mz_switch); $this->assign('mzprice_list',$mzprice_list); $this->assign('switch', tpCache('shopping.switch_list', $stoid)); $t = time(); $prom_order = M("prom_order") ->where("store_id", getMobileStoId()) ->where("start_time<=" . $t) ->where("end_time>=" . $t) ->where("is_close=0")->where('is_end', 0) ->order(" id desc")->limit(1)->select(); $this->assign('prom_order', $prom_order); upload_ylp_log('商品详情'); //商品图片 $imgurl = getImg($goods['original_img'],curHostURL().NOIMG); $msg = $this->img_curl_url($imgurl, 2); $shareimg = $msg['data']; $this->assign('shareimg',$shareimg); //二维码也用64位 $shareurl=curHostURL().'/index.php/mobile/goods/goodsInfo/stoid/'.$stoid.'/id/'.$goods_id."/first_leader/".$user['user_id']; $this->assign('shareurl',$shareurl); $qc = new \app\home\controller\Index(); $shareurl=$qc->qr_code_64($shareurl); $this->assign('shareurlimg',$shareurl); return $this->fetch('', getMobileStoId()); } /** * 商品详情页 */ public function detail() { // form表单提交 C('TOKEN_ON', true); $goods_id = I("get.id/d"); $goods = M('Goods')->where("goods_id", $goods_id)->find(); $this->assign('goods', $goods); upload_ylp_log('商品页-商品详情'); return $this->fetch('', getMobileStoId()); } /* * 商品评论 */ public function comment() { $goods_id = I("goods_id/d", 0); $this->assign('goods_id', $goods_id); return $this->fetch('', getMobileStoId()); } /* * ajax获取商品详情 */ public function ajaxComment() { $stoid=getMobileStoId(); $goods_id = I("goods_id/d", 0); $commentType = I('commentType', '1'); // 1 全部 2好评 3 中评 4差评 5晒图 $where = "1=1"; if ($commentType == 5) { $where .= " and c.goods_id =" . $goods_id . " and c.parent_id = 0 and c.img !='' and c.img NOT LIKE 'N;%' "; } else { $typeArr = array('1' => '0,1,2,3,4,5', '2' => '4,5', '3' => '3', '4' => '0,1,2'); $where .= " and c.goods_id =" . $goods_id . " and c.parent_id = 0 and round((c.deliver_rank + c.goods_rank + c.service_rank) / 3) in($typeArr[$commentType])"; } $where .= ' and c.store_id=' . getMobileStoId(); $where .= ' and c.is_show=1 '; $count = M('Comment') ->alias('c') ->where($where)->count("1"); $page_count = 5; $page = new AjaxPage($count, $page_count); $list = M('Comment') ->alias('c') ->join('__USERS__ u', 'u.user_id = c.user_id', 'LEFT') ->where($where) ->order("add_time desc") ->field('u.head_pic,u.nickname,c.username,c.add_time,c.content,c.img,c.comment_id,round((c.deliver_rank + c.goods_rank + c.service_rank) / 3)as service_rank,u.card_field') ->limit($page->firstRow . ',' . $page->listRows) ->select(); foreach ($list as $k => $v) { $list[$k]['img'] = unserialize($v['img']); // 晒单图片 //商家回复 $replyList = M('Comment')->where(array('goods_id'=>$goods_id,'parent_id'=>$v['comment_id']))->field('content,add_time')->order("add_time desc")->select(); $list[$k]['replylist']=$replyList; //点赞的统计 $zannum=M("comment_zan")->where("store_id",getMobileStoId())->where("comment_id",$v['comment_id'])->select(); if($zannum){ $list[$k]['zannum']= count($zannum); $user_id= Cookie::get('user_id'); if($user_id){ foreach ($zannum as $kl=>$vl){ if($vl['user_id']==$user_id){ $list[$k]['iszan']=1; break; } } } } else $list[$k]['zannum']=0; } //获取所有的等级卡 $all_card=get_plus_price_arr($stoid); $rs_dd=$all_card; $new_card_dd=null; if($rs_dd) { foreach ($rs_dd as $kl => $vl) { if ($vl) { switch ($vl['CorrPrice']) { case "Price1": $new_card_dd['cardprice1'] = $vl['CardName']; break; case "Price2": $new_card_dd['cardprice2'] = $vl['CardName']; break; case "Price3": $new_card_dd['cardprice3'] = $vl['CardName']; break; } } } $this->assign('new_card_dd', $new_card_dd); } $this->assign('goods_id', $goods_id);//商品id $this->assign('commentlist', $list);// 商品评论 $this->assign('commentType', $commentType);// 1 全部 2好评 3 中评 4差评 5晒图 // $this->assign('replyList', $replyList); // 管理员回复 $this->assign('count', $count);//总条数 $this->assign('page_count', $page_count);//页数 $this->assign('current_count', $page_count * I('p'));//当前条 $this->assign('p', I('p'));//页数 upload_ylp_log('商品页-商品评论'); return $this->fetch('', getMobileStoId()); } /* * ajax获取商品评论 */ public function ajaxdetail() { $goods_id = I("goods_id/d", 0); $gd = M("goods")->where("goods_id", $goods_id)->field('goods_content')->find(); $this->assign("goods_content", $gd["goods_content"]); return $this->fetch('', getMobileStoId()); } /* * 获取商品规格 */ public function goodsAttr() { $goods_id = I("get.goods_id/d", 0); $goods_attribute = M('GoodsAttribute')->getField('attr_id,attr_name'); // 查询属性 $goods_attr_list = M('GoodsAttr')->where("goods_id", $goods_id)->select(); // 查询商品属性表 $this->assign('goods_attr_list', $goods_attr_list); $this->assign('goods_attribute', $goods_attribute); upload_ylp_log('商品页-商品规格'); return $this->fetch('', getMobileStoId()); } /** * 积分商城 */ public function integralMall() { $rank = I('get.rank'); //以兑换量(购买量)排序 if ($rank == 'num') { $ranktype = 'sales_sum'; $order = 'desc'; } //以需要积分排序 if ($rank == 'integral') { $ranktype = 'exchange_integral'; $order = 'desc'; } $point_rate = tpCache('shopping.point_rate', getMobileStoId()); $goods_where = array( 'is_on_sale' => 1, //是否上架 ); //积分兑换筛选 $exchange_integral_where_array = array(array('gt', 0)); // 分类id if (!empty($cat_id)) { $goods_where['cat_id'] = array('in', getCatGrandson($cat_id)); } //我能兑换 $user_id = cookie('user_id'); if (!empty($user_id)) { //获取用户积分 $user_pay_points = intval(M('users')->where(array('user_id' => $user_id))->getField('pay_points')); if ($user_pay_points !== false) { array_push($exchange_integral_where_array, array('lt', $user_pay_points)); } } $goods_where['exchange_integral'] = $exchange_integral_where_array; //拼装条件 $goods_list_count = M('goods')->where($goods_where)->count(); //总页数 $page = new Page($goods_list_count, 15); $goods_list = M('goods')->where($goods_where)->order($ranktype, $order)->limit($page->firstRow . ',' . $page->listRows)->select(); $goods_category = M('goods_category')->where(array('level' => 1))->select(); $this->assign('goods_list', $goods_list); $this->assign('page', $page->show()); $this->assign('goods_list_count', $goods_list_count); $this->assign('goods_category', $goods_category);//商品1级分类 $this->assign('point_rate', $point_rate);//兑换率 $this->assign('totalPages', $page->totalPages);//总页数 if (IS_AJAX) { return $this->fetch('ajaxIntegralMall', getMobileStoId()); //获取更多 } upload_ylp_log('积分商城'); return $this->fetch('', getMobileStoId()); } /** * 商品搜索列表页 */ public function search() { $uid = Cookie::get('user_id'); $this->assign('uid', $uid); $stoid = I('stoid/d'); $filter_param = array(); // 帅选数组 $id = I('get.id/d', 0); // 当前分类id $brand_id = I('brand_id', 0); $nation_id = I('nation_id', 0); $sort = I('sort', 'sort'); // 排序 $sort_asc = I('sort_asc', 'asc'); // 排序 $price = I('price', ''); // 价钱 if($sort=="") $sort_asc="desc"; $id && ($filter_param['id'] = $id); //加入帅选条件中 $price && ($filter_param['price'] = $price); //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中 $nation_id && ($filter_param['nation_id'] = $nation_id); //加入筛选条件中 $start_price = trim(I('start_price', '0')); // 输入框价钱 $end_price = trim(I('end_price', '0')); // 输入框价钱 if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱 $q = urldecode(trim(I('q', ''))); // 关键字搜索 $q && ($_GET['q'] = $filter_param['q'] = $q); //加入帅选条件中 $qtype = I('qtype', ''); $where2="1=1"; $where22=" and 1=1"; if ($qtype) { $filter_param['qtype'] = $qtype; //$where2[$qtype] = 1; $where2.=" and ".$qtype."=1"; $where22.=" and a.".$qtype."=1"; } if ($q) { //$where2['keywords|goods_sn|goods_name'] = array('like', '%' . $q . '%'); $where2.=" and (keywords like '%".$q."%' or goods_sn like '%".$q."%' or sku like '%".$q."%' or goods_name like '%".$q."%')"; $where22.=" and (a.keywords like '%".$q."%' or a.goods_sn like '%".$q."%' or sku like '%".$q."%' or a.goods_name like '%".$q."%')"; } //$where2['is_on_sale'] = 1; //$where2['store_id'] = getMobileStoId(); $goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类 $filter_goods_id = M('goods')->where($where2)->where('is_on_sale',1) ->where('store_id',getMobileStoId())->getField("goods_id", true); $whereall=""; // 过滤帅选的结果集里面找商品 if ($brand_id || $nation_id)// 品牌或者价格 { if($brand_id) $whereall.=" and a.brand_id=".$brand_id; if($nation_id) $whereall.=" and a.nation_id=".$nation_id; $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice2($brand_id, $nation_id); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 //$sel = I('sel'); //if ($sel) { // $goods_id_4 = $goodsLogic->get_filter_selected($sel); // $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4); //} /*--如果有价格条件--*/ $where = ""; if ($price) { $pricearr = explode('-', $price); $where = " having final_price>=" . $pricearr[0] . " and final_price<=" . $pricearr[1]; } $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'search', 1); // 获取指定分类下的帅选品牌 $filter_nation = $goodsLogic->get_filter_nation($filter_goods_id, $filter_param, 'search', 1); // 获取指定分类下的帅选品牌 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); $this->assign('filter_param', $filter_param); // 帅选条件 $this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_nation', $filter_nation);// 列表页帅选属性 -国别 if (input('is_ajax')) { $user = session('user'); $time = time(); $where11 = ""; //if (count($filter_goods_id) > 0) // $where11 = " and a.goods_id in(" . implode(',', $filter_goods_id) . ")"; //else // $where11 = " and a.goods_id=0"; $str = "select a.market_price,a.goods_name,a.goods_id,a.original_img, a.sales_sum,a.is_new,a.is_hot,a.mz_price,a.prom_type,a.prom_id,a.cardprice1,a.cardprice2,a.cardprice3,a.is_mainshow, CAST(case when (a.prom_type>0 and a.prom_type<3 and b.id<>'') or (a.prom_type=4 and b.is_show=1 and b.id<>'' ) or (a.prom_type=6 and b.id<>'') then b.prom_price else a.shop_price end as decimal(9,2)) as final_price,b.prom_integral from __PREFIX__goods a left join (select id,commission,is_show,prom_price,type,expression,prom_integral,goods_listid,good_object,prom_type from __PREFIX__activitylist where is_end=0 and (s_time<=" . $time . " or (warm_uptime<=" . $time . " and warm_uptime<>0)) and e_time>=" . $time . " and store_id=" . $stoid . ") as b on locate(CONCAT(',',a.goods_id,','),b.goods_listid)>0 and (b.good_object=1 or b.prom_type<>3) where a.store_id=" . $stoid .$where22. $where11.$whereall. " and a.is_on_sale=1 and a.on_time<".$time." and (a.down_time>".$time." or a.down_time=0) and a.is_mainshow=1 " . $where . " order by " . $sort . " " . $sort_asc; $arr = Db::query($str); $count = count($arr); $pricearr = get_arr_column($arr, 'final_price'); //$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'search'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price2($pricearr, $filter_param, 'search'); // 帅选的价格期间 $this->assign('filter_price', $filter_price);// 帅选的价格期间 $this->assign('filter_price1', json_encode($filter_price));// 帅选的价格期间 $end = I('p/d', 1) * 10; $mshow = 0; if ($count > 0) { //$goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->limit($page->firstRow . ',' . $page->listRows)->select(); $fir = I('p/d', 1) * 10 - 10; if ($count < $end) $end = $count; for ($i = $fir; $i < $end; $i++) { $arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2); if ($arr[$i]['is_mainshow'] == 1) $goods_list[] = $arr[$i]; } /*---- $filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); if ($filter_goods_id2) $goods_images = M('goods_images') ->where("goods_id", "in", implode(',', $filter_goods_id2))->select();--*/ } //$goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组 if ($count > I('p/d', 1) * 10) { $this->assign('mshow', 1); } else { $this->assign('mshow', 0); } $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格 $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格 $this->assign('rank_switch', $rank_switch); $this->assign('mz_switch', $mz_switch); if (!empty($rank_switch)){ //$this->assign('rank_field',$user['card_field']); $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']); $card_field=$rand_end>time()?$user['card_field']:0; $this->assign('rank_field',$card_field); //----读取等级卡标签--- $all_card=get_plus_price_arr($stoid); if($all_card) { $this->assign('all_card', $all_card); //--读取卡的分类--- $new_card_dd = null; foreach ($all_card as $kl => $vl) { if ($vl) { switch ($vl['CorrPrice']) { case "Price1": $new_card_dd['cardprice1'] = $vl['CardName']; break; case "Price2": $new_card_dd['cardprice2'] = $vl['CardName']; break; case "Price3": $new_card_dd['cardprice3'] = $vl['CardName']; break; } } } mlog("1:".json_encode($all_card),"/".getMobileStoId()); mlog("2:".json_encode($new_card_dd),"/".getMobileStoId()); $card_label = $new_card_dd[$card_field]; mlog("3:".json_encode($new_card_dd),"/".getMobileStoId()); $len = mb_strlen($card_label, "utf-8"); if ($len > 4) $card_label = mb_substr($card_label, 0, 4, "utf-8"); $this->assign('card_label', $card_label); } } if (!empty($mz_switch)){ $this->assign('mz_vip',$user['is_mzvip']); } $this->assign('stoid', getMobileStoId()); $this->assign('goods_list', $goods_list); //$this->assign('goods_category', $goods_category); //$this->assign('goods_images', $goods_images); // 相册图片 //$this->assign('filter_menu', $filter_menu); // 帅选菜单 //$this->assign('page', $page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON', false); upload_ylp_log('商品搜索列表'); return $this->fetch('ajaxGoodsList', $stoid); } return $this->fetch('', $stoid); } /** * 分销商品搜索列表页 */ public function searchdistribution() { $filter_param = array(); // 帅选数组 $id = I('get.id/d', 0); // 当前分类id $brand_id = I('brand_id', 0); $sort = I('sort', 'goods_id'); // 排序 $sort_asc = I('sort_asc', 'desc'); // 排序 $price = I('price', ''); // 价钱 $start_price = trim(I('start_price', '0')); // 输入框价钱 $end_price = trim(I('end_price', '0')); // 输入框价钱 if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中 $price && ($filter_param['price'] = $price); //加入帅选条件中 $q = urldecode(trim(I('q', ''))); // 关键字搜索 $q && ($_GET['q'] = $filter_param['q'] = $q); //加入帅选条件中 $qtype = I('qtype', ''); if ($qtype) { $where = array('is_on_sale' => 1); $filter_param['qtype'] = $qtype; $where[$qtype] = 1; } if ($q) $where['goods_name'] = array('like', '%' . $q . '%'); $where['store_id'] = getMobileStoId(); $goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类 $filter_goods_id = M('goods')->where($where)->getField("goods_id", true); // 过滤帅选的结果集里面找商品 if ($brand_id || $price)// 品牌或者价格 { $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id, $price); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 $sel = I('sel'); if ($sel) { $goods_id_4 = $goodsLogic->get_filter_selected($sel); $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4); } $filter_menu = $goodsLogic->get_filter_menu($filter_param, 'searchdistribution'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price($filter_goods_id, $filter_param, 'searchdistribution'); // 帅选的价格期间 $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'searchdistribution', 1); // 获取指定分类下的帅选品牌 $count = count($filter_goods_id); $page = new Page($count, 2); if ($count > 0) { $goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id)) ->order("$sort $sort_asc")->limit($page->firstRow . ',' . $page->listRows)->select(); $filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); if ($filter_goods_id2) $goods_images = M('goods_images') ->where("goods_id", "in", implode(',', $filter_goods_id2))->select(); } $goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组 $this->assign('stoid', getMobileStoId()); $this->assign('goods_list', $goods_list); $this->assign('goods_category', $goods_category); $this->assign('goods_images', $goods_images); // 相册图片 $this->assign('filter_menu', $filter_menu); // 帅选菜单 $this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_price', $filter_price);// 帅选的价格期间 $this->assign('filter_param', $filter_param); // 帅选条件 $this->assign('page', $page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON', false); upload_ylp_log('分销商品搜索列表'); if (input('is_ajax')) return $this->fetch('ajaxdistribution', getMobileStoId()); else return $this->fetch('', getMobileStoId()); } /** * 商品搜索列表页 */ public function ajaxSearch() { return $this->fetch('', getMobileStoId()); } /** * 品牌街 */ public function brandstreet() { $getnum = 9; //取出数量 $goods = M('goods')->where(array('is_recommend' => 1, 'is_on_sale' => 1)) ->page(1, $getnum)->cache("brandstreet_" . getMobileStoId(), TPSHOP_CACHE_TIME)->select(); //推荐商品 for ($i = 0; $i < ($getnum / 3); $i++) { //3条记录为一组 $recommend_goods[] = array_slice($goods, $i * 3, 3); } $where = array( 'is_hot' => 1, //1为推荐品牌 ); $count = M('brand')->where($where)->count(); // 查询满足要求的总记录数 $Page = new Page($count, 20); $show = $Page->show();// 分页显示输出 $brand_list = M('brand')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('sort desc')->select(); $this->assign('Page', $show); //赋值分页输出 $this->assign('recommend_goods', $recommend_goods); //品牌列表 $this->assign('brand_list', $brand_list); //推荐商品 if (I('is_ajax')) { return $this->fetch('ajaxBrandstreet', getMobileStoId()); } return $this->fetch('', getMobileStoId()); } /** * 商品列表—分销商上下架 增加 20170321 */ public function goodsList_distribution() { $filter_param = array(); // 帅选数组 $id = I('id/d', 0); // 当前分类id $brand_id = I('brand_id/d', 0); $spec = I('spec', 0); // 规格 $attr = I('attr', ''); // 属性 $sort = I('sort', 'goods_id'); // 排序 $sort_asc = I('sort_asc', 'desc'); // 排序 $price = I('price', ''); // 价钱 $start_price = trim(I('start_price', '0')); // 输入框价钱 $end_price = trim(I('end_price', '0')); // 输入框价钱 if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中 $spec && ($filter_param['spec'] = $spec); //加入帅选条件中 $attr && ($filter_param['attr'] = $attr); //加入帅选条件中 $price && ($filter_param['price'] = $price); //加入帅选条件中 $goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类 // 分类菜单显示 $goodsCate = M('GoodsCategory')->where("id", $id)->find();// 当前分类 //($goodsCate['level'] == 1) && header('Location:'.U('Home/Channel/index',array('cat_id'=>$id))); //一级分类跳转至大分类馆 $cateArr = $goodsLogic->get_goods_cate($goodsCate); // 帅选 品牌 规格 属性 价格 $cat_id_arr = getCatGrandson($id); $filter_goods_id = M('goods')->where("is_on_sale=1")->where("cat_id", "in", implode(',', $cat_id_arr))->getField("goods_id", true); // 过滤帅选的结果集里面找商品 if ($brand_id || $price)// 品牌或者价格 { $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id, $price); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集 } if ($spec)// 规格 { $goods_id_2 = $goodsLogic->getGoodsIdBySpec($spec); // 根据 规格 查找当所有商品id $filter_goods_id = array_intersect($filter_goods_id, $goods_id_2); // 获取多个帅选条件的结果 的交集 } if ($attr)// 属性 { $goods_id_3 = $goodsLogic->getGoodsIdByAttr($attr); // 根据 规格 查找当所有商品id $filter_goods_id = array_intersect($filter_goods_id, $goods_id_3); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 $sel = I('sel'); if ($sel) { $goods_id_4 = $goodsLogic->get_filter_selected($sel, $cat_id_arr); $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4); } $filter_menu = $goodsLogic->get_filter_menu($filter_param, 'goodsList'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price($filter_goods_id, $filter_param, 'goodsList'); // 帅选的价格期间 $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选品牌 $filter_spec = $goodsLogic->get_filter_spec($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选规格 $filter_attr = $goodsLogic->get_filter_attr($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选属性 $count = count($filter_goods_id); $page = new Page($count, 2); if ($count > 0) { $goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->limit($page->firstRow . ',' . $page->listRows)->select(); $filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); if ($filter_goods_id2) $goods_images = M('goods_images')->where("goods_id", "in", implode(',', $filter_goods_id2))->select(); } $goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组 $this->assign('goods_list', $goods_list); $this->assign('goods_category', $goods_category); $this->assign('goods_images', $goods_images); // 相册图片 $this->assign('filter_menu', $filter_menu); // 帅选菜单 $this->assign('filter_spec', $filter_spec); // 帅选规格 $this->assign('filter_attr', $filter_attr); // 帅选属性 $this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_price', $filter_price);// 帅选的价格期间 $this->assign('goodsCate', $goodsCate); $this->assign('cateArr', $cateArr); $this->assign('filter_param', $filter_param); // 帅选条件 $this->assign('cat_id', $id); $this->assign('page', $page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON', false); if (input('is_ajax')) return $this->fetch('ajaxGoodsList'); else return $this->fetch(); } /** * 看相似 * $author lxl * $time 2017-1 */ // public function similar(){ // $good_id = I('id',''); // $now_good = M('goods')->where("goods_id=$good_id")->find(); //当前商品 // $where_id_list = M('goods')->field('cat_id,spec_type')->where("goods_id=$good_id")->find(); //相似条件,分类id,类型id // $count = M('goods')->where($where_id_list) ->count(); //符合条件的总数 // $pagesize = C('PAGESIZE'); //每页显示数 // $Page = new Page($count,$pagesize); // $goods_list = M('goods')->where($where_id_list) ->limit($Page->firstRow.','.$Page->listRows)->select(); //获取相似商品 // $this->assign('goods_list',$goods_list); // $this->assign('now_good',$now_good); // if(I('is_ajax')){ // return $this->fetch('ajax_similar',getMobileStoId()); // } // return $this->fetch('',getMobileStoId()); // } public function firstsetCaChe() { $key = I("key"); $url = I("url"); Cache::set($key, "1"); Cache::set($key . '_url', $url); $co = Cache::get($key); if($co==false) $co=1; return $co; } public function firstgetCaChe() { $key = I("key"); $co = Cache::get($key); return $co; } /*-----------获取门店排行20191128------------------*/ public function getStorageList() { $lx = I('lx'); $ly = I('ly'); if(empty($lx)) $lx=0; if(empty($ly)) $ly=0; $uid = session('user')['user_id']; $stoid = I('stoid'); $dis=I('distr_type/d');//商品物流方式 $user_def_sto=mb_get_user_sto($dis,$lx,$ly); /*-----查看销售规则,采用线下规则要计算所有规格的商品在线下的库存----*/ $mstore = tpCache('basic.sales_rules', $stoid); $switch_list=tpCache('basic.switch_list', $stoid); $switch_list=json_decode($switch_list,true); $is_newsales_rules=$switch_list['is_newsales_rules']; mlog("[".$uid."]is_newsales_rules:".$is_newsales_rules,"getStorageList/".$stoid); //--当是线下规则的时候,且不是最新的取门店方法-- if ($mstore == 2 ) { $id = I('goodsid'); $goods = M("goods")->where('store_id', $stoid) ->where('goods_id', $id)->field('erpwareid,goods_id')->find(); $time = time(); $gidarr4[$goods['erpwareid']]=$goods['goods_id']; $this->assign('is_bline', 1); $blinesto = []; if($is_newsales_rules){ $blinesto =get_isnewrules_store($stoid,$id,$dis,$lx,$ly); }else{ if ($lx == 0 && $ly == 0) { $blinesto = getblinesto($gidarr4, getMobileStoId(),$dis); } else { session('ulx'.$uid, $lx); session('uly'.$uid, $ly); $blinesto = getblinesto_sortlocation($gidarr4, getMobileStoId(),$id, $lx, $ly,$dis); } } mlog('获取线下库存'.json_encode($blinesto), 'blinestore0/'.$stoid); if ($blinesto == -1) { return json(['code' => -2, 'msg' => '获取库存失败', 'is_bline' => 1]); mlog('系统获取线下库存失败', 'getdownkun/' . $stoid . '/' . $goods_id); } else if ($blinesto == -2) { return json(['code' => -2, 'msg' => '门店库存不足', 'is_bline' => 1]); mlog('系统未设置线下库存', 'getdownkun/' . $stoid . '/' . $goods_id); } else if ($blinesto == -3) { return json(['code' => -2, 'msg' => '未找到门店', 'is_bline' => 1]); mlog('未找到门店', 'getdownkun/' . $stoid . '/' . $goods_id); } else { //--运行数量,计算预出库的库存数量要减掉-- if(!$is_newsales_rules) { //---线下库存判断预存是多少,组装map数组,快速查找--- $strq = 'select pickup_id,sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id=' . $id . ' and store_id='.$stoid.' group by pickup_id'; $dd = Db::query($strq); $ddd=[]; foreach ($dd as $kl=>$vl){ $ypkid=$vl['pickup_id']; $ddd[$id."-".$ypkid]=$vl['sum0']; } $count = 0; foreach ($blinesto['res'] as $k0 => $v0) { //--预出库库存计算-- foreach ($v0['list'] as $km => $vm) { $pkid = $vm['pickup_id']; $gid0 = $k0; if ($ddd[$gid0 . '-' . $pkid]) { $vm['count'] = $blinesto['res'][$k0]['list'][$km]['count'] = $vm['count'] - $ddd[$gid0 . '-' . $pkid]; } //--如果库存为零-- if ($vm['count'] == 0) { unset($blinesto['res'][$k0]['list'][$km]); } } } } $list=$blinesto['res'][$id]['list']; //本商品的门店列表,不同是商品是由不同的list $count=count($list); $res1=M("storage_category")->where('store_id', $stoid)->field("cat_id,cat_name") ->order('sort asc') ->where("is_show",1)->select(); $count0=M("storage_category")->where('store_id', $stoid)->count(); if($count<=5 || $count0<=0){ return json(['code' => 1, 'msg' => 'ok','type'=>1,'is_bline' => 1,'user_def_sto'=>$user_def_sto, 'sto_data' => $list, 'min' =>$list[0] ]); }else { foreach ($res1 as $k1 => $v1) { $result =[]; foreach($list as $k=>$v){ if($v1['cat_id']==$v['cat_id']){ $result[]=$v;} } if (empty($result)) { unset($res1[$k1]); } else { $res1[$k1]['list'] = $result; } } return json(['code' => 1, 'msg' => 'ok', 'is_bline' => 1,'user_def_sto'=>$user_def_sto, 'sto_data' => $res1, 'min' => $blinesto['min'],'def_list'=>$blinesto['def_list']]); } } } else { if ($lx != 0 || $ly != 0) { session('ulx'.getMobileStoId(), $lx); session('uly'.getMobileStoId(), $ly); } $mindate = []; /*--剔除不显示门店分类底下的门店--*/ $res0 = M("storage_category")->where('store_id', $stoid)->where('is_show', 0)->field("cat_id")->select(); $count0=M("storage_category")->where('store_id', $stoid)->count(); $res0=get_arr_column($res0,'cat_id'); $wh="1=1"; if(!empty($res0)) $wh="category_id not in(".implode(',',$res0).")"; if($dis==0){ $where1="1=1"; }else { $where1 = "distr_type=" . $dis . " or distr_type=0"; } if($lx || $ly){ $result0=M("pick_up")->where('store_id',$stoid)->where('isstop<>1')->where($wh)->where($where1) ->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance') ->order('distance asc,pickup_id asc') ->select(); }else{ $result0=M("pick_up")->where('store_id',$stoid)->where('isstop<>1')->where($wh)->where($where1) ->field("*,'null' AS distance") ->order('pickup_id asc') ->select(); } //---计算默认一开始的5个门店--- $def_list=[]; foreach ($result0 as $k5=>$v5){ if($k5>4) break; $def_list[]=$v5; } $count=count($result0); if ($count == 0){ return json(['code' => -2, 'msg' => '未找到门店', 'is_bline' => 0]); } /*--当数量小于5--*/ if($count<=5 || $count0<=0){ mlog("[".$uid."]门店数:".$count,"getStorageList/".$stoid); return json(['code' => 1,'is_bline'=>0,'msg' => 'ok','sto_data' => $result0,'type'=>1,'user_def_sto'=>$user_def_sto,]); }else { /*----选择门店-----*/ $res1 = M("storage_category")->where('store_id', $stoid)->where('is_show', 1) ->order('sort asc')->select(); foreach ($res1 as $k1 => $v1) { $result =[]; foreach($result0 as $k=>$v){ if($v1['cat_id']==$v['category_id']){ $result[]=$v;} } if (empty($result)) { unset($res1[$k1]); } else { $res1[$k1]['list'] = $result; } } mlog("[".$uid."]门店数:".$count,"getStorageList/".$stoid); return json(['code' => 1, 'msg' => 'ok', 'is_bline' => 0, 'sto_data' => $res1,'user_def_sto'=>$user_def_sto, 'min' => $def_list[0],'def_list'=>$def_list]); } } } /*--搭配促销列表--*/ public function prom_list() { $id = I('id/d'); $user_id = cookie('user_id'); $goods_id = I('goods_id/d'); $good = M('goods')->where(['goods_id' => $goods_id])->field('goods_id,goods_name,goods_spec,goods_color,store_count,shop_price,original_img,sales_sum,viplimited,distr_type')->find(); if (empty($good['viplimited'])){ $good['viplimited'] = 10000; }else{ $limit=M('order')->alias('a')->join('order_goods b','a.order_id=b.order_id')->where(['b.goods_id'=>$goods_id,'a.user_id'=>$user_id,'a.order_status'=>[['=',4],['<',3],'or']])->sum('b.goods_num'); $good['viplimited']-=$limit; } if ($good['goods_spec'] == '') { if ($good['goods_color'] == '') { $good['spec'] = '规格1'; } else { $good['spec'] = $good['goods_color']; } } else { $good['spec'] = $good['goods_spec']; if (!empty($good['goods_color'])) { $good['spec'] .= '/' . $good['goods_color']; } } $list = M('collocation_list')->where('prom_id', $id)->select(); foreach ($list as $k => $v) { $goods = M('goods')->where(['goods_id' => $v['goods_id'], 'store_count' => ['>', 0]])->field('shop_price,goods_spec,goods_color,original_img,distr_type')->find(); if (!empty($goods)) { if ($goods['goods_spec'] == '') { if ($goods['goods_color'] == '') { $list[$k]['spec'] = '规格1'; } else { $list[$k]['spec'] = $goods['goods_color']; } } else { $list[$k]['spec'] = $goods['goods_spec']; if (!empty($goods['goods_color'])) { $list[$k]['spec'] .= '/' . $goods['goods_color']; } } $list[$k]['original_img'] = $goods['original_img']; $list[$k]['shop_price'] = $goods['shop_price']; $list[$k]['dist_type'] = $goods['distr_type']; } else { unset($list[$k]); } } $this->assign([ 'list' => $list, 'good' => $good, ]); return $this->fetch('', getMobileStoId()); } /*优惠促销商品列表*/ public function prom_goods() { $uid = Cookie::get('user_id'); $stoid = I('stoid/d'); $prom_id = I('prom_id/d'); $all = I('all/d'); $key = I('key/s', ''); $where['store_id'] = $stoid; $where['is_on_sale'] = 1; $where['store_count'] = ['>', 0]; if ($all == 0) { $where['prom_type'] = 0; } else { $where['prom_type'] = 3; $where['prom_id'] = $prom_id; } if (!empty($key)) { $where['goods_name'] = ['like', "%$key%"]; } $time=time(); $arr = M('goods')->where("on_time<".$time." and (down_time>$time or down_time=0 and down_time='' or down_time is null)") ->where($where)->field('goods_name,goods_id,original_img,sales_sum,shop_price as final_price')->select(); $count = M('goods')->where("on_time<".$time." and (down_time>$time or down_time=0 and down_time='' or down_time is null)") ->where($where)->count(); /*--计算分页--*/ $end = I('page/d', 1) * 10; $mshow = 0; if ($count > 0) { $fir = I('page/d', 1) * 10 - 10; if ($count < $end) $end = $count; for ($i = $fir; $i < $end; $i++) { $arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2); $goods_list[] = $arr[$i]; } } $this->assign('uid', $uid); $this->assign('prom_id', $prom_id); $this->assign('all', $all); $this->assign('goods_list', $goods_list); if ($count > $end) { $mshow = 1; } $this->assign('mshow', $mshow); if (input('is_ajax')) { return $this->fetch('ajaxGoodsList', $stoid); } else { $now = time(); if ($prom_id > 0) { $prom_active = M('prom_goods')->where(['end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'is_end' => 0, 'id' => $prom_id])->find(); } else { $prom_active = M('prom_goods')->where(['end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'is_end' => 0, 'good_object' => 0])->find(); } if (!empty($prom_active)) { $prom_list = M('prom_goods_list')->where('prom_id', $prom_active['id'])->order('condition', 'asc')->select(); foreach ($prom_list as $k => $v) { $rule = json_decode($v['preferential_type'], true); $prom_list[$k]['money'] = $rule['money']; $prom_list[$k]['sale'] = $rule['sale']; $prom_list[$k]['past'] = $rule['is_past']; $prom_list[$k]['int'] = $rule['int']; $id = $rule['coupon']; if ($id > 0) { $coupon = M('coupon')->where(['id' => $id, 'send_start_time' => ['lt', $now], 'send_end_time' => ['gt', $now]])->field('id,money')->find(); $prom_list[$k]['coupon'] = (int)$coupon['money']; $prom_list[$k]['coupon_id'] = (int)$coupon['id']; } $id = $rule['gift']; if ($id > 0) { $gift = M('gift')->where(['id' => $id, 'start_time' => ['lt', $now], 'end_time' => ['gt', $now], 'goods_num' => ['>', 0], 'is_end' => 0])->field('id,goods_name,goods_id')->find(); $prom_list[$k]['goods_name'] = $gift['goods_name']; $prom_list[$k]['gift_id'] = (int)$gift['id']; } } $this->assign('prom_list', $prom_list);// 商品促销 } return $this->fetch('', $stoid); } } //查找商品限购 public function getGoodslimit($id){ $user = session('user'); if(empty($id)) $id=I('id',0); $t=time(); /*查找商品*/ $goods = M('Goods') ->where("on_time<".$t." and (down_time>".$t." or down_time='')") ->where("goods_id", $id)->where('is_on_sale', 1) ->find(); // 找出这个商品 if(empty($goods)) return ['num'=>0]; if (empty($goods['viplimited'])) { return ['num'=>100000]; } else { $limit = M('order')->alias('a')->join('order_goods b', 'a.order_id=b.order_id') ->where(['b.goods_id' => $id, 'a.user_id' => $user['user_id'], 'a.order_status' => [['=', 4], ['<', 3], 'or']]) ->sum('b.goods_num'); $limit += M('cart')->where(['goods_id' => $id, 'user_id' => $user['user_id']]) ->where('state',0)->sum('goods_num'); if ($limit >= $goods['viplimited']) { $goods['viplimited'] = 0; } else { $goods['viplimited'] -= $limit; } return ['num'=>$goods['viplimited']]; } } // 网址图片生成BASE64 function img_curl_url($url,$type=0,$timeout=30) { $msg = ['code' => 2100, 'status' => 'error', 'msg' => '未知错误!']; $imgs = ['image/jpeg' => 'jpeg', 'image/jpg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png', 'text/html' => 'html', 'text/plain' => 'txt', 'image/pjpeg' => 'jpg', 'image/x-png' => 'png', 'image/x-icon' => 'ico' ]; if (!stristr($url, 'http')) { $msg['code'] = 2101; $msg['msg'] = 'url地址不正确!'; return $msg; } $dir = pathinfo($url); //var_dump($dir); $host = $dir['dirname']; $refer = $host . '/'; $ch = curl_init($url); //不验证https curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_REFERER, $refer); //伪造来源地址 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//返回变量内容还是直接输出字符串,0输出,1返回内容 curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);//在启用CURLOPT_RETURNTRANSFER的时候,返回原生的(Raw)输出 curl_setopt($ch, CURLOPT_HEADER, 0); //是否输出HEADER头信息 0否1是 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //超时时间 $data = curl_exec($ch); //$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE); //$httpContentType = curl_getinfo($ch,CURLINFO_CONTENT_TYPE); $info = curl_getinfo($ch); curl_close($ch); $httpCode = intval($info['http_code']); $httpContentType = $info['content_type']; $httpSizeDownload = intval($info['size_download']); if ($httpCode != '200') { $msg['code'] = 2102; $msg['msg'] = 'url返回内容不正确!'; return $msg; } if ($type > 0 && !isset($imgs[$httpContentType])) { $msg['code'] = 2103; $msg['msg'] = 'url资源类型未知!'; return $msg; } if ($httpSizeDownload < 1) { $msg['code'] = 2104; $msg['msg'] = '内容大小不正确!'; return $msg; } $msg['code'] = 200; $msg['status'] = 'success'; $msg['msg'] = '资源获取成功'; if ($type == 0 or $httpContentType == 'text/html') $msg['data'] = $data; $base_64 = base64_encode($data); if ($type == 1) $msg['data'] = $base_64; elseif ($type == 2) $msg['data'] = "data:{$httpContentType};base64,{$base_64}"; elseif ($type == 3) $msg['data'] = ""; else $msg['msg'] = '未知返回需求!'; unset($info, $data, $base_64); return $msg; } public function get_pj_list(){ $stoid=I('stoid'); $gd_id=I('goods_id'); $pageSize=I('pageSize'); $page=I('page'); //获取所有的等级卡 $tk=tpCache("shop_info.api_token",$stoid); $rs_dd = getApiData("wxd.mem.bershipcard.list.get", $tk, null, null, null, null, 'CardCode desc'); $rs_dd=json_decode($rs_dd,true); $rs_dd=$rs_dd['data']; if($rs_dd){ $new_card_dd=null; foreach ($rs_dd as $kl=>$vl){ if($vl){ switch ($vl['CorrPrice']){ case "Price1": $new_card_dd['cardprice1']=$vl['CardName']; break; case "Price2": $new_card_dd['cardprice2']=$vl['CardName']; break; case "Price3": $new_card_dd['cardprice3']=$vl['CardName']; break; } } } $this->assign('new_card_dd', $new_card_dd); } $url=Mini_Host()."/api/weshop/comment/pageComment?store_id=".$stoid ."&goods_id=".$gd_id."&pageSize=".$pageSize."&parent_id=0&page=".$page; $data=httpRequest($url); $data=json_decode($data,true); if($data['code']==0){ $data=$data['data']['pageData']; if($data){ foreach ($data as $kk=>$vv){ $data[$kk]['img']=unserialize($vv['img']); $user=M('users')->where('user_id',$vv['user_id']) ->field('card_field')->find(); $data[$kk]['card_field']=$user['card_field']; } $this->assign("pg_list",$data); } } return $this->fetch("",$stoid); } public function get_free_quan() { $type = I("get_type"); $stoid = I("stoid"); $user = session('user'); $tt = time(); if ($type == 0) { $coupon = M('coupon')->where("type = 1 and store_id = " . getMobileStoId() . " and " . $tt . " >= send_start_time and send_end_time >= " . $tt) ->order('add_time desc')->limit(3)->select(); $this->assign("coupon", $coupon); return $this->fetch('', $stoid); } else { $coupon = M('coupon')->where("type = 1 and store_id = " . getMobileStoId() . " and " . $tt . " >= send_start_time and send_end_time >= " . $tt) ->order('add_time desc')->select(); $this->assign("coupon", $coupon); $this->assign("user", $user); return $this->fetch('get_free_quan_list', $stoid); } } //---设置默认门店--- public function set_def_store(){ $stoid=I("stoid"); $pickup_id=I("pickup_id"); $uid = Cookie::get('user_id'); $rs= M('users')->where("store_id",$stoid)->where('user_id',$uid)->save(['def_pickup_id'=>$pickup_id]); if($rs===false){ return json(['code'=>-1,'msg'=>'修改失败']); } return json(['code'=>0,'msg'=>'修改成功']); } }