[ 'class' => LoginBehavior::className(), ], ]); } public function actionIndex() { if(\Yii::$app->request->isAjax){ $form = new CommonIntegralMallGoodsListForm(); $form->attributes = \Yii::$app->request->get(); $form->cx_mch_id = $this->cx_mch_id; $form->plugin_sign = SysConst::$cxPluginSceneIntegralMall; $form->setFields('g.id,g.goods_hub_id,g.status,g.price,g.goods_stock,g.virtual_sales,g.sort,g.created_at,g.payment_people,g.payment_amount,g.payment_num,g.payment_order,g.sales,g.viewed_count,gh.name,gh.cover_pic,gh.unit,gh.type'); $data = $form->search(); return $this->responseHandler($data); } $cat_list = Cat::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'type' => Cat::TYPE_INTEGRAL_GOODS, ]) ->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC]) ->select('id,name')->asArray()->all(); return $this->render('index',[ 'cat_list' => $cat_list ]); } public function actionEdit($id = 0) { $model = Goods::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'id' => $id, 'plugin_sign' => SysConst::$cxPluginSceneIntegralMall ]); if($model == null) $model = new Goods(); if(\Yii::$app->request->isPost){ $form = new CommonIntegralMallGoodsEditForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->plugin_sign = SysConst::$cxPluginSceneIntegralMall; $form->model = $model; $form->type = 0;//默认实体商品 $data = $form->save(); return $this->responseHandler($data); } $cat_list = Cat::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'type' => Cat::TYPE_INTEGRAL_GOODS, ]) ->select('id,name')->asArray()->all(); $cat_list = Cat::getTagTreeArray(0, Cat::TYPE_INTEGRAL_GOODS, $this->cx_mch_id); foreach($cat_list as $index => $item){ $checked = false; $temp = GoodsCat::findOne([ 'goods_hub_id' => $model->isNewRecord ? 0 : $model->goodsHub->id, 'cat_id' => $item['id'], 'is_delete' => 0 ]); $checked = $temp == null ? false : true; $item['checked'] = $checked; $item['prefix'] = str_repeat("-", 2 * $item['level']); $cat_list[$index] = $item; } $attr = []; $attr_groups = []; if($model->use_attr == 1){ $attr_groups = !empty($model->attr_groups) ? json_decode($model->attr_groups,true) : []; $attr = GoodsAttr::find()->alias('ga') ->leftJoin(['imga' => IntegralMallGoodsAttr::tableName()],'imga.goods_attr_id=ga.id') ->where([ 'ga.goods_id' => $model->id, 'ga.is_delete' => 0 ]) ->select('ga.id,ga.price,ga.stock,ga.serial_no,ga.weight,ga.cover_pic,ga.sign_id,imga.integral_num') ->asArray()->all(); foreach($attr as $index => $item){ $item['attr_list'] = []; $sign_ids = explode(':', $item['sign_id']); foreach ($sign_ids as $attr_id){ $attr_info = $this->getAttrInfo($attr_id, $attr_groups); if(!empty($attr_info)){ $item['attr_list'][] = $attr_info; } } $attr[$index] = $item; } } $return_url = \Yii::$app->request->referrer; return $this->render('edit', [ 'model' => $model, 'return_url' => $return_url, 'cat_list' => $cat_list, 'attr' => $attr, 'attr_groups' => $attr_groups ]); } private function getAttrInfo($attr_id, $attr_groups) { $attr_info = []; foreach ($attr_groups as $index => $attr_group){ foreach ($attr_group['attr_list'] as $j => $attr ){ if($attr['attr_id'] == $attr_id){ $attr_info['attr_group_id'] = $attr_group['attr_group_id']; $attr_info['attr_group_name'] = $attr_group['attr_group_name']; $attr_info['attr_id'] = $attr['attr_id']; $attr_info['attr_name'] = $attr['attr_name']; return $attr_info; } } } return $attr_info; } public function actionDelete() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonGoodsActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->plugin_sign = SysConst::$cxPluginSceneIntegralMall; $data = $form->delete(); return $this->responseHandler($data); } public function actionOnline() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonGoodsActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->plugin_sign = SysConst::$cxPluginSceneIntegralMall; $data = $form->online(); return $this->responseHandler($data); } public function actionOffline() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonGoodsActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->plugin_sign = SysConst::$cxPluginSceneIntegralMall; $data = $form->offline(); return $this->responseHandler($data); } public function actionCat() { if(\Yii::$app->request->isAjax){ $form = new CommonCatListForm(); $form->attributes = \Yii::$app->request->get(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->search(); return $this->responseHandler($data); } return $this->render('cat'); } public function actionCatEdit($id = 0) { $model = Cat::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'id' => $id, 'type' => Cat::TYPE_INTEGRAL_GOODS, ]); if($model == null){ $model = new Cat(); $model->status = 1; } if(\Yii::$app->request->isPost){ $form = new CommonCatEditForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->model = $model; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->save(); return $this->responseHandler($data); } $cat_ids = []; $cat_ids[] = $model->isNewRecord ? 0 : $model->id; $parent_list = Cat::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'type' => Cat::TYPE_INTEGRAL_GOODS, ]) ->andWhere([ 'NOT IN', 'id', $cat_ids ]) ->select('id,name')->asArray()->all(); $is_has_parent = false;//开启是否有父节点 $parent_list = $is_has_parent ? $parent_list : []; array_unshift($parent_list,['id' => 0, 'name' => '无父节点']); $return_url = \Yii::$app->request->referrer; return $this->render('cat-edit', [ 'model' => $model, 'return_url' => $return_url, 'parent_list' => $parent_list ]); } public function actionCatDelete() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->delete(); return $this->responseHandler($data); } public function actionCatShow() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->show(); return $this->responseHandler($data); } public function actionCatHide() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->hide(); return $this->responseHandler($data); } public function actionCatOpen() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->open(); return $this->responseHandler($data); } public function actionCatClose() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_INTEGRAL_GOODS; $data = $form->close(); return $this->responseHandler($data); } }