/** * 商品分类列表 * * @param $pagesize * @param $pageIndex * @return array */ public function CatList($pageIndex, $pagesize) { $criteria = new CDbCriteria(); $criteria->select = '*,t2.name AS type_name'; $criteria->join = 'left join {{b2c_goods_type}} t2 ON (t.type_id = t2.type_id)'; $criteria->condition = "t.disabled = 'false'"; $criteria->order = 'cat_path ASC'; // 求总的记录数 $count = GoodsCat::model()->count($criteria); $criteria->limit = $pagesize; $criteria->offset = ($pageIndex - 1) * $pagesize; $list = GoodsCat::model()->findAll($criteria); $item = array(); foreach ($list as $v) { $str_count = substr_count($v['cat_path'], ','); $cat_path_arr = explode(',', $v['cat_path']); $row['cat_id'] = $v['cat_id']; $row['cat_name'] = $v['cat_name']; $row['path'] = $str_count; $row['p_order'] = $v['p_order']; $row['img_url'] = $v['img_url']; $row['type_name'] = $v['type_name']; if ($str_count == 1) { $item[$v['cat_id']][$v['cat_id']] = $row; } elseif ($str_count == 2) { $item[$v['parent_id']][$v['cat_id']] = $row; } elseif ($str_count == 3) { $item[$cat_path_arr[1]][$cat_path_arr[2]]['child'][] = $row; } } $items = array(); foreach ($item as $v) { foreach ($v as $vv) { $items[] = $vv; if (isset($vv['child']) && $vv['child']) { foreach ($vv['child'] as $vvv) { $items[] = $vvv; } } } } return array('item' => $items, 'count' => $count); }
/** * Ajax获取商品分类 */ public function actionAjaxgoodscat() { $cat_id = $this->post('cat_id'); $GoodsCat = new GoodsCat(); $default = $this->post('default'); $result = $GoodsCat->CatSelect($cat_id, $default); $goods_select = $result['item']; if ($default == 0) { $cat_one = isset($goods_select['one']) ? $goods_select['one'] : array(); $cat_two = isset($goods_select['two']) ? $goods_select['two'] : array(); //$cat_three = isset($goods_select['three'])?$goods_select['three']:array(); $cat_three = array(); echo $this->renderPartial('_model_goods_cat', array('cat_id' => $cat_id, 'cat_one' => $cat_one, 'cat_two' => $cat_two, 'cat_three' => $cat_three, 'active' => $result['active']), true); } else { if ($default == 1) { $cat_two = $goods_select['two']; echo TbHtml::navList($cat_two); } else { if ($default == 2) { $cat_three = $goods_select['three']; echo TbHtml::navList($cat_three); } } } }
/** * 商品编辑 */ public function actionUpdate() { $goods_id = $this->get('goods_id'); $model['goods_row'] = Goods::model()->find('goods_id = :goods_id', array(':goods_id' => $goods_id)); $ImageImage = new ImageImage(); if ($_POST) { //商品主表信息 $goods_attributes = $this->post('Goods'); $goods_attributes['update_time'] = time(); $result = Goods::model()->updateByPk($goods_id, $goods_attributes); if (!$result) { $Goods = new Goods(); $this->message('error', CHtml::errorSummary($Goods), $this->createUrl('index')); } //商品图片 $image_attributes = $this->post('Image'); $image_attach_attributes = $this->post('ImageAttach'); $image_ids = $this->post('ImageId'); $result = $ImageImage->imageList($image_attributes, $image_attach_attributes, $image_ids, $goods_id); if (!$result) { $this->message('error', CHtml::errorSummary($ImageImage), $this->createUrl('index')); } //类型改变 if ($model['goods_row']['type_id'] != $goods_attributes['type_id']) { $Product = new Products(); $product_attributes = array('bn' => $goods_attributes['bn'], 'price' => $goods_attributes['price'], 'cost' => $goods_attributes['cost'], 'mktprice' => $goods_attributes['mktprice'], 'name' => $goods_attributes['name'], 'weight' => $goods_attributes['weight'], 'unit' => $goods_attributes['unit'], 'store' => $goods_attributes['store'], 'disabled' => 'false', 'is_default' => 'true', 'uptime' => time()); $result = $Product->typeProduct($goods_id, $product_attributes); if (!$result) { $this->message('error', '编辑失败', $this->createUrl('index')); } } $this->referrer(); } //商品分类 $cat = GoodsCat::model()->find('cat_id = :cat_id', array(':cat_id' => $model['goods_row']['cat_id'])); $model['cat_row'] = isset($cat->cat_name) ? $cat->cat_name : ''; //商品类型 $type_list = GoodsType::model()->findAll(); $type_arr = array(); if ($type_list) { foreach ($type_list as $v) { $type_arr[$v->type_id] = $v->name; } } $model['type'] = $type_arr; //商品关键字 $GoodsKeywords = new GoodsKeywords(); $model['keywords'] = $GoodsKeywords->merge($model['goods_row']['goods_id']); //品牌 $TypeBrand = new TypeBrand(); $model['brand'] = $TypeBrand->type_brand($model['goods_row']['type_id']); //会员价格 $MemberLv = new MemberLv(); $model['member_lv_price'] = $MemberLv->MemberGoodsLvPrice($model['goods_row']['goods_id']); //商品图片 $model['image'] = $ImageImage->goods_image($model['goods_row']['goods_id']); //商品-货品信息 $model['product'] = Products::model()->find('goods_id = :goods_id', array(':goods_id' => $model['goods_row']['goods_id'])); //规格 $data['spec_info'] = ''; $data['product_num'] = 0; if (!empty($model['goods_row']['spec_desc'])) { $GoodsTypeSpec = new GoodsTypeSpec(); $data['spec_info'] = $GoodsTypeSpec->ProductSpecList($goods_id); //货品数量 $data['product_num'] = Products::model()->count('goods_id = :goods_id', array(':goods_id' => $model['goods_row']['goods_id'])); } $model['spec'] = $data; $this->render('update', array('model' => $model)); }