function act_addInput() { //$pidNew = $_POST['pidNew']?post_check($_POST['pidNew']):'';//类别 $finalIdArr = $_POST['finalIdStr']; //新建属性-类别4 $inputName = $_POST['inputName'] ? post_check($_POST['inputName']) : ''; //类别 $textStatus = $_POST['textStatus'] ? post_check($_POST['textStatus']) : ''; //文本方式 if (empty($finalIdArr) || empty($inputName)) { self::$errCode = 101; self::$errMsg = '类别或属性名不能为空'; return false; } if (intval($textStatus) <= 0) { self::$errCode = 102; self::$errMsg = '文本方式有误'; return false; } $tmpArr = array(); if (!is_array($finalIdArr)) { $tmpArr[] = $finalIdArr; $finalIdArr = $tmpArr; } $finalPathArr = array(); foreach ($finalIdArr as $cid) { $catePath = CategoryModel::getCategoryPathById($cid); if (empty($catePath)) { self::$errCode = 109; self::$errMsg = '类别有误'; return false; } $finalPathArr[] = $catePath; } $tName = 'pc_goods_category'; foreach ($finalPathArr as $value) { $where = "WHERE path like'%{$value}-%' and is_delete=0"; $count = OmAvailableModel::getTNameCount($tName, $where); if ($count) { self::$errCode = 105; self::$errMsg = '只能在最小分类进行复制'; return false; } } try { $pidNewStr = ''; BaseModel::begin(); $tName = 'pc_archive_input'; foreach ($finalPathArr as $value) { $where = "WHERE inputName='{$inputName}' AND categoryPath='{$value}'"; $countIN = OmAvailableModel::getTNameCount($tName, $where); if (!$countIN) { $pidNewStr .= CategoryModel::getCategoryNameByPath($value) . ' '; $set = "SET inputName='{$inputName}',categoryPath='{$value}',textStatus='{$textStatus}'"; OmAvailableModel::addTNameRow($tName, $set); } } BaseModel::commit(); BaseModel::autoCommit(); self::$errCode = 200; self::$errMsg = "{$inputName} 添加到 {$pidNewStr} 成功"; return true; } catch (Exception $e) { BaseModel::rollback(); BaseModel::autoCommit(); self::$errCode = 201; self::$errMsg = $e->getMessage(); return false; } }
public function view_updatePropertyOn() { $id = $_GET['id']; $propertyName = $_GET['propertyName'] ? post_check(trim($_GET['propertyName'])) : ''; $pid = $_GET['pid'] ? post_check(trim($_GET['pid'])) : ''; $isRadio = $_GET['isRadio'] ? post_check(trim($_GET['isRadio'])) : ''; $isRequired = $_GET['isRequired'] ? post_check(trim($_GET['isRequired'])) : ''; if (intval($id) == 0) { $status = "属性Id错误"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } if (empty($propertyName)) { if (intval($id) == 0) { $status = "属性Id错误"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $tName = 'pc_archive_spu_property_value_relation'; $where = "WHERE propertyId={$id}"; $countPP = OmAvailableModel::getTNameCount($tName, $where); if ($countPP) { $status = "该属性已经绑定了SPU,不能删除"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $tName = 'pc_archive_property_value'; $select = 'id'; $where = "WHERE propertyId={$id}"; $ppvList = OmAvailableModel::getTNameList($tName, $select, $where); //该属性下所有的属性值 foreach ($ppvList as $value) { $propertyValueId = $value['id']; if (intval($propertyValueId) != 0) { $tName = 'pc_archive_spu_property_value_relation'; $where = "WHERE propertyId={$id} and propertyValueId={$propertyValueId}"; $countPPV = OmAvailableModel::getTNameCount($tName, $where); if ($countPPV) { $status = "该属性下已有属性值绑定了SPU,不能删除"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } } } try { BaseModel::begin(); foreach ($ppvList as $value) { $propertyValueId = $value['id']; if (intval($propertyValueId) != 0) { $tName = 'pc_archive_property_value'; $where = "WHERE id={$propertyValueId}"; OmAvailableModel::deleteTNameRow($tName, $where); } } $tName = 'pc_archive_property'; $where = "WHERE id={$id}"; OmAvailableModel::deleteTNameRow($tName, $where); BaseModel::commit(); BaseModel::autoCommit(); $status = "属性删除成功"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } catch (Exception $e) { BaseModel::rollback(); BaseModel::autoCommit(); $status = $e->getMessage(); header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } } if (empty($pid)) { $status = "类型不能为空"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } if (empty($isRadio)) { $status = "录入方式不能为空"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } if (intval($isRequired) == 0) { $status = "是否必填不能为空"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $tName = 'pc_archive_property'; $select = '*'; $where = "WHERE id='{$id}'"; $propertyList = OmAvailableModel::getTNameList($tName, $select, $where); if (empty($propertyList)) { $status = "不存在该属性记录"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $categoryName = getAllCateNameByPath($pid); $pathImplodeStr = getAllPathBypid($pid); $i = strrpos($pathImplodeStr, ','); if ($i !== false) { $pathImplodeStr = substr($pathImplodeStr, 0, $i); } $where = "WHERE propertyName='{$propertyName}' and categoryPath IN ({$pathImplodeStr})"; $count = OmAvailableModel::getTNameCount($tName, $where); if ($count) { $status = "{$categoryName} 其父类已经存在 {$propertyName} 属性"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $where = "WHERE propertyName='{$propertyName}' and categoryPath='{$pid}' and id<>{$id}"; $count = OmAvailableModel::getTNameCount($tName, $where); if ($count) { $status = "{$categoryName} 已经存在 {$propertyName} 属性"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $set = "SET propertyName='{$propertyName}',categoryPath='{$pid}',isRadio='{$isRadio}',isRequired='{$isRequired}'"; $where = "WHERE id='{$id}'"; $affectRow = OmAvailableModel::updateTNameRow($tName, $set, $where); if (!$affectRow) { $status = "无数据修改"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); exit; } $categoryName1 = CategoryModel::getCategoryNameByPath($propertyList[0]['categoryPath']); $categoryName2 = CategoryModel::getCategoryNameByPath($pid); $isRadioStr = $isRadio == 1 ? '单选' : '多选'; $status = "{$categoryName1} 下 {$propertyList[0]['propertyName']} 修改为 {$categoryName2} 下 {$propertyName} 成功,录入方式为 {$isRadioStr}"; header("Location:index.php?mod=property&act=getPropertyList&status={$status}"); }