public function actionUpdate($id) { $params = $this->getParams(); if (empty($params['status']) || !isset($params['price'])) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $storeGoods = StoreGoods::findByPk(new \MongoId($id)); if (empty($storeGoods)) { throw new InvalidParameterException(Yii::t('store', 'invalid_goods_id')); } $storeGoods->pictures = empty($params['pictures']) ? $storeGoods->pictures : $params['pictures']; $price = floatval($params['price']); if ($price <= 0) { throw new InvalidParameterException(Yii::t('store', 'price_error')); } $storeGoods->price = $price; if ($params['status'] == StoreGoods::STATUS_ON) { $storeGoods->status = StoreGoods::STATUS_ON; $storeGoods->onSaleTime = new \MongoDate(); } else { if ($params['status'] == StoreGoods::STATUS_OFF && isset($params['onSaleTime']) && $params['onSaleTime'] !== '') { if (time() > TimeUtil::ms2sTime($params['onSaleTime'])) { throw new InvalidParameterException(['onSaleTime' => \Yii::t('product', 'not_less_than_current')]); } else { $storeGoods->status = StoreGoods::STATUS_OFF; $storeGoods->onSaleTime = new \MongoDate(TimeUtil::ms2sTime($params['onSaleTime'])); } } else { if ($params['status'] == StoreGoods::STATUS_OFF && (!isset($params['onSaleTime']) || $params['onSaleTime'] === '')) { $storeGoods->status = StoreGoods::STATUS_OFF; $storeGoods->onSaleTime = null; $storeGoods->offShelfTime = new \MongoDate(); } else { throw new BadRequestHttpException(Yii::t('common', 'data_error')); } } } if ($storeGoods->save(true)) { $storeGoods->_id = (string) $storeGoods->_id; return $storeGoods; } else { throw new ServerErrorHttpException(Yii::t('common', 'save_fail')); } }