Ejemplo n.º 1
0
 public function actionSearchcollege()
 {
     //echo "university search by state and city ";die;
     // $unvname=$_POST['name'];
     //echo $state=$_POST['state'];
     //echo $city=$_POST['city'];die;
     if (isset($_POST['name']) && $_POST['name'] != '') {
         $model = University::find()->where(['name' => $_POST['name']])->all();
         return $this->render('index', ['model' => $model]);
     } else {
         if (isset($_POST['state']) && $_POST['state'] != '' && isset($_POST['city']) && $_POST['city'] != '') {
             $model = Address::find()->where(['state_id' => $_POST['state'], 'city_id' => $_POST['city']])->all();
             $universityID = array();
             foreach ($model as $val) {
                 array_push($universityID, $val->university_id);
             }
             $model = University::find()->where(['IN', 'id', $universityID])->all();
             return $this->render('index', ['model' => $model]);
         } else {
             if (isset($_POST['state']) && $_POST['state'] != '') {
                 $model = Address::find()->where(['state_id' => $_POST['state']])->all();
                 $universityID = array();
                 foreach ($model as $val) {
                     array_push($universityID, $val->university_id);
                 }
                 $model = University::find()->where(['IN', 'id', $universityID])->all();
                 return $this->render('index', ['model' => $model]);
             } else {
                 $model = University::find()->all();
                 return $this->render('index', ['model' => $model]);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Address::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, 'default' => $this->default, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'name', $this->name])->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]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * Lists all Address models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = Address::find()->where(['user_id' => Yii::$app->user->id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeOrder']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $this->render('index', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]);
 }
Ejemplo n.º 4
0
 public function actionUpdateProfile()
 {
     $rootPath = str_replace(DIRECTORY_SEPARATOR . 'backend', "", Yii::$app->basePath);
     $img_move_to = $rootPath . '/web/images/uploads/';
     $userdetails = \Yii::$app->user->identity;
     $model = UserProfile::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($model)) {
         $model = new UserProfile();
     }
     $address = Address::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($address)) {
         $address = new Address();
     }
     $userpay = UserPay::find()->where(['user_profile_id' => $userdetails->id])->one();
     if (empty($userpay)) {
         $userpay = new UserPay();
     }
     $user = Userform::findOne(['id' => $userdetails->id]);
     if (!empty($model->image)) {
         $oldpic = $model->image;
     } else {
         $oldpic = '';
     }
     if (isset($_POST['UserProfile'])) {
         $model->attributes = $_POST['UserProfile'];
         if (isset($model) && $model->user_id) {
             $model->modified = new \yii\db\Expression('NOW()');
         } else {
             $model->created = new \yii\db\Expression('NOW()');
         }
         $model->user_id = $userdetails->id;
         $model->description = $_POST['UserProfile']['description'];
         $dateofbirth = explode('/', $_POST['UserProfile']['DOB']);
         $model->DOB = $dateofbirth[2] . '-' . $dateofbirth[1] . '-' . $dateofbirth[0];
         $model->gender = $_POST['UserProfile']['gender'];
         $model->image = $oldpic;
         $profileimg = UploadedFile::getInstance($model, 'image');
         $model->image = $profileimg->name;
         $ext = end(explode('.', $profileimg));
         $rndstrngprofile = Yii::$app->security->generateRandomString('32') . "." . $ext;
         $path = Yii::$app->basePath . '/uploads/';
         $model->image = 'images/uploads/' . $rndstrngprofile;
         if ($model->validate() && $user->validate()) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($model->save()) {
                     $profileimg->saveAs($img_move_to . $rndstrngprofile);
                     $address->user_id = $model->id;
                     $address->address = $_POST['Address']['address'];
                     $address->landmark = $_POST['Address']['landmark'];
                     $address->pincode = $_POST['Address']['pincode'];
                     $address->country_id = $_POST['Address']['country_id'];
                     $address->state_id = $_POST['Address']['state_id'];
                     $address->city_id = $_POST['Address']['city_id'];
                     $userpay->user_profile_id = $model->id;
                     $userpay->currency_id = 1;
                     $userpay->time_slot_id = 5;
                     $userpay->amount = $_POST['UserPay']['amount'];
                     $user->fname = $_POST['Userform']['phone'];
                     $user->lname = $_POST['Userform']['phone'];
                     $user->phone = $_POST['Userform']['phone'];
                     if ($address->validate() && $userpay->validate()) {
                         $address->save();
                         $userpay->save();
                         $user->save();
                     }
                 }
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollback();
             }
         }
     }
     return $this->render('updateprofile', ['model' => $model, 'user' => $user, 'address' => $address, 'userpay' => $userpay]);
 }
