Exemple #1
0
 /**
  * 订单商品
  *
  * @param $order_idArr
  * @return array|bool|string
  */
 public function OrderProduct($order_idArr)
 {
     if (!$order_idArr) {
         return '';
     }
     $item_sql = "SELECT i.order_id,i.product_id,i.goods_id,i.bn,i.name,i.price,i.nums,i.addon,i.cost,p.mktprice\n                        FROM {{b2c_order_items}} as i left join {{b2c_products}}\n                        as p on p.product_id = i.product_id";
     if (is_array($order_idArr)) {
         $order_ids = implode(',', $order_idArr);
         $item_sql .= " WHERE order_id IN ({$order_ids})";
     } else {
         $item_sql .= " WHERE order_id = {$order_idArr}";
     }
     $items = $this->ModelQueryAll($item_sql);
     $itemsOrder = $goods_ids = $goods_image = array();
     foreach ($items as $k => $v) {
         $goods_ids[] = $v['goods_id'];
         $items[$k]['price'] = number_format($v['price'], '2', '.', '');
         $items[$k]['cost'] = number_format($v['cost'], '2', '.', '');
         $items[$k]['mktprice'] = number_format($v['mktprice'], '2', '.', '');
     }
     $itemProduct = Help::ArrayListByKey($items, 'goods_id');
     if (!$goods_ids) {
         return $itemsOrder;
     }
     $goods_str = implode(',', $goods_ids);
     $Product = new ModelProduct();
     $goods_image = $Product->GoodsDefaultImage($goods_str);
     foreach ($goods_image as $k => $v) {
         $itemProduct[$k]['image'] = $this->img_url . $v['s_url'];
     }
     foreach ($items as $v) {
         $item = $v;
         $item['image'] = isset($itemProduct[$v['goods_id']]['image']) ? $itemProduct[$v['goods_id']]['image'] : '';
         $itemsOrder[$v['order_id']][] = $item;
     }
     if (!is_array($order_idArr)) {
         return $itemsOrder[$order_idArr];
     }
     return $itemsOrder;
 }