public function actionView($id) { $id = new MongoId($id); $store = Store::findByPk($id); if (empty($store)) { throw new BadRequestHttpException(Yii::t('common', 'data_error')); } $location = $store->getStoreLocation(); $result = $store->toArray(); $result['location'] = $location; $accountId = $this->getAccountId(); $result['storeGoods'] = StoreGoods::getTotal($id, $accountId); $result['staff'] = Staff::getTotal($id, $accountId); return $result; }
public function actionIndex() { $params = $this->getQuery(); $accountId = $this->getAccountId(); $provider = Product::search($params, $accountId); if (!empty($params['storeId'])) { $products = []; foreach ($provider->getModels() as $product) { $storeGoods = StoreGoods::getByProductAndStore($product->_id, new MongoId($params['storeId'])); $product = $this->serializeData($product); $product['isStoreGoods'] = !empty($storeGoods); $products[] = $product; } $provider->setModels($products); } return $provider; }
public function actionDelete($id) { $params = $this->getParams(); $accountId = $this->getAccountId(); $idstrList = explode(',', $id); $ids = []; foreach ($idstrList as $perId) { $ids[] = new \MongoId($perId); } //check the store goods are not on shelves if (!empty(StoreGoods::getOnSaleByIds($ids, $accountId))) { throw new InvalidParameterException(Yii::t('store', 'delete_on_shelves')); } $condition = ['_id' => ['$in' => $ids]]; if (StoreGoods::deleteAll($condition) == false) { throw new ServerErrorHttpException(Yii::t('common', 'delete_fail')); } Yii::$app->getResponse()->setStatusCode(204); }
public static function updateStatusByIds($storeGoodsIds, $status, $onSaleTime, $offShelfTime = null) { $attributes = ['status' => $status, 'onSaleTime' => $onSaleTime]; if ($offShelfTime !== null) { $attributes['offShelfTime'] = $offShelfTime; } StoreGoods::updateAll(['$set' => $attributes], ['_id' => ['$in' => $storeGoodsIds]]); }
/** * @args {"description": "Delay: Store goods on sale every minute"} */ public function perform() { StoreGoods::updateAll(['$set' => ['status' => StoreGoods::STATUS_ON]], ['status' => StoreGoods::STATUS_OFF, 'onSaleTime' => ['$lte' => new MongoDate(strtotime('+1 minute'))]]); }
public function delete($productIds) { Goods::deleteAll(['productId' => ['$in' => $productIds]]); StoreGoods::deleteAll(['productId' => ['$in' => $productIds]]); }
/** * Update the status of goods for store module. */ public function actionStoreGoodsSale() { $result = StoreGoods::updateAll(['$set' => ['status' => StoreGoods::STATUS_ON]], ['status' => StoreGoods::STATUS_OFF, 'onSaleTime' => ['$lte' => new \MongoDate(strtotime('+1 minute'))]]); echo $result; }