public function view_printOptimal() { $list = isset($_GET['list']) ? post_check($_GET['list']) : ''; $this->smarty->assign('list', $list); if ($_POST['route_index']) { $userName = $_SESSION['userName']; if (empty($list)) { echo "请选择需要生成索引的列表"; exit; } $GroupRouteAct = new GroupRouteAct(); $group_index = $GroupRouteAct->act_groupIndex(); $this->smarty->assign('status', $group_index); $order_count = GroupRouteModel::getRouteIndexNum("where user='******'"); $this->smarty->assign('count', $order_count); $this->smarty->assign('group_bool', 1); } $navlist = array(array('url' => '', 'title' => '首页'), array('url' => 'index.php?mod=orderWaitforPrint&act=printList', 'title' => '打印发货单'), array('url' => 'index.php?mod=PrintOrder&act=printOptimal', 'title' => '订单最优打印')); $this->smarty->assign('navlist', $navlist); $this->smarty->assign('toptitle', '订单最优打印'); $this->smarty->assign('secnev', 1); $this->smarty->assign('curusername', $_SESSION['userName']); $toplevel = 2; //顶层菜单 $this->smarty->assign('toplevel', $toplevel); $secondlevel = '22'; //当前的二级菜单 $this->smarty->assign('secondlevel', $secondlevel); $this->smarty->display('printOrder.htm'); }
function act_groupGenerate() { $k = 1; $group_bool = trim($_POST['group_bool']); if (!empty($group_bool)) { $userName = $_SESSION['userName']; $create_time = strtotime(date("Y-m-d")); $time = time(); $status_info = GroupRouteModel::getOrderGroup("*", "where createdTime>'{$create_time}' and user='******' order by id desc limit 0,1"); //当天打印次数 if (empty($status_info)) { $sequence = 1; } else { $sequence = $status_info[0]['todaySequence'] + 1; } //获取当前最后一个清单编号 $group_info = GroupRouteModel::getOrderGroup("*", "order by id desc limit 0,1"); if (empty($group_info)) { $num = 0; } else { $num = substr($group_info[0]['shipOrderGroup'], 2); } $text = ''; $bool = true; $group_infos = GroupRouteModel::getRouteIndex("*", "where user='******' order by id asc"); $count = count($group_infos); $group_amount = ceil($count / 30); for ($i = 0; $i < $group_amount; $i++) { $sku_arr = array(); for ($j = 0; $j < 30; $j++) { $route_id = $j + 30 * $i; if ($route_id == $count) { break; } $car_number = $j + 1; $shipOrderId = $group_infos[$route_id]['shipOrderId']; $sku_array = GroupRouteModel::getOrderPositionIDGroup($shipOrderId); foreach ($sku_array as $sku_detail) { $sku_arr[$sku_detail['pName']][] = array('sku' => $sku_detail['sku'], 'amount' => $sku_detail['total'], 'orders' => $shipOrderId, 'car_number' => $car_number); } } ksort($sku_arr); $group_num = $num + $k; $group_num = str_pad($group_num, 9, "0", STR_PAD_LEFT); $group_num = "PH" . $group_num; $string = ""; foreach ($sku_arr as $position => $position_info) { foreach ($position_info as $sku_info) { $string .= "('" . $sku_info['sku'] . "','" . $sku_info['amount'] . "','" . $sku_info['orders'] . "','" . $group_num . "','" . $sku_info['car_number'] . "','" . $sequence . "','" . $userName . "','" . $time . "','" . $position . "'),"; } } $string = trim($string, ","); $list_one = GroupRouteModel::insertOrderGroup($string); if ($list_one) { $text .= $group_num . "配货清单生成成功;"; } else { $text .= $group_num . "配货清单生成失败;"; $bool = false; } $k++; } if ($bool) { self::$errMsg = "订单配货分组完成,请打印"; return true; } else { self::$errCode = "003"; self::$errMsg = $text; return false; } } else { self::$errCode = "003"; self::$errMsg = "请先生成订单最优配货索引"; return false; } }