Example #1
0
 /**
  * 属性内容
  *
  * @return [type] [description]
  */
 public function actionAttr2content()
 {
     $catalog = intval($this->_gets->getPost('catalog'));
     $attrModel = Attr::model()->findAll(array('condition' => 'scope=:scope AND catalog_id=:catalogId', 'params' => array('scope' => 'post', 'catalogId' => $catalog)));
     if ($attrModel) {
         $var['state'] = 'success';
         $var['message'] = '找到属性';
         $var['text'] = $this->renderPartial('/_include/attr2content', array('attrModel' => $attrModel), true);
     } else {
         $var['state'] = 'error';
         $var['message'] = '没有属性';
     }
     exit(CJSON::encode($var));
 }
Example #2
0
 public function actionDeleteattr($id)
 {
     $gr = Attr::model()->findByPk($id);
     if (!empty($gr)) {
         /*
                         $attr_vals = AttrVal::model()->findAll(array('condition'=>'attr_id=:attr_id','params'=>array(':attr_id'=>$id)));
                         foreach($attr_vals as $attr_val)
                         {
                             $attr_val->delete();
                         }*/
         try {
             $gr->delete();
         } catch (CDbException $e) {
             $this->redirect($this->createUrl('install/index', array('msg' => $e->getMessage(), 'msgtype' => 'error')));
         }
         $this->redirect($this->createUrl('install/index', array('msg' => '[!] Атрибут успешно удален', 'msgtype' => 'success')));
     } else {
         $this->redirect($this->createUrl('install/index', array('msg' => '[!] Ошибка: нет такого атрибута', 'msgtype' => 'error')));
     }
 }
Example #3
0
 /**
  * 文档数据导出
  * 导出及备份系统制定字段的数据
  * 20130419 容易导致混乱,有整体导出即可,本功能暂停开发
  */
 public function actionCExport()
 {
     exit;
     $tableName = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
     //表明
     //验证表明是否为实体表
     if (!preg_match('/^item/i', $tableName)) {
         $this->redirect_back();
     }
     $selectedFields = isset($_POST['checked']) ? $_POST['checked'] : array();
     //选中
     //获取数据库对象和所有字段列表
     $db = CardItem::model()->getDb();
     $nameInfo = explode('_', $tableName);
     $attr = Attr::model()->getAll($nameInfo[1], $nameInfo[2]);
     $fields = array_merge(array('name', 'edittime', 'addtime'), array_keys($attr));
     //获取字段列表
     //获取需要导出的字段列表,并导出
     if (!empty($_POST)) {
         $contents = "";
         //内容
         array_unshift($selectedFields, '_id');
         //加入必选字段id
         //data	获取文档数据
         $cursor = $db->selectCollection($tableName)->find(array(), $selectedFields);
         //查询指定字段数据
         foreach ($cursor as $one) {
             $one_id = is_object($one['_id']) ? '' . $one['_id'] : $one['_id'];
             //id类型处理
             unset($one['_id']);
             //$contents .= '{_id:"'.$one_id.'"},{$set:'.$this->_exportJSON($one).'}'."\n";
             $contents .= $this->json_unicode_utf8(json_encode(array('_id' => $one_id))) . ',{"$set":' . $this->json_unicode_utf8(json_encode($one)) . '}' . "\n";
         }
         unset($cursor);
         $fiels_ext = '';
         array_shift($selectedFields);
         //移出顶部的_id
         $sfcount = count($selectedFields);
         //字段数量
         if ($sfcount > 2) {
             $fiels_ext = $selectedFields[0] . ',' . $selectedFields[1] . '...[' . $sfcount . ']';
         } else {
             $fiels_ext = implode(',', $selectedFields);
         }
         file_put_contents(yiiBase::getPathOfAlias($this->dirpath . '.export') . '/' . date("YmdHis") . '-' . $tableName . '-' . $fiels_ext . '.js', $contents);
     }
     //扫描导出文件并获取列表
     $exportTables = $this->findDir($this->dirpath . '.export', 'js');
     $exe_msg = $this->_exe_message();
     $this->render('cexport', array('fields' => $fields, 'selectedFields' => $selectedFields, 'tableName' => $tableName, 'exportTables' => $exportTables, 'exe_msg' => $exe_msg));
 }
Example #4
0
 /**
  * Save good attribute values from array
  * @param $data array with good attribute values
  */
 public function SaveFeatures($data)
 {
     //save good features
     if (!isset($data)) {
         return;
     }
     //check exist good features first
     $featureValues = GoodAttrVal::model()->findAllByAttributes(array('good_id' => $this->id));
     foreach ($featureValues as $featureValue) {
         if (isset($featureValue->attrValue)) {
             if ($featureValue->attrValue->attr->type == '1') {
                 //if feature is string type
                 if (empty($data['normal'][$featureValue->attrValue->attr->id])) {
                     $featureValue->delete();
                 } elseif ($data['normal'][$featureValue->attrValue->attr->id] != $featureValue->attr_value_id) {
                     if ($data['normal'][$featureValue->attrValue->attr->id] == '0') {
                         $featureValue->attr_value_id = $data['new'][$featureValue->attrValue->attr->id];
                     } else {
                         $featureValue->attr_value_id = $data['normal'][$featureValue->attrValue->attr->id];
                     }
                     $featureValue->save();
                 }
             }
         } elseif (isset($featureValue->attr)) {
             if ($featureValue->attr->type == '2') {
                 //if feature is boolean type
                 if ($data['normal'][$featureValue->attr->id] == '0') {
                     $featureValue->delete();
                 } elseif ($data['normal'][$featureValue->attr->id] != $featureValue->value) {
                     $featureValue->value = $data['normal'][$featureValue->attr->id];
                     $featureValue->save();
                 }
             } elseif ($featureValue->attr->type == '3') {
                 //if feature is numeric type
                 if (empty($data['normal'][$featureValue->attr->id])) {
                     $featureValue->delete();
                 } elseif ($data['normal'][$featureValue->attr->id] != $featureValue->value) {
                     $featureValue->value = $data['normal'][$featureValue->attr->id];
                     $featureValue->save();
                 }
             }
         }
     }
     $newFeature = TRUE;
     foreach ($data['normal'] as $featureId => $feature) {
         foreach ($featureValues as $featureValue) {
             if ($featureValue->attrValue !== null && $featureValue->attrValue->attr_id == $featureId) {
                 $newFeature = FALSE;
             }
             if ($featureValue->attr->id == $featureId) {
                 $newFeature = FALSE;
             }
         }
         if ($newFeature) {
             $attr = Attr::model()->findByPk($featureId);
             $newGoodFeature = new GoodAttrVal();
             $newGoodFeature->good_id = $this->id;
             if ($attr->type == '1') {
                 if ($feature == '0' && !empty($data['new'][$featureId])) {
                     //add new attribute value
                     $newAttrValue = new AttrValue();
                     $newAttrValue->attr_id = $attr->id;
                     $newAttrValue->value = $data['new'][$featureId];
                     $newAttrValue->save();
                     $newAttrValue->refresh();
                     $newGoodFeature->attr_value_id = $newAttrValue->id;
                     $newGoodFeature->save();
                 } elseif ($feature != '0') {
                     $newGoodFeature->attr_value_id = $feature;
                     $newGoodFeature->save();
                 }
             } elseif ($attr->type == '2' && $feature != '0') {
                 $newGoodFeature->value = $feature;
                 $newGoodFeature->attr_id = $featureId;
                 $newGoodFeature->save();
             } elseif ($attr->type == '3' && !empty($feature)) {
                 $newGoodFeature->value = $feature;
                 $newGoodFeature->attr_id = $featureId;
                 $newGoodFeature->save();
             }
         }
         $newFeature = TRUE;
     }
 }
Example #5
0
 public function actionGroupAttributes()
 {
     if (isset($_POST['group_id']) && !empty($_POST['group_id'])) {
         $attributes = Attr::model()->findAll(array('condition' => 'attr_group_id=' . $_POST['group_id'], 'order' => 'pos'));
         foreach ($attributes as $attribute) {
             echo $attribute->pos . ' ' . $attribute->name . '<br/>';
         }
     }
 }
 /**
  * Search goods
  */
 public function actionSearch()
 {
     if (!isset($_POST['feature'])) {
         echo 'Категория пуста';
         return;
     }
     //print_r($_POST);
     $catId = $_POST['category_id'];
     if (isset($_POST['brand'])) {
         foreach ($_POST['brand'] as $key => $value) {
             $brands[] = $key;
         }
     }
     $price = $_POST['price'];
     $res = array();
     $first_step = true;
     foreach ($_POST['feature'] as $featureId => $feature) {
         if (!empty($feature) || $feature == '0') {
             $attr = Attr::model()->cache(3600)->findByPk($featureId);
             if ($attr->type == '2' && $feature == '2') {
                 continue;
             }
             if ($attr->type == '3' && empty($feature['min']) && empty($feature['max'])) {
                 continue;
             }
             $criteria = new CDbCriteria();
             $criteria->compare('category_id', $catId, false);
             if (!empty($brands)) {
                 $criteria->compare('brand_id', $brands, false);
             }
             if (!empty($price) && !empty($price['min'])) {
                 $criteria->condition .= ' AND price >= ' . $price["min"];
             }
             if (!empty($price) && !empty($price['max'])) {
                 $criteria->condition .= ' AND price <= ' . $price["max"];
             }
             $criteria->join = 'left join good_attr_val v ON v.good_id=t.id';
             if ($attr->type == '1') {
                 $values = array();
                 foreach ($feature as $key => $value) {
                     if ($value == '1') {
                         $values[] = $key;
                     }
                 }
                 $criteria->compare('v.attr_value_id', $values);
             }
             if ($attr->type == '2') {
                 $criteria->condition .= ' AND v.value=' . $feature . ' and v.attr_id=' . $attr->id;
             }
             if ($attr->type == '3') {
                 if (!empty($feature['min']) && !empty($feature['max'])) {
                     $criteria->condition .= ' AND v.value>=' . $feature['min'] . ' AND v.value<=' . $feature['max'] . ' AND v.attr_id =' . $attr->id;
                 } elseif (!empty($feature['min']) && empty($feature['max'])) {
                     $criteria->condition .= ' AND v.value>=' . $feature['min'] . ' AND v.attr_id =' . $attr->id;
                 } elseif (empty($feature['min']) && !empty($feature['max'])) {
                     $criteria->condition .= ' AND v.value<=' . $feature['max'] . ' AND v.attr_id =' . $attr->id;
                 }
             }
             $goods = Good::model()->with(array('goodImages'))->findAll($criteria);
             $good_ids = array();
             foreach ($goods as $good) {
                 $good_ids[] = $good->id;
             }
             //echo 'id=' . $featureId . '<br>';
             if (empty($res) && $first_step) {
                 //print_r($good_ids);echo '<br>';
                 $res = $good_ids;
                 if (empty($res) && !$first_step) {
                     echo 'Ничего не найдено по этим критериям';
                     return;
                 }
                 $first_step = FALSE;
                 continue;
             }
             if (empty($good_ids)) {
                 echo 'Ничего не найдено по этим критериям';
                 return;
             }
             foreach ($res as $good_id) {
                 if (!in_array($good_id, $good_ids)) {
                     unset($res[array_search($good_id, $res)]);
                 }
             }
         }
     }
     if ($first_step) {
         $criteria = new CDbCriteria();
         $criteria->compare('category_id', $catId, false);
         if (!empty($brands)) {
             $criteria->compare('brand_id', $brands, false);
         }
         if (!empty($price) && !empty($price['min'])) {
             $criteria->condition .= ' AND price >= ' . $price["min"];
         }
         if (!empty($price) && !empty($price['max'])) {
             $criteria->condition .= ' AND price <= ' . $price["max"];
         }
         if (!empty($_POST['order'])) {
             $criteria->order = $_POST['order'] . ' ';
         }
         $count = Good::model()->count($criteria);
         $pages = new CPagination($count);
         $pages->pageSize = 10;
         $pages->setCurrentPage($_POST['page']);
         $pages->applyLimit($criteria);
         $goods = Good::model()->with(array('goodImages'))->findAll($criteria);
     } else {
         if (count($res) == 0) {
             echo 'Ничего не найдено по этим критериям';
             return;
         }
         $new_res = array();
         foreach ($res as $value) {
             $new_res[] = $value;
         }
         $count = count($new_res);
         $criteria = new CDbCriteria();
         $pages = new CPagination($count);
         $pages->pageSize = 10;
         $pages->setCurrentPage($_POST['page']);
         $pages->applyLimit($criteria);
         $criteria->compare('id', $new_res);
         if (!empty($_POST['order'])) {
             $criteria->order = $_POST['order'] . ' ';
         }
         $goods = Good::model()->with(array('goodImages'))->findAll($criteria);
     }
     $this->renderPartial('search-result', array('goods' => $goods, 'pages' => $pages, 'count' => $count));
 }
Example #7
0
            ?>
" class="qtipm"  ><img src="/images/admin/help.png" height="16" alt="help"></span>
                                <?php 
            $this->widget('application.extensions.editor.CKkceditor', array('model' => $catalog, 'attribute' => $catalog->id_attr, "height" => '200px', "width" => '850px', "filespath" => $_SERVER['DOCUMENT_ROOT'] . "/userfiles/editor/", "filesurl" => "/userfiles/editor/"));
            break;
        case 'string':
            echo CHtml::activeTextField($catalog, $catalog->id_attr);
            break;
        case 'price':
            echo CHtml::activeTextField($catalog, $catalog->id_attr, array('id' => 'price'));
            break;
        case 'count':
            echo CHtml::activeTextField($catalog, $catalog->id_attr, array('id' => 'count'));
            break;
        case 'yes_no':
            echo CHtml::activeCheckBox($catalog, $catalog->id_attr);
            break;
        case 'fk':
            $attr = Attr::model()->findByPk($catalog->id_attr);
            $var = $catalog->id_attr;
            echo CHtml::listBox('AttrVal[' . $catalog->id_attr . ']', explode(',', $catalog->{$var}), Stre::getElementList($attr->fk), array('multiple' => 'multiple', 'style' => 'width:600px;'));
            break;
        default:
            echo CHtml::activeTextField($catalog, $catalog->id_attr);
    }
    ?>

                </td>
            </tr>
            <?php 
}
Example #8
0
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if (XUtils::method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif (XUtils::method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
         is_array($ids) && ($ids = implode(',', $ids));
     } else {
         XUtils::message('errorBack', '只支持POST,GET数据');
     }
     empty($ids) && XUtils::message('error', '未选择记录');
     switch ($command) {
         case 'delete':
             parent::_acl('attr_delete');
             AdminLogger::_create(array('catalog' => 'delete', 'intro' => '属性删除,ID:' . $ids));
             $attrModel = Attr::model()->findByPk($ids);
             Attr::clear(array('attrId' => $attrModel->id, 'attrName' => $attrModel->attr_name_alias, 'oldScope' => 'all'));
             parent::_delete(new Attr(), $ids, array('index'));
             break;
         default:
             throw new CHttpException(404, '错误的操作类型:' . $command);
             break;
     }
 }