Exemplo n.º 1
0
 /**
  * 购物车商品列表
  */
 public function CartGoodsCache($goods_list)
 {
     if (!$goods_list) {
         return array();
     }
     $goods_list_new = array();
     foreach ($goods_list as $v) {
         $goods_list_new[$v['product_id']] = $v;
         $product_ids[] = $v['product_id'];
         $goods_ids[] = $v['goods_id'];
     }
     if (!isset($product_ids) || isset($product_ids) && !$product_ids) {
         return false;
     }
     $product_ids = implode(',', $product_ids);
     $goods_ids = implode(',', $goods_ids);
     $result = array();
     if ($product_ids) {
         $product_sql = "SELECT * FROM {{b2c_products}} WHERE product_id IN ({$product_ids})";
         $product_list = GlobalFunc::ArrayListByKey($this->ModelQueryAll($product_sql), 'product_id');
         $image_list = $this->GoodsDefaultImage($goods_ids);
         foreach ($goods_list_new as $v) {
             if (!isset($product_list[$v['product_id']])) {
                 continue;
             }
             $item = $v;
             $item['product_name'] = $product_list[$v['product_id']]['name'];
             $item['price'] = isset($promotion_pro[$v['product_id']]) && $promotion_pro[$v['product_id']] ? $promotion_pro[$v['product_id']] : sprintf('%.2f', $product_list[$v['product_id']]['price']);
             $item['mktprice'] = sprintf('%.2f', $product_list[$v['product_id']]['mktprice']);
             $spec = str_replace(array(' ', '、'), ' ', $product_list[$v['product_id']]['spec_info']);
             $item['spec'] = explode(' ', $spec);
             if (isset($image_list[$v['goods_id']])) {
                 $item['image'] = $image_list[$v['goods_id']]['s_url'];
             } else {
                 $item['image'] = '';
             }
             $result['item'][] = $item;
         }
     }
     return $result;
 }