1. /**
  2. * @title 店铺装修--根据分类获取商品列表
  3. * @param source 是 int 来源(1--h5、2--app)
  4. * @param type 是 string 店铺类型--首页进去(other)、我的蜂店进去(me)
  5. * @param store_id 是 string 店铺id
  6. * @param type_id 是 int 分类类型(0-全部、1-平台、2-特色)
  7. * @param sort 否 int 排序字段(1销量由高到低、2价格由低到高、3价格由高到低)--不传默认1
  8. * @param keywords 否 string 搜索字段(商品名称)
  9. * @param cate_type 是 string 商品所属分类id--格式:13,20,24,16
  10. * @param brand_id 否 string 品牌id--格式:3,4,5,6
  11. * @param page 否 int 页码(不传默认1)
  12. * @param pagesize 否 int 每页显示条数(不传默认10)
  13. * @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"}
  14. * @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未选中
  15. * @method POST
  16. * @author 邹柯
  17. */
  18. public function getGoodsListByCate($res){
  19. $userId=session(\'user.user_id\');
  20. //商品类型
  21. $type_id=$res[\'type_id\'];
  22. if(empty($type_id)){
  23. $type_id=0;
  24. }
  25. if($type_id !=0 && $type_id !=1 && $type_id !=2){
  26. E(\'700416\');
  27. }
  28. $store_id=$res[\'store_id\'];
  29. //品牌id
  30. $brand_id=$res[\'brand_id\'];
  31. //搜索--宝贝名称
  32. $keywords=$res[\'keywords\'];
  33. //排序字段(1销量由高到低、2价格由低到高、3价格由高到低)
  34. $sort=$res[\'sort\'];
  35. if(empty($sort)){
  36. $sort=1;
  37. }
  38. if(!empty($sort)){
  39. if($sort !=1 && $sort !=2 && $sort !=3){
  40. E(\'700410\');
  41. }
  42. }
  43. //商品所属分类
  44. $cate_type=$res[\'cate_type\'];
  45. if(empty($cate_type)){
  46. $cate_type=0;
  47. }
  48. //页码
  49. $page = $res[\'page\'];
  50. if(empty($page)){
  51. $page=1;
  52. }
  53. //每页显示条数
  54. $pageSize = $res[\'pagesize\'];
  55. if(empty($pageSize)){
  56. $pageSize=10;
  57. }
  58. $proStoreGoods = new FlagShopCategoryModel();
  59. $list=$proStoreGoods->getGoodsListByCate($userId,$sort,$cate_type,$brand_id,$page,$pageSize,$keywords,$type_id,$store_id);
  60. return $list;
  61. }

 

返回结果

  1. {
  2. "status":"0",
  3. "errorCode":"0",
  4. "msg":"成功",
  5. "result":{
  6. "goods_info":[
  7. {
  8. "product_id":"P000873",
  9. "brand_id":"3",
  10. "search_name":null,
  11. "seascapes":[
  12. ],
  13. "img":"",
  14. "sell_nums":"1",
  15. "title":"【0元购返399元】斐讯K2 1200M智能双频无线路由器 WIFI穿墙 PSG1218",
  16. "sku_id":"8032715893",
  17. "soft_text":null,
  18. "is_zero_goods":"0",
  19. "restriction":null,
  20. "yuding":"1",
  21. "sku_no":"P0028792",
  22. "market_price":null,
  23. "sell_price":"0.01",
  24. "cost_price":"0.01",
  25. "product_num":"1",
  26. "profit":"0.00",
  27. "spec_name":": : ",
  28. "store_id":"115075399495199",
  29. "activity_info":{
  30. "productPrice":"00.00",
  31. "costPrice":"00.00",
  32. "activityId":null,
  33. "activityType":null,
  34. "title":null,
  35. "isAct":false
  36. },
  37. "select_status":2
  38. }
  39. ],
  40. "foot":{
  41. "current_page":"1",
  42. "pagesize":"10",
  43. "total_page":1
  44. },
  45. "brand_info":[
  46. {
  47. "id":"3",
  48. "brand_name":"斐讯",
  49. "list_status":1
  50. },
  51. {
  52. "id":"6",
  53. "brand_name":"迅捷",
  54. "list_status":2
  55. }
  56. ],
  57. "cate_info":[
  58. {
  59. "id":"109",
  60. "name":"斐讯K3C+E1组合套装",
  61. "list_status":2
  62. },
  63. {
  64. "id":"108",
  65. "name":"斐讯N1预售",
  66. "list_status":2
  67. }
  68. ]
  69. }
  70. }

 

  1. //根据分类获取商品列表
  2. public function getGoodsListByCate($userId,$sort,$cate_type,$brand_id,$page,$pageSize,$keywords,$type_id,$store_id){
  3. $store=M(\'store\');
  4. $s_where[\'id\']=$store_id;
  5. $store_user_id=$store->field(\'id\')->where($s_where)->getField(\'user_id\');
  6. //排序
  7. switch ($sort) {
  8. case 1:
  9. //销量由高到低排序
  10. $order = \'sell_nums desc\';
  11. break;
  12. case 2:
  13. //价格从低到高
  14. $order = \'sell_price asc\';
  15. break;
  16. default:
  17. //价格从高到低
  18. $order = \'sell_price desc\';
  19. break;
  20. }
  21. $origin=1; //1搜索、2店铺首页或商品管理
  22. $res2=$this->getGoodsInfoNew($keywords,$cate_type,$page,$pageSize,$order,$brand_id,$store_id,\'me\',2,$origin,$type_id,$userId,$store_user_id);
  23. if(empty($res2[\'goods_info\'])){
  24. $res2=null;
  25. }
  26. foreach($res2[\'goods_info\'] as $k=>$v){
  27. $arrs[]=array(
  28. \'productId\'=>$v[\'product_id\'],
  29. \'skuNo\'=>$v[\'sku_no\']
  30. );
  31. }
  32. $home_special_session=new HomeSpecialSessionModel();
  33. $res_info=$home_special_session->getGoodsActInfo($arrs);
  34. foreach($res_info as $k=>$v){
  35. unset($res_info[$k][\'productId\']);
  36. unset($res_info[$k][\'skuNo\']);
  37. unset($res_info[$k][\'status\']);
  38. }
  39. foreach($res2[\'goods_info\'] as $k=>$v){
  40. $res2[\'goods_info\'][$k][\'activity_info\']=$res_info[$v[\'sku_no\']];
  41. }
  42. $search_info= $res2;
  43. $ob=new FlagShipShopDecorateModel();
  44. $sku_ids=array_column($res2[\'goods_info\'],\'sku_id\');
  45. $tt=$ob->getSelectStatus($userId,$type_id);
  46. foreach($sku_ids as $k=>$v){
  47. if(in_array($v,$tt)){
  48. $atr=1;
  49. }else{
  50. $atr=2;
  51. }
  52. $search_info[\'goods_info\'][$k][\'select_status\']=$atr;
  53. }
  54. return $search_info;
  55. }
  56. //组装商品信息--新(修改商品列表sku显示为商品显示)
  57. private function getGoodsInfoNew($keywords,$cate_type,$page,$pageSize,$order,$brand_id,$store_id,$store_type,$source,$origin,$type_id,$user_id,$store_user_id){
  58. $img_base=C(\'img_base\');
  59. //获取平台商品的ID
  60. $pingtai_goods=C(\'pingtai_goods\');
  61. //获取特色商品的ID
  62. $tese_goods=C(\'tese_goods\');
  63. $store_goods=M(\'store_goods sg\');
  64.  
  65. $ob=new FlagShipShopDecorateModel();
  66. $res=$ob->isParentUserId($user_id,$store_user_id);
  67. if($type_id==1){ //平台商品
  68. $where2 ="gs.goods_type=$pingtai_goods";
  69. }elseif($type_id==2){//特色商品
  70. $where2 ="gs.goods_type=$tese_goods";
  71. }else{
  72. $where2 ="1=1";
  73. if($res===false){
  74. $where2 .=" and goods_type=2";
  75. }
  76. }
  77. if(!empty($keywords)){
  78. $where2 .=" and (gs.title like \'%$keywords%\' or gd.search_name like \'%$keywords%\')";
  79. }
  80. $where3=$where2;
  81. //品牌
  82. if(!empty($brand_id)){
  83. $where2 .=" and gd.brand_id in ($brand_id)";
  84. }
  85. if(!empty($cate_type)){
  86. $where ="sgc.id in ($cate_type)";
  87. }else{
  88. $where ="1=1";
  89. }
  90. if($type_id==1){ //平台商品
  91. $where .=" and type_id=$pingtai_goods";
  92. }elseif($type_id==2){ //特色商品
  93. $where .=" and sg.store_id=\'".$store_id."\' and type_id=$tese_goods";
  94. }else{
  95. if($res===false){
  96. $where .=" and (sg.store_id=\'".$store_id."\' and type_id=$tese_goods)";
  97. }else{
  98. $where .=" and ((sg.store_id=\'".$store_id."\' and type_id=$tese_goods) or type_id=$pingtai_goods)";
  99. }
  100. }
  101. $where .=" and sg.is_deleted=1 and sg.is_open=1 ";
  102. $store_goods_info=$store_goods->field(\'sg.sku_id,sg.g_cats,sgc.id\')
  103. ->join(\'left join lc_store_goods_category sgc on sg.g_cats=sgc.path\')
  104. ->where($where)
  105. ->select();
  106. $sku_ids =implode(",",array_column($store_goods_info,\'sku_id\'));
  107. $goods_sku_m = M(\'goods_sku gs\');
  108. if(!empty($store_goods_info)){
  109. //根据sku_id查找对应的商品
  110. $sku_ids = "\'".str_replace(",","\',\'",$sku_ids)."\'";
  111. $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\';
  112. $where4=$where3;
  113. $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\';
  114. $gd_info = $goods_sku_m
  115. ->join(\'left join __GOODS__ gd on gd.product_id=gs.product_id\')
  116. ->field("gd.brand_id,gs.sku_id")
  117. ->where($where4)
  118. ->select();
  119. //选中品牌,品牌分类不变
  120. $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\';
  121. $gd_info2 = $goods_sku_m
  122. ->join(\'left join __GOODS__ gd on gd.product_id=gs.product_id\')
  123. ->field("gd.brand_id,gs.sku_id")
  124. ->where($where3)
  125. ->select();
  126. if(!empty($gd_info2)){
  127. $brand_ids2=array_unique(array_column($gd_info2,\'brand_id\'));
  128. }else{
  129. $brand_ids2=null;
  130. }
  131. if(!empty($brand_ids2)){
  132. $brands=implode(\',\',$brand_ids2);
  133. }else{
  134. $brands=null;
  135. }
  136. $brand_info=$this->getBrandInfo($brands,$brand_id);
  137. if(!empty($gd_info2)){
  138. $sku_ids2 =implode(",",array_unique(array_column($gd_info,\'sku_id\')));
  139. $sku_ids2 = "\'".str_replace(",","\',\'",$sku_ids2)."\'";
  140. $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";
  141. $store_goods_info5=$store_goods->field(\'sgc.id,sg.g_cats\')
  142. ->join(\'left join lc_store_goods_category sgc on sg.g_cats=sgc.path\')
  143. ->where($where5)
  144. ->select();
  145. $cate_infos=array_unique(array_column($store_goods_info5,\'id\'));
  146. if(!empty($cate_infos)){
  147. foreach($cate_infos as $k=>$v){
  148. if(empty($v)){
  149. unset($cate_infos[$k]);
  150. }
  151. }
  152. $cate_infos=array_merge($cate_infos);
  153. }else{
  154. $cate_infos=null;
  155. }
  156. if(!empty($cate_infos)){
  157. $cate_infos=implode(\',\',$cate_infos);
  158. $cate_info=$this->getCateInfo($cate_type,$cate_infos);
  159. }
  160. }else{
  161. $cate_info=null;
  162. }
  163. $count=$goods_sku_m->join(\'left join __GOODS__ gd on gd.product_id=gs.product_id\')->where($where2)->count(\'DISTINCT gs.product_id\');
  164. //组装分页信息
  165. $total_page=ceil($count/$pageSize);
  166. if($page > $total_page){
  167. $page=1;
  168. }
  169. $goods_info = $goods_sku_m
  170. ->join(\'left join __GOODS__ gd on gd.product_id=gs.product_id\')
  171. ->field("gd.product_id,gd.brand_id,gd.search_name,gd.seascapes,gs.img,sum(gs.sell_nums) as sell_nums,gs.title")
  172. ->where($where2)
  173. ->group(\'gs.product_id\')
  174. ->order($order)
  175. ->page($page,$pageSize)
  176. ->select();
  177. $product_ids=implode(",",array_unique(array_column($goods_info,\'product_id\')));
  178. $product_ids = "\'".str_replace(",","\',\'",$product_ids)."\'";
  179. $sku_where="product_id in ($product_ids) and gs.status=1 and gs.is_deleted=0 and gs.is_show=0";
  180. $sku_info = $goods_sku_m
  181. ->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")
  182. ->where($sku_where)
  183. ->order(\'sell_price asc,gs.sell_nums desc\')
  184. ->select();
  185. $sku_info=$this->remove_duplicate($sku_info);
  186. foreach($sku_info as $k=>$v){
  187. $sku[$v[\'product_id\']][\'properties\']=$v[\'properties\'];
  188. $sku[$v[\'product_id\']][\'sku_id\']=$v[\'sku_id\'];
  189. $sku[$v[\'product_id\']][\'soft_text\']=$v[\'soft_text\'];
  190. $sku[$v[\'product_id\']][\'is_zero_goods\']=$v[\'is_zero_goods\'];
  191. $sku[$v[\'product_id\']][\'restriction\']=$v[\'restriction\'];
  192. $sku[$v[\'product_id\']][\'yuding\']=$v[\'yuding\'];
  193. $sku[$v[\'product_id\']][\'img\']=$v[\'img\'];
  194. $sku[$v[\'product_id\']][\'sku_no\']=$v[\'sku_no\'];
  195. $sku[$v[\'product_id\']][\'market_price\']=$v[\'market_price\'];
  196. $sku[$v[\'product_id\']][\'sell_price\']=$v[\'sell_price\'];
  197. $sku[$v[\'product_id\']][\'cost_price\']=$v[\'cost_price\'];
  198. }
  199. foreach($goods_info as $k=>$v){
  200. $goods_info[$k][\'properties\']= $sku[$v[\'product_id\']][\'properties\'];
  201. $goods_info[$k][\'sku_id\']= $sku[$v[\'product_id\']][\'sku_id\'];
  202. $goods_info[$k][\'soft_text\']= $sku[$v[\'product_id\']][\'soft_text\'];
  203. $goods_info[$k][\'is_zero_goods\']= $sku[$v[\'product_id\']][\'is_zero_goods\'];
  204. $goods_info[$k][\'restriction\']= $sku[$v[\'product_id\']][\'restriction\'];
  205. $goods_info[$k][\'yuding\']= $sku[$v[\'product_id\']][\'yuding\'];
  206. $goods_info[$k][\'img\']= $sku[$v[\'product_id\']][\'img\'];
  207. $goods_info[$k][\'sku_no\']= $sku[$v[\'product_id\']][\'sku_no\'];
  208. $goods_info[$k][\'market_price\']= $sku[$v[\'product_id\']][\'market_price\'];
  209. $goods_info[$k][\'sell_price\']= $sku[$v[\'product_id\']][\'sell_price\'];
  210. $goods_info[$k][\'cost_price\']= $sku[$v[\'product_id\']][\'cost_price\'];
  211. }
  212. $public = new PublicModel();
  213. //查询商品是否有多个sku
  214. if(empty($goods_info)){
  215. foreach ($goods_info as $key=>$value){
  216. $goods_info[$key][\'product_num\']=\'\';
  217. }
  218. }else{
  219. $product_info=$public->isMoreSku(array_column($goods_info,\'product_id\'));
  220. $new_data=[];
  221. foreach ($product_info as $key=>$value){
  222. $new_data[$value[\'product_id\']]=$value[\'num\'];
  223. }
  224. foreach ($goods_info as $key=>$value){
  225. $goods_info[$key][\'product_num\']=empty($new_data[$value[\'product_id\']])?\'\':$new_data[$value[\'product_id\']];
  226. }
  227. }
  228. if(!empty($goods_info)){
  229. foreach ($goods_info as $k =>$v) {
  230. //利润:
  231. $profit=$v[\'sell_price\']-$v[\'cost_price\'];
  232. $goods_info[$k][\'profit\']=$profit?number_format($profit, 2, \'.\', \',\'):\'0.00\';
  233. $seascapes=explode(\',\',$v[\'seascapes\']);
  234. if(!empty($seascapes)){
  235. $seascapes_t= array();
  236. foreach($seascapes as $v1){
  237. if(!empty($v1)){
  238. $seascapes_t[]=$img_base.$v1;
  239. }
  240. }
  241. }
  242. $goods_info[$k][\'seascapes\']=$seascapes_t;
  243. $goods_info[$k][\'img\']=empty($v[\'img\'])?\'\':$img_base.$v[\'img\'];
  244. //单个产品相关的规格
  245. $spec = $public->getSkuPropName(\'\',$v[\'properties\']);
  246. $goods_info[$k][\'spec_name\'] = $spec;
  247. //app
  248. if($source==2){
  249. $inf2=$public->shopDeal($store_id);
  250. }else{ //h5
  251. $inf2=$public->shopDealH5($store_id,$store_type);
  252. }
  253. $inf=$public->getTeSeGoods($v[\'sku_id\']);
  254. if(empty($inf)){//平台商品
  255. $store_id=$inf2;
  256. }else{
  257. $store_id=$inf[\'store_id\'];
  258. }
  259. $goods_info[$k][\'store_id\']=$store_id;
  260. unset($goods_info[$k][\'properties\']);
  261. }
  262. }
  263. }else{
  264. $goods_info=null;
  265. if($origin==1){
  266. $brand_info=null;
  267. $cate_info=null;
  268. }
  269. }
  270. $foot=array(\'current_page\'=>$page,\'pagesize\'=>$pageSize,\'total_page\'=>$total_page);
  271. $data[\'goods_info\']=$goods_info;
  272. $data[\'foot\']=$foot;
  273. if($origin==1){
  274. //组装品牌信息
  275. $data[\'brand_info\']=$brand_info;
  276. //组装分类信息
  277. $data[\'cate_info\']=$cate_info;
  278. }
  279. return $data;
  280. }
  281. //二维数组去重
  282. public function remove_duplicate($array){
  283. $result=array();
  284. foreach ($array as $key => $value) {
  285. $has = false;
  286. foreach($result as $val){
  287. if($val[\'product_id\']==$value[\'product_id\']){
  288. $has = true;
  289. break;
  290. }
  291. }
  292. if(!$has)
  293. $result[]=$value;
  294. }
  295. return $result;
  296. }
  297. //获取品牌列表
  298. //$brand_ids为搜索后产品所对应的品牌 $brand_id为选中的品牌列表
  299. public function getBrandInfo($brand_ids,$brand_id){
  300. if(!empty($brand_ids)){
  301. $where="id in ($brand_ids)";
  302. }else{
  303. $where="1=1";
  304. }
  305. $brand_info=M(\'brand\')->field(\'id,brand_name\')->where($where)->select();
  306. foreach($brand_info as $k=>$v){
  307. if(empty($brand_id)){
  308. $brand_info[$k][\'list_status\']=2; //未选中
  309. }else{
  310. if(in_array($v[\'id\'],explode(\',\',$brand_id))){
  311. $brand_info[$k][\'list_status\']=1; //选中
  312. }else{
  313. $brand_info[$k][\'list_status\']=2; //未选中
  314. }
  315. }
  316. }
  317. return $brand_info;
  318. }
  319. //获取分类列表
  320. //$cate_type选中的分类 $cate_infos搜索出的分类
  321. public function getCateInfo($cate_type,$cate_infos){
  322. //获取平台商品的id
  323. $pingtai_goods=C(\'pingtai_goods\');
  324. $where ="id in ($cate_infos)";
  325. $cate_info=M(\'store_goods_category\')->field(\'id,name,path\')->where($where)->order(\'sort desc\')->select();
  326. if(!empty($cate_info)){
  327. foreach($cate_info as $k=>$v){
  328. if(empty($cate_type)){
  329. $cate_info[$k][\'list_status\']=2; //未选中
  330. }else{
  331. if(in_array($v[\'id\'],explode(\',\',$cate_type))){
  332. $cate_info[$k][\'list_status\']=1; //选中
  333. }else{
  334. $cate_info[$k][\'list_status\']=2; //未选中
  335. }
  336. }
  337. unset($cate_info[$k][\'path\']);
  338. }
  339. $cate_info=array_merge($cate_info);
  340. }else{
  341. $cate_info=null;
  342. }
  343. return $cate_info;
  344. }

 

  1. //根据sku_ids获取分类选中状态
  2. public function getSelectStatus($userId,$type_id){
  3. $user_shop_decorate=M(\'user_shop_decorate\');
  4. $usd_where[\'flagship_shop\']=1;
  5. $usd_where[\'create_id\']=$userId;
  6. if($type_id==1){
  7. $usd_info=$user_shop_decorate->field(\'plate_id,plate_content_draft\')->where($usd_where)->order(\'create_time desc\')->find();
  8. }else{
  9. $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();
  10. }
  11. $shop_decorate_template=M(\'shop_decorate_template\');
  12. $us_where[\'is_deleted\']=0;
  13. $us_where[\'id\']=$usd_info[\'plate_id\'];
  14. $us_info=$shop_decorate_template->field(\'goods_nums\')->where($usd_where)->find();
  15. if(empty($usd_info)){
  16. $goods_info=$this->getDefaultGoodsInfo($us_info[\'goods_nums\'],"sell_nums desc");
  17. foreach($goods_info as $k=>$v){
  18. $arr[]=$v[\'sku_id\'];
  19. }
  20. }else{
  21. $plate_content=json_decode($usd_info[\'plate_content_draft\'],true);
  22. foreach($plate_content as $k=>$v){
  23. foreach($v[\'goods\'] as $k2=>$v2){
  24. if($v2[\'operate_type\']==1){
  25. $arr[]=$v2[\'sku_id\'];
  26. }
  27. }
  28. }
  29. }
  30. return $arr;
  31. }

 

版权声明:本文为zouke1220原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zouke1220/p/9298604.html