/** * 模特分类 * */ static function selectmodeltype() { try { $modeltype = Category::categorySelectForAll(array(9)); if ($modeltype['status'] == 0) { $modeltype = array(); } else { $modeltype = $modeltype['data']; } return $modeltype; } catch (Exception $e) { } }
/** * 通过分类表中的style查询分类数据 * @param $style 12为用户权限2级 * @return 数组 */ public static function userSeletecategoryinfoBystyle($style = "") { $category = array(); if (!empty($style)) { $category = Category::categorySelectForAll(array($style)); if ($category['status'] == 0) { $category = array(); } else { $category = $category['data']; } } return $category; }
/** * 设置衣服的风格 */ static function setClothesStyleBybrandnumber($clothes_arr, $touchid) { $ret = array('status' => 0, 'msg' => ''); try { $category_data = Category::categorySelectForAll(24); //获取所有的风格 if ($category_data['status'] == 0) { $category_data = array(); } else { $category_data = $category_data['data']; } //统计出衣服款号 $brandnumber_arr = array(); foreach ($clothes_arr as $key => $value) { $code = isset($value['code']) ? trim($value['code']) : ''; if (!empty($code)) { $brandnumber_arr[] = '\'' . $code . '\''; } } if (count($brandnumber_arr) == 0) { throw new Exception('衣服为空!'); } //根据衣服的款号极其触摸屏id号获取所有的衣服ID $clothes_data = Yii::app()->db->createCommand()->select('beu_clothes.id,beu_clothes.brandnumber,beu_clothes.brandid')->from('touch_clothes')->join('beu_clothes', 'beu_clothes.id=touch_clothes.clothesid')->where('touch_clothes.touchid=' . $touchid . ' and beu_clothes.brandnumber in(' . implode(',', $brandnumber_arr) . ')')->queryAll(); if (count($clothes_data) == 0) { throw new Exception('根据衣服款号未找到衣服!'); } //循环需要修改的衣服数组 foreach ($clothes_arr as $key => $value) { $code = isset($value['code']) ? trim($value['code']) : ''; $typetag = isset($value['typetag']) ? trim($value['typetag']) : ''; //当款号不为空才执行 if (!empty($code)) { //循环衣服数据 foreach ($clothes_data as $clothes_key => $clothes_value) { if ($code == $clothes_value['brandnumber']) { //当衣服的款号等于当前衣服的款号时 //查询当前衣服在数据库里已绑定的风格 $style_data = Yii::app()->db->createCommand()->select('*')->from('touch_clothes_style')->where('touchid=' . $touchid . ' and brandid=' . $clothes_value['brandid'] . ' and clothesid=' . $clothes_value['id'])->queryAll(); //if(count($style_data)>0){//如果绑定的风格不为空 $typetag_arr = array(); if (!empty($typetag)) { $typetag_arr = explode(',', $typetag); } $typetag_id_arr = array(); //将需要绑定的风格替换为风格所对应的ID foreach ($category_data as $category_key => $category_value) { if (in_array($category_value['title'], $typetag_arr)) { $typetag_id_arr[] = $category_value['id']; } } //统计已绑定的风格 $type_style_id_arr = array(); foreach ($style_data as $style_key => $style_value) { $type_style_id_arr[] = $style_value['styleid']; } $add_style = array_diff($typetag_id_arr, $type_style_id_arr); //还未绑定过的风格 $del_style = array_diff($type_style_id_arr, $typetag_id_arr); //需要删除的绑定风格 //批量绑定衣服风格 $add_arr = array(); foreach ($add_style as $add_key => $add_value) { $arr = array(); $arr[] = $clothes_value['brandid']; $arr[] = $touchid; $arr[] = $clothes_value['id']; $arr[] = $add_value; $add_arr[] = '(' . implode(',', $arr) . ')'; } //如有需要绑定的风格就绑定 if (count($add_arr) > 0) { $sql = 'insert into touch_clothes_style (brandid,touchid,clothesid,styleid) values' . implode(',', $add_arr); $ret_id = Yii::app()->db->createCommand($sql)->execute(); } //如有多余的绑定需要从数据库删除 if (count($del_style) > 0) { $sql = 'delete from touch_clothes_style where brandid=' . $clothes_value['brandid'] . ' and clothesid=' . $clothes_value['id'] . ' and touchid=' . $touchid . ' and styleid in(' . implode(',', $del_style) . ')'; $ret_id = Yii::app()->db->createCommand($sql)->execute(); } //} unset($clothes_data[$clothes_key]); //此件衣服操作完成,清除 } } } } $ret['status'] = 1; } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }