public function actionIndexadd() { if (Yii::$app->user->isGuest) { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('/site/login', ['model' => $model]); } } else { $Order = new Order(); $Order->user_id = Yii::$app->user->identity->id; $Order->date_time = date('Y-m-d H:i:s'); $Order->status_id = '1'; $Order->save(); $Card = new CardList(); $Products = $Card->getCardAndCardList(Yii::$app->user->identity->id); $Ord = new Order(); $order_id = $Ord->GetOrderId(Yii::$app->user->identity->id); for ($i = 0; $i < sizeof($Products); $i++) { $Orderlist = new Orderlist(); $Orderlist->order_id = $order_id[0]['MAX(`order_id`)']; $Orderlist->product_id = $Products[$i]['product_id']; $Orderlist->quantity = $Products[$i]['quantity']; $Orderlist->save(); } $card = new Card(); $card->DeleteCardId(Yii::$app->user->identity->id); $order = $Ord->GetOrdersFromID(Yii::$app->user->identity->id); $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one(); return $this->render('index', ['user' => $user, 'order' => $order]); } }
public function actionCheckout() { if ($postData = Yii::$app->request->post()) { $model = new Product(); $order = new Order(); $order->shipping_address = $postData['address']; $order->city = $postData['city']; $order->country = $postData['country']; $order->postal_code = $postData['postal_code']; $order->status = 0; $order->save(); $order_id = $order->order_id; $items = []; foreach ($postData['qty'] as $key => $val) { $order_detail = new OrderDetail(); $order_detail->order_id = $order_id; $order_detail->prod_id = $postData['prod_id'][$key]; $order_detail->quantity = $postData['qty'][$key]; $order_detail->unit_price = $postData['prod_price'][$key]; $order_detail->unit_sum = $postData['prod_price'][$key] * $order_detail->quantity; $order_detail->save(); $item = new Item(); $item->setName($postData['prod_name'][$key])->setCurrency('USD')->setQuantity($val)->setPrice($postData['prod_price'][$key]); $items[] = $item; } $itemList = new ItemList(); $itemList->setItems($items); $payment = preparePaypal($itemList); print_r($items); } exit; }
public function actionOrder() { $order = new Order(); /** @var ShoppingCart $cart */ $cart = \Yii::$app->cart; /* @var $products Product[] */ $products = $cart->getPositions(); if ($order->load(\Yii::$app->request->post()) && $order->validate()) { $transaction = $order->getDb()->beginTransaction(); $order->save(false); // part of the transaction; foreach ($products as $product) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->product_id = $product->id; $orderItem->title = $product->title; $orderItem->price = $product->getPrice(); $orderItem->quantity = $product->getQuantity(); if (!$orderItem->save(false)) { $transaction->rollBack(); Yii::$app->session->setFlash('error', 'Your order cannot be accepted. Please contact us!'); $this->goBack(); } } $transaction->commit(); Yii::$app->cart->removeAll(); Yii::$app->session->addFlash('message', 'Thanks for your order. We\'ll contact you soon!'); // $order->sendEmail(); $this->redirect('/'); } return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $cart->getCost()]); }
public function actionOrder() { $session = Yii::$app->getSession(); $cart = $session->has('cart') ? $session->get('cart') : []; if (!$cart) { return $this->redirect(['index']); } $model = new Order(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (is_array($cart)) { foreach ($cart as $one_goods) { $order_goods = new OrderGoods(); $order_goods->goods_id = $one_goods['id']; $order_goods->count = $one_goods['count']; $order_goods->order_id = $model->id; $order_goods->save(); } } Yii::$app->session->remove('cart'); return $this->redirect(['index']); } else { $goods_id = ArrayHelper::getColumn($cart, 'id'); $goods = Goods::find()->where(['id' => $goods_id])->asArray()->indexBy('id')->all(); $amount = 0; foreach ($cart as $one_goods) { $amount += $one_goods['count'] * $goods[$one_goods['id']]['price']; } $model->price = $amount; return $this->render('order', ['cart' => $cart, 'model' => $model, 'amount' => $amount]); } }
public function actionCreate() { $model = new Order(); $model->send_at = date("Y-m-d H:i:s"); $model->is_new = 0; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->render('thank'); } else { return $this->render('create', ['model' => $model]); } }
/** * Сохраняем наш заказ и отправляем письмо пользователю. */ public function saveOrder($user, $product, $post) { $order = new Order(); $order->user_id = $user->id; $order->summ = $product['price']; $order->created_datetime = date('Y-m-d H:i:s'); $order->finished_datetime = date('Y-m-d H:i:s'); if ($order->save(false)) { \Yii::$app->mailer->compose(['html' => 'order-html', 'text' => 'order-text'], ['user' => $user, 'product' => $product, 'post' => $post])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' робот'])->setTo($user->email)->setSubject('Заказ товара - ' . \Yii::$app->name)->send(); return true; } return false; }
public function cancel($runValidation = true) { if ($runValidation && !$this->validate()) { return false; } if ($this->_order->status !== Order::STATUS_UNSHIPPED) { return false; } if ($this->_order->payment !== Order::PAYMENT_OFFLINE) { return false; } return $this->_order->cancel($this->msg); }
public function actionIndex() { $last15days = []; $last6Month = []; $numDataOrder = []; // 订单生成数据 $numDataVolume = []; // 营业额数据 $numDataCompleted = []; // 订单完成数据 $numDataVolumeMonth = []; // 每月营业额 $today = strtotime("00:00:00"); $todayEnd = strtotime("23:59:59"); for ($i = 0; $i < 15; $i++) { $timestrap = strtotime('-' . $i . ' days', $today); $timestrapEnd = strtotime('-' . $i . ' days', $todayEnd); $where = ['and', ['store_id' => Yii::$app->user->identity->store_id], ['>=', 'created_at', $timestrap], ['<=', 'created_at', $timestrapEnd]]; array_unshift($last15days, date('m/d', $timestrap)); array_unshift($numDataOrder, Order::find()->where($where)->count()); $data = OrderVolume::find()->select(['sum(volume) AS volume', 'count(*) AS count'])->where($where)->asArray()->one(); array_unshift($numDataVolume, $data['volume']); array_unshift($numDataCompleted, $data['count']); } for ($i = 0; $i < 6; $i++) { $timestrap = strtotime("first day of -{$i} month", $today); $timestrapEnd = strtotime("last day of -{$i} month", $todayEnd); $where = ['and', ['store_id' => Yii::$app->user->identity->store_id], ['>=', 'created_at', $timestrap], ['<=', 'created_at', $timestrapEnd]]; array_unshift($last6Month, date('Y/m', $timestrap)); array_unshift($numDataVolumeMonth, OrderVolume::find()->where($where)->sum('volume')); } $data2 = OrderVolume::find()->select(['sum(volume) AS volume', 'count(*) AS count'])->where(['store_id' => Yii::$app->user->identity->store_id])->asArray()->one(); return $this->render('index', ['model' => Yii::$app->user->identity->store, 'last15days' => $last15days, 'last6Month' => $last6Month, 'numDataOrder' => $numDataOrder, 'numDataVolume' => $numDataVolume, 'numDataCompleted' => $numDataCompleted, 'numDataVolumeMonth' => $numDataVolumeMonth, 'countOrder' => Order::getCountByStoreId(Yii::$app->user->identity->store_id), 'countCompleted' => $data2['count'], 'sumVolume' => $data2['volume']]); }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Order::find()->limit(10)->where(['status' => Order::STATUS_NEW])]); $productModel = new Product(['scenario' => 'create']); $productModel->date = date('Y-m-d H:i'); return $this->render('index', ['dataProvider' => $dataProvider, 'categoryModel' => new Category(), 'productModel' => $productModel]); }
/** * 完成超过2小时未收货的订单,每小时执行一次 * * @return string */ public function actionComplete() { $transaction = Yii::$app->db->beginTransaction(); try { $twelveHoursAgo = time() - 3600 * 2; $orders = Order::find()->where(['and', ['status' => Order::STATUS_SHIPPED], ['<=', 'created_at', $twelveHoursAgo]])->all(); $count1 = 0; $count2 = 0; foreach ($orders as $key => $order) { if ($order->complete()) { $count1++; } else { $count2++; } unset($orders[$key]); } $transaction->commit(); echo "{$count1} of orders affected by the execution, {$count2} fails.\n"; return static::EXIT_CODE_NORMAL; } catch (\Exception $e) { $transaction->rollBack(); echo $e->getMessage(); return static::EXIT_CODE_ERROR; } }
/** * Creates a form model given an order id. * * @param string $id * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if order id is not valid */ public function __construct($id, $config = []) { $this->_order = Order::find()->where(['and', ['id' => $id], ['user_id' => Yii::$app->user->id], ['<>', 'status', Order::STATUS_DELETED]])->one(); if (!$this->_order) { throw new InvalidParamException('您没有该订单!'); } parent::__construct($config); }
/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Order::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionSelect($id, $hallid) { $res = Order::find()->select('session_id')->where(['session_id' => $id])->one(); if (!empty($res)) { \Yii::$app->db->createCommand("UPDATE `order` SET `seats`=:status WHERE `session_id`=:id")->bindValue(':id', $id)->bindValue(':status', $hallid)->execute(); } else { \Yii::$app->db->createCommand()->insert('order', ['session_id' => $id, 'seats' => $hallid])->execute(); } }
public function actionIndex() { $orders = Order::find()->where(['user_id' => Yii::$app->user->id])->limit(2)->all(); $productIds = ArrayHelper::map(Favorite::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->asArray()->all(), 'product_id', 'product_id'); if (count($productIds)) { $favorites = Product::find()->where(['id' => $productIds])->limit(5)->all(); } $coupons = Coupon::find()->where(['and', 'user_id = ' . Yii::$app->user->id, 'used_at = 0', 'ended_at >= ' . time()])->all(); return $this->render('index', ['orders' => $orders, 'favorites' => isset($favorites) ? $favorites : null, 'coupons' => $coupons]); }
public function actionIndex() { $model = new OrderForm(); if ($model->load(Yii::$app->request->post()) && $model->makeOrder()) { $model->good_id++; // create a new order $order = new Order(); // set total price $model->total_price = Good::findAll($model->good_id)[0]->price * $model->goods_count; // fill order props foreach ($model as $key => $value) { $order->setAttribute($key, $value); } // save the order $order->save(); return $this->redirect('/index.php?r=order%2Forders'); } return $this->render('index', ['model' => $model, 'good_names' => HelperComponent::array_pluck('name', Good::find()->select('name')->all())]); }
public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'summ' => $this->summ, 'status_index' => $this->status_index, 'created_datetime' => $this->created_datetime, 'finished_datetime' => $this->finished_datetime]); return $dataProvider; }
/** * Creates a form model given an order sn. * * @param string $orderSn * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if order sn is empty or not valid */ public function __construct($orderSn, $config = []) { if (empty($orderSn) || !is_string($orderSn)) { throw new InvalidParamException('订单号错误!'); } $this->_order = Order::find()->where(['and', ['order_sn' => $orderSn], ['user_id' => Yii::$app->user->id], ['<>', 'status', Order::STATUS_DELETED]])->one(); if (!$this->_order) { throw new InvalidParamException('您没有该订单!'); } parent::__construct($config); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find()->orderBy('id DESC'); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'notes', $this->notes])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
public function actionOrder() { $cartPositions = Yii::$app->cart->getPositions(); if (!$cartPositions or $cartPositions === null) { return $this->redirect(['index']); } $dataProvider = new ArrayDataProvider(['allModels' => $cartPositions]); $model = new Order(); if ($model->load(Yii::$app->request->post())) { $model->status = 1; $model->total_cost = Yii::$app->cart->getCost(); $model->date = date('Y-m-d H:i'); $model->data = Yii::$app->cart->getSerialized(); if ($model->validate() && $model->save()) { Yii::$app->cart->removeAll(); return $this->render('orderSuccess', ['model' => $model]); } } return $this->render('order', ['model' => $model, 'dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $query->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); if ($this->load($params) && !$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'country' => $this->country, 'province' => $this->province, 'city' => $this->city, 'district' => $this->district, 'payment_method' => $this->payment_method, 'payment_status' => $this->payment_status, 'payment_id' => $this->payment_id, 'payment_fee' => $this->payment_fee, 'shipment_status' => $this->shipment_status, 'shipment_id' => $this->shipment_id, 'shipment_fee' => $this->shipment_fee, 'amount' => $this->amount, 'tax' => $this->tax, 'status' => $this->status, 'paid_at' => $this->paid_at, 'shipped_at' => $this->shipped_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'sn', $this->sn])->andFilterWhere(['like', 'consignee', $this->consignee])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'zipcode', $this->zipcode])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'remark', $this->remark])->andFilterWhere(['like', 'payment_name', $this->payment_name])->andFilterWhere(['like', 'shipment_name', $this->shipment_name])->andFilterWhere(['like', 'invoice', $this->invoice]); return $dataProvider; }
public function actionOrder() { $order = new Order(); /* @var $cart ShoppingCart */ $cart = \Yii::$app->cart; /* @var $products Product[] */ $products = $cart->getPositions(); $total = $cart->getCost(); if ($order->load(\Yii::$app->request->post()) && $order->validate()) { $transaction = $order->getDb()->beginTransaction(); $order->save(false); foreach ($products as $product) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->title = $product->title; $orderItem->price = $product->getPrice(); $orderItem->product_id = $product->id; $orderItem->quantity = $product->getQuantity(); if (!$orderItem->save(false)) { $transaction->rollBack(); \Yii::$app->session->addFlash('error', 'Cannot place your order. Please contact us.'); return $this->redirect('catalog/list'); } } $transaction->commit(); \Yii::$app->cart->removeAll(); \Yii::$app->session->addFlash('success', 'Thanks for your order. We\'ll contact you soon.'); $order->sendEmail(); return $this->redirect('catalog/list'); } return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['id' => $this->id, 'goods_id' => $this->goods_id, 'user_id' => $this->user_id, 'active' => $this->active, 'datetime' => $this->datetime]); return $dataProvider; }
public function actionShip($id) { $model = Order::findOne($id); if (!$model) { throw new NotFoundHttpException('未找到该订单!'); } if ($model->ship()) { Yii::$app->session->setFlash('success', '设置配送成功!'); } else { Yii::$app->session->setFlash('danger', '配送请求失败!'); } return $this->redirect(['view', 'id' => $id]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['id' => $this->id, 'price' => $this->price, 'datetime' => $this->datetime]); $query->andFilterWhere(['like', 'fio', $this->fio])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find()->orderBy('status'); $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(['id' => $this->id, 'status' => $this->status, 'total_cost' => $this->total_cost, 'date' => $this->date]); $query->andFilterWhere(['like', 'data', $this->data])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'message', $this->message]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['id' => $this->id, 'orderId' => $this->orderId, 'totalPrice' => $this->totalPrice, 'dateTime' => $this->dateTime]); $query->andFilterWhere(['like', 'firstName', $this->firstName])->andFilterWhere(['like', 'lastName', $this->lastName])->andFilterWhere(['like', 'package', $this->package]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['order_id' => $this->order_id, 'user_id' => $this->user_id, 'date_time' => $this->date_time]); return $dataProvider; }
public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]); // load the seach form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->_addDigitalFilter($query, 'real_fee'); $dateBegin = strtotime($this->date); $dateEnd = $dateBegin + 86400; // adjust the query by adding the filters $query->andFilterWhere(['like', 'order_sn', $this->order_sn])->andFilterWhere(['school_id' => $this->school_id])->andFilterWhere(['store_id' => $this->store_id])->andFilterWhere(['user_id' => $this->user_id])->andFilterWhere(['payment' => $this->payment])->andFilterWhere(['status' => $this->status])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $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(['order_id' => $this->order_id]); // $query->andFilterWhere(['like', 'store_name', $this->store_name]) // ->andFilterWhere(['like', 'store_desc', $this->store_desc]) // ->andFilterWhere(['like', 'store_picture', $this->store_picture]); return $dataProvider; }
public function actionView($id) { $model = User::findOne($id); if (!$model) { throw new NotFoundHttpException('未找到该用户'); } $last15days = []; $numDataOrder = []; $today = strtotime("00:00:00"); $todayEnd = strtotime("23:59:59"); for ($i = 0; $i < 15; $i++) { $timestrap = strtotime('-' . $i . ' days', $today); $timestrapEnd = strtotime('-' . $i . ' days', $todayEnd); $where = ['and', ['user_id' => $id], ['>=', 'created_at', $timestrap], ['<=', 'created_at', $timestrapEnd]]; array_unshift($last15days, date('m/d', $timestrap)); array_unshift($numDataOrder, Order::find()->where($where)->count('id')); } return $this->render('view', ['model' => $model, 'last15days' => $last15days, 'numDataOrder' => $numDataOrder]); }