/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = ItemProp::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function run() { $categories = $this->category->children()->findAll(); $all_cat = $this->category->descendants()->findAll(); $all_cat_ids = array(); foreach ($all_cat as $cat) { $all_cat_ids[] = $cat->id; } $cri = new CDbCriteria(); $cri->addInCondition('t.category_id', $all_cat_ids); $cri->addCondition("t.type != 'input'"); $item_props = ItemProp::model()->with('propValues')->findAll($cri); $this->render('categorySearch', array('categories' => $categories, 'item_props' => $item_props)); }
<?php $childs = $model->children()->findAll(); foreach ($childs as $c) { ?> <dd><div><a><span><?php echo CHtml::link($c->name, array('/catalog/index', 'key' => $c->url)); ?> </span></a></div></dd> <?php } ?> </dl> <?php $cri = new CDbCriteria(array('condition' => 'is_sale_prop = 1 and category_id = ' . $model->id, 'order' => 'sort_order asc')); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { ?> <!-- <?php echo $p->prop_name; ?> --> <dl class="clearfix"> <dt><span class="filter_list_tit"><?php echo $p->prop_name; ?> :</span></dt> <dd><div><a><span>全部</span></a></div></dd> <?php $cri = new CDbCriteria(array('condition' => 'prop_id =' . $p->prop_id)); $values = PropValue::model()->findAll($cri);
/** * 获取指定id的所有后代,不含指定id * @param type $id 指定id, 有可能是array * @return type 所有后代id的一维数组 */ public static function getChildsId($id) { $data = array(); $ids = array(); if (!is_array($id)) { $id = array($id); } $id = implode(', ', $id); $models = ItemProp::model()->findAll('parent_prop_id in (' . $id . ')'); if ($models) { foreach ($models as $model) { $ids[] = $model->prop_id; } $ids = array_merge($ids, ItemProp::getChildsId($ids)); return $ids; } else { return $ids; } }
$sku_list = Sku::model()->findAll($cri); foreach ($sku_list as $skus) { $props = CJSON::decode($skus->props, TRUE); $count = count($props); for ($i = 0; $i < $count; $i++) { $p[$i][] = $props[$i]; } } for ($i = 0; $i < $count; $i++) { foreach (array_unique($p[$i]) as $k => $v) { $new_v = explode(':', $v); $new_arr[$new_v[0]][] = $new_v[1]; } } foreach ($new_arr as $k => $v) { $list = ItemProp::model()->findByPk($k); echo $list->prop_name . ': '; foreach ($v as $v) { $v_list = PropValue::model()->findByPk($v); echo $v_list->value_name . ' '; } echo '<br />'; } /** * 计算 */ // foreach($sku_list as $skus) { // $arr[$skus] // } ?> <li>
/** * ajax 成功后一般返回json数据 * 然后jquery读取出来 * 在写个function, 转为html */ public function actionGetPropValues() { $category_id = $_POST['category_id'] ? $_POST['category_id'] : NULL; $item_id = $_POST['item_id'] ? $_POST['item_id'] : NULL; $item = Item::model()->findByPk($item_id); $props_arr = CJSON::decode($item->props, TRUE); $skus_arr = CJSON::decode($item->skus, TRUE); // $props_arr = explode(';', $props_list->props); // foreach ($props_arr as $k => $v) { // $arr[] = explode(':', $v); // if(is_array($arr)){ // // } // } // foreach ($newarr as $k => $v) { // $v_arr = explode(',', $v[1]); // $arr[$v[0]] = $v_arr; // } // $arr = array('3'=>'106', '1'=>'78', '2'=>'82'); // 关键属性 $cri = new CDbCriteria(array('condition' => 'is_key_prop=1 and category_id =' . $category_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo '<div class="row">'; if ($p->must == 1) { echo '<label class="span2 control-label" for="">' . $p->prop_name . '<span class="required">*</span></label>'; } else { echo '<label class="span2 control-label" for="">' . $p->prop_name . '</label>'; } echo '<div class="span10">'; if ($p->type == 'input') { echo $p->getPropTextFieldValues($p->prop_name, $props_arr[$p->prop_id]); } elseif ($p->type == 'optional') { echo $p->getPropOptionValues($p->prop_name, $props_arr[$p->prop_id]); } elseif ($p->type == 'multiCheck') { echo $p->getPropCheckBoxListValues($p->prop_name, $props_arr[$p->prop_id]); } echo '</div>'; echo '</div>'; } // 非关键属性 $cri = new CDbCriteria(array('condition' => 'is_key_prop=0 and is_sale_prop=0 and category_id =' . $category_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo '<div class="row">'; if ($p->must == 1) { echo '<label class="span2 control-label" for="">' . $p->prop_name . '<span class="required">*</span></label>'; } else { echo '<label class="span2 control-label" for="">' . $p->prop_name . '</label>'; } echo '<div class="span9">'; if ($p->type == 'input') { echo $p->getPropTextFieldValues($p->prop_name, $props_arr[$p->prop_id][0]); } elseif ($p->type == 'optional') { echo $p->getPropOptionValues($p->prop_name, $props_arr[$p->prop_id]); } elseif ($p->type == 'multiCheck') { echo $p->getPropCheckBoxListValues($p->prop_name, $props_arr[$p->prop_id]); } echo '</div>'; echo '</div>'; } //销售属性 $cri = new CDbCriteria(array('condition' => 'is_sale_prop=1 and category_id =' . $category_id)); $props = ItemProp::model()->findAll($cri); if ($props) { echo '<div class="row">'; echo '<label class="span2 control-label" for="">商品规格</label>'; echo '<div class="span9">'; echo '<div class="sku-wrap">'; $ii = 0; foreach ($props as $p) { echo '<div class="sku-group"><label class="sku-head">' . $p->prop_name . '</label>'; echo '<div class="sku-box sku-color">'; if ($p->type == 'multiCheck') { echo $p->getPropCheckBoxListValues($p->prop_name, $skus_arr['checkbox'][$p->prop_id], 'change', 'skus', 'checkbox'); } $thead .= '<th> <span id="thop_' . $ii . '">' . $p->prop_name . '</span></th>'; $ii++; echo '</div></div>'; } echo '<p id="output"></p>'; echo '</div>'; echo '</div>'; echo '</div>'; echo <<<EOF \t <div class="row" style='margin-bottom:10px' style="visibility:hidden"> \t <div class="span2"> </div> \t <div class="span9" style="padding-left:0"> \t <div class="sku-map"> \t <table id="sku" class="table table-bordered"> \t <thead> \t <tr> \t\t{$thead} \t\t<th>价格</th><th>数量</th><th>商家编码</th><th>操作</th></tr> \t </thead> \t <tbody> \t </tbody> \t </table> \t </div> \t</div> </div> EOF; } }
/** * ajax 成功后一般返回json数据 * 然后jquery读取出来 * 在写个function, 转为html */ public function actionGetPropValues() { $type_id = $_POST['type_id'] ? $_POST['type_id'] : NULL; $item_id = $_POST['item_id'] ? $_POST['item_id'] : NULL; $props_list = Item::model()->findByPk($item_id); $props_arr = explode(';', $props_list->props); foreach ($props_arr as $k => $v) { $newarr[] = explode(':', $v); } foreach ($newarr as $k => $v) { $v_arr = explode(',', $v[1]); $arr[$v[0]] = $v_arr; } // $arr = array('3'=>'106', '1'=>'78', '2'=>'82'); // echo '<h5>关键属性</h5>'; $cri = new CDbCriteria(array('condition' => 'is_key_prop=1 and type_id =' . $type_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo "<div class=\"control-group \">"; echo "<label class=\"control-label\">" . $p->prop_name . "</label><div class=\"controls\">"; echo $p->getPropOptionValues($p->prop_name, $arr[$p->prop_id]); echo '</div></div>'; } // echo '<h5>销售属性</h5>'; $cri = new CDbCriteria(array('condition' => 'is_sale_prop=1 and type_id =' . $type_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo "<div class=\"control-group \">"; echo "<label class=\"control-label\">" . $p->prop_name . "</label><div class=\"controls\">"; // echo "<input id=\"ytTestForm_inlineCheckboxes\" type=\"hidden\" name=\"pid_" . $p->prop_id . "\" value=\"\">"; // foreach ($p->getPropArrayValues() as $k => $v) { // echo "<label class=\"checkbox inline\">"; // echo "<input id=\"pid_" . $p->prop_id . "_" . $k . "\" type=\"checkbox\" name=\"pid_" . $p->prop_id . "[]\" value=\"0\">"; // echo "<label>" . $v . "</label></label>"; // } echo $p->getPropCheckBoxListValues($p->prop_name, $arr[$p->prop_id]); echo '</div></div>'; } // echo '<h5>非关键属性</h5>'; $cri = new CDbCriteria(array('condition' => 'is_key_prop=0 and is_sale_prop=0 and type_id =' . $type_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo "<div class=\"control-group \">"; echo "<label class=\"control-label\">" . $p->prop_name . "</label><div class=\"controls\">"; echo $p->type == 'optional' ? $p->getPropOptionValues($p->prop_name, $arr[$p->prop_id]) : $p->getPropTextFieldValues($p->prop_name, $arr[$p->prop_id][0]); echo '</div></div>'; } }
public function actionSelectProp() { $select_id = $_GET['selectItem']; $items = Sku::model()->findAll(new CDbCriteria(array('condition' => "item_id='{$select_id}'"))); foreach ($items as $key => $item) { $list[$key]['sku_id'] = $item->sku_id; $props = json_decode($item->props, true); $pro = ''; foreach ($props as $prop) { $values = explode(':', $prop); $itemProp = ItemProp::model()->findByPk($values[0]); $propValue = PropValue::model()->findByPk($values[1]); $pro .= "{$itemProp->prop_name}:{$propValue->value_name}" . ' '; } $list[$key]['prop'] = $pro; } echo CHtml::tag("option", array("value" => ''), CHtml::encode('请选择'), true); foreach ($list as $item) { echo CHtml::tag("option", array("value" => $item['sku_id']), CHtml::encode($item['prop']), true); } }
public function actionItemProps($category_id, $item_id) { $itemProps = ItemProp::model()->with(array('propValues'))->findAllByAttributes(array('category_id' => $category_id)); $item = Item::model()->findByPk($item_id); $this->renderPartial('_form_prop', array('itemProps' => $itemProps, 'item' => $item), false, true); }
public function run() { $props = CJSON::decode($this->item->props); empty($props) && ($props = array()); $prop_data = array(); foreach ($props as $k => $v) { $item_prop = ItemProp::model()->findByPk($k); if (!$item_prop) { continue; } switch ($item_prop->type) { case 'input': $prop_value_name = $v; break; case 'optional': $prop_value = PropValue::model()->findByPk($v); if (!$prop_value) { continue; } $prop_value_name = $prop_value->value_name; break; case 'multiCheck': if (!is_array($v)) { continue; } $cri = new CDbCriteria(); $cri->addInCondition('value_id', $v); $cri->select = 'value_name'; $prop_values = PropValue::model()->findAll($cri); $prop_value_name = ''; foreach ($prop_values as $prop_value) { $prop_value_name .= ' ' . $prop_value->value_name; } $prop_value_name = substr($prop_value_name, 1); break; } $prop_data[$item_prop->prop_name] = $prop_value_name; } if ($this->showSku) { $skus = CJSON::decode($this->item->skus); if (!empty($skus['checkbox'])) { foreach ($skus['checkbox'] as $k => $v) { if (!is_array($v)) { continue; } $item_prop = ItemProp::model()->findByPk($k); if (!$item_prop) { continue; } $vids = array(); foreach ($v as $kk => $vv) { $ids = explode(':', $vv); if (!empty($ids[1])) { $vids[$kk] = $ids[1]; } } if (empty($vids)) { continue; } $cri = new CDbCriteria(); $cri->addInCondition('value_id', $vids); $cri->select = 'value_id, value_name'; $prop_values = PropValue::model()->findAll($cri); $prop_value_names = array(); $vids = array_flip($vids); foreach ($prop_values as $prop_value) { $prop_value_names[$vids[$prop_value->value_id]] = $prop_value->value_name; } $prop_data[$item_prop->prop_name] = implode(' ', $prop_value_names); } } } $this->render('itemProp', array('prop_data' => $prop_data)); }
/** * get props values combine * @param $arr * @return string * @author Lonely(qq:81106404) */ public static function get_props_values_combine($arr) { $op = ItemProp::model()->findByPk($arr[0]); $opv = PropValue::model()->findByPk($arr[1]); $data = $arr[0] . ":" . $arr[1] . ":" . F::strip_prop_strto_csv($op->prop_name) . ":" . F::strip_prop_strto_csv($opv->value_name); return $data; }
<?php $itemPropValues = json_decode($item->props, true); $itemSkus = $item->skus; $itemProps = ItemProp::model()->with('propValues')->findAll(new CDbCriteria(array('condition' => "t.`category_id` = {$model->category_id} AND t.`type` > 1"))); foreach ($itemProps as $itemProp) { if (!$itemProp->is_sale_prop) { $itemPropValue = ''; if (isset($itemPropValues[$itemProp->item_prop_id])) { $values = explode(':', $itemPropValues[$itemProp->item_prop_id]); $itemPropValue = $values[1]; } $name = 'ItemProp[' . $itemProp->item_prop_id . ']'; switch ($itemProp->type) { case 1: echo TbHtml::textFieldControlGroup($name, $itemPropValue, array('label' => $itemProp->prop_name)); break; case 2: $propValueData = CHtml::listData($itemProp->propValues, 'prop_value_id', 'value_name'); echo TbHtml::dropDownListControlGroup($name, $itemPropValue, $propValueData, array('label' => $itemProp->prop_name)); break; case 3: $propValueData = CHtml::listData($itemProp->propValues, 'prop_value_id', 'value_name'); echo TbHtml::inlineCheckBoxListControlGroup($name, $itemPropValue, $propValueData, array('label' => $itemProp->prop_name)); break; } } } ?> <hr/> <?php
public function actionIndex() { $cat = isset($_GET['cat']) ? $_GET['cat'] : 3; $category = is_numeric($cat) ? Category::model()->findByPk($cat) : Category::model()->findByAttributes(array('url' => $cat)); if (empty($category) || $category->root != 3) { throw new CHttpException(404, 'The requested page does not exist.'); } $descendantIds = $category->getDescendantIds(); $criteria = new CDbCriteria(); $criteria->addInCondition('category_id', $descendantIds); if (!empty($_GET['key'])) { $criteria->addCondition("(t.title LIKE '%{$_GET['key']}%')"); } if (!empty($_GET['floor_price']) && !empty($_GET['top_price']) && $_GET['top_price'] < $_GET['floor_price']) { $criteria->addCondition("t.price >= '{$_GET['top_price']}'"); $criteria->addCondition("t.price <= '{$_GET['floor_price']}'"); } else { if (!empty($_GET['floor_price'])) { $criteria->addCondition("t.price >= '{$_GET['floor_price']}'"); } if (!empty($_GET['top_price'])) { $criteria->addCondition("t.price <= '{$_GET['top_price']}'"); } } if (!empty($_GET['has_stock']) && $_GET['has_stock']) { $criteria->addCondition("t.stock > 0"); } if (!empty($_GET['sort'])) { switch ($_GET['sort']) { case 'sold': break; case 'soldd': break; case 'price': $criteria->order = 't.price'; break; case 'priced': $criteria->order = 't.price desc'; break; case 'new': $criteria->order = 't.update_time'; break; case 'newd': $criteria->order = 't.update_time desc'; break; default: $criteria->order = 't.click_count desc'; break; } } if (!empty($_GET['props'])) { $pvids = array(); $props = explode(';', $_GET['props']); foreach ($props as $p) { $ids = explode(':', $p); if (count($ids) >= 2) { if (isset($pvids[$ids[0]])) { if (!is_array($pvids[$ids[0]])) { $pvids[$ids[0]] = array($pvids[$ids[0]]); } $pvids[$ids[0]][] = $ids[1]; } else { $pvids[$ids[0]] = $ids[1]; } } } foreach ($pvids as $pid => $vids) { if (is_array($vids)) { $where = array(); foreach ($vids as $vid) { $where[] = "props like '%{$pid}:{$vid}%'"; } $where = '(' . implode(' OR ', $where) . ')'; $criteria->addCondition($where); } else { $criteria->addSearchCondition('props', $pid . ':' . $vids); } } } $count = Item::model()->count($criteria); $pager = new CPagination($count); $pager->pageSize = 4; $pager->applyLimit($criteria); $items = Item::model()->findAll($criteria); // var_dump($criteria);die; $parentCategories = $category->parent()->findAll(); $parentCategories = array_reverse($parentCategories); $categoryIds = array($category->category_id); $params = array(); if (!empty($_GET['key'])) { $params['key'] = $_GET['key']; } foreach ($parentCategories as $cate) { if (!$cate->isRoot()) { $params['cat'] = $cate->getUrl(); $this->breadcrumbs[] = array('name' => $cate->name . '>> ', 'url' => Yii::app()->createUrl('catalog/index', $params)); $categoryIds[] = $cate->category_id; } } $params['cat'] = $category->getUrl(); $this->breadcrumbs[] = array('name' => $category->name, 'url' => Yii::app()->createUrl('catalog/index', $params)); Yii::app()->params['categoryIds'] = $categoryIds; // Yii::app()->params['h']= $category->Keywords; // Yii::app()->params['d']= $category->des; // Yii::app()->params['t']= $category->title; $categories = $category->children()->findAll(); $itemProps = ItemProp::model()->with('propValues')->findAll(new CDbCriteria(array('condition' => "t.`category_id` = {$category->category_id} AND t.`type` > 1"))); $this->render('index', array('cat' => $cat, 'count' => $count, 'category' => $category, 'items' => $items, 'pages' => $pager, 'categories' => $categories, 'itemProps' => $itemProps, 'sort' => $_GET['sort'], 'key' => $_GET['key'])); }