<?php
class indexAction
{
	public function getSuperItem()
    {
        $getArr = $_GET;
		$getArr['shopid'] = mvc::$cfg['SHOPID'];
		unset($getArr['fun']);
		$LibPjlApi = new LibPjlApi();
		if($_GET['fun'] =='data/decodeVin') LibFc::ReturnJson(false, '403 Forbidden');
		$prores = $LibPjlApi->Get('super/getSuperItem', $getArr, $_POST);
        if($prores['data'])
        {   
            $proArr =  $prores['data'];
            $proIdArr =  array_column($proArr,'pro_id');
            $B2cProduct =  new B2cProduct();
            //取店铺分类
            if($getArr['sort_id'])
            {
                $res =  $B2cProduct->get('sh_sort join sh_sort_tree on sort_id = sot_sort_id',['sot_sort_id'],sprintf(" AND sot_psort_id = %d",$getArr['sort_id']));
                if($res['data']){
                    $sortArr = array_column($res['data'],'sot_sort_id');
                    $sortArr[] = $getArr['sort_id'];
                }else{
                    $sortArr[] = $getArr['sort_id'];
                }
                $where = sprintf(" AND prs_pro_id IN (%s) AND prs_sort_id IN (%s)", implode(',', $proIdArr),implode(',',$sortArr));
            }else{
                $where = sprintf(" AND prs_pro_id IN (%s)", implode(',', $proIdArr));
            }
            $res = $B2cProduct->get('bc_product_sort join sh_sort on sort_id = prs_sort_id', ['*'], $where);
            if ($res['data']) {
                foreach ($res['data'] as $v) {
                    $sortArr[$v['prs_pro_id']][] = $v['prs_sort_id'];
                }
            }
            
            foreach ($proArr as $key => &$pro) {
                $pro['sort_id'] = $sortArr[$pro['pro_id']] ? array_unique($sortArr[$pro['pro_id']]) : [];
            }
            unset($pro);
        }
		LibFc::ReturnJson(true,$proArr);
    }
}
