Ejemplo n.º 1
0
 function act_groupIndex()
 {
     $userName = $_SESSION['userName'];
     $order_all = array();
     $status = '';
     $list_id = trim($_POST['print_list']);
     if (empty($list_id)) {
         return "-[<font color='#FF0000'>配货单为空,请确认</font>]-";
         exit;
     }
     //清空数据库本人记录
     GroupRouteModel::delRouteIndex("where user='******'");
     //获取所有请求生成配货清单的配货单号
     $list_info = OrderPrintListModel::getPrintList("*", "where id in({$list_id}) and storeId=1 and is_delete=0");
     if ($list_info) {
         foreach ($list_info as $info) {
             $order_arr = array();
             $order_arr = array_filter(explode(',', $info['orderIds']));
             foreach ($order_arr as $orders) {
                 $order_all[] = $orders;
             }
         }
     }
     if (empty($order_all)) {
         return "-[<font color='#FF0000'>配货单为空,请确认</font>]-";
         exit;
     }
     for ($level = 8; $level > 0; $level--) {
         $order_index = array();
         if ($level == 1) {
             //剩下的全公司订单
             $string = '';
             $order_res = array();
             foreach ($order_all as $order) {
                 $now_order_info = GroupRouteModel::getRouteIndex("*", "where shipOrderId={$order} and user='******'");
                 if (!$now_order_info) {
                     $location_info = array();
                     $position_arr = GroupRouteModel::getOrderPositionIDGroup($order);
                     foreach ($position_arr as $position) {
                         $location_info[] = $position['pName'];
                     }
                     sort($location_info);
                     $order_res[$order] = $location_info[0];
                 }
             }
             asort($order_res);
             foreach ($order_res as $ord => $value) {
                 $string .= "('" . $ord . "','" . $level . "','" . $userName . "'),";
             }
             $string = trim($string, ",");
             if (!empty($string)) {
                 $list_one = GroupRouteModel::insertRouteIndex($string);
                 if ($list_one) {
                     $status .= " -[<font color='#33CC33'>操作记录: " . $level . "级索引生成成功</font>]<br/>";
                     $status .= " -[<font color='#33CC33'>操作记录: 订单生产最优配货组完成,请输入打印预览条数进行打印</font>]<br/>";
                     $status .= " -[<font color='#33CC33'>温馨提示: 生成配货索引后请不要刷新该页面,如刷新会重新生成,可能造成数据出错</font>]";
                     return $status;
                     //	$order_count = GroupRouteModel::getRouteIndexNum("where user='******'");
                     //	$group_bool = 1;
                 } else {
                     $status .= " -[<font color='#FF0000'>操作记录: " . $level . "级索引生成失败</font>]<br/>";
                     $status .= " -[<font color='#FF0000'>操作记录: 订单生产最优配货组失败,请重试</font>]";
                     return $status;
                 }
             } else {
                 $status .= " -[<font color='#33CC33'>操作记录: 订单生产最优配货组完成,请输入打印预览条数进行打印</font>]<br/>";
                 $status .= " -[<font color='#33CC33'>温馨提示: 生成配货索引后请不要刷新该页面,如刷新会重新生成,可能造成数据出错</font>]";
                 return $status;
             }
         } else {
             $string = '';
             $level_info = PositionModel::getPositonIndexList("*", "where level='{$level}'");
             //仓位级别索引
             foreach ($order_all as $order) {
                 $now_order_info = GroupRouteModel::getRouteIndex("*", "where shipOrderId={$order} and user='******'");
                 if (!$now_order_info) {
                     $position_arr = GroupRouteModel::getOrderPositionID($order);
                     //记录订单sku可能存在的级别里面的某个模块
                     if (!empty($position_arr)) {
                         foreach ($level_info as $levels) {
                             $bool = true;
                             $position_id = array_filter(explode(',', $levels['positionId']));
                             foreach ($position_arr as $position) {
                                 if (!in_array($position['positionId'], $position_id)) {
                                     $bool = false;
                                     break;
                                 }
                             }
                             if ($bool) {
                                 $order_index[$levels['piece']][] = $order;
                                 break;
                             }
                         }
                     }
                 }
             }
             foreach ($order_index as $key => $index) {
                 $piece_count = count($index);
                 //30单为配货单位
                 if ($piece_count < 30) {
                     unset($order_index[$key]);
                 } else {
                     $del_num = $piece_count % 30;
                     //for($i=0;$i<$del_num;$i++){
                     for ($i = $piece_count - 1; $i >= $piece_count - $del_num; $i--) {
                         unset($order_index[$key][$i]);
                     }
                 }
             }
             if (!empty($order_index)) {
                 foreach ($order_index as $order) {
                     foreach ($order as $o) {
                         $string .= "('" . $o . "','" . $level . "','" . $userName . "'),";
                     }
                 }
             }
             $string = trim($string, ",");
             if (!empty($string)) {
                 $list_one = GroupRouteModel::insertRouteIndex($string);
                 if ($list_one) {
                     $status .= " -[<font color='#33CC33'>操作记录: " . $level . "级索引生成成功</font>]<br/>";
                 } else {
                     $status .= " -[<font color='#FF0000'>操作记录: " . $level . "级索引生成失败</font>]<br/>";
                 }
             }
             //print_r($order_index);
         }
     }
 }