Ejemplo n.º 5
0
 public function actionCheckout()
 {
     Yii::$app->session['step'] = 2;
     $userId = Yii::$app->user->id;
     $addresses = Address::find()->where(['user_id' => $userId])->all();
     $model = new Order();
     if ($model->load(Yii::$app->request->post())) {
         if (!Yii::$app->request->post('address_id')) {
             return $this->goBack();
         }
         // 使用优惠券
         $feeCouponUser = $feeCouponCode = $feePoint = 0.0;
         $couponId = Yii::$app->request->post('coupon');
         if ($couponId && Yii::$app->request->post('checkbox-coupon')) {
             $couponUser = Coupon::findOne($couponId);
             if (!$couponUser || $couponUser->used_at > 0 || $couponUser->ended_at < time() || $couponUser->user_id != Yii::$app->user->id) {
                 return $this->goBack();
             }
             $feeCouponUser = $couponUser->money;
         }
         // 使用优惠码
         $sn = Yii::$app->request->post('sn');
         if ($sn) {
             $couponCode = Coupon::find()->where(['sn' => $sn])->one();
             if (!$couponCode || $couponCode->used_at > 0 || $couponCode->ended_at < time()) {
                 return $this->goBack();
             }
             $feeCouponCode = $couponCode->money;
         }
         // 使用积分
         $point = Yii::$app->request->post('point');
         if ($point && Yii::$app->request->post('checkbox-point')) {
             if ($point > Yii::$app->user->identity->point) {
                 return $this->goBack();
             }
             $feePoint = intval($point) / 100;
         }
         $address = Address::find()->where(['id' => Yii::$app->request->post('address_id'), 'user_id' => $userId])->one();
         $model->user_id = $userId;
         $model->sn = date('YmdHis') . rand(1000, 9999);
         $model->consignee = $address->consignee;
         $model->country = $address->country;
         $model->province = $address->province;
         $model->city = $address->city;
         $model->district = $address->district;
         $model->address = $address->address;
         $model->zipcode = $address->zipcode;
         $model->phone = $address->phone;
         $model->mobile = $address->mobile;
         $model->email = $address->email ? $address->email : Yii::$app->user->identity->email;
         if ($model->payment_method == Order::PAYMENT_METHOD_COD) {
             $model->payment_status = Order::PAYMENT_STATUS_COD;
         } else {
             $model->payment_status = Order::PAYMENT_STATUS_UNPAID;
         }
         $model->status = $model->payment_status;
         $products = Cart::find()->where(['session_id' => Yii::$app->session->id])->all();
         if (count($products)) {
             foreach ($products as $product) {
                 $model->amount += $product->number * $product->price;
             }
         } else {
             $this->redirect('/cart');
         }
         $model->amount += floatval($model->shipment_fee) - $feeCouponUser - $feeCouponCode - $feePoint;
         if ($model->save()) {
             // insert order_product and clear cart
             foreach ($products as $product) {
                 $orderProduct = new OrderProduct();
                 $orderProduct->order_id = $model->id;
                 $orderProduct->product_id = $product->product_id;
                 $orderProduct->sku = $product->sku;
                 $orderProduct->name = $product->name;
                 $orderProduct->number = $product->number;
                 $orderProduct->market_price = $product->market_price;
                 $orderProduct->price = $product->price;
                 $orderProduct->thumb = $product->thumb;
                 $orderProduct->type = $product->type;
                 $orderProduct->save();
                 // 减少商品的库存
                 Product::updateAllCounters(['stock' => -$product->number], ['id' => $product->product_id]);
             }
             // 生成订单后,清空购物车,设置优惠码,更新积分和积分记录
             Cart::deleteAll(['session_id' => Yii::$app->session->id]);
             if (isset($couponUser) && Yii::$app->request->post('checkbox-coupon')) {
                 $couponUser->used_at = time();
                 $couponUser->order_id = $model->id;
                 $couponUser->save();
             }
             if (isset($couponCode) && Yii::$app->request->post('checkbox-coupon')) {
                 $couponCode->user_id = Yii::$app->user->id;
                 $couponCode->used_at = time();
                 $couponCode->order_id = $model->id;
                 $couponCode->save();
             }
             if (isset($point) && Yii::$app->request->post('checkbox-point')) {
                 $balance = Yii::$app->user->identity->point - $point;
                 User::updateAllCounters(['point' => -$point], ['id' => Yii::$app->user->id]);
                 $pointLog = new PointLog(['user_id' => Yii::$app->user->id, 'type' => PointLog::POINT_TYPE_BUYING, 'point' => -$point, 'balance' => $balance]);
                 $pointLog->save();
             }
             // 记录订单日志
             $orderLog = new OrderLog(['order_id' => $model->id, 'status' => $model->status]);
             $orderLog->save();
             // 不同的付款方式到不同的页面
             if ($model->payment_method == Order::PAYMENT_METHOD_COD) {
                 return $this->redirect(['cart/cod', 'id' => $model->id]);
             } else {
                 return $this->redirect(['cart/pay', 'sn' => $model->sn]);
             }
         }
     }
     $products = Cart::find()->where(['session_id' => Yii::$app->session->id])->all();
     if (!count($products)) {
         return $this->redirect('/cart');
     }
     if (count($addresses)) {
         return $this->render('checkout', ['model' => $model, 'addresses' => $addresses, 'products' => $products]);
     } else {
         return $this->redirect(['cart/address']);
     }
 }