Exemple #1
0
 function act_skuVP2()
 {
     $goodsCode = post_check($_POST['goodsCode']);
     $goodsLength = trim($_POST['goodsLength']);
     $goodsWidth = trim($_POST['goodsWidth']);
     $goodsHeight = trim($_POST['goodsHeight']);
     $isPacking = trim($_POST['isPacking']);
     $packageType = trim($_POST['packageType']);
     $userId = $_SESSION['userId'];
     if (intval($userId) <= 0) {
         self::$errCode = 101;
         self::$errMsg = '登陆超时,请重新登陆';
         return false;
     }
     $pmId = trim($_POST['pmId']);
     $pmCapacity = intval(trim($_POST['pmCapacity']));
     if ($pmCapacity <= 0) {
         $pmCapacity = 1;
     }
     $pmId = getPmIdByPmCode($pmId);
     //获取对应的包材id,找不到对应包材返回false;
     if (is_numeric($goodsLength) <= 0 || is_numeric($goodsLength) > 9999) {
         self::$errCode = 102;
         self::$errMsg = '长度有误';
         return false;
     }
     if (is_numeric($goodsWidth) <= 0 || is_numeric($goodsWidth) > 9999) {
         self::$errCode = 103;
         self::$errMsg = '宽度有误';
         return false;
     }
     if (is_numeric($goodsHeight) <= 0 || is_numeric($goodsHeight) > 9999) {
         self::$errCode = 104;
         self::$errMsg = '高度有误';
         return false;
     }
     if (!$pmId) {
         self::$errCode = 105;
         self::$errMsg = '包材条码有误,找不到对应包材';
         return false;
     }
     $skuList = getSkuBygoodsCode($goodsCode);
     if (empty($skuList)) {
         self::$errCode = 107;
         self::$errMsg = '找不到对应SKU';
         return false;
     }
     $skuTmp = $skuList[0]['sku'];
     //旧的VP信息
     $oldGoodsLength = $skuList[0]['goodsLength'];
     $oldGoodsWidth = $skuList[0]['goodsWidth'];
     $oldGoodsHeight = $skuList[0]['goodsHeight'];
     //旧的包材信息
     $oldPmId = $skuList[0]['pmId'];
     $oldPmCapacity = $skuList[0]['pmCapacity'];
     $vpArr = array();
     //体积、包材、
     $volumeFlag = false;
     //体积变化标识,默认无变化
     $pmFlag = false;
     //包材变化标识,默认无变化
     if ($oldGoodsLength != $goodsLength || $oldGoodsWidth != $goodsWidth || $oldGoodsHeight != $goodsHeight) {
         //如果长,宽,高有一个与之前不相等
         $vpArr['goodsLength'] = $goodsLength;
         $vpArr['goodsWidth'] = $goodsWidth;
         $vpArr['goodsHeight'] = $goodsHeight;
         $volumeFlag = true;
         //体积变化
     }
     if ($oldPmId != $pmId || $oldPmCapacity != $pmCapacity) {
         $vpArr['pmId'] = $pmId;
         $vpArr['pmCapacity'] = $pmCapacity;
         $pmFlag = true;
         //包材变化
     }
     $vpArr['isPacking'] = $isPacking;
     $vpArr['packageType'] = $packageType;
     try {
         BaseModel::begin();
         $tName = 'pc_goods';
         $where = "WHERE sku='{$skuTmp}'";
         OmAvailableModel::updateTNameRow2arr($tName, $vpArr, $where);
         if ($volumeFlag) {
             //体积变化则添加记录到对应表中
             addVolumeBackupsModify($skuTmp, $goodsLength, $goodsWidth, $goodsHeight, $userId);
             //添加体积变化记录
         }
         if ($pmFlag) {
             //包材变化
             addPmBackupsModify($skuTmp, $pmId, $pmCapacity, $userId);
             //添加包材变化记录
         }
         $pName = PackingMaterialsModel::getPmNameById($pmId);
         $paraArr = array();
         $paraArr['goods_sn'] = str_pad($skuTmp, 3, 0, STR_PAD_LEFT);
         $paraArr['goods_length'] = $goodsLength;
         $paraArr['goods_width'] = $goodsWidth;
         $paraArr['goods_height'] = $goodsHeight;
         $is_packing = $isPacking;
         $paraArr['ispacking'] = $is_packing == 1 ? 0 : 1;
         $paraArr['ebay_packingmaterial'] = $pName;
         $paraArr['package_type'] = $packageType;
         $paraArr['capacity'] = $pmCapacity;
         $res = OmAvailableModel::newData2ErpInterfOpen('pc.erp.addGoodsVp2', $paraArr, 'gw88');
         BaseModel::commit();
         BaseModel::autoCommit();
         return array('state' => 200, 'sku' => $skuTmp . ' 单个SKU', 'pName' => $pName);
     } catch (Exception $e) {
         BaseModel::rollback();
         BaseModel::autoCommit();
         echo $e->getMessage();
     }
 }
Exemple #2
0
 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;
     }
 }