/\*\*
\* @title 店铺装修--根据分类获取商品列表
\* @param source 是 int 来源(1--h5、2--app)
\* @param type 是 string 店铺类型--首页进去(other)、我的蜂店进去(me)
\* @param store\_id 是 string 店铺id
\* @param type\_id 是 int 分类类型(0-全部、1-平台、2-特色)
\* @param sort 否 int 排序字段(1销量由高到低、2价格由低到高、3价格由高到低)--不传默认1
\* @param keywords 否 string 搜索字段(商品名称)
\* @param cate\_type 是 string 商品所属分类id--格式:13,20,24,16
\* @param brand\_id 否 string 品牌id--格式:3,4,5,6
\* @param page 否 int 页码(不传默认1)
\* @param pagesize 否 int 每页显示条数(不传默认10)
\* @example FlagShipShopDecorate.getGoodsListByCate? 调用参数说明:{"method":"FlagShipShopDecorate.getGoodsListByCate","username":"17721355485","check\_code":"123456","type\_id":"0","sort":"1","keywords":"","cate\_type":"1","brand\_id":"","page":"1","pagesize":"10","store\_id":"115075399495199"}
\* @return\_param\_explain 分类入口搜索返回字段说明: select\_status:选中状态(1是、2否) img:宫格图片 seascapes:海景图 sell\_nums:已卖数量 sku\_id:商品属性id sku\_no:商品属性编号 title:商品标题 sell\_price:零售价 store\_id:店铺id is\_zero\_goods:是否为0元购(1:0元购,0:不是0元购) restriction:限购数量 yuding:是否可预定 market\_price:市场价 cost\_price:成本价 profit:利润 spec\_name:规格名称 activity\_info--- activityId:活动编码 activityType:活动类型 productPrice:活动售价 costPrice:成本价 title:活动标题 isAct:是否是活动(true:是、false:不是) >>>foot: current\_page:当前页 pagesize:每页显示条数 total\_page:总页数 >>>cate\_info: id:分类id name:分类名称 list\_status:1选中、2未选中 >>>brand\_info: id:品牌id brand\_name:品牌名称 list\_status:1选中、2未选中
\* @method POST
\* @author 邹柯
\*/
public function getGoodsListByCate($res){
$userId=session('user.user\_id');
//商品类型
$type\_id=$res\['type\_id'\];
if(empty($type\_id)){
$type\_id=;
}
if($type\_id != && $type\_id != && $type\_id !=){
E('');
}
$store\_id=$res\['store\_id'\];
//品牌id
$brand\_id=$res\['brand\_id'\];
//搜索--宝贝名称
$keywords=$res\['keywords'\];
//排序字段(1销量由高到低、2价格由低到高、3价格由高到低)
$sort=$res\['sort'\];
if(empty($sort)){
$sort=;
}
if(!empty($sort)){
if($sort != && $sort != && $sort !=){
E('');
}
}
//商品所属分类
$cate\_type=$res\['cate\_type'\];
if(empty($cate\_type)){
$cate\_type=;
}
//页码
$page = $res\['page'\];
if(empty($page)){
$page=;
}
//每页显示条数
$pageSize = $res\['pagesize'\];
if(empty($pageSize)){
$pageSize=;
}
$proStoreGoods = new FlagShopCategoryModel();
$list=$proStoreGoods->getGoodsListByCate($userId,$sort,$cate\_type,$brand\_id,$page,$pageSize,$keywords,$type\_id,$store\_id);
return $list;
}
返回结果
{
"status":"",
"errorCode":"",
"msg":"成功",
"result":{
"goods_info":[
{
"product_id":"P000873",
"brand_id":"",
"search_name":null,
"seascapes":[
\],
"img":"",
"sell\_nums":"",
"title":"【0元购返399元】斐讯K2 1200M智能双频无线路由器 WIFI穿墙 PSG1218",
"sku\_id":"",
"soft\_text":null,
"is\_zero\_goods":"",
"restriction":null,
"yuding":"",
"sku\_no":"P0028792",
"market\_price":null,
"sell\_price":"0.01",
"cost\_price":"0.01",
"product\_num":"",
"profit":"0.00",
"spec\_name":": : ",
"store\_id":"",
"activity\_info":{
"productPrice":"00.00",
"costPrice":"00.00",
"activityId":null,
"activityType":null,
"title":null,
"isAct":false
},
"select\_status":
}
\],
"foot":{
"current\_page":"",
"pagesize":"",
"total\_page":
},
"brand\_info":\[
{
"id":"",
"brand\_name":"斐讯",
"list\_status":
},
{
"id":"",
"brand\_name":"迅捷",
"list\_status":
}
\],
"cate\_info":\[
{
"id":"",
"name":"斐讯K3C+E1组合套装",
"list\_status":
},
{
"id":"",
"name":"斐讯N1预售",
"list\_status":
}
\]
}
}
//根据分类获取商品列表
public function getGoodsListByCate($userId,$sort,$cate\_type,$brand\_id,$page,$pageSize,$keywords,$type\_id,$store\_id){
$store=M('store');
$s\_where\['id'\]=$store\_id;
$store\_user\_id=$store->field('id')->where($s\_where)->getField('user\_id');
//排序
switch ($sort) {
case :
//销量由高到低排序
$order = 'sell\_nums desc';
break;
case :
//价格从低到高
$order = 'sell\_price asc';
break;
default:
//价格从高到低
$order = 'sell\_price desc';
break;
}
$origin=; //1搜索、2店铺首页或商品管理
$res2=$this->getGoodsInfoNew($keywords,$cate\_type,$page,$pageSize,$order,$brand\_id,$store\_id,'me',,$origin,$type\_id,$userId,$store\_user\_id);
if(empty($res2\['goods\_info'\])){
$res2=null;
}
foreach($res2\['goods\_info'\] as $k=>$v){
$arrs\[\]=array(
'productId'=>$v\['product\_id'\],
'skuNo'=>$v\['sku\_no'\]
);
}
$home\_special\_session=new HomeSpecialSessionModel();
$res\_info=$home\_special\_session->getGoodsActInfo($arrs);
foreach($res\_info as $k=>$v){
unset($res\_info\[$k\]\['productId'\]);
unset($res\_info\[$k\]\['skuNo'\]);
unset($res\_info\[$k\]\['status'\]);
}
foreach($res2\['goods\_info'\] as $k=>$v){
$res2\['goods\_info'\]\[$k\]\['activity\_info'\]=$res\_info\[$v\['sku\_no'\]\];
}
$search\_info= $res2;
$ob=new FlagShipShopDecorateModel();
$sku\_ids=array\_column($res2\['goods\_info'\],'sku\_id');
$tt=$ob->getSelectStatus($userId,$type\_id);
foreach($sku\_ids as $k=>$v){
if(in\_array($v,$tt)){
$atr=;
}else{
$atr=;
}
$search\_info\['goods\_info'\]\[$k\]\['select\_status'\]=$atr;
}
return $search\_info;
}
//组装商品信息--新(修改商品列表sku显示为商品显示)
private function getGoodsInfoNew($keywords,$cate\_type,$page,$pageSize,$order,$brand\_id,$store\_id,$store\_type,$source,$origin,$type\_id,$user\_id,$store\_user\_id){
$img\_base=C('img\_base');
//获取平台商品的ID
$pingtai\_goods=C('pingtai\_goods');
//获取特色商品的ID
$tese\_goods=C('tese\_goods');
$store\_goods=M('store\_goods sg');
$ob=new FlagShipShopDecorateModel();
$res=$ob->isParentUserId($user\_id,$store\_user\_id);
if($type\_id==){ //平台商品
$where2 ="gs.goods\_type=$pingtai\_goods";
}elseif($type\_id==){//特色商品
$where2 ="gs.goods\_type=$tese\_goods";
}else{
$where2 ="1=1";
if($res===false){
$where2 .=" and goods\_type=2";
}
}
if(!empty($keywords)){
$where2 .=" and (gs.title like '%$keywords%' or gd.search\_name like '%$keywords%')";
}
$where3=$where2;
//品牌
if(!empty($brand\_id)){
$where2 .=" and gd.brand\_id in ($brand\_id)";
}
if(!empty($cate\_type)){
$where ="sgc.id in ($cate\_type)";
}else{
$where ="1=1";
}
if($type\_id==){ //平台商品
$where .=" and type\_id=$pingtai\_goods";
}elseif($type\_id==){ //特色商品
$where .=" and sg.store\_id='".$store\_id."' and type\_id=$tese\_goods";
}else{
if($res===false){
$where .=" and (sg.store\_id='".$store\_id."' and type\_id=$tese\_goods)";
}else{
$where .=" and ((sg.store\_id='".$store\_id."' and type\_id=$tese\_goods) or type\_id=$pingtai\_goods)";
}
}
$where .=" and sg.is\_deleted=1 and sg.is\_open=1 ";
$store\_goods\_info=$store\_goods->field('sg.sku\_id,sg.g\_cats,sgc.id')
->join('left join lc\_store\_goods\_category sgc on sg.g\_cats=sgc.path')
->where($where)
->select();
$sku\_ids =implode(",",array\_column($store\_goods\_info,'sku\_id'));
$goods\_sku\_m = M('goods\_sku gs');
if(!empty($store\_goods\_info)){
//根据sku\_id查找对应的商品
$sku\_ids = "'".str\_replace(",","','",$sku\_ids)."'";
$where2 .=' and gs.sku\_id in ('.$sku\_ids.') and gs.status=1 and gs.is\_deleted=0 and gd.is\_deleted =0 and gd.is\_online =1 and gs.is\_show=0';
$where4=$where3;
$where4 .=' and gs.status=1 and gs.is\_deleted=0 and gd.is\_deleted =0 and gd.is\_online =1 and gs.is\_show=0';
$gd\_info = $goods\_sku\_m
->join('left join \_\_GOODS\_\_ gd on gd.product\_id=gs.product\_id')
->field("gd.brand\_id,gs.sku\_id")
->where($where4)
->select();
//选中品牌,品牌分类不变
$where3 .=' and gs.sku\_id in ('.$sku\_ids.') and gs.status=1 and gs.is\_deleted=0 and gd.is\_deleted =0 and gd.is\_online =1 and gs.is\_show=0';
$gd\_info2 = $goods\_sku\_m
->join('left join \_\_GOODS\_\_ gd on gd.product\_id=gs.product\_id')
->field("gd.brand\_id,gs.sku\_id")
->where($where3)
->select();
if(!empty($gd\_info2)){
$brand\_ids2=array\_unique(array\_column($gd\_info2,'brand\_id'));
}else{
$brand\_ids2=null;
}
if(!empty($brand\_ids2)){
$brands=implode(',',$brand\_ids2);
}else{
$brands=null;
}
$brand\_info=$this->getBrandInfo($brands,$brand\_id);
if(!empty($gd\_info2)){
$sku\_ids2 =implode(",",array\_unique(array\_column($gd\_info,'sku\_id')));
$sku\_ids2 = "'".str\_replace(",","','",$sku\_ids2)."'";
$where5 ="sg.sku\_id in ($sku\_ids2) and concat(sg.g\_cats,'/') like '".$pingtai\_goods."/%' and sg.is\_deleted=1 and sg.is\_open=1";
$store\_goods\_info5=$store\_goods->field('sgc.id,sg.g\_cats')
->join('left join lc\_store\_goods\_category sgc on sg.g\_cats=sgc.path')
->where($where5)
->select();
$cate\_infos=array\_unique(array\_column($store\_goods\_info5,'id'));
if(!empty($cate\_infos)){
foreach($cate\_infos as $k=>$v){
if(empty($v)){
unset($cate\_infos\[$k\]);
}
}
$cate\_infos=array\_merge($cate\_infos);
}else{
$cate\_infos=null;
}
if(!empty($cate\_infos)){
$cate\_infos=implode(',',$cate\_infos);
$cate\_info=$this->getCateInfo($cate\_type,$cate\_infos);
}
}else{
$cate\_info=null;
}
$count=$goods\_sku\_m->join('left join \_\_GOODS\_\_ gd on gd.product\_id=gs.product\_id')->where($where2)->count('DISTINCT gs.product\_id');
//组装分页信息
$total\_page=ceil($count/$pageSize);
if($page > $total\_page){
$page=;
}
$goods\_info = $goods\_sku\_m
->join('left join \_\_GOODS\_\_ gd on gd.product\_id=gs.product\_id')
->field("gd.product\_id,gd.brand\_id,gd.search\_name,gd.seascapes,gs.img,sum(gs.sell\_nums) as sell\_nums,gs.title")
->where($where2)
->group('gs.product\_id')
->order($order)
->page($page,$pageSize)
->select();
$product\_ids=implode(",",array\_unique(array\_column($goods\_info,'product\_id')));
$product\_ids = "'".str\_replace(",","','",$product\_ids)."'";
$sku\_where="product\_id in ($product\_ids) and gs.status=1 and gs.is\_deleted=0 and gs.is\_show=0";
$sku\_info = $goods\_sku\_m
->field("gs.product\_id,gs.properties,gs.sku\_id,gs.soft\_text,gs.is\_zero\_goods,gs.restriction,gs.yuding,gs.img,gs.sku\_no,gs.market\_price,gs.sell\_price,gs.cost\_price")
->where($sku\_where)
->order('sell\_price asc,gs.sell\_nums desc')
->select();
$sku\_info=$this->remove\_duplicate($sku\_info);
foreach($sku\_info as $k=>$v){
$sku\[$v\['product\_id'\]\]\['properties'\]=$v\['properties'\];
$sku\[$v\['product\_id'\]\]\['sku\_id'\]=$v\['sku\_id'\];
$sku\[$v\['product\_id'\]\]\['soft\_text'\]=$v\['soft\_text'\];
$sku\[$v\['product\_id'\]\]\['is\_zero\_goods'\]=$v\['is\_zero\_goods'\];
$sku\[$v\['product\_id'\]\]\['restriction'\]=$v\['restriction'\];
$sku\[$v\['product\_id'\]\]\['yuding'\]=$v\['yuding'\];
$sku\[$v\['product\_id'\]\]\['img'\]=$v\['img'\];
$sku\[$v\['product\_id'\]\]\['sku\_no'\]=$v\['sku\_no'\];
$sku\[$v\['product\_id'\]\]\['market\_price'\]=$v\['market\_price'\];
$sku\[$v\['product\_id'\]\]\['sell\_price'\]=$v\['sell\_price'\];
$sku\[$v\['product\_id'\]\]\['cost\_price'\]=$v\['cost\_price'\];
}
foreach($goods\_info as $k=>$v){
$goods\_info\[$k\]\['properties'\]= $sku\[$v\['product\_id'\]\]\['properties'\];
$goods\_info\[$k\]\['sku\_id'\]= $sku\[$v\['product\_id'\]\]\['sku\_id'\];
$goods\_info\[$k\]\['soft\_text'\]= $sku\[$v\['product\_id'\]\]\['soft\_text'\];
$goods\_info\[$k\]\['is\_zero\_goods'\]= $sku\[$v\['product\_id'\]\]\['is\_zero\_goods'\];
$goods\_info\[$k\]\['restriction'\]= $sku\[$v\['product\_id'\]\]\['restriction'\];
$goods\_info\[$k\]\['yuding'\]= $sku\[$v\['product\_id'\]\]\['yuding'\];
$goods\_info\[$k\]\['img'\]= $sku\[$v\['product\_id'\]\]\['img'\];
$goods\_info\[$k\]\['sku\_no'\]= $sku\[$v\['product\_id'\]\]\['sku\_no'\];
$goods\_info\[$k\]\['market\_price'\]= $sku\[$v\['product\_id'\]\]\['market\_price'\];
$goods\_info\[$k\]\['sell\_price'\]= $sku\[$v\['product\_id'\]\]\['sell\_price'\];
$goods\_info\[$k\]\['cost\_price'\]= $sku\[$v\['product\_id'\]\]\['cost\_price'\];
}
$public = new PublicModel();
//查询商品是否有多个sku
if(empty($goods\_info)){
foreach ($goods\_info as $key=>$value){
$goods\_info\[$key\]\['product\_num'\]='';
}
}else{
$product\_info=$public->isMoreSku(array\_column($goods\_info,'product\_id'));
$new\_data=\[\];
foreach ($product\_info as $key=>$value){
$new\_data\[$value\['product\_id'\]\]=$value\['num'\];
}
foreach ($goods\_info as $key=>$value){
$goods\_info\[$key\]\['product\_num'\]=empty($new\_data\[$value\['product\_id'\]\])?'':$new\_data\[$value\['product\_id'\]\];
}
}
if(!empty($goods\_info)){
foreach ($goods\_info as $k =>$v) {
//利润:
$profit=$v\['sell\_price'\]-$v\['cost\_price'\];
$goods\_info\[$k\]\['profit'\]=$profit?number\_format($profit, , '.', ','):'0.00';
$seascapes=explode(',',$v\['seascapes'\]);
if(!empty($seascapes)){
$seascapes\_t= array();
foreach($seascapes as $v1){
if(!empty($v1)){
$seascapes\_t\[\]=$img\_base.$v1;
}
}
}
$goods\_info\[$k\]\['seascapes'\]=$seascapes\_t;
$goods\_info\[$k\]\['img'\]=empty($v\['img'\])?'':$img\_base.$v\['img'\];
//单个产品相关的规格
$spec = $public->getSkuPropName('',$v\['properties'\]);
$goods\_info\[$k\]\['spec\_name'\] = $spec;
//app
if($source==){
$inf2=$public->shopDeal($store\_id);
}else{ //h5
$inf2=$public->shopDealH5($store\_id,$store\_type);
}
$inf=$public->getTeSeGoods($v\['sku\_id'\]);
if(empty($inf)){//平台商品
$store\_id=$inf2;
}else{
$store\_id=$inf\['store\_id'\];
}
$goods\_info\[$k\]\['store\_id'\]=$store\_id;
unset($goods\_info\[$k\]\['properties'\]);
}
}
}else{
$goods\_info=null;
if($origin==){
$brand\_info=null;
$cate\_info=null;
}
}
$foot=array('current\_page'=>$page,'pagesize'=>$pageSize,'total\_page'=>$total\_page);
$data\['goods\_info'\]=$goods\_info;
$data\['foot'\]=$foot;
if($origin==){
//组装品牌信息
$data\['brand\_info'\]=$brand\_info;
//组装分类信息
$data\['cate\_info'\]=$cate\_info;
}
return $data;
}
//二维数组去重
public function remove_duplicate($array){
$result=array();
foreach ($array as $key => $value) {
$has = false;
foreach($result as $val){
if($val['product_id']==$value['product_id']){
$has = true;
break;
}
}
if(!$has)
$result[]=$value;
}
return $result;
}
//获取品牌列表
//$brand_ids为搜索后产品所对应的品牌 $brand_id为选中的品牌列表
public function getBrandInfo($brand_ids,$brand_id){
if(!empty($brand_ids)){
$where="id in ($brand_ids)";
}else{
$where="1=1";
}
$brand_info=M('brand')->field('id,brand_name')->where($where)->select();
foreach($brand_info as $k=>$v){
if(empty($brand_id)){
$brand_info[$k]['list_status']=; //未选中
}else{
if(in_array($v['id'],explode(',',$brand_id))){
$brand_info[$k]['list_status']=; //选中
}else{
$brand_info[$k]['list_status']=; //未选中
}
}
}
return $brand_info;
}
//获取分类列表
//$cate_type选中的分类 $cate_infos搜索出的分类
public function getCateInfo($cate_type,$cate_infos){
//获取平台商品的id
$pingtai_goods=C('pingtai_goods');
$where ="id in ($cate_infos)";
$cate_info=M('store_goods_category')->field('id,name,path')->where($where)->order('sort desc')->select();
if(!empty($cate_info)){
foreach($cate_info as $k=>$v){
if(empty($cate_type)){
$cate_info[$k]['list_status']=; //未选中
}else{
if(in_array($v['id'],explode(',',$cate_type))){
$cate_info[$k]['list_status']=; //选中
}else{
$cate_info[$k]['list_status']=; //未选中
}
}
unset($cate_info[$k]['path']);
}
$cate_info=array_merge($cate_info);
}else{
$cate_info=null;
}
return $cate_info;
}
//根据sku\_ids获取分类选中状态
public function getSelectStatus($userId,$type\_id){
$user\_shop\_decorate=M('user\_shop\_decorate');
$usd\_where\['flagship\_shop'\]=;
$usd\_where\['create\_id'\]=$userId;
if($type\_id==){
$usd\_info=$user\_shop\_decorate->field('plate\_id,plate\_content\_draft')->where($usd\_where)->order('create\_time desc')->find();
}else{
$usd\_info=$user\_shop\_decorate->field('plate\_id\_features plate\_id,plate\_content\_draft\_features plate\_content\_draft')->where($usd\_where)->order('create\_time desc')->find();
}
$shop\_decorate\_template=M('shop\_decorate\_template');
$us\_where\['is\_deleted'\]=;
$us\_where\['id'\]=$usd\_info\['plate\_id'\];
$us\_info=$shop\_decorate\_template->field('goods\_nums')->where($usd\_where)->find();
if(empty($usd\_info)){
$goods\_info=$this->getDefaultGoodsInfo($us\_info\['goods\_nums'\],"sell\_nums desc");
foreach($goods\_info as $k=>$v){
$arr\[\]=$v\['sku\_id'\];
}
}else{
$plate\_content=json\_decode($usd\_info\['plate\_content\_draft'\],true);
foreach($plate\_content as $k=>$v){
foreach($v\['goods'\] as $k2=>$v2){
if($v2\['operate\_type'\]==){
$arr\[\]=$v2\['sku\_id'\];
}
}
}
}
return $arr;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章