Exemplo n.º 1
0
 /**
  * 获取商品图片
  *
  * @param $goods_id
  * @return mixed
  */
 public function goods_image($goods_id)
 {
     $attach = ImageImageAttach::model()->findAll('target_id = :target_id', array(':target_id' => $goods_id));
     $image_id = array();
     foreach ($attach as $v) {
         $image_id[] = "'" . $v->image_id . "'";
     }
     $image_ids = implode(',', $image_id);
     $image = array();
     if (!empty($image_ids)) {
         $image = ImageImage::model()->findAll('image_id IN (' . $image_ids . ')');
     }
     return $image;
 }
Exemplo n.º 2
0
 /**
  * 获取单个图片
  *
  * @param $image_id
  * @param string $type
  * @return mixed
  */
 public static function Item($image_id, $type = 's')
 {
     $ImageImage = new ImageImage();
     $row = $ImageImage->ImageUrl($image_id);
     return $row[$type . '_url'];
 }
Exemplo n.º 3
0
 /**
  * 商品添加
  */
 public function actionCreate()
 {
     if ($_POST) {
         $Goods = new Goods();
         $ImageImage = new ImageImage();
         $goods_attributes = $this->post('Goods');
         //判断货号是否存在
         $bn_goods = Goods::model()->find('bn = :bn', array(':bn' => $goods_attributes['bn']));
         if ($bn_goods) {
             $this->message('error', '货号冲突', $this->createUrl('index'));
         }
         $goods_attributes['update_time'] = time();
         $Goods->attributes = $goods_attributes;
         if (!$Goods->save()) {
             $this->message('error', CHtml::errorSummary($Goods), $this->createUrl('index'));
         }
         $goods_id = Yii::app()->db->getLastInsertID();
         //商品图片
         $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'));
         }
         //创建货品
         $product_attributes = array('goods_id' => $goods_id, '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'], 'freez' => 0, 'goods_type' => 'normal', 'is_default' => 'true', 'uptime' => time(), 'marketable' => 'true');
         $Product = new Products();
         $Product->attributes = $product_attributes;
         if (!$Product->save()) {
             $this->message('error', CHtml::errorSummary($Product), $this->createUrl('index'));
         }
         $this->referrer();
     }
     //商品类型
     $type_list = GoodsType::model()->findAll();
     $type_arr = array();
     if ($type_list) {
         foreach ($type_list as $v) {
             $type_arr[$v->type_id] = $v->name;
         }
     }
     //品牌
     $TypeBrand = new TypeBrand();
     $model['brand'] = $TypeBrand->type_brand();
     $model['type'] = $type_arr;
     $this->render('create', array('model' => $model));
 }