public function updateInsUserOrders($insUserList)
 {
     $objInstagramUserModel = new Instagram_User();
     $orderModel = new Order();
     $whereIn = implode(',', array_unique(array_map(function ($v) {
         return $v->ins_user_id;
     }, $insUserList)));
     $insUserStatus = $objInstagramUserModel->updateUserDetails(['rawQuery' => 'ins_user_id IN(' . $whereIn . ')'], ['cronjob_status' => 1]);
     //replace with 1
     foreach ($insUserList as $insUser) {
         $whereInsUser = ['rawQuery' => 'ins_user_id=?', 'bindParams' => [$insUser->ins_user_id]];
         // this script runs only when the instagram user script is not started. adn if the current time is greater than the start time
         if (intval($insUser->ig_user_status) == 5 && $insUser->start_date_time < time()) {
             $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, ['ig_user_status' => 2, 'cronjob_status' => 0, 'message' => 'The script is waiting for new post. Searching new post in every 5 minutes!']);
         }
         $where = ['rawQuery' => 'orders.by_user_id=? and orders.for_user_id=? and orders.auto_order_status=?', 'bindParams' => [$insUser->by_user_id, $insUser->ins_user_id, 1]];
         $selectedColumns = [DB::raw('
             sum(case when orders.status IN(1,2,3) and ' . $insUser->reset_counter_time . ' < orders.added_time and plans.plan_type=0 then 1 else 0 end) as likesDoneCount,
             sum(case when orders.status IN(1,2,3) and ' . $insUser->reset_counter_time . ' < orders.added_time and ( plans.plan_type=2 or plans.plan_type=3) then 1 else 0 end) as commentsDoneCount,
             sum(case when orders.status IN(1,2,3) and ' . $insUser->reset_counter_time . ' < orders.added_time and plans.plan_type=4 then 1 else 0 end) as viewsDoneCount
             '), DB::raw('max(orders.updated_time) as updated_time')];
         $orderDetails = $orderModel->getAutolikesOrderStatus($where, $selectedColumns);
         if ($orderDetails[0]->likesDoneCount != null && $orderDetails[0]->commentsDoneCount != null && $orderDetails[0]->viewsDoneCount != null && $orderDetails[0]->updated_time != null) {
             if (intval($insUser->daily_post_limit) > 0) {
                 if (intval($insUser->daily_post_done) < intval($insUser->daily_post_limit)) {
                     if (intval($insUser->pics_done) < intval($insUser->pics_limit)) {
                         $updatedData1 = array();
                         if (intval($insUser->plan_type) == 0) {
                             // for likes
                             $updatedData1['pics_done'] = intval($orderDetails[0]->likesDoneCount);
                         } else {
                             if ($insUser->plan_id_for_autoComments != null) {
                                 // for comments
                                 $updatedData1['comments_per_pic_done_count'] = intval($orderDetails[0]->commentsDoneCount);
                             } elseif (intval($insUser->plan_type) == 4) {
                                 // for views
                                 $updatedData1['pics_done'] = intval($orderDetails[0]->viewsDoneCount);
                                 //pics_done is same as views done
                             }
                         }
                         $updatedData1['last_delivery'] = intval($orderDetails[0]->updated_time);
                         $updatedData1['cronjob_status'] = 0;
                         $updatedData1['message'] = 'The script is waiting for new post. Searching new post in every 5 minutes!';
                         $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, $updatedData1);
                     } else {
                         $updatedData2 = ['cronjob_status' => 0, 'ig_user_status' => 1, 'message' => 'Thank You!! Your order has been finished. We have processed all your ' . $insUser->pics_limit . ' posts. If you want to restart it again, just restart the total counter . :) '];
                         $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, $updatedData2);
                     }
                 } else {
                     $updatedData31 = ['cronjob_status' => 0, 'ig_user_status' => 3, 'message' => 'Daily post limit for this user has been reached! The script will start searching new post after 24 hrs!'];
                     $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, $updatedData31);
                 }
             } elseif (intval($insUser->daily_post_limit == 0)) {
                 if (intval($insUser->pics_done) < intval($insUser->pics_limit)) {
                     //modified by Saurabh //daily_post_done
                     $updatedData4 = array();
                     if (intval($insUser->plan_type) == 0) {
                         // for likes
                         $updatedData4['pics_done'] = intval($orderDetails[0]->likesDoneCount);
                     } else {
                         if ($insUser->plan_id_for_autoComments != null) {
                             // for comments
                             $updatedData4['comments_per_pic_done_count'] = intval($orderDetails[0]->commentsDoneCount);
                         } elseif (intval($insUser->plan_type) == 4) {
                             // for views
                             $updatedData4['pics_done'] = intval($orderDetails[0]->viewsDoneCount);
                             //pics_done is same as views done
                         }
                     }
                     $updatedData4['last_delivery'] = $orderDetails[0]->updated_time;
                     $updatedData4['cronjob_status'] = 0;
                     $updatedData4['message'] = 'The script is waiting for new post. Searching new post in every 5 minutes!';
                     $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, $updatedData4);
                 } else {
                     $updatedData5 = ['ig_user_status' => 1, 'cronjob_status' => 0, 'message' => 'Thank You!! Your order has been finished. We have processed all your ' . $insUser->pics_limit . ' posts. If you want to restart it again, just restart the total counter . :) '];
                     $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, $updatedData5);
                 }
             }
         } else {
             $queryResult = $objInstagramUserModel->updateUserDetails($whereInsUser, ['cronjob_status' => 0]);
         }
     }
     // end of foreach loop
 }