function get_sale_alarm_list() { $start_time = strtotime(date('Y-m-1', strtotime("-3 month"))); $end_time = strtotime(date('Y-m-1', $_SERVER['REQUEST_TIME'])); $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1; $recorder_size = 7; /*获取各商品三个月的总销量*/ $where = " WHERE i.add_time>={$start_time} AND i.add_time<={$end_time} AND i.order_status IN (1,5) AND shipping_status IN(1,2,0)"; $tmp_goods_list = get_goods_num($where); //公式:库存>此前三个月平均销量*6 foreach ($tmp_goods_list as &$val) { $val['three_month_sale'] = floor($val['goods_number'] / 3); $goods_sn_list[] = $val['goods_sn']; } if (is_array($goods_sn)) { $goods_sn_str = implode("','", $goods_sn_list); $sql_select = 'SELECT goods_sn,goods_name,SUM(quantity) AS quantity FROM ' . $GLOBALS['ecs']->table('stock_goods') . " WHERE goods_sn IN('{$goods_sn_str}') AND quantity>0 GROUP BY goods_sn"; $goods_quantity_list = $GLOBALS['db']->getAll($sql_select); $goods_list = array(); foreach ($tmp_goods_list as $val) { foreach ($goods_quantity_list as $quantity_list) { if ($val['goods_sn'] == $quantity_list['goods_sn'] && $val['three_month_sale'] * 6 < $quantity_list['quantity']) { $val['goods_name'] = $quantity_list['goods_name']; $val['quantity'] = $quantity_list['quantity']; $goods_list[] = $val; } } } $recorder_count = count($goods_list); $page_size = ceil($recorder_count / $recorder_size); $page = $page > $page_size ? 1 : $page; for ($i = ($page - 1) * $recorder_size, $j = 0; $j < $recorder_size; $i++) { if ($goods_list[$i]) { $sale_alarm_list['sale_alarm'][] = $goods_list[$i]; $j++; } else { break; } } $list_page = array(); for ($i = 1; $i <= $page_size; $i++) { $list_page[] = $i; } $filter = array('page' => $page, 'recorder_size' => $recorder_size, 'list_page' => $list_page, 'end' => $page_size, 'recorder' => $recorder, 'action' => "getSaleAlarm({$page},{$recorder_size})"); $sale_alarm_list['filter'] = $filter; } else { $sale_alarm_list['sale_alarm'] = '没有记录'; } return $sale_alarm_list; }
* 盘点前下单(盘点时发货) @before_inventory * 盘点前下间(盘点时还没发货)@before_inventory_not_send * */ $end_time = $_SERVER['REQUEST_TIME']; $sql_select = 'SELECT start_time FROM ' . $GLOBALS['ecs']->table('inventory_storage') . ' WHERE end_time = 0 LIMIT 1'; $start_time = $GLOBALS['db']->getOne($sql_select); $where_inventory = " WHERE i.confirm_time BETWEEN {$start_time} AND {$end_time}-1"; $where_pre_inventory = " WHERE i.confirm_time<{$start_time} AND i.shipping_time BETWEEN {$start_time} AND {$end_time}-1"; $wait_shipping = ' AND order_status=1 AND shipping_status=0 '; $had_shipping = ' AND order_status=5 AND shipping_status=1 '; $place_goods_num = $where_inventory . $wait_shipping; $delive_goods_num = $where_inventory . " AND shipping_time BETWEEN {$start_time} AND {$end_time}-1 " . $had_shipping; $before_inventory_num = $where_pre_inventory . $had_shipping; $goods_list['place_goods_num'] = get_goods_num($place_goods_num); $goods_list['delive_goods_num'] = get_goods_num($delive_goods_num); $goods_list['before_inventory_num'] = get_goods_num($before_inventory_num); $sql_select = 'SELECT storage_id,goods_sn,place_goods_num,delive_goods_num,before_inventory_num FROM ' . $GLOBALS['ecs']->table('inventory_storage') . ' WHERE end_time=0'; $pre_inventory = $GLOBALS['db']->getAll($sql_select); $sql_select = 'SELECT SUM(quantity) quantity,goods_sn FROM ' . $GLOBALS['ecs']->table('stock_goods') . ' GROUP BY goods_sn'; $actual_quantity = $GLOBALS['db']->getAll($sql_select); foreach ($pre_inventory as &$pre) { if ($goods_list['place_goods_num']) { foreach ($goods_list['place_goods_num'] as &$place) { if ($pre['goods_sn'] == $place['goods_sn']) { $pre['place_goods_num'] = $place['goods_number']; unset($place); break; } } } if ($goods_list['delive_goods_num']) {