public function act_getSMCBySpuOrCombineSpu() { $spu = $_GET['spu'] ? post_check(trim($_GET['spu'])) : ''; //sku $returnArr = array(); if (empty($spu)) { self::$errCode = "101"; self::$errMsg = "SPU为空"; return; } $tName = 'pc_goods'; $select = 'specialStatus,goodsWeight,goodsCategory,pmId'; $where = "WHERE is_delete=0 and spu='{$spu}'"; $spuList = OmAvailableModel::getTNameList($tName, $select, $where); if (!empty($spuList)) { //如果Spu在goods表中存在,则表示传递过来的是单料号 $specialStatusArr = array(); //状态数组 $maxWeight = 0; //重量最大值 $categoryPath = ''; //类别 $pmId = 0; $pmWeight = 0; foreach ($spuList as $value) { $specialStatus = $value['specialStatus']; if (!empty($specialStatus)) { $tmpSpecialStatusArr = explode(',', $specialStatus); //将状态值单个解析出来 foreach ($tmpSpecialStatusArr as $tmpSpecialStatus) { if (!empty($tmpSpecialStatus)) { $specialStatusArr[] = $tmpSpecialStatus; } } } if (intval($value['pmId']) > 0) { $pmId = $value['pmId']; } if ($value['goodsWeight'] >= $maxWeight) { $maxWeight = $value['goodsWeight']; $categoryPath = $value['goodsCategory']; } } if (!empty($pmId)) { $tName = 'pc_packing_material'; $select = 'pmWeight'; $where = "WHERE id='{$pmId}'"; $pmList = OmAvailableModel::getTNameList($tName, $select, $where); $pmWeight = $pmList[0]['pmWeight']; } $specialStatusArr = array_unique($specialStatusArr); //去除重复值 sort($specialStatusArr); $returnArr['specialStatus'] = $specialStatusArr; $returnArr['maxWeight'] = $maxWeight + $pmWeight; $returnArr['goodsCategory'] = $categoryPath; self::$errCode = "200"; self::$errMsg = "success"; return $returnArr; } $tName = 'pc_goods_combine'; $select = 'combineSku'; $where = "WHERE combineSpu='{$spu}'"; $combineSpuList = OmAvailableModel::getTNameList($tName, $select, $where); if (!empty($combineSpuList)) { //如果虚拟料号列表不为空则表示该spu是combineSpu,//对于组合料号来说,按整体来计算重量,及包括SKU对应数量 $specialStatusArr = array(); //状态数组 $maxWeight = 0; //重量最大值 $categoryPath = ''; //类别 $combineSkuArr = array(); foreach ($combineSpuList as $value) { $combineSku = $value['combineSku']; if (!empty($combineSku)) { $tName = 'pc_sku_combine_relation'; $select = 'sku'; $where = "WHERE combineSku='{$combineSku}'"; $combineSkuRelationArr = OmAvailableModel::getTNameList($tName, $select, $where); foreach ($combineSkuRelationArr as $skuRelationArr) { $sku = $skuRelationArr['sku']; $tName = 'pc_goods'; $select = 'specialStatus,goodsCategory'; $where = "WHERE sku='{$sku}'"; $skuList = OmAvailableModel::getTNameList($tName, $select, $where); if (!empty($skuList[0]['goodsCategory'])) { $categoryPath = $skuList[0]['goodsCategory']; } $specialStatus = $skuList[0]['specialStatus']; if (!empty($specialStatus)) { $tmpSpecialStatusArr = implode(',', $specialStatus); foreach ($tmpSpecialStatusArr as $tmpSpecialStatus) { if (!empty($tmpSpecialStatus)) { $specialStatusArr[] = $tmpSpecialStatus; } } } } //$combineSkuArr[] = $combineSku;//combineSku数组 $combineSkuCWArr = getTrueCWForCombineSku($combineSku); //获取虚拟SKU对应的总重量和成本 $combineSkuPMCWArr = getTruePMCWForCombineSku($combineSku); //获取虚拟SKU对应的包材成本和包材重量 // print_r($combineSkuPMCWArr); // exit; $combineSkuWeight = $combineSkuCWArr['totalWeight']; $combineSkuPmWeight = $combineSkuPMCWArr['pmTotalWeight']; if ($combineSkuWeight + $combineSkuPmWeight > $maxWeight) { $maxWeight = $combineSkuWeight + $combineSkuPmWeight; } } } if (!empty($specialStatusArr)) { $specialStatusArr = array_unique($specialStatusArr); sort($specialStatusArr); } $returnArr['specialStatus'] = $specialStatusArr; $returnArr['maxWeight'] = $maxWeight; $returnArr['goodsCategory'] = $categoryPath; self::$errCode = "200"; self::$errMsg = "success"; return $returnArr; } else { self::$errCode = "400"; self::$errMsg = "无该SPU信息"; return $returnArr; } }
public function view_getCombineList() { //调用action层, 获取列表数据 $searchComField = isset($_GET['searchComField']) ? post_check($_GET['searchComField']) : ''; $fieldValue = isset($_GET['fieldValue']) ? post_check($_GET['fieldValue']) : ''; $flag = false; $tName = 'pc_goods_combine'; $where = 'where is_delete=0 '; if (!empty($fieldValue)) { if (intval($searchComField) == 1) { $where .= "and combineSpu='{$fieldValue}' "; $flag = true; } elseif (intval($searchComField) == 2) { $tmpTName = 'pc_sku_combine_relation'; $tmpSelect = 'combineSku'; $tmpWhere = "WHERE sku REGEXP '^{$fieldValue}(_[A-Z0-9]+)*\$'"; $combineSkuList = OmAvailableModel::getTNameList($tmpTName, $tmpSelect, $tmpWhere); $combineSkuArr = array(); foreach ($combineSkuList as $value) { if (!empty($value['combineSku'])) { $combineSkuArr[] = "'" . $value['combineSku'] . "'"; } } if (!empty($combineSkuArr)) { $combineSkuStr = implode(',', $combineSkuArr); $where .= "and combineSku in({$combineSkuStr}) "; $flag = true; } else { $where .= "and 1=0 "; $flag = true; } } } $total = OmAvailableModel::getTNameCount($tName, $where); $num = 50; //每页显示的个数 $page = new Page($total, $num, '', 'CN'); $where .= "order by combineSpu desc " . $page->limit; $select = '*'; if ($flag == false) { $combineList = array(); } else { $combineList = OmAvailableModel::getTNameList($tName, $select, $where); } if (!empty($_GET['page'])) { if (intval($_GET['page']) <= 1 || intval($_GET['page']) > ceil($total / $num)) { $n = 1; } else { $n = (intval($_GET['page']) - 1) * $num + 1; } } else { $n = 1; } if ($total > $num) { //输出分页显示 $show_page = $page->fpage(array(0, 2, 3, 4, 5, 6, 7, 8, 9)); } else { $show_page = $page->fpage(array(0, 2, 3)); } $navlist = array(array('url' => 'index.php?mod=goods&act=getGoodsList', 'title' => '产品信息'), array('url' => 'index.php?mod=goods&act=getCombineList', 'title' => '虚拟料号管理')); $this->smarty->assign('navlist', $navlist); $this->smarty->assign('onevar', 1); $this->smarty->assign('twovar', 12); $this->smarty->assign('show_page', $show_page); $this->smarty->assign('title', '虚拟料号列表'); if (!empty($combineList)) { $countCombineList = count($combineList); for ($i = 0; $i < $countCombineList; $i++) { if ($i > 0 && $combineList[$i]['combineSpu'] == $combineList[$i - 1]['combineSpu']) { $combineList[$i]['visibleSpu'] = ''; } else { $combineList[$i]['visibleSpu'] = $combineList[$i]['combineSpu']; } $combineSku = $combineList[$i]['combineSku']; $cwArr = getTrueCWForCombineSku($combineSku); //根据combineSku返回真实的成本及重量 $combineList[$i]['totalCost'] = $cwArr['totalCost']; $combineList[$i]['totalWeight'] = $cwArr['totalWeight']; $trueSkuList = OmAvailableModel::getTrueSkuForCombine($combineSku); //获取真实料号数组 $combineList[$i]['trueSkuListCount'] = count($trueSkuList); for ($j = 0; $j < $combineList[$i]['trueSkuListCount']; $j++) { $tName = 'pc_goods'; $select = 'goodsName'; $where = "WHERE sku='{$trueSkuList[$j]['sku']}'"; $goodsNameList = OmAvailableModel::getTNameList($tName, $select, $where); $goodsName = $goodsNameList[0]['goodsName']; $trueSkuList[$j]['goodsName'] = $goodsName; } $combineList[$i]['trueSkuList'] = $trueSkuList; } } $this->smarty->assign('combineList', empty($combineList) ? null : $combineList); $this->smarty->display("combineList.htm"); }