コード例 #1
0
ファイル: goods.action.php プロジェクト: ohjack/newErp
 function act_updateStatusBatch()
 {
     $spu = isset($_POST['spu']) ? $_POST['spu'] : "";
     $goodsStatus = isset($_POST['goodsStatus']) ? $_POST['goodsStatus'] : 0;
     $reason = isset($_POST['reason']) ? $_POST['reason'] : '';
     $userId = $_SESSION['userId'];
     $now = time();
     if (empty($spu) || empty($goodsStatus)) {
         self::$errCode = '101';
         self::$errMsg = "SPU或者状态为空";
         return false;
     }
     if (intval($userId) <= 0) {
         self::$errCode = '103';
         self::$errMsg = "登陆超时,请重试";
         return false;
     }
     $tName = 'pc_goods';
     $select = 'sku,goodsStatus';
     $where = "WHERE is_delete=0 and spu='{$spu}'";
     $skuList = OmAvailableModel::getTNameList($tName, $select, $where);
     if (empty($skuList)) {
         self::$errCode = '102';
         self::$errMsg = "不存在该SPU的料号";
         return false;
     }
     try {
         BaseModel::begin();
         //更新状态
         $tName = 'pc_goods';
         $set = "SET goodsStatus='{$goodsStatus}',goodsUpdateTime='{$now}'";
         $where = "WHERE spu='{$spu}'";
         OmAvailableModel::updateTNameRow($tName, $set, $where);
         $skuListarr = array();
         foreach ($skuList as $value) {
             $sku = $value['sku'];
             $oldGoodsStatus = $value['goodsStatus'];
             if ($oldGoodsStatus != $goodsStatus) {
                 addStatusBackupsModify($sku, $goodsStatus, $reason, $userId);
                 //添加成本历史记录
                 $skuListarr[] = $value['sku'];
             }
         }
         $skuListStr = implode(',', $skuListarr);
         //已经更新的SKU字符串
         //同步数据到旧系统
         $goodsArr = array();
         $goodsArr['goods_sn'] = $spu;
         if ($goodsStatus == 1) {
             //在线
             $goodsArr['isuse'] = 0;
         } elseif ($goodsStatus == 51) {
             //PK产品
             $goodsArr['isuse'] = 51;
         } elseif ($goodsStatus == 2) {
             //停售
             $goodsArr['isuse'] = 1;
         } elseif ($goodsStatus == 3) {
             //暂时停售
             $goodsArr['isuse'] = 3;
         } else {
             //其余的都做下线处理
             $goodsArr['isuse'] = 1;
         }
         $res = OmAvailableModel::newData2ErpInterfOpen('pc.erp.updateStatusBatch', $goodsArr, 'gw88');
         //同步到旧ERP系统中
         BaseModel::commit();
         BaseModel::autoCommit();
         self::$errCode = '200';
         self::$errMsg = !empty($skuListStr) ? "SPU下料号:{$skuListStr} 状态批量更新成功!" : "无修改!";
         return true;
     } catch (Exception $e) {
         BaseModel::rollback();
         BaseModel::autoCommit();
         self::$errCode = '404';
         self::$errMsg = "更新失败,请联系相关人员!";
         return false;
     }
 }
