Example #1
0
 function act_searchOrAddCombineInfo()
 {
     $spu = isset($_GET['goods_sn']) ? post_check(trim($_GET['goods_sn'])) : '';
     $amount = isset($_GET['amount']) ? $_GET['amount'] : '';
     $amount = intval($amount);
     $combineUserId = isset($_GET['truename']) ? $_GET['truename'] : '';
     $combineUserId = intval($combineUserId);
     $now = time();
     if (!preg_match("/^[A-Z0-9]+\$/", $spu)) {
         //sku不合规范
         self::$errCode = '101';
         self::$errMsg = 'SPU不合法';
         return false;
     }
     if ($amount <= 0) {
         //不是正数
         self::$errCode = '102';
         self::$errMsg = '数量不合法';
         return false;
     }
     if ($combineUserId <= 0) {
         //不是正数
         self::$errCode = '103';
         self::$errMsg = '组合人id不合法';
         return false;
     }
     $tName = 'pc_goods';
     $select = 'spu,sku';
     $where = "WHERE spu='{$spu}' and is_delete=0";
     $pcGoodsList = OmAvailableModel::getTNameList($tName, $select, $where);
     if (empty($pcGoodsList)) {
         //如果spu找不到
         $select = 'spu,sku';
         $where = "WHERE sku='{$spu}' and is_delete=0";
         $pcGoodsList = OmAvailableModel::getTNameList($tName, $select, $where);
         if (empty($pcGoodsList)) {
             //spu找不到去sku找
             self::$errCode = '104';
             self::$errMsg = "SPU {$spu} 不存在";
             return false;
         }
     }
     $tName = 'pc_sku_combine_relation';
     $select = '*';
     $where = "WHERE sku REGEXP '^{$spu}(_[A-Z0-9]+)*\$' and count={$amount} and combineSku REGEXP '^CB[0-9]{6}(_[A-Z0-9]+)*\$'";
     //符合条件
     $pcCombineRelList = OmAvailableModel::getTNameList($tName, $select, $where);
     if (!empty($pcCombineRelList)) {
         //如果真实料号对应的虚拟料号存在,则直接返回
         $arr = array();
         $arrDetail = array();
         foreach ($pcCombineRelList as $value) {
             $arrTmp = array();
             $arrTmp['CBSku'] = $value['combineSku'];
             $arrTmp['bindSku'] = $value['sku'] . '*' . $amount;
             $arrDetail[] = $arrTmp;
         }
         $arr['spu'] = substr($pcCombineRelList[0]['combineSku'], 0, 8);
         //spu
         $arr['detail'] = $arrDetail;
         self::$errCode = '200';
         self::$errMsg = "信息存在,查询返回成功";
         return json_encode($arr);
     } else {
         //如果不存在的话,则插入数据,然后再返回,此时要现在autoCreateSpu表中和combine表中,选出最大的CB为前缀的数字
         $numberCombine = OmAvailableModel::getMaxSpu('CB', 2);
         //取得pc_goods_combine表中以CB为前缀的最大的数字
         $tName = 'pc_auto_create_spu';
         $select = 'spu';
         $where = "WHERE prefix='CB' order by sort desc limit 1";
         $autoCreSpuList = OmAvailableModel::getTNameList($tName, $select, $where);
         $numberAutoCreSpu = intval(substr($autoCreSpuList[0]['spu'], 2, 6));
         $maxNumber = $numberCombine > $numberAutoCreSpu ? $numberCombine : $numberAutoCreSpu;
         $maxNumber = $maxNumber + 1;
         //要生成CB为前缀的最大数字
         try {
             BaseModel::begin();
             $arr = array();
             //返回数组
             $arrDetail = array();
             //要同步到深圳ERP组合料号的数据变量
             $insertIdCom = 1;
             //添加组合料号的insert_id
             $dataRelation = array();
             //关联真实料号的数组
             $dataRelationMem = array();
             //关联真实料号的mem
             $ebayProductsCombineArr = array();
             if (count($pcGoodsList) == 1) {
                 //如果真实SPU料号只有一条记录的话,表示该SPU下没有分料号
                 $tmpSpu = 'CB' . str_pad($maxNumber, 6, '0', STR_PAD_LEFT);
                 $tName = 'pc_auto_create_spu';
                 $set = "SET spu='{$tmpSpu}',purchaseId='{$combineUserId}',createdTime='{$now}',sort='{$maxNumber}',status=2,prefix='CB',isSingSpu=2";
                 OmAvailableModel::addTNameRow($tName, $set);
                 //add by zqt ,20140403 添加关联销售记录
                 //addSalerInfoForAny($tmpSpu, 2, $combineUserId, $combineUserId);//改变逻辑
                 $tName = 'pc_goods_combine';
                 $set = "SET combineSpu='{$tmpSpu}',combineSku='{$tmpSpu}',combineUserId={$combineUserId},addTime='{$now}'";
                 $insertIdCom = OmAvailableModel::addTNameRow($tName, $set);
                 $tName = 'pc_sku_combine_relation';
                 $set = "SET combineSku='{$tmpSpu}',sku='{$pcGoodsList[0]['sku']}',count={$amount}";
                 OmAvailableModel::addTNameRow($tName, $set);
                 $arr['spu'] = $tmpSpu;
                 $arrTmp = array();
                 $arrTmp['CBSku'] = $tmpSpu;
                 $arrTmp['bindSku'] = $pcGoodsList[0]['sku'] . '*' . $amount;
                 $arrDetail[] = $arrTmp;
                 $arr['detail'] = $arrDetail;
                 $dataRelation[] = array('combineSku' => $tmpSpu, 'sku' => $pcGoodsList[0]['sku'], 'count' => $amount);
                 $dataRelationMem[] = array('sku' => $pcGoodsList[0]['sku'], 'count' => $amount);
                 //将新添加的sku添加到mem中
                 $dataCom = array();
                 $dataCom['combineSpu'] = $tmpSpu;
                 $dataCom['combineSku'] = $tmpSpu;
                 $dataCom['combineNote'] = $amount . '个' . $pcGoodsList[0]['sku'] . '#';
                 $dataCom['combineUserId'] = $combineUserId;
                 $dataCom['addTime'] = time();
                 $dataCom['detail'] = $dataRelationMem;
                 $value = $dataCom;
                 $key = 'pc_goods_combine_' . $tmpSpu;
                 setMemNewByKey($key, $value);
                 //这里不保证能添加成功
                 //同步新数据到旧系统中
                 $ebayProductsCombine = array();
                 $ebayProductsCombine['id'] = $insertIdCom;
                 $ebayProductsCombine['goods_sn'] = $tmpSpu;
                 $str = $pcGoodsList[0]['sku'] . '*' . $amount;
                 $strTrue = '[' . $pcGoodsList[0]['sku'] . ']';
                 $ebayProductsCombine['goods_sncombine'] = $str;
                 $ebayProductsCombine['cguser'] = getPersonNameById($combineUserId);
                 $ebayProductsCombine['ebay_user'] = '******';
                 $ebayProductsCombine['createdtime'] = time();
                 $ebayProductsCombine['truesku'] = $strTrue;
                 $ebayProductsCombineArr[] = $ebayProductsCombine;
             } else {
                 //有分料号
                 $tmpSpu = 'CB' . str_pad($maxNumber, 6, '0', STR_PAD_LEFT);
                 $tName = 'pc_auto_create_spu';
                 $set = "SET spu='{$tmpSpu}',purchaseId='{$combineUserId}',createdTime='{$now}',sort='{$maxNumber}',status=2,prefix='CB',isSingSpu=2";
                 OmAvailableModel::addTNameRow($tName, $set);
                 //add by zqt ,20140403 添加关联销售记录
                 //addSalerInfoForAny($tmpSpu, 2, $combineUserId, $combineUserId);//改变逻辑
                 $i = 0;
                 foreach ($pcGoodsList as $value) {
                     $suffTmp = explode($spu, $value['sku']);
                     $suff = isset($suffTmp[1]) ? $suffTmp[1] : '';
                     //取得分料号去除SPU后的后缀
                     $i++;
                     if (strpos($suff, '_') !== 0) {
                         //如果找出的spu下的sku不带_,则默认按1,2,3,来区分
                         $suff = '_' . $i;
                     }
                     $tmpSku = 'CB' . str_pad($maxNumber, 6, '0', STR_PAD_LEFT) . $suff;
                     $tmpSku = trim($tmpSku);
                     $goods_sncom = $value['sku'] . '*' . $amount;
                     $now = time();
                     $tName = 'pc_goods_combine';
                     $set = "SET combineSpu='{$tmpSpu}',combineSku='{$tmpSku}',combineUserId='{$combineUserId}',addTime='{$now}'";
                     $insertIdCom = OmAvailableModel::addTNameRow($tName, $set);
                     $tName = 'pc_sku_combine_relation';
                     $set = "SET combineSku='{$tmpSku}',sku='{$value['sku']}',count={$amount}";
                     OmAvailableModel::addTNameRow($tName, $set);
                     $arrTmp = array();
                     $arrTmp['CBSku'] = $tmpSku;
                     $arrTmp['bindSku'] = $goods_sncom;
                     $arrDetail[] = $arrTmp;
                     $dataRelation[] = array('combineSku' => $tmpSku, 'sku' => $value['sku'], 'count' => $amount);
                     $dataRelationMem[] = array('sku' => $value['sku'], 'count' => $amount);
                     //将新添加的sku添加到mem中
                     $dataCom = array();
                     $dataCom['combineSpu'] = $tmpSpu;
                     $dataCom['combineSku'] = $tmpSku;
                     $dataCom['combineNote'] = $amount . '个' . $value['sku'] . '#';
                     $dataCom['combineUserId'] = $combineUserId;
                     $dataCom['addTime'] = time();
                     $dataCom['detail'] = $dataRelationMem;
                     $valueMem = $dataCom;
                     $key = 'pc_goods_combine_' . $tmpSku;
                     setMemNewByKey($key, $valueMem);
                     //这里不保证能添加成功
                     //同步新数据到旧系统中
                     $ebayProductsCombine = array();
                     $ebayProductsCombine['id'] = $insertIdCom;
                     $ebayProductsCombine['goods_sn'] = $tmpSku;
                     $str = $value['sku'] . '*' . $amount;
                     $strTrue = '[' . $value['sku'] . ']';
                     $ebayProductsCombine['goods_sncombine'] = $str;
                     $ebayProductsCombine['cguser'] = getPersonNameById($combineUserId);
                     $ebayProductsCombine['ebay_user'] = '******';
                     $ebayProductsCombine['createdtime'] = time();
                     $ebayProductsCombine['truesku'] = $strTrue;
                     $ebayProductsCombineArr[] = $ebayProductsCombine;
                 }
                 $arr['spu'] = $tmpSpu;
                 $arr['detail'] = $arrDetail;
             }
             BaseModel::commit();
             BaseModel::autoCommit();
             if (!empty($tmpSpu)) {
                 //添加销售人员信息
                 addSalerInfoForAny($tmpSpu, 2, $combineUserId, $combineUserId);
             }
             $dataAuto = array();
             $dataAuto['sku'] = $tmpSpu;
             $dataAuto['cguser'] = getPersonNameById($combineUserId);
             $dataAuto['mainsku'] = $maxNumber;
             $dataAuto['status'] = 2;
             $dataAuto['addtime'] = time();
             $dataAuto['type'] = 7;
             OmAvailableModel::newData2ErpInterfOpen('pc.erp.addAutoCreatSpu', $dataAuto, 'gw88');
             //插入自動生成spu
             foreach ($ebayProductsCombineArr as $value) {
                 $ret = OmAvailableModel::newData2ErpInterfOpen('pc.erp.addGoodsCombine', $value, 'gw88');
                 //插入生成的CB料號
             }
             self::$errCode = '200';
             self::$errMsg = "不存在真实料号信息,插入记录成功";
             return json_encode($arr);
         } catch (Exception $e) {
             BaseModel::rollback();
             BaseModel::autoCommit();
             self::$errCode = '404';
             self::$errMsg = $e->getMessage();
             return false;
         }
     }
 }
