ecshop物料库存管理,ecshop库存管理_PHP教程
ecshop物料库存管理,ecshop库存管理
1、创建物流库存表。sql语句:
CREATE TABLE IF NOT EXISTS `emws_materials` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`name` varchar(60) NOT NULL,
`modulus` varchar(60) NOT NULL,
`stock_number` smallint(5) unsigned NOT NULL default '0',
`stock_in` smallint(5) unsigned NOT NULL default '0',
`stock_out` smallint(5) unsigned NOT NULL default '0',
`safe_day` smallint(5) unsigned NOT NULL default '0',
`intent_day` smallint(5) unsigned NOT NULL default '0',
`is_buy` tinyint(1) unsigned NOT NULL default '1',
`buy_url` varchar(60) NOT NULL,
`price` decimal(10,2) NOT NULL,
`weight` smallint(5) unsigned NOT NULL default '0',
`img` varchar(60) NOT NULL,
`desc_info` varchar(60) NOT NULL,
`remark` varchar(60) NOT NULL,
`admin_id` smallint(5) unsigned NOT NULL,
`update_time` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
2、php程序,materials.php:
1 php 2 define('IN_ECS', true); 3 require(dirname(__FILE__) . '/includes/init.php'); 4 include_once(ROOT_PATH . 'includes/cls_image.php'); 5 $image = new cls_image($_CFG['bgcolor']); 6 $exc = new exchange($ecs->table("materials"), $db, 'id', 'name'); 7 $_REQUEST['act']=!empty($_REQUEST['act']) ? $_REQUEST['act']:'list'; 8 admin_priv('stock_alert');//权限:库存数量修改 9 if($_REQUEST['act'] == 'list') 10 { 11 $stock_list=material_list(); 12 $smarty->assign('ur_here', '物料库存列表'); 13 $smarty->assign('stock_list', $stock_list['stock_list']); 14 $smarty->assign('filter', $stock_list['filter']); 15 $smarty->assign('record_count', $stock_list['record_count']); 16 $smarty->assign('page_count', $stock_list['page_count']); 17 18 $smarty->assign('shelf_list', $shelf_list); 19 $smarty->assign('full_page', 1); 20 $smarty->assign('action_link', array('href' => 'goods_stock.php?act=list', 'text' => '商品库存列表')); 21 $smarty->assign('action_link2', array('href' => 'materials.php?act=export', 'text' => '导出采购单')); 22 $smarty->assign('action_link3', array('href' => 'materials.php?act=add', 'text' => '添加物料')); 23 24 $smarty->display('material_list.htm'); 25 } 26 elseif($_REQUEST['act'] == 'add') 27 { 28 $smarty->assign('ur_here', "添加物料"); 29 $smarty->assign('action_link', array('href' => 'materials.php?act=list', 'text' => '返回物料库存列表')); 30 $smarty->assign('form_action', "insert"); 31 32 assign_query_info(); 33 $smarty->display('material_info.htm'); 34 } 35 elseif($_REQUEST['act'] == 'insert') 36 { 37 $material['is_buy'] = isset($_REQUEST['is_buy']) ? intval($_REQUEST['is_buy']) : 1; 38 $material['name'] = isset($_REQUEST['name']) ? trim($_REQUEST['name']) : ''; 39 $material['modulus'] = isset($_REQUEST['modulus']) ? trim($_REQUEST['modulus']) : ''; 40 $material['safe_day'] = isset($_REQUEST['safe_day']) ? intval($_REQUEST['safe_day']) : 0; 41 $material['intent_day']= isset($_REQUEST['intent_day']) ? intval($_REQUEST['intent_day']) : 0; 42 $material['price'] = isset($_REQUEST['price']) ? floatval($_REQUEST['price']) : '0.00'; 43 $material['weight'] = isset($_REQUEST['weight']) ? intval($_REQUEST['weight']) : 0; 44 $material['desc_info'] = isset($_REQUEST['desc_info']) ? trim($_REQUEST['desc_info']) : ''; 45 $material['remark'] = isset($_REQUEST['remark']) ? trim($_REQUEST['remark']) : ''; 46 $material['update_time']= gmtime(); 47 $material['admin_id'] = $_SESSION['admin_id']; 48 49 if(empty($material['name']) || empty($material['modulus']) || empty($material['safe_day']) || empty($material['intent_day'])) 50 { 51 sys_msg('名称、系数、安全天数、目标天数,不能为空或者格式不正确', 1); 52 } 53 54 $is_only = $exc->is_only('name', $material['name']); 55 if (!$is_only) 56 { 57 sys_msg($material['name'].',已存在', 1); 58 } 59 60 /*处理图片*/ 61 $material['img'] = basename($image->upload_image($_FILES['img'],'material')); 62 /*处理URL*/ 63 $material['buy_url'] = sanitize_url($_POST['buy_url']); 64 /*插入数据*/ 65 $db->autoExecute($ecs->table('materials'), $material, 'INSERT', '', 'SILENT'); 66 67 $link[0]['text'] = '继续添加'; 68 $link[0]['href'] = 'materials.php?act=add'; 69 $link[1]['text'] = '返回列表'; 70 $link[1]['href'] = 'materials.php?act=list'; 71 sys_msg('添加成功', 0, $link); 72 } 73 elseif($_REQUEST['act'] == 'updata') 74 { 75 $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; 76 $material['is_buy'] = isset($_REQUEST['is_buy']) ? intval($_REQUEST['is_buy']) : 1; 77 $material['name'] = isset($_REQUEST['name']) ? trim($_REQUEST['name']) : ''; 78 $material['modulus'] = isset($_REQUEST['modulus']) ? trim($_REQUEST['modulus']) : ''; 79 $material['safe_day'] = isset($_REQUEST['safe_day']) ? intval($_REQUEST['safe_day']) : 0; 80 $material['intent_day']= isset($_REQUEST['intent_day']) ? intval($_REQUEST['intent_day']) : 0; 81 $material['price'] = isset($_REQUEST['price']) ? floatval($_REQUEST['price']) : '0.00'; 82 $material['weight'] = isset($_REQUEST['weight']) ? intval($_REQUEST['weight']) : 0; 83 $material['desc_info'] = isset($_REQUEST['desc_info']) ? trim($_REQUEST['desc_info']) : ''; 84 $material['remark'] = isset($_REQUEST['remark']) ? trim($_REQUEST['remark']) : ''; 85 $material['update_time']= gmtime(); 86 $material['admin_id'] = $_SESSION['admin_id']; 87 88 if(empty($id)) 89 { 90 sys_msg('ID不能为空', 1); 91 } 92 93 if(empty($material['name']) || empty($material['modulus']) || empty($material['safe_day']) || empty($material['intent_day'])) 94 { 95 sys_msg('名称、系数、安全天数、目标天数,不能为空或者格式不正确', 1); 96 } 97 98 /*处理图片*/ 99 if(!empty($_FILES['img']['name'])) 100 { 101 $material['img'] = basename($image->upload_image($_FILES['img'],'material')); 102 } 103 /*处理URL*/ 104 $material['buy_url'] = sanitize_url($_POST['buy_url']); 105 /*插入数据*/ 106 $db->autoExecute($ecs->table('materials'), $material, 'UPDATE', "id = '$id'"); 107 108 $link[0]['text'] = '继续编辑'; 109 $link[0]['href'] = 'materials.php?act=edit&id='.$id; 110 $link[1]['text'] = '返回列表'; 111 $link[1]['href'] = 'materials.php?act=list'; 112 sys_msg('编辑成功', 0, $link); 113 } 114 elseif ($_REQUEST['act'] =='edit') 115 { 116 $sql = "SELECT * FROM " .$ecs->table('materials'). " WHERE id='$_REQUEST[id]'"; 117 $material = $db->GetRow($sql); 118 $smarty->assign('ur_here', "编辑物料"); 119 $smarty->assign('action_link', array('href' => 'materials.php?act=list', 'text' => '返回物料库存列表')); 120 $smarty->assign('material', $material); 121 $smarty->assign('form_action', 'updata'); 122 assign_query_info(); 123 $smarty->display('material_info.htm'); 124 } 125 elseif ($_REQUEST['act'] == 'remove') 126 { 127 $id = intval($_GET['id']); 128 $exc->drop($id); 129 $url = 'materials.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']); 130 ecs_header("Location: $url\n"); 131 exit; 132 } 133 elseif ($_REQUEST['act'] == 'drop_img') 134 { 135 $id = isset($_GET['id']) ? intval($_GET['id']) : 0; 136 137 $sql = "SELECT img FROM " .$ecs->table('materials'). " WHERE id = '$id'"; 138 $img_name = $db->getOne($sql); 139 140 if (!empty($img_name)) 141 { 142 @unlink(ROOT_PATH . DATA_DIR . '/material/' .$img_name); 143 $sql = "UPDATE " .$ecs->table('materials'). " SET img = '' WHERE id = '$id'"; 144 $db->query($sql); 145 } 146 $link= array(array('text' => '继续编辑', 'href' => 'materials.php?act=edit&id=' . $id), array('text' => '返回物料库存列表', 'href' => 'materials.php?act=list')); 147 sys_msg('图片删除成功', 0, $link); 148 } 149 elseif ($_REQUEST['act'] == 'edit_stock_in') //更改入库 150 { 151 $id = intval($_POST['id']); 152 $val = json_str_iconv(trim($_POST['val'])); 153 /* 检查格式 */ 154 if(!is_numeric($val) || $val )上一篇: 关于CSS中浮动属性的简单介绍
下一篇: 浅析Java内部类的各种用法(代码示例)