/** * 修改单品的主次关系 * @parm clothes 衣服数组 键值对 键为衣服id 值为衣服即将修改的状态 * @parm touchid 触摸屏id **/ static function upmainClothes($clothes, $touchid) { $ret = array('status' => 0, 'msg' => ''); try { $Display_status_num = 11; //上架显示状态 $no_Display_status_num = 10; //上架不显示状态 $out_status_num = 8; //下架状态 $ForSale_status_num = 12; //待售状态 $Logic_clothes_arr = array(); //逻辑整理后的单品 $Logic_clothes_arr[$Display_status_num] = array(); $Logic_clothes_arr[$no_Display_status_num] = array(); $Logic_clothes_arr[$out_status_num] = array(); $Logic_clothes_arr[$ForSale_status_num] = array(); $Related_arr = self::beuRelatedSelectByClothesid(implode(',', array_keys($clothes))); // 获取衣服的不同色 //将衣服对应的每组不同色提取出来 $Related_clothes_arr = array(); //单品的不同色数组 $Different_clothes_arr = array(); //单品的不同穿数组 $clothesid_arr = array(); //衣服数组 用于查询其状态 $clothes_status_arr = array(); //衣服数组 用于查询其状态 foreach ($Related_arr as $value) { $c_arr = array(); foreach ($value as $v_key => $v_value) { if ($v_key == 'id' || empty($v_value)) { continue; } $c_arr[] = $v_value; $clothesid_arr[] = $v_value; } if (count($c_arr) > 0) { $Related_clothes_arr[] = $c_arr; } } $no_Related_arr = Comm::array_diff_fast(array_keys($clothes), $clothesid_arr); //获取还未做个SKU关联的单品 $clothesid_arr = array_merge($clothesid_arr, $no_Related_arr); //将还未做个SKU关联的单品拼接进衣服数组做状态查询 foreach ($no_Related_arr as $value) { $Related_clothes_arr[] = array($value); } //查询单品的状态 $t_clothes_ret = self::getTouchclothesinfo('clothesid,status', array('touchid' => '=' . $touchid, 'clothesid' => ' in(' . implode(',', $clothesid_arr) . ')')); if ($t_clothes_ret['status'] == 0) { throw new Exception($t_clothes_ret['msg']); } //获取单品的不同穿 $Different_arr = self::beuDifferentSelectByClothesid(implode(',', $clothesid_arr)); $Diff_clothes = array(); foreach ($Different_arr as $value) { $c_arr = array(); foreach ($value as $v_key => $v_value) { if ($v_key == 'id' || empty($v_value)) { continue; } $c_arr[] = $v_value; $Diff_clothes[] = $v_value; } if (count($c_arr) > 0) { $Different_clothes_arr[] = $c_arr; } } $no_Different_arr = Comm::array_diff_fast(array_keys($clothes), $Diff_clothes); //获取还未做个SKC关联的单品 foreach ($no_Different_arr as $value) { $Different_clothes_arr[] = array($value); } //将单品的状态进行归总 foreach ($t_clothes_ret['data'] as $value) { $clothes_status_arr[$value['clothesid']] = $value['status']; if (in_array($value['clothesid'], $no_Different_arr)) { //当前单品属于未做SKU关联的单品 $Logic_clothes_arr[$clothes[$value['clothesid']]][] = $value['clothesid']; } } //逻辑判断单品修改后的状态 foreach ($Related_clothes_arr as $value) { $current_status = array(); //当前SKU状态数组 $up_status = array(); //SKU修改状态数组 $Display_clothes = array(); //逻辑判断后的显示单品 $no_Display_clothes = array(); //逻辑判断后的不显示单品 $out_clothes = array(); //逻辑判断后的下架单品 $ForSale_clothes = array(); //逻辑判断后的待售单品 $up_Related_clothes = array(); //需要修改的SKU单品数组 foreach ($value as $v_key => $v_value) { $s_str = $clothes_status_arr[$v_value]; //获取单品的当前状态 if (!isset($current_status[$s_str])) { //当前SKU状态数组 不存在此状态时对其添加 $current_status[$s_str] = array(); } $current_status[$s_str][] = $v_value; //将单品添加到 SKU状态数组对应状态下 $up_Related_clothes[] = $v_value; if (isset($clothes[$v_value])) { $up_s_str = $clothes[$v_value]; //获取单品修改状态 if (!isset($up_status[$up_s_str])) { //SKU修改状态数组 不存在此状态时对其添加 $up_status[$up_s_str] = array(); } $up_status[$up_s_str][] = $v_value; //将单品添加到 SKU修改状态数组对应状态下 } } //显示单品 if (isset($up_status[$Display_status_num])) { //SKU修改状态数组里存在显示单品时 就将其第一个设为显示 其他设为不显示 $Display_clothes[0] = $up_status[$Display_status_num][0]; } //下架单品 if (isset($up_status[$out_status_num])) { //SKU修改状态数组存在下架状态 $out_clothes = $up_status[$out_status_num]; } //待售单品 if (isset($up_status[$ForSale_status_num])) { //SKU修改状态数组存在待售状态 $ForSale_clothes = $up_status[$ForSale_status_num]; } if (isset($current_status[$Display_status_num])) { //当前SKU状态数组存在显示单品时 $current_status[$Display_status_num] = Comm::array_diff_fast($current_status[$Display_status_num], array_merge($out_clothes, $ForSale_clothes)); //去除原有上架修改为下架或待售的单品 if (count($current_status[$Display_status_num]) > 0) { if (isset($up_status[$Display_status_num])) { $Display_intersect = Comm::array_intersect_fast($current_status[$Display_status_num], $up_status[$Display_status_num]); //获取其同时存在显示状态的单品 if (count($Display_intersect) > 0) { //SKU修改状态数组需要显示单品与当前SKU状态数组显示单品存在相同单品 就显示其第一个相同单品 $Display_clothes[0] = $Display_intersect[0]; } } else { $Display_clothes[0] = $current_status[$Display_status_num][0]; } } } //获取未设置的单品 $dirr_Related = Comm::array_diff_fast($value, array_merge($ForSale_clothes, $out_clothes, $Display_clothes)); foreach ($dirr_Related as $dirr_value) { if (isset($up_status[$Display_status_num]) && in_array($dirr_value, $up_status[$Display_status_num])) { //暂未设置单品需设为上架,因已有单品上架 所以修改为上架不显示 $no_Display_clothes[] = $dirr_value; } else { if ($clothes_status_arr[$dirr_value] == $Display_status_num) { $no_Display_clothes[] = $dirr_value; } else { if ($clothes_status_arr[$dirr_value] == $ForSale_status_num) { $ForSale_clothes[] = $dirr_value; } else { if ($clothes_status_arr[$dirr_value] == $out_status_num) { $out_clothes[] = $dirr_value; } else { $no_Display_clothes[] = $dirr_value; } } } } } //将SKU的下单品的按状态加入到数组 $Logic_clothes_arr[$Display_status_num] = array_merge($Logic_clothes_arr[$Display_status_num], $Display_clothes); $Logic_clothes_arr[$no_Display_status_num] = array_merge($Logic_clothes_arr[$no_Display_status_num], $no_Display_clothes); $Logic_clothes_arr[$out_status_num] = array_merge($Logic_clothes_arr[$out_status_num], $out_clothes); $Logic_clothes_arr[$ForSale_status_num] = array_merge($Logic_clothes_arr[$ForSale_status_num], $ForSale_clothes); } //去除单品状态数组里的重复值和空值 foreach ($Logic_clothes_arr as $key => $value) { $value = array_filter($value); $Logic_clothes_arr[$key] = array_unique($value); } //单品不同穿状态设置 foreach ($Different_clothes_arr as $value) { $out_c_arr = Comm::array_intersect_fast($value, $Logic_clothes_arr[$out_status_num]); //获取当前不同穿关联 是否做下架处理 $ForSale_c_arr = Comm::array_intersect_fast($value, $Logic_clothes_arr[$ForSale_status_num]); //获取当前不同穿关联 是否做待售处理 if (count($out_c_arr) > 0) { //当前单品状态为下架 那么其不同穿关联就做下架 $Logic_clothes_arr[$out_status_num] = array_merge($Logic_clothes_arr[$out_status_num], $value); } else { if (count($ForSale_c_arr) > 0) { //当前单品状态为待售 那么其不同穿关联就做待售 $Logic_clothes_arr[$ForSale_status_num] = array_merge($Logic_clothes_arr[$ForSale_status_num], $value); } else { $Display_c_arr = Comm::array_intersect_fast($value, $Logic_clothes_arr[$Display_status_num]); //获取当前不同穿关联 是否做显示处理 $Display_clothes_id_arr = array(); $Display_c_arr_len = count($Display_c_arr); if ($Display_c_arr_len > 0) { $Display_clothes_id_arr = array(array_shift($Display_c_arr)); } //当前单品状态为上架不显示 $no_Display_c_arr = Comm::array_diff_fast($value, array_merge($Display_clothes_id_arr, $Logic_clothes_arr[$ForSale_status_num], $Logic_clothes_arr[$out_status_num], $Logic_clothes_arr[$Display_status_num])); $Logic_clothes_arr[$no_Display_status_num] = array_merge($Logic_clothes_arr[$no_Display_status_num], $no_Display_c_arr); //上架单品数量大于1时 只取第一个做上架 其他做上架不显示 if ($Display_c_arr_len > 1) { $Logic_clothes_arr[$Display_status_num] = Comm::array_diff_fast($Logic_clothes_arr[$Display_status_num], $Display_c_arr); } } } foreach ($Related_clothes_arr as $R_key => $R_value) { if (count(Comm::array_intersect_fast($value, $R_value)) > 0) { $R_value = array_merge($R_value, $value); $R_value = array_unique($R_value); $Related_clothes_arr[$R_key] = $R_value; break; } } } //检查关联单品 是否有上架单品存在 /*foreach($Related_clothes_arr as $value){ $no_Display_v_arr=Comm::array_intersect_fast($value,$Logic_clothes_arr[$no_Display_status_num]); $Display_v_arr=Comm::array_intersect_fast($value,$Logic_clothes_arr[$Display_status_num]); if(count($Display_v_arr)==0 && count($no_Display_v_arr)>0){//当前关联单品组合是没有上架单品 将不显示单品提取一个改为上架 $s_vlue=array_shift($Display_c_arr); $Logic_clothes_arr[$Display_status_num][]=$s_vlue; unset($Logic_clothes_arr[$no_Display_status_num][array_search($s_vlue,$Logic_clothes_arr[$no_Display_status_num])]); } } print_r($Logic_clothes_arr);*/ //修改单品的状态 foreach ($Logic_clothes_arr as $key => $value) { $value = array_filter($value); $value = array_unique($value); if (count($value) == 0) { continue; } Yii::app()->db->createCommand('update touch_clothes set status=' . $key . ' where clothesid in(' . implode(',', $value) . ') and touchid=' . $touchid)->execute(); } $ret['status'] = 1; } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }