public function view_changePurchaseBatchOn() { $useId = $_SESSION['userId']; $personName = getPersonNameById($useId); if (empty($personName)) { $status = "<font color=red>系统找不到登录人信息!</font><br/>"; echo $status; exit; } if (isset($_POST['submit']) && $_POST['submit'] != '') { $uploadfile = 'changePurchaseBatch' . date("Y") . date("m") . date("d") . date("H") . date('i') . date('s') . '_' . $personName . ".xls"; if (move_uploaded_file($_FILES['upfile']['tmp_name'], 'upload/' . $uploadfile)) { echo "<font color=BLUE>文件上传成功!</font><br>"; } else { echo "<font color=red> 文件上传失败!</font>"; exit; } $fileName = 'upload/' . $uploadfile; $filePath = $fileName; $PHPExcel = new PHPExcel(); $PHPReader = new PHPExcel_Reader_Excel2007(); if (!$PHPReader->canRead($filePath)) { $PHPReader = new PHPExcel_Reader_Excel5(); if (!$PHPReader->canRead($filePath)) { echo 'no Excel'; return; } } $PHPExcel = $PHPReader->load($filePath); $currentSheet = $PHPExcel->getSheet(0); $highestRow = $currentSheet->getHighestRow(); //表格中的最大行数 $tmpArr = array(); $status = ''; $flag = true; //标识检测结果 for ($i = 2; $i <= $highestRow; $i++) { //先检查导入表格的正确性 $sku = trim($currentSheet->getCell('A' . $i)->getValue()); //sku $sku = preg_replace("/(\\s|\\ \\;| | )/", "", $sku); $purchaseName = trim($currentSheet->getCell('B' . $i)->getValue()); //采购人名称 $purchaseName = preg_replace("/(\\s|\\ \\;| | )/", "", $purchaseName); $sku = strpos($sku, '_') === false ? str_pad($sku, 3, '0', STR_PAD_LEFT) : $sku; if (empty($sku)) { $status .= "<font color=red>第 {$i} 行,SKU为空!</font><br/>"; echo $status; exit; } if (empty($purchaseName)) { $status .= "<font color=red>第 {$i} 行,采购为空!</font><br/>"; echo $status; exit; } if (!isSkuExist($sku)) { $status .= "<font color=red>第 {$i} 行,找不到该SKU信息!</font><br/>"; $flag = false; } $purchaseId = getPersonIdByName($purchaseName); if (empty($purchaseId)) { $status .= "<font color=red>第 {$i} 行,找不到该采购员!</font><br/>"; $flag = false; } } if (!$flag) { $status .= '<font color=red>更新失败!</font>'; echo $status; exit; } $status = ''; for ($i = 2; $i <= $highestRow; $i++) { //如果通过了检测,则批量更新数据 $sku = trim($currentSheet->getCell('A' . $i)->getValue()); //sku $sku = preg_replace("/(\\s|\\ \\;| | )/", "", $sku); $purchaseName = trim($currentSheet->getCell('B' . $i)->getValue()); //采购人名称 $purchaseName = preg_replace("/(\\s|\\ \\;| | )/", "", $purchaseName); $sku = strpos($sku, '_') === false ? str_pad($sku, 3, '0', STR_PAD_LEFT) : $sku; $purchaseId = getPersonIdByName($purchaseName); $tName = 'pc_goods'; $dataPurchase = array(); $dataPurchase['purchaseId'] = $purchaseId; $where = "WHERE sku='{$sku}'"; OmAvailableModel::updateTNameRow2arr($tName, $dataPurchase, $where); OmAvailableModel::newData2ErpInterfOpen('pc.erp.updateCguser', array('goods_sn' => $sku, 'cguser' => $purchaseName, 'gw88')); //同步到深圳ERP $status .= "<font color=green>{$sku} 采购 {$purchaseName} 更新成功</font><br/>"; } $status .= '<font color=green>更新成功!</font>'; echo $status; exit; } }
function act_addGoodsWhIdLocationRaletion() { $start = 0; //循环的下标 $per = 200; //每次通过接口取得的记录数 $i = 1; //标识第几次通过接口取数据,初始值为第一次 do { echo "这是第 {$i} 次 调用接口取得数据 \n"; echo "下标为 {$start} 取数为 {$per} \n"; $skuInfoList = UserCacheModel::getOpenSysApi('', array('start' => $start, 'per' => $per)); //调用idc上的仓库系统接口,返回指定下标及对应记录数 $totalNum = $skuInfoList['totalNum']; //返回数据的记录数 $skuInfo = $skuInfoList['skuInfo']; //具体的sku信息数组 if (intval($totalNum) <= 0) { echo "{$totalNum} <= 0 或者不是数字 \n"; continue; } echo "本次要处理的记录数为 {$totalNum} \n"; if (empty($skuInfo) || !is_array($skuInfo)) { echo "{$skuInfo} 为空或者不是数组 \n"; continue; } foreach ($skuInfo as $value) { $sku = $value['sku']; $whId = $value['whId']; $location = post_check(trim($value['location'])); $storageTime = intval($value['storageTime']); if (!isSkuExist($sku)) { //检测sku是否在产品中心存在,不存在则跳过 echo "{$sku} 在产品中心不存在,跳过 \n"; continue; } if (intval($whId) <= 0) { echo "{$sku} 所在的仓库id {$whId} 不是数字或小于等于0,跳过 \n"; continue; //如果该sku所在仓库id不合法,则跳过 } try { BaseModel::begin(); $tName = 'pc_goods_whId_location_raletion'; $where = "WHERE sku='{$sku}'"; OmAvailableModel::deleteTNameRow($tName, $where); //先删除掉该skuInfo的记录 $set = "SET sku='{$sku}',whId='{$whId}',location='{$location}',storageTime='{$storageTime}'"; OmAvailableModel::addTNameRow($tName, $set); BaseModel::commit(); BaseModel::autoCommit(); echo "删除表中的 {$sku} 记录 成功\n"; echo "添加 {$sku} 记录 成功,SET sku='{$sku}',whId='{$whId}',location='{$location}',storageTime='{$storageTime}' \n"; } catch (Exception $e) { //发生错误则进行下次循环 BaseModel::rollback(); BaseModel::autoCommit(); echo "{$sku} 记录 删除 或 插入 SET sku='{$sku}',whId='{$whId}',location='{$location}',storageTime='{$storageTime}' 失败,数据回滚,进入下次循环\n"; continue; } $start += $per; //下次循环的下标 $i++; } } while ($totalNum >= $per); }
function act_addIoStoreDetail() { $sku = $_POST['sku'] ? post_check(trim($_POST['sku'])) : ''; $iostoreId = intval($_POST['iostoreId']); $addUserId = intval($_SESSION['userId']); if ($iostoreId <= 0) { echo '无效单据'; exit; } $tName = 'pc_products_iostore'; $select = '*'; $where = "WHERE is_delete=0 AND id={$iostoreId}"; $ioStoreList = OmAvailableModel::getTNameList($tName, $select, $where); $ioStore = $ioStoreList[0]; if (empty($ioStore)) { echo '单据有误!'; exit; } $mod = 'products'; $act = 'getOutStoreDetailList'; if ($ioStore['iostoreTypeId'] == 2) { $act = 'getInStoreDetailList'; } if ($addUserId <= 0) { $status = "登陆超时"; header("Location:index.php?mod={$mod}&act={$act}&iostoreId={$iostoreId}&status={$status}"); exit; } if (empty($sku)) { $status = "SKU为空"; header("Location:index.php?mod={$mod}&act={$act}&iostoreId={$iostoreId}&status={$status}"); exit; } if (!isSkuExist($sku)) { $status = "{$sku} 不存在"; header("Location:index.php?mod={$mod}&act={$act}&iostoreId={$iostoreId}&status={$status}"); exit; } $tName = 'pc_products_iostore_detail'; $ioStoreDetailArr = array(); $ioStoreDetailArr['iostoreId'] = $iostoreId; $ioStoreDetailArr['iostoreStatus'] = $ioStore['iostoreStatus']; $ioStoreDetailArr['iostoreTypeId'] = $ioStore['iostoreTypeId']; $ioStoreDetailArr['useTypeId'] = $ioStore['useTypeId']; $ioStoreDetailArr['sku'] = $sku; $ioStoreDetailArr['whId'] = $ioStore['whId']; $ioStoreDetailArr['addUserId'] = $addUserId; $ioStoreDetailArr['addTime'] = time(); $ioStoreDetailArr['isAudit'] = $ioStore['isAudit']; $ioStoreDetailArr['isComfirm'] = $ioStore['isComfirm']; OmAvailableModel::addTNameRow2arr($tName, $ioStoreDetailArr); $status = "{$sku} 添加成功"; header("Location:index.php?mod={$mod}&act={$act}&iostoreId={$iostoreId}&status={$status}"); exit; }