/** * 获取商品对象 */ public function getGoods() { if ($this->getIsNewRecord()) { return []; } $data = Goods::findOne($this->getAttribute('gid')); return $data; }
/** * goodsIdList = [goodID => quantity] * @param int $orderID * @param array $goodsIdList */ public static function saveOrderItems($orderID, $goodsIdList) { foreach ($goodsIdList as $id => $quantity) { $orderItemModel = new OrderItems(); $orderItemModel->order_id = $orderID; $orderItemModel->goods_id = $id; $orderItemModel->multiplicity = $quantity; $orderItemModel->firm_id = Goods::findOne($id)->firm_id; $orderItemModel->save(); } }
/** * Render product module mobile pages */ public function actionProduct($page) { if ($page === 'detail') { $goodsId = Yii::$app->request->get('goodsId'); Goods::updateAll(['$inc' => ['clicks' => 1]], ['_id' => new \MongoId($goodsId)]); } if ($page === 'list' || $page === 'detail') { $this->registerBodyJsFile(self::VENDOR_PATH . 'Swiper/dist/js/swiper.min.js'); } $js = '$($(".mb-breadcrumb-back").click(function(){window.history.back()}))'; $this->view->registerJs($js, View::POS_END); $params = Yii::$app->request->get(); $isPreview = !empty($params['preview']); return $this->renderPage($page, false, !$isPreview, !$isPreview); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $pagination = 10) { $query = Goods::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => $pagination]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['goods_id' => $this->goods_id, 'shop_price' => $this->shop_price, 'promote_price' => $this->promote_price, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'goods_sn', $this->goods_sn])->andFilterWhere(['like', 'goods_name', $this->goods_name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * @param integer $firmID * * @return ActiveDataProvider */ public function search($params, $firmID) { /* if($params != []){ var_dump($params);die();}*/ $query = Goods::find()->where(['like', 'firm_id', $firmID]); //-> orderBy('id ASC'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['is_active' => $this->is_active]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'price_with_vat', $this->price_with_vat])->andFilterWhere(['like', 'price_without_vat', $this->price_without_vat])->andFilterWhere(['like', 'increment_price', $this->increment_price])->andFilterWhere(['like', 'percentage', $this->percentage])->andFilterWhere(['like', 'expiration_date', $this->expiration_date])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'picture', $this->picture]); return $dataProvider; }
public static function del($id) { $connection = Yii::$app->db; //开启事务 $transaction = $connection->beginTransaction(); try { Goods::findOne($id)->delete(); GoodsColor::deleteAll(['gid' => $id]); GoodsInventory::deleteAll(['gid' => $id]); //提交 $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollBack(); return false; } }
public function actionIndex() { $request = Yii::$app->getRequest(); $id = current($request->get()); //查询商品数据 $goods = Goods::findOne($id); //查询收藏数量 $collectNum = Collect::find()->where(['gid' => $id])->count('id'); //颜色 $goodsColor = GoodsColor::findAll(['gid' => $id]); $waresDir = 'static/uploaded/wares/i' . $id; //读取放大镜图片 $files = scandir($waresDir); foreach ($files as $file) { if ($file == '.' || $file == '..' || $file == 'thumbnail') { continue; } $waresFilePath[] = $waresDir . '/' . $file; } $imgextraDir = 'static/uploaded/imgextra/i' . $id; //读取介绍图片 $files = scandir($imgextraDir); foreach ($files as $file) { if ($file == '.' || $file == '..' || $file == 'thumbnail') { continue; } $imgextraFilePath[] = $imgextraDir . '/' . $file; } //查询商品评论 $discuss = Discuss::findAll(['gid' => $id]); // 查询出商品库存总数和尺码 $inventory = GoodsInventory::findAll(['gid' => $id]); $num = 0; foreach ($inventory as $key => $value) { $num += $value['inventory']; $size[$value['size']] = $value['size']; } $data = ['goods' => $goods, 'size' => $size, 'inventory' => $num, 'discuss' => $discuss, 'color' => $goodsColor, 'collectNum' => $collectNum, 'waresFile' => $waresFilePath, 'imgextraFile' => $imgextraFilePath]; // print_r($goods);exit; return $this->render('index', $data); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $tp = 0) { //if(Yii::$app->user->can('operatorSQL')){ if ($tp == 0) { $query = Goods::find(); } else { $query = Goods::find()->where(['typeprices_id' => $tp]); } //print_r($query); //die(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->pagination = FALSE; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['good_id' => $this->good_id, 'good_price' => $this->good_price, 'typeprices_id' => $this->typeprices_id]); $query->andFilterWhere(['like', 'good_name', $this->good_name])->andFilterWhere(['like', 'good_logo', $this->good_logo]); return $dataProvider; }
/** * Finds the Goods model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Goods the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Goods::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function delete($productIds) { Goods::deleteAll(['productId' => ['$in' => $productIds]]); StoreGoods::deleteAll(['productId' => ['$in' => $productIds]]); }
public function getGoods() { return $this->hasOne(Goods::className(), ['good_id' => 'good_id']); }
public static function getGoodsName($params, $accountId) { $where = ['accountId' => $accountId, 'productId' => ['$in' => $params['id']]]; return Goods::findAll($where); }
/** * 获取商品对象 * @return $object array */ public static function getGoods() { return Goods::findAll(['is_show' => 0]); }
/** * get the name from product by string * */ public function actionName() { $params = $this->getQuery(); if (empty($params['id'])) { throw new BadRequestHttpException('missing params'); } $accountId = $this->getAccountId(); if (strrpos($params['id'], ',') !== false) { $ids = explode(',', $params['id']); foreach ($ids as $key => $id) { $ids[$key] = new \MongoId($id); } $params['id'] = $ids; } else { $params['id'] = [new \MongoId($params['id'])]; } $products = Goods::getGoodsName($params, $accountId); $names = []; foreach ($products as $product) { $names[] = $product->productName; } return $names; }
public function actionDetails() { $session = new Sitesession(); $user_id = $session->getUserId(); $goods = $session->getGoods($user_id); $order_id = $session->getOrderId(); $order = null; if (!empty($order_id)) { $order = Orders::findOne($order_id); } $user = null; if ($user_id) { //获取user_id用户信息 /*$connection = \Yii::$app->db; $command = $connection->createCommand('SELECT * FROM customer WHERE id='.$user_id); $user = $command->queryOne();*/ $user = Customer::findOne($user_id); } $count = 0; if (is_array($goods) && !empty($goods)) { /*$str = ''; foreach ($goods as $key => $value) { if(empty($str)) { $str = $str." ".$value; } else { $str = $str.", ".$value; } } */ $count = count($goods); //获取goods $connection = \Yii::$app->db; $transaction = $connection->beginTransaction(); try { // 所有的查询都在主服务器上执行 //$goods = $connection->createCommand('SELECT * FROM goods WHERE goods_id in ('.$str.')')->queryAll(); $goods = Goods::findAll($goods); $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); throw $e; } } else { $goods = false; } return $this->render('details', ['user' => $user, 'goods' => $goods, 'count' => $count, 'order' => $order]); }
/** * The default implementation returns the names of the columns whose values have been populated into Product. */ public function fields() { return array_merge(parent::fields(), ['sku', 'name', 'pictures', 'category' => function () { $categorys = $this->category; if (!empty($categorys['id'])) { $categorys['id'] = $categorys['id'] . ''; } return $categorys; }, 'intro' => function () { return ProductInfo::findByPk($this->_id)['intro']; }, 'isAssigned' => function () { if ($this->isBindCode) { return true; } else { return false; } }, 'codeNum' => function () { return PromotionCode::count(['productId' => $this->_id]); }, 'isSelected' => function () { $goods = Goods::findOne(['productId' => $this->_id]); if (empty($goods)) { return false; } else { return true; } }]); }
/** * @args {"description": "Delay: Goods on sale every minute"} * @see \backend\components\resque\SchedulerJob::perform() */ public function perform() { Goods::updateAll(['$set' => ['status' => Goods::STATUS_ON]], ['status' => Goods::STATUS_OFF, 'onSaleTime' => ['$lte' => new MongoDate(strtotime('+1 minute'))]]); }
<div class="listofgoods-form"> <?php $form = ActiveForm::begin(); ?> <?php if ($orders_order_id != 0) { echo '<p> Номер текущего заказа ' . $orders_order_id . '</p>'; } else { echo $form->field($model, 'orders_order_id')->textInput(['value' => $orders_order_id]); } ?> <?php echo $form->field($model, 'goods_good_1c_id')->dropDownList(ArrayHelper::map(Goods::find()->where(['typeprices_id' => $tp])->all(), 'good_id', 'good_name'), ['prompt' => 'Выберите товар...']); ?> <?php echo $form->field($model, 'good_count')->textInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Готово' : 'Редактировать', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * goodsIdList = [goodID => quantity] * @param array $goodsIdList * @return int $orderID */ public static function saveOrder($goodsIdList) { /* all the goods in $goodsIdList are ordered from the same firm */ $goodID = key($goodsIdList); $firmID = Goods::findOne($goodID)->firm_id; $totalGoods = $priceWithVat = $priceWithoutVat = $incrementPrice = 0; foreach ($goodsIdList as $id => $quantity) { $totalGoods += $quantity; $good = Goods::findOne($id); $priceWithVat += $good->price_with_vat * $quantity; $priceWithoutVat += $good->price_without_vat * $quantity; $incrementPrice += $good->increment_price * $quantity; } $order = new Orders(); $order->firm_id = $firmID; $order->price_with_vat = $priceWithVat; $order->price_without_vat = $priceWithoutVat; $order->increment_price = $incrementPrice; $order->total_types = count($goodsIdList); $order->total_goods = $totalGoods; $order->save(); $orderID = $order->getPrimaryKey(); return $orderID; }
public function actionDelete($id) { $idstrList = explode(',', $id); $ids = []; foreach ($idstrList as $perId) { $ids[] = new MongoId($perId); } $where = ['_id' => ['$in' => $ids]]; $goodsWhere = ['productId' => ['$in' => $ids]]; $result = Product::findOne(array_merge($where, ['isBindCode' => true])); if (!empty($result)) { throw new BadRequestHttpException(Yii::t('product', 'can_not_delete_before_promocode')); } if (!empty(Campaign::getByProductIds($ids)) || !empty(Goods::findOne($goodsWhere))) { throw new BadRequestHttpException(Yii::t('product', 'can_not_delete')); } if (Product::deleteAll($where) == false) { throw new ServerErrorHttpException('Failed to delete the object for unknown reason.'); } //delete the product intro ProductInfo::deleteAll($where); //delete goods and storeGoods $this->attachBehavior('ProductBehavior', new ProductBehavior()); $this->delete($ids); Yii::$app->getResponse()->setStatusCode(204); }
/** * Update the status of goods for goods module. */ public function actionGoodsSale() { $result = Goods::updateAll(['$set' => ['status' => Goods::STATUS_ON]], ['status' => Goods::STATUS_OFF, 'onSaleTime' => ['$lte' => new \MongoDate(strtotime('+1 minute'))]]); echo $result; }