/** *功能:处理异常采购订单,例:采购补单、二次录入 *@param $type 处理类型 *@param $dataarray 料号 数量 *@param $purid 采购员编号 *日期:2013/08/05 *作者:王民伟 */ public static function handleUnusualOrder() { $checkPur = UnusualOrderAct::checkPower(); if ($checkPur !== true) { self::$errMsg = '无权限操作'; return false; } $type = $_GET['type']; $dataarray = $_GET['datalist']; $purid = $_GET['purid']; global $dbConn; $errArr = array(); if ($type == 'patchOrder') { //不能重复补单 if (!empty($dataarray)) { $dbConn->begin(); //开启事物 $datalist = explode('@', $dataarray); $datanum = count($datalist); for ($i = 0; $i < $datanum; $i++) { $infolist = explode('*', $datalist[$i]); if (count($infolist) == 3) { $oid = $infolist[0]; $oidlist = "('" . $oid . "')"; $sku = $infolist[1]; $amount = $infolist[2]; $skulist[] = $sku; $rtn_infolist = PurchaseOrderModel::getPurSkuInfo($skulist, $purid); //过滤不是自己负责的SKU,并返回所需数据 unset($skulist); if (empty($rtn_infolist)) { $errArr[] = $sku . '不属于你负责的sku'; } else { //符合条件开始补单 $info_list_num = count($rtn_infolist); for ($i = 0; $i < $info_list_num; $i++) { $detailinfo = array(); $rtn_sku = $rtn_infolist[$i]['sku']; //返回SKU $rtn_partner_id = $rtn_infolist[$i]['partnerid']; //返回供应商编号 $rtn_price = $rtn_infolist[$i]['goodsCost']; //返回采购单价 $isExistPatchOrdersn = PurchaseOrderModel::isExistPatchOrdersn($rtn_partner_id, $purid); //查找条件符合的补单号??? if (empty($isExistPatchOrdersn)) { //不存在符合的补单号 //此次需判断生成订单跟踪号前缀---0:SWB;1:FZ;2:ZG $recordnumber = PurchaseOrderModel::autoCreateOrderSn($purid, 0); //生成采购补单号 $maininfo['recordnumber'] = $recordnumber; //订单号 $maininfo['purchaseuser_id'] = $purid; //采购员编号 $maininfo['partner_id'] = $rtn_partner_id; //供应商编号 $maininfo['company_id'] = 1; //公司编号 $rtn_mainorder = PurchaseOrderModel::insertPatchMainOrder($maininfo); //添加补单主体信息 if ($rtn_mainorder) { //主体添加成功 $detailinfo['sku_id'] = PurchaseOrderModel::getSkuIdBySku($rtn_sku); //根据sku获SKU编号 $detailinfo['price'] = $rtn_price; //采购单价 $detailinfo['count'] = $amount; //补单数量 $detailinfo['sku'] = $sku; //sku $poid = PurchaseOrderModel::getOrderIdByNum($recordnumber); $rtn_detailorder = PurchaseOrderModel::insertPatchDetailOrder($poid, $detailinfo); if ($rtn_detailorder) { $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'patchorder', $recordnumber); //通过API更新状态 if ($rtn_api) { $dbConn->commit(); } else { $dbConn->rollback(); $errArr[] = $sku . '仓库数据修改失败'; } } else { $dbConn->rollback(); $errArr[] = $sku . '详情增加失败'; } } else { $dbConn->rollback(); $errArr[] = $sku . '主订单增加失败'; } //self::$errMsg = 'success'; } else { //存在符合条件的补单号 $detailinfo['sku_id'] = PurchaseOrderModel::getSkuIdBySku($rtn_sku); //根据sku获SKU编号 $detailinfo['price'] = $rtn_price; //采购单价 $detailinfo['count'] = $amount; //补单数量 $detailinfo['sku'] = $sku; //sku $poid = PurchaseOrderModel::getOrderIdByNum($isExistPatchOrdersn); //根据跟踪号取编号 $rtn_detailorder = PurchaseOrderModel::insertPatchDetailOrder($poid, $detailinfo); //添加采购订单明细 if ($rtn_detailorder) { $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'patchorder', $isExistPatchOrdersn); //通过API更新状态 if ($rtn_api) { $dbConn->commit(); } else { $dbConn->rollback(); $errArr[] = $sku . '仓库数据修改失败'; } } else { $dbConn->rollback(); $errArr[] = $sku . '详情增加失败'; } } } } } } } else { $errArr[] = '未传入sku数据'; } if (count($errArr) > 0) { $errStr = implode("<br/>", $errArr); self::$errMsg = $errStr; } else { self::$errCode = "111"; } } else { if ($type == 'secondStockIn') { //二次补录 if (!empty($dataarray)) { $datalist = explode('@', $dataarray); $datanum = count($datalist); for ($i = 0; $i < $datanum; $i++) { $infolist = explode('*', $datalist[$i]); if (count($infolist) == 3) { $oid = $infolist[0]; $oidlist = "('" . $oid . "')"; $sku = $infolist[1]; $amount = $infolist[2]; $skuid = PurchaseOrderModel::getSkuIdBySku($sku); if (empty($skuid)) { $errArr[] = $sku . "不存在库存中"; continue; } $rtnlist = PurchaseOrderModel::checkStockInOrder($skuid); if (!empty($rtnlist)) { //过滤找不到的,不再参与入库操作,否则会继续生成未订单 $rtn = PurchaseOrderAct::act_stockIn($sku, $amount); $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'secondstockin', 'no'); if (!$rtn_api) { $errArr[] = $sku . "数据提交仓库系统失败"; break; } } else { $errArr[] = $sku . "未找到二次录入符合条件"; } } } } else { $errArr[] = "传参有误"; } if (count($errArr) > 0) { self::$errMsg = implode("<br/>", $errArr); return false; } self::$errCode = "111"; return true; } else { if ($type == 'setZero') { if (!empty($dataarray)) { $dataarray_num = count($dataarray); for ($i = 0; $i < $dataarray_num; $i++) { $oidlist .= "'" . $dataarray[$i] . "',"; } $oidlist = "(" . substr($oidlist, 0, strlen($oidlist) - 1) . ")"; $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'setzero', 'no'); $rtn['msg'] = $rtn_api; } else { $rtn['msg'] = 'null'; } return $rtn; exit; } else { if ($type == 'comfirmOrder') { if (!empty($dataarray)) { $dataarray_num = count($dataarray); for ($i = 0; $i < $dataarray_num; $i++) { $oidlist .= "'" . $dataarray[$i] . "',"; } $oidlist = "(" . substr($oidlist, 0, strlen($oidlist) - 1) . ")"; $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'comfirmorder', 'no'); $rtn['msg'] = $rtn_api; } else { $rtn['msg'] = 'null'; } return $rtn; } else { if ($type == 'backOrder') { //订单退货 $dataStr = trim($_GET['dataStr']); $order_type = trim($_GET['order_type']); $dbConn->begin(); if (!empty($dataarray) && !empty($dataStr) && !empty($order_type)) { $dataarray_num = count($dataarray); for ($i = 0; $i < $dataarray_num; $i++) { $oidlist .= "'" . $dataarray[$i] . "',"; } $oidlist = "(" . substr($oidlist, 0, strlen($oidlist) - 1) . ")"; //生成退货订单 $datalist = explode('@', $dataStr); $datanum = count($datalist); for ($i = 0; $i < $datanum; $i++) { $infolist = explode('*', $datalist[$i]); if (count($infolist) == 3) { $oid = $infolist[0]; $oidlist = "('" . $oid . "')"; $sku = $infolist[1]; $amount = $infolist[2]; $skulist[] = $sku; $rtn_infolist = PurchaseOrderModel::getPurSkuInfo($skulist, $purid); //过滤不是自己负责的SKU,并返回所需数据 unset($skulist); if (empty($rtn_infolist)) { $errArr[] = $sku . '不属于你负责的sku'; } else { //符合条件开始补单 $info_list_num = count($rtn_infolist); for ($i = 0; $i < $info_list_num; $i++) { $detailinfo = array(); $rtn_sku = $rtn_infolist[$i]['sku']; //返回SKU $rtn_partner_id = $rtn_infolist[$i]['partnerid']; //返回供应商编号 $rtn_price = $rtn_infolist[$i]['goodsCost']; //返回采购单价 $status_type = " status = 5 AND order_type = {$order_type}"; $isExistPatchOrdersn = PurchaseOrderModel::isExistPatchOrdersn($rtn_partner_id, $purid, $status_type); //查找条件符合的退货单??? if (empty($isExistPatchOrdersn)) { //不存在符合的单号 //此次需判断生成订单跟踪号前缀---0:SWB;1:FZ;2:ZG $recordnumber = PurchaseOrderModel::autoCreateOrderSn($purid, 0); //生成采购补单号 $maininfo['recordnumber'] = $recordnumber; //订单号 $maininfo['purchaseuser_id'] = $purid; //采购员编号 $maininfo['partner_id'] = $rtn_partner_id; //供应商编号 $maininfo['company_id'] = 1; //公司编号 $status = 5; $rtn_mainorder = PurchaseOrderModel::insertPatchMainOrder($maininfo, $status, $order_type); //添加主体信息 if ($rtn_mainorder) { //主体添加成功 $detailinfo['sku_id'] = PurchaseOrderModel::getSkuIdBySku($rtn_sku); //根据sku获SKU编号 $detailinfo['price'] = $rtn_price; //采购单价 $detailinfo['count'] = $amount; //数量 $detailinfo['sku'] = $sku; $poid = PurchaseOrderModel::getOrderIdByNum($recordnumber); $rtn_detailorder = PurchaseOrderModel::insertPatchDetailOrder($poid, $detailinfo); if ($rtn_detailorder) { $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'backorder', 'no'); if ($rtn_api) { $dbConn->commit(); } else { $dbConn->rollback(); $errArr[] = $sku . '仓库数据修改失败'; } } else { $dbConn->rollback(); $errArr[] = $sku . '详情增加失败'; } } else { $dbConn->rollback(); $errArr[] = $sku . '主订单增加失败'; } //self::$errMsg = 'success'; } else { //存在符合条件的补单号 $detailinfo['sku_id'] = PurchaseOrderModel::getSkuIdBySku($rtn_sku); //根据sku获SKU编号 $detailinfo['price'] = $rtn_price; //采购单价 $detailinfo['count'] = $amount; //补单数量 $detailinfo['sku'] = $sku; $poid = PurchaseOrderModel::getOrderIdByNum($isExistPatchOrdersn); //根据跟踪号取编号 $rtn_detailorder = PurchaseOrderModel::insertPatchDetailOrder($poid, $detailinfo); //添加采购订单明细 if ($rtn_detailorder) { $rtn_api = ApiAct::update_unusualOrderSataus($purid, $oidlist, 'backorder', 'no'); if ($rtn_api) { $dbConn->commit(); } else { $dbConn->rollback(); $errArr[] = $sku . '仓库数据修改失败'; } } else { $dbConn->rollback(); $errArr[] = $sku . '详情增加失败'; } } } } } } } else { $errArr[] = "传参有误"; } if (count($errArr) > 0) { self::$errMsg = implode("<br/>", $errArr); return false; } self::$errCode = "111"; return true; } } } } } }
public function addOrder() { global $dbConn; $dataArr = $_POST["dataArr"]; $now = time(); $status = 1; //未审核的订单 $order_type = 4; //采购补单 $warehouse_id = 1; $flag = array(); $unOrderIdArr = array(); $operater = $_SESSION['sysUserId']; $skuObj = new SkuAct(); $skuComObj = new CommonAct(); foreach ($dataArr as $item) { $price = PurchaseOrderModel::getPriceBySku($item['sku']); //SKU单价 $partnerId = CommonAct::actgetPartnerIdBySku($item['sku']); //供应商ID $orderData = $this->getOrderSN($partnerId, $item['purchaseId'], 4); //判断同供应商、采购员跟踪号是否已存在 $orderSN = $orderData['recordnumber']; if (isset($orderSN)) { //同一个供应商的订单已经存在 $poid = $orderData['id']; $recordnumber = $orderSN; } else { $recordnumber = $this->autoCreateOrderSn($item['purchaseId'], 1); $sql = "INSERT INTO `ph_order`(`recordnumber`, `addtime`, `aduittime`, `status`, `order_type`, `warehouse_id`, `purchaseuser_id`, `aduituser_id`, `partner_id`, `company_id`, `note`) VALUES ('{$recordnumber}',{$now},{$now},{$status},{$order_type},{$warehouse_id},{$item['purchaseId']},{$item['purchaseId']},{$partnerId},1,'异常到货采购补单')"; if ($dbConn->execute($sql)) { $poid = PurchaseOrderModel::getOrderIdByNum($recordnumber); //根据跟踪号取采购主订单编号 } } if (isset($poid)) { $sql = "select id totalNum from ph_order_detail where sku='{$item['sku']}' and po_id='{$poid}' "; $sql = $dbConn->execute($sql); $detailInfo = $dbConn->fetch_one($sql); if (isset($detailInfo['id'])) { $sql = "update ph_order_detail set count=count+{$item['num']} WHERE id='{$poid}'"; } else { $sql = "insert into ph_order_detail (po_id,unOrderId,recordnumber,sku,count,price,stockqty) values ({$poid},'{$item['unOrderId']}','{$recordnumber}','{$item['sku']}',{$item['num']},{$price},'{$item['num']}')"; } if ($dbConn->execute($sql)) { $usql = "UPDATE `ph_sku_reach_record` SET `ordersn`='{$recordnumber}',operatime={$now}, operatorId={$operater},status = 1 WHERE id={$item['id']}"; //$skuObj->tallySkuRecord($item['sku'],$item['num'],1); // hold 住一部分数量 $dbConn->execute($usql); $skuComObj->calcAlert($item['sku']); $flag[] = 1; $unOrderIdArr[] = $item["unOrderId"]; } else { $flag[] = 0; } } } //$pushObj = new CommonAct(); //$pushObj->setTallyIsUse($unOrderIdArr); return json_encode($flag); }