将数据导入阵列

时间:2015-10-24 04:59:12

标签: laravel

我在一些基于商家的电子商务网站上工作。提交订单时存在问题。问题是,当我选择相同的商家时,订单将成功存储,但是当我从不同的商家选择多个产品时,我的功能是通过未定义的偏移误差:1。这是我的功能。

public function post_order(){
    $data = Input::all();
    $count = count($data['invoice_no']);
    $order = array();
    for($i=0; $i<$count; $i++){
        if(!empty($data['invoice_no'][$i])){
            array_push($order, array(
                'order_no'          => $data['order_no'][$i],
                'invoice_prefix'    => $data['invoice_prefix'][$i],
                'invoice_no'        => $data['invoice_no'][$i],
                'merchant_id'       => $data['merchant_id'][$i],
                'customer_id'       => $data['customer_id'][$i],
                'buytokri_order'    => $data['order_name'][$i],
                'name'              => $data['name'][$i],
                'pincode'           => $data['pincode'][$i],
                'address'           => $data['address'][$i],
                'landmark'          => $data['landmark'][$i],
                'city'              => $data['city'][$i],
                'state'             => $data['state'][$i],
                'country'           => $data['country'][$i],
                'mobile'            => $data['mobile'][$i],
                'subtotal'          => $data['selling_price'][$i],
                'payment_type'      => $data['payment_type'][$i],
                'txn_id'            => $data['txn'][$i],
                'shipping'          => $data['shipping'][$i],
                'total'             => $data['subtotal'][$i]
            ));
        }
    }
    Order::insert($order);
    $var = $data['order_no'];
    foreach ($var as $vars) {
        $id = DB::table('ads_order')->where('order_no', $vars)->get();
    }
$count = count($data['invoice_no']);
    $orderhistory = array();
    for($i=0; $i<=$count; $i++){
        if(!empty($data['invoice_no'][$i])){
            array_push($orderhistory, array(                    
                'order_id'          => $id[$i]->id,
                'merchant_id'       => $data['merchant_id'][$i],
                'customer_id'       => $data['customer_id'][$i],
                'order_status'      => $data['order_status'][$i],
                'comment'           => $data['comment'][$i],
                'notify'            => $data['notify'][$i],
                'default'           => $data['default'][$i],
                'status'            => $data['status'][$i]
            ));             
        }
    }
    Orderhistory::insert($orderhistory);
return Redirect::intended('/ordersuccess');
}

0 个答案:

没有答案