Beispiel #1
0
 /**
  * 修改状态
  * @param $cat_id
  * @param int $status
  * @return bool|int
  */
 public function setEnabled($cat_id, $status = 1)
 {
     if (!in_array($status, [0, 1])) {
         return false;
     }
     return GoodsType::updateAll(['enabled' => $status], 'cat_id = :cat_id', [':cat_id' => $cat_id]);
 }
 public function actionEnabled($act_id, $status = 1)
 {
     if (!$this->is_access('goodstype/update')) {
         exit;
     }
     $model = new GoodsType();
     if ($model->setEnabled($act_id, $status)) {
         echo '1';
     } else {
         echo '0';
     }
 }
Beispiel #3
0
 /**
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('goods/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     $GoodsGallery = new GoodsGallery();
     $post = Yii::$app->request->post();
     if ($model->load($post)) {
         $GoodsGallery->load($post);
         if ($model->validate() && $GoodsGallery->validate()) {
             // 商品封面图片
             if ($_FILES['Goods']['error']['goods_img'] === 0) {
                 $model->goods_img = File::uploadImage($model, 'goods_img', 'shop');
                 $model->goods_thumb = Images::thumb('./' . $model->goods_img, 250, 250);
             }
             if ($model->save(false)) {
                 // 商品相册
                 if ($_FILES['GoodsGallery']['error']['img_url'][0] === 0) {
                     $img_url = File::uploadImages($GoodsGallery, 'img_url', 'goods');
                     $GoodsGallery->addData($model->goods_id, $img_url);
                 }
                 // 商品属性
                 GoodsAttr::addData($model->goods_id);
             }
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         // 商品分类
         $Category = new Category();
         $categoryList = $Category->parent(0, false);
         // 品牌
         $Brand = new Brand();
         $brandList = $Brand->getLists();
         // 商品类型
         $GoodsType = new GoodsType();
         $goodsTypeList = $GoodsType->dropList();
         // 相册
         $goodsGalleryList = $GoodsGallery->getGoodsGallery($id);
         Yii::$app->view->params['meta_title'] = '编辑商品';
         return $this->render('update', ['model' => $model, 'GoodsGallery' => $GoodsGallery, 'categoryList' => $categoryList, 'brandList' => $brandList, 'goodsTypeList' => $goodsTypeList, 'goodsGalleryList' => $goodsGalleryList]);
     }
 }
Beispiel #4
0
?>
')" value=" 搜索 " class="button">

        </form>

    </div>

    <?php 
echo Html::beginForm(['deleteall']);
?>
    <?php 
Pjax::begin();
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'showFooter' => true, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn', 'name' => 'id', 'footer' => Html::button('批量删除', ['class' => 'btn btn-danger', 'onclick' => 'submits()']), 'options' => ['width' => 70]], 'attr_id', ['header' => Html::a('商品类型', 'javascript:;'), 'content' => function ($model) {
    return GoodsType::findOne($model->cat_id)->cat_name;
}], 'attr_name', ['header' => Html::a('录入方式', 'javascript:;'), 'content' => function ($model) {
    $typeList = ['0' => '手工录入', '1' => '从列表中选择', '2' => '多行文本框'];
    return $typeList[$model->attr_input_type];
}], ['attribute' => 'attr_values', 'value' => function ($model) {
    $content = str_replace("\r\n", ', ', $model->attr_values);
    return Functions::truncate_utf8_string($content, 28);
}, 'options' => ['width' => 430]], ['attribute' => 'sort_order', 'value' => function ($model) {
    return $model->sort_order;
}, 'options' => ['width' => 70]], ['class' => 'yii\\grid\\ActionColumn', 'header' => Html::a('操作', 'javascript:void(0);'), 'template' => '{update} {delete} {deletes}']]]);
?>
    <?php 
Pjax::end();
?>
    <?php 
echo Html::endForm();
Beispiel #5
0
 public function getType()
 {
     return $this->hasOne(GoodsType::className(), ['type_id' => 'type_id']);
 }
 /**
  * 获取一个类型分组 ( 表单页面 )
  * @param int $cat_id 商品类型id
  * @param int $attr_group_id
  */
 public function actionAttrgroup($cat_id, $attr_group_id = 0)
 {
     $attr_group = GoodsType::findOne($cat_id)->attr_group;
     if (!empty($attr_group)) {
         // 组合成option下拉
         $attr_group = explode("\r\n", $attr_group);
         $option = '';
         foreach ($attr_group as $key => $val) {
             $selected = $attr_group_id == $key ? 'selected' : '';
             $option .= "<option {$selected} value='{$key}'>{$val}</option>";
         }
         exit($option);
     }
 }
Beispiel #7
0
 public function actionGoodsadd()
 {
     //获取商品类型及其属性
     $type = GoodsType::find()->all();
     //获取商品分类信息
     $category = new GoodsCategory();
     $cate = $category->list_cate();
     //获取商品品牌信息
     $brand = GoodsBrand::find()->all();
     $model = new Goods();
     return $this->render('goodsadd', ['type' => $type, 'cate' => $cate, 'brand' => $brand, 'model' => $model]);
 }
 public function actionAttredit()
 {
     if (Yii::$app->request->get('id')) {
         $type = GoodsType::find()->all();
         //商品类型数据填充
         $id = Yii::$app->request->get('id');
         $type_id = Yii::$app->request->get('type_id');
         //商品类型id
         $model = Attribute::findOne($id);
         return $this->render('attredit', ['id' => $id, 'type_id' => $type_id, 'model' => $model, 'type' => $type]);
     } elseif (Yii::$app->request->post('id')) {
         $id = Yii::$app->request->post('id');
         $model = Attribute::findOne($id);
         if ($model === null) {
             Yii::$app->getSession()->setFlash("info", '编辑失败');
             return $this->redirect(['attrlist', 'type_id' => $model->type_id]);
         }
         if ($model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 Yii::$app->getSession()->setFlash('info', '编辑成功!');
                 return $this->redirect(['attrlist', 'type_id' => $model->type_id]);
             }
         }
     }
 }