示例#1
0
 public static function mergeProduct($sourceId, $disId)
 {
     $resultInfo = array();
     $checkMergeResult = self::checkMergeable($sourceId, $disId);
     if (CommonService::$ApiResult['FAIL'] == $checkMergeResult['status']) {
         return $checkMergeResult;
     }
     $sourceProductInfo = Product::model()->findByPk($sourceId);
     $moduleInfo = array();
     $moduleInfo['name'] = $sourceProductInfo['name'];
     $moduleInfo['display_order'] = 0;
     $moduleInfo['product_id'] = $disId;
     $createModuleResult = ProductModuleService::editProductModule($moduleInfo);
     if (CommonService::$ApiResult['FAIL'] == $createModuleResult['status']) {
         return $createModuleResult;
     }
     $newModuleId = $createModuleResult['detail']['id'];
     try {
         //update top layer module
         Yii::app()->db->createCommand()->setText('update {{product_module}} set product_id=' . $disId . ',grade=grade+1' . ',full_path_name=CONCAT(' . Yii::app()->db->quoteValue($sourceProductInfo['name'] . ProductModule::MODULE_SPLITTER) . ',full_path_name),parent_id=' . $newModuleId . ' where product_id=' . $sourceId . ' and parent_id is null')->execute();
         //update other layer module
         Yii::app()->db->createCommand()->setText('update {{product_module}} set product_id=' . $disId . ',grade=grade+1' . ',full_path_name=CONCAT(' . Yii::app()->db->quoteValue($sourceProductInfo['name'] . ProductModule::MODULE_SPLITTER) . ',full_path_name) where product_id=' . $sourceId . ' and parent_id is not null')->execute();
         $infoTypeArr = array(Info::TYPE_BUG, Info::TYPE_CASE, Info::TYPE_RESULT);
         foreach ($infoTypeArr as $infoType) {
             Yii::app()->db->createCommand()->setText('update {{' . $infoType . '_info}} set product_id=' . $disId . ',productmodule_id=' . $newModuleId . ' where product_id=' . $sourceId . ' and productmodule_id is null')->execute();
             Yii::app()->db->createCommand()->setText('update {{' . $infoType . '_info}} set product_id=' . $disId . ' where productmodule_id in( select id from {{product_module}} where product_id=' . $disId . ')')->execute();
             $fieldNameStr = FieldConfigService::getActiveCustomFieldName($disId, $infoType);
             Yii::app()->db->createCommand()->setText('insert into {{etton' . $infoType . '_' . $disId . '}} (' . $fieldNameStr . ') select ' . $fieldNameStr . ' from {{etton' . $infoType . '_' . $sourceId . '}}')->execute();
             Yii::app()->db->createCommand()->setText('drop table if exists {{etton' . $infoType . '_' . $sourceId . '}} ')->execute();
         }
         //delete related record
         $relatedTableNameArr = array('field_config', 'map_product_user', 'map_product_group', 'user_query', 'user_template');
         foreach ($relatedTableNameArr as $relatedTableName) {
             Yii::app()->db->createCommand()->setText('delete from {{' . $relatedTableName . '}} where product_id =' . $sourceId)->execute();
         }
         //delete be merged product
         Yii::app()->db->createCommand()->setText('delete from {{product}} where id =' . $sourceId)->execute();
     } catch (Exception $e) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $e->getMessage();
         return $resultInfo;
     }
     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
     return $resultInfo;
 }
示例#2
0
 public function actionIndex()
 {
     self::checkEditable();
     $productId = $_GET['product_id'];
     $productInfo = Product::model()->findByPk($_GET['product_id']);
     $this->breadcrumbs = array(Yii::t('Product', 'Back To Product List') => array('/product/index'), $productInfo->name . Yii::t('ProductModule', 'Edit Product Modules'));
     $selectedId = 0;
     $selectedParentId = 0;
     $addedModel = new ProductModule();
     $addedModel->product_id = $productId;
     $addedModel->parent_id = 0;
     $addedModel->display_order = 0;
     $moduleOptionArr = ProductModuleService::getSelectModuleListOption($productId);
     if (isset($_GET['selected_id']) && 0 != $_GET['selected_id']) {
         $selectedId = $_GET['selected_id'];
         $editedModel = ProductModuleService::loadModel($selectedId);
         if ($editedModel->parent_id != null) {
             $selectedParentId = $editedModel->parent_id;
         }
         $addedModel->parent_id = $_GET['selected_id'];
     } else {
         $editedModel = new ProductModule();
     }
     if (isset($_POST['ProductModule'])) {
         $returnJson = array();
         $productModuleInfo = $_POST['ProductModule'];
         $productModuleInfo['product_id'] = $productId;
         //delete product module
         if (!empty($_POST['is_delete'])) {
             $editResult = ProductModuleService::deleteModule($_POST['ProductModule']['id']);
         } else {
             if (!empty($_POST['separate_as_product'])) {
                 $editResult = ProductModuleService::separateModule($_POST['ProductModule']['id']);
             } else {
                 if (isset($_POST['ProductModule']['id'])) {
                     if (!empty($_POST['is_delete'])) {
                         ProductModule::model()->findByPk($_POST['ProductModule']['id'])->delete();
                     }
                     $editedModel->attributes = $_POST['ProductModule'];
                     $productModuleInfo['add_owner_name'] = $productModuleInfo['owner_name'];
                 } else {
                     $addedModel->attributes = $_POST['ProductModule'];
                     $productModuleInfo['owner_name'] = $productModuleInfo['add_owner_name'];
                     if (!empty($_GET['selected_id'])) {
                         $productModuleInfo['parent_id'] = $_GET['selected_id'];
                     } else {
                         $productModuleInfo['parent_id'] = 0;
                     }
                 }
                 $editResult = ProductModuleService::editProductModule($productModuleInfo);
             }
         }
         $returnJson['status'] = $editResult['status'];
         if ($editResult['status'] == CommonService::$ApiResult['FAIL']) {
             if (isset($_POST['ProductModule']['id'])) {
                 $editedModel->addErrors($editResult['detail']);
                 $returnJson['formid'] = 'edit';
             } else {
                 $addedModel->addErrors($editResult['detail']);
                 $returnJson['formid'] = 'add';
             }
             $returnJson['detail'] = $editResult['detail'];
         } else {
             if (!empty($_POST['is_delete'])) {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module deleted successfully');
             } elseif (!empty($_POST['separate_as_product'])) {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module separated as product successfully');
             } elseif (isset($_POST['ProductModule']['id'])) {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module edited successfully');
             } else {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module added successfully');
             }
         }
         echo json_encode($returnJson);
         return;
     }
     $this->render('index', array('productId' => $productInfo->id, 'selectedId' => $selectedId, 'selectedParentId' => $selectedParentId, 'productName' => $productInfo->name, 'addedModel' => $addedModel, 'editedModel' => $editedModel, 'moduleOptionArr' => $moduleOptionArr));
 }