php 实现店铺装修8
- /**
- * @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;
- }
php 实现店铺装修8的更多相关文章
- 关于淘宝店铺装修弹出层popup的记录
小龙最近做了一下下淘宝的店铺装修,里面封装的widget深不见底,刚刚整明白popup,也就是弹出层的使用方法,大神勿喷: <div class="area001">触 ...
- Adobe Photoshop CC2018最新教程+某宝店铺装修教程
PS免费教程,ps淘宝店铺装修教程.该资源为本人从某商网站重金买来,现免费分享给大家,下载地址:百度网盘,https://pan.baidu.com/s/127PjFbGwVVUVce1litHFsw
- php 实现店铺装修5
/** * @title 选中蜂店装修模板样式 * @param plate_id 是 int 商品(平台或特色)装修样式ID * @param type_id 是 int 要装修商品的类型(1-平台 ...
- php 实现店铺装修6
/** * @title 获取预览或发布的蜂店模板样式 * @param store_id 是 string 店铺id * @param type 是 int 装修模板的状态:1-预览蜂店装修模板样式 ...
- php 实现店铺装修7
type_id=0的情况 type_id=1的情况 type_id=2的情况 /** * @title 店铺装修--商品分类 * @param type ...
- php 实现店铺装修3
/** * @title 装修店铺 * @param plate_id 是 int 店铺装修样式ID * @param type 是 int 模板样式子板块类型(4-海景.6-二宫格.8-三宫格.9- ...
- php 实现店铺装修2
<?php namespace Webapp\Model; use Common\Model\DataModel\FlagShopCategoryModel; use Common\Model\ ...
- php 实现店铺装修1
一.原型分析 1.店铺未装修的情况下,使用默认样式,哪个是默认样式由后台告知: 2.所有的样式由后台进行维护(但后台始终有一个默认样式,不可删除不可编辑),所有样式,只要用户未编辑过,则默认按照商品的 ...
- php 实现店铺装修4
/** * @title 发布装修的店铺 * @example FlagShipShopDecorate.fabu? 调试参数:{"username":"17721355 ...
随机推荐
- PHP序列化与反序列化(二)
题目(攻防世界): __construct和__destruct的魔术方法是默认执行的,我们可以忽视他们,__wake up执行以后会返回当前主页上,需要绕过,下面的正则匹配preg_match也需要 ...
- dfs & bfs总结
dfs 最简单的三种形式递归总结 bfs 百度https://baike.baidu.com/item/%E5%AE%BD%E5%BA%A6%E4%BC%98%E5%85%88%E6%90%9C%E7 ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 从已有的数组创建数组
import numpy as np x = [1,2,3] a = np.asarray(x) print (a) import numpy as np x = (1,2,3) a = np.asa ...
- Codeforces Round #592 (Div. 2)G(模拟)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[1000007],b[ ...
- leetCode练题——21. Merge Two Sorted Lists(照搬大神做法)
1.题目 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new l ...
- java8新特性1:lambda表达式和函数式接口
1.lambda的介绍: 1.1.为什么java语言需要引入lambda表达式? java语言诞生于1995年,历史时间已经相对较长了.在其后的各种新型编程语言中,都有着lambda表达式的内容,并且 ...
- SpringBoot 集成Log4j、集成AOP
集成Log4j (1)在pom.xml中添加依赖 <!--去掉springboot默认的日志--> <dependency> <groupId>org.spring ...
- 一步步动手实现高并发的Reactor模型 —— Kafka底层如何充分利用多线程优势去处理网络I/O与业务分发
一.从<Apeche Kafka源码剖析>上搬来的概念和图 Kafka网络采用的是Reactor模式,是一种基于事件驱动的模式.熟悉Java编程的读者应该了解Java NIO提供了Reac ...
- Java 代码中如何调用 第三方Api
在代码中调用第三方API 获取数据 package com.example.demo.utils; import com.alibaba.fastjson.JSONObject; import lom ...
- JS - false 的 六种类型
document.write("--------------");document.write(!false);document.write("------------- ...