コード例 #2
0
ファイル: goods.view.php プロジェクト: ohjack/newErp
 public function view_updateSkuSingOn()
 {
     $id = $_POST['id'] ? post_check(trim($_POST['id'])) : '';
     $spu = $_POST['spu'] ? post_check(trim($_POST['spu'])) : '';
     $pid = $_POST['pid'] ? post_check(trim($_POST['pid'])) : '';
     $sku = $_POST['sku'] ? post_check(trim($_POST['sku'])) : '';
     $goodsName = $_POST['goodsName'] ? trim($_POST['goodsName']) : '';
     $goodsCost = $_POST['goodsCost'] ? post_check(trim($_POST['goodsCost'])) : '';
     $goodsNote = $_POST['goodsNote'] ? trim($_POST['goodsNote']) : '';
     $goodsStatus = $_POST['goodsStatus'] ? post_check(trim($_POST['goodsStatus'])) : '';
     $isNew = $_POST['isNew'] ? post_check(trim($_POST['isNew'])) : '';
     $goodsColor = $_POST['goodsColor'] ? post_check(trim($_POST['goodsColor'])) : '';
     $goodsSize = $_POST['goodsSize'] ? post_check(trim($_POST['goodsSize'])) : '';
     $userId = $_SESSION['userId'];
     if (intval($id) == 0) {
         $status = "非法id";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     if (intval($userId) == 0) {
         $status = "登陆超时,请重新登陆";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     if (empty($pid)) {
         $status = "类别为空";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     if (empty($sku)) {
         $status = "sku为空";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     if (empty($goodsName)) {
         $status = "描述不能为空";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     if (strpos($goodsName, '#') !== false || strpos($goodsNote, '#') !== false) {
         //如果描述中有#则报错
         $status = "{$sku} 的描述/备注 不能含有'井'号等特殊字符";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     if (!is_numeric($goodsCost) || $goodsCost <= 0) {
         $status = "成本必须为正数";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-1);
               </script>';
         exit;
     }
     $tName = 'pc_goods';
     $select = 'goodsCost,goodsStatus';
     $where = "WHERE sku='{$sku}' and id={$id}";
     $skuList = OmAvailableModel::getTNameList($tName, $select, $where);
     if (empty($skuList)) {
         $status = "系统中不存在 {$sku}";
         header("Location:index.php?mod=goods&act=getGoodsList&status={$status}");
         exit;
     }
     try {
         BaseModel::begin();
         $dataSku = array();
         $dataSku['goodsCategory'] = $pid;
         $dataSku['goodsName'] = $goodsName;
         if ($goodsName == '无') {
             //删除料号
             $status = "系统已经不允许删除料号了!";
             echo $status;
             exit;
         }
         if ($goodsCost != $skuList[0]['goodsCost']) {
             //成本变化时
             $dataSku['goodsCost'] = $goodsCost;
             addCostBackupsModify($sku, $goodsCost, $userId);
             //添加成本历史记录
         }
         $dataSku['goodsNote'] = $goodsNote;
         $dataSku['goodsStatus'] = $goodsStatus;
         if ($goodsStatus != $skuList[0]['goodsStatus']) {
             //状态变化时
             $dataSku['goodsUpdateTime'] = time();
             $reason = $_POST['reason'] ? post_check(trim($_POST['reason'])) : '';
             addStatusBackupsModify($sku, $goodsStatus, $reason, $userId);
             //添加状态改变记录
         }
         $dataSku['isNew'] = $isNew;
         $dataSku['goodsColor'] = $goodsColor;
         $dataSku['goodsSize'] = $goodsSize;
         $tName = 'pc_goods';
         $where = "WHERE id={$id}";
         OmAvailableModel::updateTNameRow2arr($tName, $dataSku, $where);
         $dataSkuArray2Sql = array2sql($dataSku);
         $addUserName = getPersonNameById($userId);
         error_log(date('Y-m-d_H:i') . "——{$sku} {$dataSkuArray2Sql} by {$addUserName} \r\n", 3, WEB_PATH . "log/updateSkuSingLog.txt");
         //更新mem中的sku
         $tName = 'pc_goods';
         $select = '*';
         $where = "WHERE id={$id}";
         $memInfo = OmAvailableModel::getTNameList($tName, $select, $where);
         $memInfo = $memInfo[0];
         $key = 'pc_goods_' . $sku;
         $value = $memInfo;
         setMemNewByKey($key, $value);
         //这里不保证能添加成功
         //同步新数据到旧系统中
         $ebayGoods = array();
         $ebayGoods['goods_id'] = $id;
         $ebayGoods['goods_name'] = preg_replace("/(\\s|\\&nbsp\\;| | )/", "", $goodsName);
         $ebayGoods['goods_sn'] = $sku;
         $ebayGoods['goods_price'] = $goodsCost;
         $ebayGoods['goods_cost'] = $goodsCost;
         $ebayGoods['goods_note'] = preg_replace("/(\\s|\\&nbsp\\;| | )/", "", $goodsNote);
         $ebayGoods['is_new'] = $isNew;
         if ($goodsStatus == 1) {
             //在线
             $ebayGoods['isuse'] = 0;
         } elseif ($goodsStatus == 51) {
             //PK产品
             $ebayGoods['isuse'] = 51;
         } elseif ($goodsStatus == 2) {
             //停售
             $ebayGoods['isuse'] = 1;
         } elseif ($goodsStatus == 3) {
             //暂时停售
             $ebayGoods['isuse'] = 3;
         } else {
             //其余的都做下线处理
             $ebayGoods['isuse'] = 1;
         }
         $ebayGoods['color'] = $goodsColor;
         $ebayGoods['size'] = $goodsSize;
         $res = OmAvailableModel::newData2ErpInterfOpen('pc.erp.updateGoods', $ebayGoods, 'gw88');
         BaseModel::commit();
         BaseModel::autoCommit();
         $status = "{$sku} 修改成功";
         if (!empty($statusDel)) {
             $status = $statusDel;
         }
         echo '<script language="javascript">
                 alert("' . $status . '");
                 history.go(-2);
               </script>';
         exit;
     } catch (Exception $e) {
         BaseModel::rollback();
         BaseModel::autoCommit();
         echo $e->getMessage();
     }
 }
コード例 #3
0
ファイル: autoCreateSpu.view.php プロジェクト: ohjack/newErp
 public function view_addSkuSingOn()
 {
     $spu = $_POST['spu'] ? post_check(trim($_POST['spu'])) : '';
     $pid = $_POST['pid'] ? post_check(trim($_POST['pid'])) : '';
     $id = $_POST['id'] ? post_check(trim($_POST['id'])) : '';
     $goodsStatus = $_POST['goodsStatus'] ? post_check(trim($_POST['goodsStatus'])) : '';
     $isNew = $_POST['isNew'] ? post_check(trim($_POST['isNew'])) : '';
     if (!preg_match("/^[A-Z0-9]+\$/", $spu)) {
         $status = "非法spu";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     if (empty($pid)) {
         $status = "类别为空";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     $skuArr = $_POST['sku'];
     $goodsNameArr = $_POST['goodsName'];
     $goodsCostArr = $_POST['goodsCost'];
     $goodsNoteArr = $_POST['goodsNote'];
     $goodsColorArr = $_POST['goodsColor'];
     $goodsSizeArr = $_POST['goodsSize'];
     if (!isset($skuArr[0])) {
         $status = "空的SKU记录";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     if (empty($skuArr[0]) && !empty($skuArr[1])) {
         $status = "只能是一个子料号情况下,SKU才能为空";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     if (count($skuArr) != count(array_unique($skuArr))) {
         $status = "错误,存在重复的SKU";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     $userId = $_SESSION['userId'];
     if (intval($userId) <= 0) {
         $status = "登陆超时,请重新登陆!";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     for ($i = 0; $i < count($skuArr); $i++) {
         $sku = post_check($spu . trim($skuArr[$i]));
         if (strlen($sku) > 30) {
             $status = "{$sku} 字符长度大于30,错误!";
             echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
             exit;
         }
         if (!preg_match("/^{$spu}(_[A-Z0-9]+)*\$/", $sku)) {
             $status = "{$sku} 格式非法";
             echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
             exit;
         }
         $goodsName = !empty($goodsNameArr[$i]) ? $goodsNameArr[$i] : '';
         $goodsCost = !empty($goodsCostArr[$i]) ? $goodsCostArr[$i] : 0;
         $goodsNote = !empty($goodsNoteArr[$i]) ? $goodsNoteArr[$i] : '';
         $goodsColor = !empty($goodsColorArr[$i]) ? $goodsColorArr[$i] : 0;
         $goodsSize = !empty($goodsSizeArr[$i]) ? $goodsSizeArr[$i] : 0;
         if ($i >= 1 && $sku == $spu) {
             continue;
         }
         if (empty($goodsName)) {
             $status = "{$sku} 的描述不能为空";
             echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
             exit;
         }
         if (strpos($goodsName, '#') !== false || strpos($goodsNote, '#') !== false) {
             //如果描述中有#则报错
             $status = "{$sku} 的描述/备注 不能含有'井'号等特殊字符";
             echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
             exit;
         }
         if (!is_numeric($goodsCost) || $goodsCost <= 0) {
             $status = "{$sku} 的成本必须为正数";
             echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
             exit;
         }
         $tName = 'pc_goods';
         $where = "WHERE is_delete=0 AND sku='{$sku}'";
         $count = OmAvailableModel::getTNameCount($tName, $where);
         if ($count) {
             $status = "{$sku} 已经存在";
             echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
             exit;
         }
     }
     try {
         $ebayGoodsArr = array();
         //同步数据数组
         BaseModel::begin();
         for ($i = 0; $i < count($skuArr); $i++) {
             $sku = post_check($spu . trim($skuArr[$i]));
             $goodsName = !empty($goodsNameArr[$i]) ? $goodsNameArr[$i] : '';
             $goodsCost = !empty($goodsCostArr[$i]) ? $goodsCostArr[$i] : 0;
             $goodsNote = !empty($goodsNoteArr[$i]) ? $goodsNoteArr[$i] : '';
             $goodsColor = !empty($goodsColorArr[$i]) ? $goodsColorArr[$i] : 0;
             $goodsSize = !empty($goodsSizeArr[$i]) ? $goodsSizeArr[$i] : 0;
             if ($i >= 1 && $sku == $spu) {
                 continue;
             }
             $dataSku = array();
             $dataSku['spu'] = $spu;
             $dataSku['goodsCategory'] = $pid;
             $dataSku['purchaseId'] = $userId;
             $dataSku['goodsCreatedTime'] = time();
             $dataSku['goodsSort'] = intval(substr($spu, 2));
             $dataSku['sku'] = $sku;
             $dataSku['goodsName'] = $goodsName;
             $dataSku['goodsCost'] = $goodsCost;
             $dataSku['goodsNote'] = $goodsNote;
             $dataSku['goodsStatus'] = $goodsStatus;
             $dataSku['isNew'] = $isNew;
             $dataSku['goodsColor'] = $goodsColor;
             $dataSku['goodsSize'] = $goodsSize;
             $tName = 'pc_goods';
             $insertId = OmAvailableModel::addTNameRow2arr($tName, $dataSku);
             addWeightBackupsModify($sku, 0, $userId, false);
             //添加默认的重量变化记录
             addVolumeBackupsModify($sku, 0, 0, 0, $userId, false);
             //添加默认的体积变化记录
             addPmBackupsModify($sku, 0, 1, $userId, false);
             //添加默认的包材变化记录
             addCostBackupsModify($sku, $goodsCost, $userId, false);
             //添加默认的成本变化记录
             addStatusBackupsModify($sku, $goodsStatus, '', $userId, false);
             //添加默认的状态变化记录
             //将新添加的sku添加到mem中
             $key = 'pc_goods_' . $sku;
             $value = $dataSku;
             setMemNewByKey($key, $value);
             //这里不保证能添加成功
             //同步新数据到旧系统中
             $ebayGoods = array();
             $ebayGoods['goods_id'] = $insertId;
             $ebayGoods['goods_name'] = preg_replace("/(\\s|\\&nbsp\\;| | )/", "", $goodsName);
             $ebayGoods['goods_sn'] = $sku;
             $ebayGoods['goods_price'] = $goodsCost;
             $ebayGoods['goods_cost'] = $goodsCost;
             //$ebayGoods['goods_weight'] = $goodsWeight;
             $ebayGoods['goods_note'] = preg_replace("/(\\s|\\&nbsp\\;| | )/", "", $goodsNote);
             $ebayGoods['goods_category'] = $pid;
             //$ebayGoods['isPacking'] = $isPacking;
             $ebayGoods['ebay_user'] = '******';
             //$ebayGoods['factory'] = $partnerId;
             $ebayGoods['cguser'] = empty($_SESSION['userId']) ? '' : getPersonNameById($_SESSION['userId']);
             //$ebayGoods['capacity'] = $pmCapacity;
             //$ebayGoods['ebay_packingmaterial'] = empty($pmId)?'':PackingMaterialsModel::getPmNameById($pmId);
             $ebayGoods['add_time'] = time();
             $ebayGoods['spu'] = $spu;
             $ebayGoods['goods_code'] = $insertId + 1000000;
             $ebayGoods['color'] = $goodsColor;
             $ebayGoods['size'] = $goodsSize;
             if ($goodsStatus == 1) {
                 //在线
                 $ebayGoods['isuse'] = 0;
             } elseif ($goodsStatus == 51) {
                 //PK产品
                 $ebayGoods['isuse'] = 51;
             } else {
                 //其余的都做下线处理
                 $ebayGoods['isuse'] = 1;
             }
             $ebayGoodsArr[] = $ebayGoods;
         }
         BaseModel::commit();
         BaseModel::autoCommit();
         //同步数据到深圳ERP
         foreach ($ebayGoodsArr as $value) {
             $res = OmAvailableModel::newData2ErpInterfOpen('pc.erp.addGoods', $value, 'gw88');
         }
         $status = "添加成功";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 window.parent.location.href = "index.php?mod=goods&act=getGoodsList&searchs=1&status=' . $status . '&seachdata=' . $spu . '";
               </script>';
         exit;
     } catch (Exception $e) {
         BaseModel::rollback();
         BaseModel::autoCommit();
         $status = $e->getMessage();
         echo '<script language="javascript">
                 alert("' . '添加失败——' . $status . '");
                 window.parent.location.href = "index.php?mod=goods&act=getGoodsList&searchs=1&status=' . $status . '&seachdata=' . $spu . '";
               </script>';
         exit;
     }
 }