Ejemplo n.º 1
0
 function _parse_tabao_prop($cid, $sale_attr, $sale_attr_alias, $goods_id)
 {
     $i = 0;
     // 规格数量
     $spec_kind = 0;
     // 规格种类数
     $spec_price_stock = array();
     // 价格和库存
     $sale_attr = preg_replace("/:[^:]*-[^:]*:/U", '::', $sale_attr);
     // 屏蔽商家编码干扰
     $sale_attr = explode(';', $sale_attr);
     //dump($sale_attr);
     $pvs = '';
     // 淘宝销售属性编码
     /* 分离库存价格与属性编码 */
     foreach ($sale_attr as $k => $v) {
         $pos_2 = strpos($v, '::');
         if ($pos_2 > 0) {
             $pos_1 = strpos($v, ':');
             //dump($_pos);
             //$price_stock = explode(':', substr($v, 0,))
             $spec_price_stock[$i]['price'] = round(substr($v, 0, $pos_1), 2);
             $spec_price_stock[$i]['stock'] = substr($v, $pos_1 + 1, $pos_2 - $pos_1 - 1);
             $pvs .= substr($v, $pos_2 + 2) . ';';
             $i++;
         } else {
             if ($v) {
                 $pvs .= $v . ';';
             }
         }
     }
     if (empty($spec_price_stock)) {
         $spec_kind = 0;
     } else {
         $spec_kind = substr_count($pvs, ';') / count($spec_price_stock);
     }
     /* 根据编码解析销售属性 */
     import('taobaoprop.lib');
     $TaobaoProp = new TaobaoProp($cid, $pvs, '12009827', '8c02e9f524f66199e100e27fdfdb9bbd');
     $prop = $TaobaoProp->get_prop();
     if (!$prop || $TaobaoProp->has_error()) {
         return array();
     }
     /* 编码转换 */
     if (CHARSET == 'big5') {
         $prop = ecm_iconv_deep('utf-8', 'gbk', $prop);
         $prop = ecm_iconv_deep('gbk', 'big5', $prop);
     } else {
         $prop = ecm_iconv_deep('utf-8', CHARSET, $prop);
     }
     /* 销售属性别名 */
     if ($sale_attr_alias) {
         $sale_attr_alias = explode(';', $sale_attr_alias);
         foreach ($sale_attr_alias as $_k => $_v) {
             $pos_delimiter = strrpos($_v, ':');
             $pv = substr($_v, 0, $pos_delimiter);
             $alias_name = substr($_v, $pos_delimiter + 1);
             $sale_attr_alias[$pv] = $alias_name;
             unset($sale_attr_alias[$_k]);
         }
         foreach ($prop as $key => $value) {
             $pv = $value['pid'] . ':' . $value['vid'];
             if (isset($sale_attr_alias[$pv])) {
                 $prop[$key]['name_alias'] = $sale_attr_alias[$pv];
             }
         }
     }
     /* 组合成ECMall规格 */
     $spec = array();
     // 规格数据
     foreach ($spec_price_stock as $_k => $_v) {
         $spec['item'][$_k] = $_v;
         $spec['item'][$_k]['goods_id'] = $goods_id;
         if ($spec_kind == 2) {
             $spec['item'][$_k]['spec_1'] = $prop[2 * $_k]['name_alias'];
             $spec['item'][$_k]['spec_2'] = $prop[2 * $_k + 1]['name_alias'];
             $spec['spec_name'] = array('spec_name_1' => $prop[0]['prop_name'], 'spec_name_2' => $prop[1]['prop_name']);
         } else {
             if ($spec_kind = 1) {
                 $spec['item'][$_k]['spec_1'] = $prop[$_k]['name_alias'];
                 $spec['spec_name'] = array('spec_name_1' => $prop[0]['prop_name']);
             }
         }
         if ($_v['stock'] == 0) {
             unset($spec['item'][$_k]);
         }
     }
     $spec['spec_kind'] = $spec_kind;
     return addslashes_deep($spec);
     // 因经过转码,必须要重新转义
 }
Ejemplo n.º 2
0
 function _parse_tabao_prop($cid, $pvs, $goods_id)
 {
     $i = 0;
     // 规格数量
     $spec_kind = 0;
     // 规格种类数
     $spec_price_stock = array();
     // 价格和库存
     $arr_temp = explode(';', $pvs);
     $pvs = '';
     // 淘宝销售属性编码
     /* 分离库存价格与属性编码 */
     foreach ($arr_temp as $k => $v) {
         $pos_2 = strpos($v, '::');
         if ($pos_2 > 0) {
             $pos_1 = strpos($v, ':');
             //dump($_pos);
             //$price_stock = explode(':', substr($v, 0,))
             $spec_price_stock[$i]['price'] = round(substr($v, 0, $pos_1), 2);
             $spec_price_stock[$i]['stock'] = substr($v, $pos_1 + 1, $pos_2 - $pos_1 - 1);
             $pvs .= substr($v, $pos_2 + 2) . ';';
             $i++;
         } else {
             if ($v) {
                 $pvs .= $v . ';';
             }
         }
     }
     $spec_kind = substr_count($pvs, ';') / count($spec_price_stock);
     /* 根据编码解析销售属性 */
     import('taobaoprop.lib');
     $TaobaoProp = new TaobaoProp($cid, $pvs);
     $prop = $TaobaoProp->get_prop();
     if (!$prop || $TaobaoProp->has_error()) {
         return array();
     }
     if (CHARSET == 'big5') {
         $prop = ecm_iconv_deep('utf-8', 'gbk', $prop);
         $prop = ecm_iconv_deep('gbk', 'big5', $prop);
     } else {
         $prop = ecm_iconv_deep('utf-8', CHARSET, $prop);
     }
     /* 组合成ECMall规格 */
     $spec = array();
     // 规格数据
     foreach ($spec_price_stock as $_k => $_v) {
         $spec['item'][$_k] = $_v;
         $spec['item'][$_k]['goods_id'] = $goods_id;
         if ($spec_kind == 2) {
             $spec['item'][$_k]['spec_1'] = $prop['prop_value'][2 * $_k]['name'];
             $spec['item'][$_k]['spec_2'] = $prop['prop_value'][2 * $_k + 1]['name'];
             $spec['spec_name'] = array('spec_name_1' => $prop['prop_value'][0]['prop_name'], 'spec_name_2' => $prop['prop_value'][1]['prop_name']);
         } else {
             if ($spec_kind = 1) {
                 $spec['item'][$_k]['spec_1'] = $prop['prop_value'][$_k]['name'];
                 $spec['spec_name'] = array('spec_name_1' => $prop['prop_value'][0]['prop_name']);
             }
         }
     }
     $spec['spec_kind'] = $spec_kind;
     return addslashes_deep($spec);
     // 因经过转码,必须要重新转义
 }