예제 #1
0
 /**
  * Deletes an existing GoodsType model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if (!$this->is_access('goodstype/delete')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $this->findModel($id)->delete();
     // 删除类型的属性
     \common\models\Attribute::deleteAll(['cat_id' => $id]);
     return $this->redirect(['index']);
 }
예제 #2
0
 public static function getAttributeId($attrib_name = '')
 {
     $model = Attribute::findOne(['name' => $attrib_name]);
     if ($model) {
         return $model->id;
     } else {
         return 0;
     }
 }
예제 #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAttr()
 {
     return $this->hasOne(Attribute::className(), ['attr_id' => 'attr_id']);
 }
예제 #4
0
 /**
  * 获取商品类型的属性表单
  * @param int $cat_id 商品类型id
  * @param int $goods_id
  */
 public function actionGetattribute($cat_id, $goods_id = 0)
 {
     $Attribute = new Attribute();
     echo $Attribute->attributeHtml($cat_id, $goods_id);
 }
예제 #5
0
 /**
  * 批量删除
  */
 public function actionDeleteall()
 {
     if (!$this->is_access('attribute/delete')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     if (Yii::$app->request->isPost) {
         $attr_id = $_POST['id'];
         if (is_array($attr_id)) {
             $attr_id = '(' . implode(',', $attr_id) . ')';
             Attribute::deleteAll('attr_id in ' . $attr_id);
             Yii::$app->session->setFlash('success', '删除成功');
         }
     }
     $this->redirect(Yii::$app->request->getReferrer());
 }
예제 #6
0
 public function actionAjaxattr()
 {
     if (Yii::$app->request->post('type_id')) {
         //获取类型id
         $type_id = Yii::$app->request->post('type_id');
         $attrs = Attribute::find()->where(['type_id' => $type_id])->all();
         //根据获取到的属性值构造html字符串
         $html = '';
         foreach ($attrs as $v) {
             $html .= "<div class='form-group'>";
             $html .= "<label class='col-lg-4 control-label'>" . $v['attr_name'] . "</label>";
             $html .= "<div class='col-lg-3'>";
             $html .= "<input type='hidden' name='attr_id_list[]' value='" . $v['attr_id'] . "'>";
             switch ($v['attr_input_type']) {
                 case 0:
                     # 文本框
                     $html .= "<input name='attr_value_list[]'' type='text' size='40' class='form-control'>";
                     break;
                 case 1:
                     # 下拉列表
                     $arr = explode(PHP_EOL, $v['attr_value']);
                     $html .= "<select name='attr_value_list[]' class='form-control'>";
                     $html .= "<option value=''>请选择...</option>";
                     foreach ($arr as $v) {
                         $html .= "<option value='{$v}'>{$v}</option>";
                     }
                     $html .= "</select>";
                     break;
                 case 2:
                     //多行文本框
                     $html .= "<textarea placeholder='...'' rows='4' name='attr_value_list[]' class='form-control'></textarea>";
                     break;
                 default:
                     $html .= "请选择商品类型";
                     break;
             }
             $html .= "</div>";
             $html .= "</div>";
         }
         echo $html;
     }
 }
예제 #7
0
 public function actionAttrdel($id, $type_id)
 {
     $model = Attribute::findOne($id);
     if ($model->delete()) {
         Yii::$app->getSession()->setFlash('info', '操作删除成功!');
         return $this->redirect(['attrlist', 'type_id' => $type_id]);
     }
 }