public function actionUpdate($id) { $params = $this->getParams(); $accountId = $this->getAccountId(); if (empty($params['name'])) { throw new BadRequestHttpException("category required"); } $productCategoryInfo = ProductCategory::findByPk($id); if (ProductCategory::RESERVATION_CATEGORY_NAME == $productCategoryInfo->name) { throw new InvalidParameterException(Yii::t('product', 'can_not_update')); } if (ProductCategory::RESERVATION_CATEGORY_NAME == $params['name']) { throw new InvalidParameterException(Yii::t('product', 'categoryName_isUsed')); } $result = CategoryProperty::checkUniqueName('category', $params['name'], $id, $accountId, ''); if (false === $result) { throw new InvalidParameterException([$id => Yii::t("product", "categoryName_isUsed")]); } $where = ['_id' => new \MongoId($id), 'accountId' => $accountId, 'isDeleted' => false]; ProductCategory::updateAll(['name' => $params['name']], $where); Product::updateAll(['category.name' => $params['name']], ['category.id' => new \MongoId($id)]); return ProductCategory::findByPk($id); }
/** * update the property * @param $id,int,proprty id * @param $params,array * @param $accountId,MongoId */ public static function updateProperty($id, $params, $accountId) { //update category property $where = ['accountId' => $accountId, '_id' => new \MongoId($id), 'properties.id' => $params['propertyId']]; $categoryPropertyInfo = ProductCategory::findOne($where); if ($categoryPropertyInfo) { //only update the name and isrequired $addproperties = []; if (!empty($categoryPropertyInfo->properties)) { $where = ['properties.id' => $params['propertyId']]; ProductCategory::updateAll(['$set' => ['properties.$.name' => $params['name'], 'properties.$.isRequired' => $params['isRequired']]], $where); } //check whether have properties $productInfo = Product::findOne(['category.id' => new \MongoId($id)]); if ($productInfo) { $where = ['category.properties.id' => $params['propertyId']]; $updateData = ['category.properties.$.name' => $params['name'], 'category.properties.$.value' => $params['defaultValue']]; Product::updateAll(['$set' => $updateData], $where); unset($productInfo); } unset($where); return $categoryPropertyInfo; } else { throw new BadRequestHttpException("categoryId or propertyId invalid"); } }
public function changeProductStatus($productId) { $product = Product::findByPk($productId); if (false == $product['isBindCode']) { Product::updateAll(['isBindCode' => true], ['_id' => $productId]); } }
public function actionCreate() { $params = $this->getParams(); if (empty($params['productId']) || empty($params['codeType'])) { throw new BadRequestHttpException('missing param'); } $product = Product::findByPk(new \MongoId($params['productId'])); if (empty($product)) { throw new BadRequestHttpException(Yii::t("product", "product_deleted")); } $accountId = $this->getAccountId(); if ($params['codeType'] == 'generate') { $count = intval($params['count']); if ($count <= 0) { throw new InvalidParameterException(['promotionCodeCount' => Yii::t('product', 'count_too_small')]); } if ($count > PromotionCode::BIGGEST_COUNT) { throw new InvalidParameterException(['promotionCodeCount' => Yii::t('product', 'count_too_large')]); } if (!empty($product->batchCode) && $product->batchCode >= 36) { throw new InvalidParameterException(Yii::t('product', 'batch_code_limit')); } $jobArgs = ['accountId' => $accountId . '', 'productId' => $params['productId'], 'count' => $count, 'type' => 'generate', 'description' => 'Direct: Generate promotion codes']; $jobId = Yii::$app->job->create('backend\\modules\\product\\job\\PromotionCode', $jobArgs); Product::updateAll(['$inc' => ['batchCode' => 1]], ['_id' => $product->_id]); //update product batchcode } else { if (empty($params['filename']) && $params['import']) { throw new BadRequestHttpException('missing param filename'); } $jobArgs = ['accountId' => $accountId . '', 'productId' => $params['productId'], 'type' => 'insert', 'import' => $params['import'], 'filename' => $params['filename'], 'description' => 'Direct: Import promotion codes']; $jobId = Yii::$app->job->create('backend\\modules\\product\\job\\PromotionCode', $jobArgs); } return ['message' => 'OK', 'data' => $jobId]; }
/** * support multiple id to delete the product category * @param $id,string * @param $accountId,MongoId */ public static function deleteProductCategory($id, $accountId) { $idList = self::getCategoryList($id, ','); $where = array_merge(['in', 'category.id', $idList], ['accountId' => $accountId, 'isDeleted' => false]); Product::updateAll(['category' => []], $where); }