/** * WarningModel::addStock() * 生成海外备货清单 * @param string $ids * @param string $purchase * @return bool */ public static function addStock($ids, $purchase) { self::initDB(); require_once WEB_PATH . "model/purchaseOrder.model.php"; $sql = "SELECT sku,goodsCost FROM " . self::$prefix . self::$showtab . " WHERE id IN ({$ids})"; $query = self::$dbConn->query($sql); if ($query) { $ret = self::$dbConn->fetch_array_all($query); $nowtime = time(); $stocksn = PurchaseOrderModel::autoCreateOrderSn(66, 3); $sqlstock = "INSERT INTO " . self::$prefix . self::$owtab . "(ordersn,adduser,addtime,status) VALUES('{$stocksn}','{$purchase}','{$nowtime}','1')"; $query = self::$dbConn->query($sqlstock); foreach ($ret as $v) { $skusql = "INSERT INTO " . self::$prefix . self::$owdetailtab . "(ordersn,sku,cost) VALUES('{$stocksn}', '{$v['sku']}', '{$v['goodsCost']}')"; $query = self::$dbConn->query($skusql); } return true; } else { self::$errCode = "1060"; self::$errMsg = "获取数据失败"; return false; } }
/** *功能:处理异常采购订单,例:采购补单、二次录入 *@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; } } } } } }
/** * 生成海外备货单,根据下单人合并订单明细 * Enter description here ... */ public function createOwOrder() { global $dbConn; $skulist = $_POST['skulist']; $operator_id = $_SESSION[C('USER_AUTH_SYS_ID')]; //操作人员ID $comid = $_SESSION[C('USER_COM_ID')]; //公司ID $type = $_POST['type']; $rollback = false; $existSku = ''; $ismark = 0; BaseModel::begin(); //开始事务 foreach ($skulist as $key => $sku) { $price = PurchaseOrderModel::getPriceBySku($sku['sku']); //SKU单价 $purid = OwOrderModel::getPurchaseidBySku($sku['sku']); $parid = OwOrderModel::getPartnerId($sku['sku']); //供应商ID $parid = $parid['partnerId']; $storeid = 1; //仓库ID $orderData = OwOrderModel::getOwOrderNum($operator_id); //判断同操作员跟踪号是否已存在(未审核状态下) $orderSN = $orderData['recordnumber']; $main = array(); $detail = array(); if (!empty($orderSN)) { //存在符合条件的跟踪号,直接插入采购订单明细 /* $orderHasSku = OwOrderModel::orderExistSku($sku['sku']); if($orderHasSku){ $existSku .= '['.$sku['sku'].'],'; continue; }*/ $detail['sku'] = $sku['sku']; $detail['price'] = $price; //单价 $detail['count'] = $sku['rec']; //采购数量 $detail['goods_recommend_count'] = $sku['rec']; //采购数量 $detail['recordnumber'] = $orderData['recordnumber']; $poid = $orderData['id']; //根据跟踪号取采购主订单编号 $detail['parid'] = $parid; //料号供应商ID $detail['po_id'] = $poid; $dataSet = array2sql($detail); $sql = "insert into ph_ow_order_detail set {$dataSet} "; $rtndetail = $dbConn->execute($sql); if ($rtndetail === false) { $rollback = true; } else { $ismark = 1; } } else { //不存在符合条件的跟踪号重新生成 $recordnumber = PurchaseOrderModel::autoCreateOrderSn($purid, $comid); //生成对应公司的采购订单跟踪号 if (!empty($recordnumber)) { //生成采购订单号成功 $main['recordnumber'] = $recordnumber; //跟踪号 $main['purchaseuser_id'] = $purid; //采购员ID $main['operator_id'] = $operator_id; //操作人员id $main['warehouse_id'] = $storeid; //仓库ID $main['company_id'] = $comid; //公司编号 $main['partner_id'] = $parid; //供应商ID $main['addtime'] = time(); if ($type == "oversea") { $main['order_type'] = 5; // 给海外仓备货的订单 } else { $main['order_type'] = 1; // 正常订单 } $dataSet = array2sql($main); $sql = "insert into ph_ow_order set {$dataSet} "; $rtnmain = $dbConn->execute($sql); if ($rtnmain) { //主订单添加成功 /* $orderHasSku = OwOrderModel::orderExistSku($sku['sku']); if($orderHasSku){ $existSku .= '['.$sku['sku'].'],'; continue; }*/ $detail['sku'] = $sku['sku']; $detail['price'] = $price; //单价 $detail['count'] = $sku['rec']; //采购数量 $detail['goods_recommend_count'] = $sku['rec']; //采购数量 $detail['parid'] = $parid; //料号供应商ID $detail['recordnumber'] = $recordnumber; $poid = OwOrderModel::getOwPoid($recordnumber); //根据跟踪号取采购主订单编号 $detail['po_id'] = $poid; $dataSet = array2sql($detail); $sql = "insert into ph_ow_order_detail set {$dataSet} "; $rtndetail = $dbConn->execute($sql); if ($rtndetail === false) { $rollback = true; } else { $ismark = 1; } } else { $rollback = true; } } else { $rollback = true; } } } //$existSku = substr($existSku, 0, strlen($existSku) - 1); if ($rollback == false) { //if($ismark == 1){ BaseModel::commit(); BaseModel::autoCommit(); $result['msg'] = 'yes'; //}else{ // $result['msg'] = 'warn'; //} //$result['tip'] = $existSku; } else { BaseModel::rollback(); BaseModel::autoCommit(); $result['msg'] = 'no'; } return json_encode($result); }
public function pickupOrder() { global $dbConn; $skulist = $_POST['skulist']; $operator_id = $_SESSION[C('USER_AUTH_SYS_ID')]; //操作人员ID $comid = $_SESSION[C('USER_COM_ID')]; //公司ID $type = $_POST['type']; BaseModel::begin(); //开始事务 $rollback = false; foreach ($skulist as $key => $sku) { $price = PurchaseOrderModel::getPriceBySku($sku['sku']); //SKU单价 //$parid = CommonAct::actgetPartnerIdBySku($sku['sku']);//供应商ID $purid = $this->getPurchaseidBySku($sku['sku']); $parid = $this->getPartnerId($sku['sku']); //供应商ID $parid = $parid['partnerId']; $storeid = 1; //仓库ID $orderData = $this->getOwOrderSN($parid, $purid); //判断同供应商、采购员跟踪号是否已存在 $orderSN = $orderData['recordnumber']; if ($key == 0 && $type == "oversea") { $orderSN = null; } $main = array(); $detail = array(); if (!empty($orderSN)) { //存在符合条件的跟踪号,直接插入采购订单明细 //$detail['sku_id'] = $skuid;//SKU编号 $detail['sku'] = $sku['sku']; $detail['price'] = $price; //单价 $detail['count'] = $sku['rec']; //采购数量 //$detail['is_new'] = $sku['is_new'];// 是否是新品 $detail['goods_recommend_count'] = $sku['rec']; //采购数量 $detail['recordnumber'] = $orderData['recordnumber']; $poid = $orderData['id']; //根据跟踪号取采购主订单编号 $detail['po_id'] = $poid; $dataSet = array2sql($detail); $sql = "insert into ph_ow_order_detail set {$dataSet} "; $rtndetail = $dbConn->execute($sql); if ($rtndetail === false) { $rollback = true; } } else { //不存在符合条件的跟踪号重新生成 //生成跟踪号需通过公司编号生成前缀 $recordnumber = PurchaseOrderModel::autoCreateOrderSn($purid, $comid); //生成对应公司的采购订单跟踪号 if (!empty($recordnumber)) { //生成采购订单号成功 $main['recordnumber'] = $recordnumber; //跟踪号 $main['purchaseuser_id'] = $purid; //采购员ID $main['operator_id'] = $operator_id; //操作人员id $main['warehouse_id'] = $storeid; //仓库ID $main['partner_id'] = $parid; //供应商ID $main['company_id'] = $comid; //公司编号 $main['addtime'] = time(); if ($type == "oversea") { $main['order_type'] = 5; // 给海外仓备货的订单 } else { $main['order_type'] = 1; // 正常订单 } $dataSet = array2sql($main); $sql = "insert into ph_ow_order set {$dataSet} "; $rtnmain = $dbConn->execute($sql); if ($rtnmain) { //主订单添加成功 $detail['sku'] = $sku['sku']; $detail['price'] = $price; //单价 $detail['count'] = $sku['rec']; //采购数量 $detail['goods_recommend_count'] = $sku['rec']; //采购数量 //$detail['is_new'] = $sku['is_new'];// 是否是新品 $detail['recordnumber'] = $recordnumber; $poid = PurchaseOrderModel::getOrderIdByNum($recordnumber); //根据跟踪号取采购主订单编号 $detail['po_id'] = $poid; $dataSet = array2sql($detail); $sql = "insert into ph_ow_order_detail set {$dataSet} "; $dbConn->execute($sql); if ($rtndetail === false) { $rollback = true; } } else { $rollback = true; } } else { $rollback = true; } } } if ($rollback == false) { BaseModel::commit(); BaseModel::autoCommit(); $result['msg'] = 'success'; } else { BaseModel::rollback(); BaseModel::autoCommit(); $result['msg'] = ''; } return json_encode($result); }
public function addNewOrder() { global $dbConn; $skulist = $_POST['skulist']; //$purchaseId = $_SESSION[C('USER_AUTH_SYS_ID')];//采购员ID $purchaseId = $skulist[0]["cguserId"]; //采购员ID $comid = $_SESSION[C('USER_COM_ID')]; //公司ID $skuComObj = new CommonAct(); //重新计算这个sku 的已订购数量 $purchaseOrder = new PurchaseOrderAct(); $rollback = false; foreach ($skulist as $sku) { $price = $sku['price']; //SKU单价 $partnerId = $purchaseOrder->getPartnerId($sku['sku']); //供应商ID $partnerId = $partnerId['partnerId']; $storeid = 1; //仓库ID $orderData = $purchaseOrder->getOrderSN($partnerId, $purchaseId); //判断同供应商、采购员跟踪号是否已存在 $orderSN = $orderData['recordnumber']; $main = array(); $detail = array(); if (!empty($orderSN)) { //存在符合条件的跟踪号,直接插入采购订单明细 $detail['sku'] = $sku['sku']; $detail['price'] = $price; //单价 $detail['count'] = $sku['rec']; //采购数量 $detail['goods_recommend_count'] = $sku['rec']; //采购数量 $dataSet = array2sql($detail); $sql = "insert into ph_order_detail set {$dataSet} "; $dbConn->execute($sql); } else { //不存在符合条件的跟踪号重新生成 $recordnumber = PurchaseOrderModel::autoCreateOrderSn($purchaseId, $comid); //生成对应公司的采购订单跟踪号 if (!empty($recordnumber)) { //生成采购订单号成功 $main['recordnumber'] = $recordnumber; //跟踪号 $main['purchaseuser_id'] = $purchaseId; //采购员ID $main['warehouse_id'] = $storeid; //仓库ID $main['partner_id'] = $partnerId; //供应商ID $main['company_id'] = $comid; //公司编号 $dataSet = array2sql($main); $sql = "insert into ph_order set {$dataSet} "; $dbConn->execute($sql); if ($rtnmain) { //主订单添加成功 $detail['sku'] = $sku['sku']; $detail['price'] = $price; //单价 $detail['count'] = $sku['rec']; //采购数量 $detail['goods_recommend_count'] = $sku['rec']; //采购数量 $detail['recordnumber'] = $recordnumber; $dataSet = array2sql($detail); $sql = "insert into ph_order_detail set {$dataSet} "; $dbConn->execute($sql); $skuComObj->calcAlert($detail['sku']); //重新计算已订购数量 } } } } }