Example #2
0
 public function view_addCombineOn()
 {
     $combineSpu = $_POST['combineSpu'] ? post_check(trim($_POST['combineSpu'])) : '';
     if (empty($combineSpu)) {
         $status = "空的SPU";
         echo '<script language="javascript">
                 alert("' . $status . '");      
               </script>';
         exit;
     }
     if (intval($_SESSION['userId']) <= 0) {
         $status = "登陆超时!";
         echo '<script language="javascript">
                 alert("' . $status . '");      
               </script>';
         exit;
     }
     $tName = 'pc_auto_create_spu';
     $select = 'status';
     $where = "WHERE spu='{$combineSpu}' and is_delete=0";
     $autoSpuList = OmAvailableModel::getTNameList($tName, $select, $where);
     if (empty($autoSpuList)) {
         $status = "自动生成SPU列表中不存在 {$combineSpu}";
         echo '<script language="javascript">
                 alert("' . $status . '");      
               </script>';
         exit;
     }
     $amount = $_POST['amount'] ? post_check(trim($_POST['amount'])) : 0;
     $amount = intval($amount);
     if ($amount <= 0 || $amount > 500) {
         $status = "数量必须在1-500之间";
         echo '<script language="javascript">
                 alert("' . $status . '");      
               </script>';
         exit;
     }
     $tName = 'pc_goods_combine';
     $where = "WHERE is_delete=0 AND combineSpu='{$combineSpu}'";
     $countComSpu = OmAvailableModel::getTNameCount($tName, $where);
     $tmpArr = array();
     for ($index = 0; $index <= $amount; $index++) {
         $combineSku = $_POST['combineSku' . $index] ? post_check(trim($_POST['combineSku' . $index])) : '';
         $combineSku = $combineSpu . $combineSku;
         if ($index == 0 && $countComSpu > 0 && $combineSku == $combineSpu) {
             $status = "存在为空的子料号,请检查!";
             echo '<script language="javascript">
                     alert("' . $status . '");      
                   </script>';
             exit;
         }
         if ($index > 0 && $combineSku == $combineSpu) {
             //只可能index=0时候,$combineSku==$combineSpu,其他表示无效
             continue;
         }
         $combineLength = $_POST['combineLength' . $index] ? post_check(trim($_POST['combineLength' . $index])) : '';
         $combineWidth = $_POST['combineWidth' . $index] ? post_check(trim($_POST['combineWidth' . $index])) : '';
         $combineHeight = $_POST['combineHeight' . $index] ? post_check(trim($_POST['combineHeight' . $index])) : '';
         $combineNote = $_POST['combineNote' . $index] ? trim($_POST['combineNote' . $index]) : '';
         $skuArr = $_POST['sku' . $index];
         $countArr = $_POST['count' . $index];
         if (strlen($combineSku) > 30) {
             $status = "{$combineSku} 字符长度大于30,错误!";
             echo '<script language="javascript">
                     alert("' . $status . '");      
                   </script>';
             exit;
         }
         if (!preg_match("/^{$combineSpu}(_[A-Z0-9]+)*\$/", $combineSku)) {
             $status = "{$combineSku} 不规范,请检查格式是否正确";
             echo '<script language="javascript">
                     alert("' . $status . '");      
                   </script>';
             exit;
         }
         if ($combineSku == $combineSpu && $amount > 1) {
             $status = "存在SKU为空的参数";
             echo '<script language="javascript">
                     alert("' . $status . '");
                   </script>';
             exit;
         }
         $tmpArr[] = $combineSku;
         if (!empty($combineLength)) {
             if (!is_numeric($combineLength) || $combineLength < 0) {
                 $status = "{$combineSku} 长度必须为数字";
                 echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
                 exit;
             }
         }
         if (!empty($combineWidth)) {
             if (!is_numeric($combineWidth) || $combineWidth < 0) {
                 $status = "{$combineSku} 宽度必须为数字";
                 echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
                 exit;
             }
         }
         if (!empty($combineHeight)) {
             if (!is_numeric($combineHeight) || $combineHeight < 0) {
                 $status = "{$combineSku} 高度必须为数字";
                 echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
                 exit;
             }
         }
         if (empty($skuArr[0]) || empty($countArr[0])) {
             $status = "{$combineSku} 至少要包含一条不为空的真实料号对应记录";
             echo '<script language="javascript">
                     alert("' . $status . '");
                   </script>';
             exit;
         }
         $tName = 'pc_goods_combine';
         $where = "WHERE combineSku='{$combineSku}' and is_delete=0";
         $count = OmAvailableModel::getTNameCount($tName, $where);
         if ($count) {
             $status = "{$combineSku} 已经存在";
             echo '<script language="javascript">
                     alert("' . $status . '");
                   </script>';
             exit;
         }
         if (count($skuArr) != count(array_unique($skuArr))) {
             $status = "{$combineSku} 中存在重复的真实料号,请检查";
             echo '<script language="javascript">
                     alert("' . $status . '");
                   </script>';
             exit;
         }
         $tName = 'pc_goods';
         foreach ($skuArr as $value) {
             if (!empty($value)) {
                 $where = "WHERE sku='{$value}' and is_delete=0";
                 $count = OmAvailableModel::getTNameCount($tName, $where);
                 if (!$count) {
                     $status = "{$combineSku} 真实料号 {$value} 不存在";
                     echo '<script language="javascript">
                             alert("' . $status . '");
                           </script>';
                     exit;
                 }
             }
         }
         foreach ($countArr as $value) {
             if (intval($value) <= 0) {
                 $status = "{$combineSku} 对应真实料号的数量有误";
                 echo '<script language="javascript">
                         alert("' . $status . '");
                       </script>';
                 exit;
             }
         }
     }
     $tmpArr = array_filter($tmpArr);
     if (count($tmpArr) != count(array_unique($tmpArr))) {
         $status = "存在重复的虚拟子料号,请检查!";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
         exit;
     }
     try {
         $ebayGoodsArr = array();
         //同步数据数组
         BaseModel::begin();
         for ($index = 0; $index <= $amount; $index++) {
             $combineSku = $_POST['combineSku' . $index] ? post_check(trim($_POST['combineSku' . $index])) : '';
             $combineSku = $combineSpu . $combineSku;
             if ($index > 0 && $combineSku == $combineSpu) {
                 //只可能index=0时候,$combineSku==$combineSpu,其他表示无效
                 continue;
             }
             $combineLength = $_POST['combineLength' . $index] ? post_check(trim($_POST['combineLength' . $index])) : '';
             $combineWidth = $_POST['combineWidth' . $index] ? post_check(trim($_POST['combineWidth' . $index])) : '';
             $combineHeight = $_POST['combineHeight' . $index] ? post_check(trim($_POST['combineHeight' . $index])) : '';
             $combineNote = $_POST['combineNote' . $index] ? trim($_POST['combineNote' . $index]) : '';
             $skuArr = $_POST['sku' . $index];
             $countArr = $_POST['count' . $index];
             $dataCom = array();
             $dataCom['combineSpu'] = $combineSpu;
             $dataCom['combineSku'] = $combineSku;
             $dataCom['combineCost'] = $combineCost;
             $dataCom['combineWeight'] = $combineWeight;
             $dataCom['combineLength'] = $combineLength;
             $dataCom['combineWidth'] = $combineWidth;
             $dataCom['combineHeight'] = $combineHeight;
             $dataCom['combineNote'] = $combineNote;
             $dataCom['combineUserId'] = $_SESSION['userId'];
             $dataCom['addTime'] = time();
             $tName = 'pc_goods_combine';
             $insertIdCom = OmAvailableModel::addTNameRow2arr($tName, $dataCom);
             if (!$insertIdCom) {
                 throw new Exception('add combine error');
             }
             $dataRelation = array();
             $dataRelationMem = array();
             for ($i = 0; $i < count($skuArr); $i++) {
                 if (!empty($skuArr[$i]) && !empty($countArr[$i])) {
                     $dataRelation[] = array('combineSku' => $combineSku, 'sku' => $skuArr[$i], 'count' => $countArr[$i]);
                     $dataRelationMem[] = array('sku' => $skuArr[$i], 'count' => $countArr[$i]);
                 }
             }
             if (!empty($dataRelation)) {
                 $tName = 'pc_sku_combine_relation';
                 $where = "WHERE combineSku='{$combineSku}'";
                 $dataRelationCount = OmAvailableModel::getTNameCount($tName, $where);
                 if ($dataRelationCount) {
                     OmAvailableModel::deleteTNameRow($tName, $where);
                 }
                 foreach ($dataRelation as $value) {
                     if (!empty($value['combineSku']) && !empty($value['sku']) && !empty($value['count'])) {
                         $insertId = OmAvailableModel::addTNameRow2arr($tName, $value);
                     }
                 }
             }
             if ($autoSpuList[0]['status'] != 2) {
                 $tName = 'pc_auto_create_spu';
                 $set = "SET status=2";
                 $where = "WHERE spu='{$combineSpu}'";
                 $affectRow = OmAvailableModel::updateTNameRow($tName, $set, $where);
             }
             //将新添加的sku添加到mem中
             $key = 'pc_goods_combine_' . $combineSku;
             $dataCom['detail'] = $dataRelationMem;
             $value = $dataCom;
             setMemNewByKey($key, $value);
             //这里不保证能添加成功
             //同步新数据到旧系统中
             $ebayProductsCombine = array();
             $ebayProductsCombine['id'] = $insertIdCom;
             $ebayProductsCombine['goods_sn'] = $combineSku;
             $goods_sncombine = array();
             $truesku = array();
             foreach ($dataRelationMem as $value) {
                 $str = '';
                 $strTrue = '';
                 $str = $value['sku'] . '*' . $value['count'];
                 $strTrue = '[' . $value['sku'] . ']';
                 $goods_sncombine[] = $str;
                 $truesku[] = $strTrue;
             }
             $ebayProductsCombine['goods_sncombine'] = implode(',', $goods_sncombine);
             $ebayProductsCombine['notes'] = $combineNote;
             $ebayProductsCombine['goods_price'] = $combineCost;
             $ebayProductsCombine['goods_weight'] = $combineWeight;
             $ebayProductsCombine['cguser'] = getPersonNameById($_SESSION['userId']);
             $ebayProductsCombine['ebay_user'] = '******';
             $ebayProductsCombine['createdtime'] = time();
             $ebayProductsCombine['truesku'] = implode(',', $truesku);
             $ebayGoodsArr[] = $ebayProductsCombine;
         }
         BaseModel::commit();
         BaseModel::autoCommit();
         addSalerInfoForAny($combineSpu, 2, $_SESSION['userId'], $_SESSION['userId']);
         //add by zqt 20140519,添加销售人逻辑
         //同步数据到深圳ERP
         foreach ($ebayGoodsArr as $value) {
             $ret = OmAvailableModel::newData2ErpInterfOpen('pc.erp.addGoodsCombine', $value, 'gw88');
         }
         $status = "添加成功";
         echo '<script language="javascript">
                 alert("' . $status . '");
                 window.parent.location.href = "index.php?mod=goods&act=getCombineList&searchComField=1&fieldValue=' . $combineSpu . '";
               </script>';
         exit;
     } catch (Exception $e) {
         BaseModel::rollback();
         BaseModel::autoCommit();
         echo $e->getMessage();
         $status = "添加失败,请联系系统技术部,谢谢";
         echo '<script language="javascript">
                 alert("' . $status . '");
               </script>';
     }
 }