Laravel8,mongodb-我有一个表,我想再向其中添加3列

6psbrbz9  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(283)

因此,我试图通过从mongodb获取数据,向已经存在的表中再添加3列。但是,这让我头疼。
控制器中的代码:

public function checkPendingPickups(){
        $last2DaysDate = date('Y-m-d',  strtotime(date('Y-m-d').' -30 days'));
        $orderids = \App\Models\Cart::where('created_at','>=',new \DateTime($last2DaysDate))->whereIn('order_status',['open'])->whereNotIn('cancel_by',['system','customer'])->whereNotIn('status',['-1'])->lists('order_id')->toArray();

        $receivedOrders = $this->packageService->receivedOrders($last2DaysDate);
        $receviedNDocketNoUpdatedOrders = $this->packageService->getOrdersNotDeliveredDocketStatus($receivedOrders);

        if(!empty($receviedNDocketNoUpdatedOrders)){
            $allOrderids = array_merge($receviedNDocketNoUpdatedOrders,$orderids);
            $allOrderids = array_unique($allOrderids);
        }else{
            $allOrderids = array_unique($orderids);
        }

    if(!empty($allOrderids)){
        echo '<table>';
        echo '<tr>';
        echo '  <th>Pickup Number </th>';
        echo '  <th>Pickup Date </th>';
        echo '  <th>Docket Number</th>';
        echo '  <th>Carrier Name</th>';
        echo '  <th>Account Name</th>';
        echo '  <th>Docket Status</th>';
        echo '  <th>Order Date </th>';
        echo '  <th>Sender Pincode </th>';
        echo '  <th>Sender Phone Number </th>';
        echo '  <th>Sender Pickup State </th>';
        echo '</tr>';  
        foreach ($allOrderids as $oid){

            // $last2MonthsDate = date('Y-m-d',  strtotime(date('Y-m-d').' -2 month'));

            $cartsData  = \App\Models\Cart::where('order_id',(int)$oid)->where('created_at','>=',new \DateTime($last2DaysDate))->whereIn('order_status',['open'])->whereNotIn('cancel_by',['system','customer'])->whereNotIn('status',['-1'])->get()->toArray();
            $order = \App\Models\Order::where('_id',(int)$oid)->select('created_at')->first();

            if(!empty($cartsData)){
                foreach ($cartsData as $value){
                    if(!isset($value['courier_code']) || !isset($value['tracking_no'])){
                        //check for package couriers 

                        $packageIds = \App\Models\Package::where('order_id',(int)$value['order_id'])->lists('_id')->toArray();
                        if(!empty($packageIds)){
                            $shippingData = \App\Models\ShippingPackages::where('carrier','courier')->whereIn('package_id',array_map('intval',$packageIds))->get()->toArray();
                            if(!empty($shippingData)){
                                foreach ($shippingData as $shippingValue){
                                    $genieData = \App\Models\Genie::where('_id',(int)$value['customer_id'])->select('name')->first();
                                    $OrderTrackingData = \App\Models\OrderTracking::where('order_id',(int)$value['order_id'])->where('docket_num' , $shippingValue['docket_num'])->select('status')->first();
                                    $pickup_number = isset($shippingValue['pickup_num'])?$shippingValue['pickup_num']:"Not Available";
                                    $pickup_date = isset($shippingValue['pickup_date'])?$shippingValue['pickup_date']:"Not Available"; 
                                    $doeckt_number = isset($shippingValue['docket_num'])?$shippingValue['docket_num']:"Not Available";
                                    $carrier_name = isset($shippingValue['courier_name'])?$shippingValue['courier_name']:"Not Available";
                                    $account_name = isset($genieData['name'])?$genieData['name']:"Not Available";
                                    $status = isset($OrderTrackingData['status'])?$OrderTrackingData['status']:"Not Available"; 

                                    echo '<tr><td>' . $pickup_number . '&nbsp;&nbsp;</td><td>' . $pickup_date . '&nbsp;&nbsp;</td><td>' . $doeckt_number . 
                                        '&nbsp;&nbsp;</td><td>' . $carrier_name . '&nbsp;&nbsp;</td><td>' . $account_name . '&nbsp;&nbsp;</td><td>' . $status .'&nbsp;&nbsp;</td><td>' . date("d/m/Y", strtotime($order['created_at'])) . '&nbsp;&nbsp;</td></tr>';

                                }// close of foreach
                            }
                        }

                    }else{
                        $genieData = \App\Models\Genie::where('_id',(int)$value['customer_id'])->select('name')->first();
                        $OrderTrackingData = \App\Models\OrderTracking::where('order_id',(int)$value['order_id'])->where('docket_num' , $value['tracking_no'])->select('status')->first();
                        $pickup_number = isset($value['pickup_num'])?$value['pickup_num']:"Not Available";
                        $pickup_date = isset($value['pickup_date'])?$value['pickup_date']:"Not Available"; 
                        $doeckt_number = isset($value['tracking_no'])?$value['tracking_no']:"Not Available";
                        $carrier_name = isset($value['courier_code'])?$value['courier_code']:"Not Available";
                        $account_name = isset($genieData['name'])?$genieData['name']:"Not Available";
                        $status = isset($OrderTrackingData['status'])?$OrderTrackingData['status']:"Not Available"; 

                        echo '<tr><td>' . $pickup_number . '&nbsp;&nbsp;</td><td>' . $pickup_date . '&nbsp;&nbsp;</td><td>' . $doeckt_number . 
                            '&nbsp;&nbsp;</td><td>' . $carrier_name . '&nbsp;&nbsp;</td><td>' . $account_name . '&nbsp;&nbsp;</td><td>' . $status .'&nbsp;&nbsp;</td><td>' . date("d/m/Y", strtotime($order['created_at'])) . '&nbsp;&nbsp;</td></tr>';
                    }
                }
            }
        }
        echo '</table>';
    }
}

我应该在现有代码中做哪些必要的更改以添加三列,即发件人pincode、发件人电话号码和发件人收件地址。我应该在mongodb中进行任何更改吗?请帮忙。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题