Inheritance: extends yii\db\ActiveRecord
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 a new College model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new College();
     $addressmodel = new Address();
     $contactmodel = new Contacts();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $image_logo = UploadedFile::getInstance($model, 'logo');
         $image_banner = UploadedFile::getInstance($model, 'banner');
         $model->logo = $image_logo->name;
         $ext_logo = end(explode('.', $image_logo));
         $ext_banner = end(explode('.', $image_banner));
         $rndstrngLogo = Yii::$app->security->generateRandomString('32') . "." . $ext_logo;
         $rndstrngBanner = Yii::$app->security->generateRandomString('32') . "." . $ext_banner;
         $path = Yii::$app->basePath . '/uploads/';
         $model->logo = 'backend/uploads/' . $rndstrngLogo;
         $model->banner = 'backend/uploads/' . $rndstrngBanner;
         $model->establish = $_POST['College']['establish'];
         $model->created = new Expression('NOW()');
         $addressmodel->address = $_POST['Address']['address'];
         $addressmodel->landmark = $_POST['Address']['landmark'];
         $addressmodel->country_id = $_POST['Address']['country_id'];
         $addressmodel->state_id = $_POST['Address']['state_id'];
         $addressmodel->city_id = $_POST['Address']['city_id'];
         $addressmodel->pincode = $_POST['Address']['pincode'];
         $addressmodel->created = new Expression('NOW()');
         $contactmodel->email = $_POST['Contacts']['email'];
         $contactmodel->landline = $_POST['Contacts']['landline'];
         $contactmodel->mobile = $_POST['Contacts']['mobile'];
         $contactmodel->created = new Expression('NOW()');
         $contactmodel->fax = $_POST['Contacts']['fax'];
         $contactmodel->status = $_POST['College']['status'];
         if ($model->save()) {
             $image_logo->saveAs($path . $rndstrngLogo);
             $image_banner->saveAs($path . $rndstrngBanner);
             $contactmodel->college_id = $model->id;
             $addressmodel->college_id = $model->id;
             if ($addressmodel->validate() && $contactmodel->validate()) {
                 $contactmodel->save();
                 $addressmodel->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAddress($schoolId = null)
 {
     $query = $this->hasMany(Address::className(), ['user_id' => 'id']);
     if ($schoolId !== null) {
         $query->where(['school_id' => $schoolId]);
     }
     return $query->orderBy('school_id ASC, building_id ASC, is_default DESC');
 }
Ejemplo n.º 4
0
 /**
  * Creates a new University model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $rootPath = str_replace(DIRECTORY_SEPARATOR . 'backend', "", Yii::$app->basePath);
     $img_move_to = $rootPath . '/frontend/web/images/uploads/';
     $model = new University();
     $addressmodel = new Address();
     $contactmodel = new Contacts();
     $implink = new ImportantLink();
     $downloadlink = new DownloadLink();
     if ($model->load(Yii::$app->request->post())) {
         $image_logo = UploadedFile::getInstance($model, 'logo');
         $image_banner = UploadedFile::getInstance($model, 'banner');
         $model->logo = $image_logo->name;
         $ext_logo = end(explode('.', $image_logo));
         $ext_banner = end(explode('.', $image_banner));
         $rndstrngLogo = Yii::$app->security->generateRandomString('32') . "." . $ext_logo;
         $rndstrngBanner = Yii::$app->security->generateRandomString('32') . "." . $ext_banner;
         $path = Yii::$app->basePath . '/uploads/';
         $model->logo = 'images/uploads/' . $rndstrngLogo;
         $model->banner = 'images/uploads/' . $rndstrngBanner;
         $model->establish = $_POST['University']['establish'];
         $model->created = new Expression('NOW()');
         $addressmodel->address = $_POST['Address']['address'];
         $addressmodel->landmark = $_POST['Address']['landmark'];
         $addressmodel->country_id = $_POST['Address']['country_id'];
         $addressmodel->state_id = $_POST['Address']['state_id'];
         $addressmodel->city_id = $_POST['Address']['city_id'];
         $addressmodel->pincode = $_POST['Address']['pincode'];
         $addressmodel->created = new Expression('NOW()');
         $contactmodel->email = $_POST['Contacts']['email'];
         $contactmodel->landline = $_POST['Contacts']['landline'];
         $contactmodel->mobile = $_POST['Contacts']['mobile'];
         $contactmodel->created = new Expression('NOW()');
         $contactmodel->fax = $_POST['Contacts']['fax'];
         //$contactmodel->status=$_POST['University']['status'];
         $implink->name = $_POST['ImportantLink']['name'];
         $implink->url = $_POST['ImportantLink']['url'];
         $downloadlink->name = $_POST['DownloadLink']['name'];
         $downloadlink->url = $_POST['DownloadLink']['url'];
         if ($model->save()) {
             $image_logo->saveAs($img_move_to . $rndstrngLogo);
             $image_banner->saveAs($img_move_to . $rndstrngBanner);
             $contactmodel->university_id = $model->id;
             $addressmodel->university_id = $model->id;
             $implink->university_id = $model->id;
             $downloadlink->university_id = $model->id;
             if ($addressmodel->validate() && $contactmodel->validate() && $downloadlink->validate() && $implink->validate()) {
                 $contactmodel->save();
                 $addressmodel->save();
                 $downloadlink->save();
                 $implink->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 5
0
 public function actionDelete($id)
 {
     $model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if ($model) {
         if (!$model->delete()) {
             return ['status' => 'fail', 'data' => ['message' => '收货地址删除失败!']];
         }
     }
     return ['status' => 'success', 'data' => []];
 }
Ejemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['addressId', 'payment'], 'required', 'message' => '请选择{attribute}'], [['addressId'], 'exist', 'targetClass' => Address::className(), 'targetAttribute' => 'id', 'filter' => ['user_id' => Yii::$app->user->id, 'school_id' => $this->_store->school_id]], [['payment'], 'in', 'range' => [Order::PAYMENT_ONLINE, Order::PAYMENT_OFFLINE]], [['preferential'], 'default', 'value' => Order::PREFERENTIAL_NONE], [['preferential'], 'in', 'range' => [Order::PREFERENTIAL_DOWN, Order::PREFERENTIAL_GIFT, Order::PREFERENTIAL_NONE]], [['newDown'], 'default', 'value' => '0'], [['newDown'], 'boolean'], [['bookTime'], function ($attribute, $params) {
         $list = $this->getBookTimeItems();
         if (empty($list)) {
             $this->bookTime = '0';
         } elseif (!isset($list[$this->bookTime])) {
             $this->addError($attribute, '请重新选择送达时间。');
         }
     }], [['remark'], 'trim'], [['remark'], 'default'], [['remark'], 'string', 'max' => 255]];
 }
Ejemplo n.º 7
0
 public static function createDuplicate($addressId)
 {
     $address = Address::findOne($addressId);
     $model = new self();
     $model->consignee = $address->consignee;
     $model->cellphone = $address->cellphone;
     $model->gender = $address->gender;
     $model->school = $address->school->name;
     $model->building = $address->building->name;
     $model->room = $address->room;
     return $model;
 }
Ejemplo n.º 8
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.º 9
0
 public function actionDefault($id)
 {
     $model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if (!$model) {
         throw new NotFoundHttpException('未找到收货地址!');
     }
     $model->is_default = Address::BOOL_TRUE;
     if ($model->save(false)) {
         Yii::$app->session->setFlash('success', '设置默认地址成功。');
     } else {
         Yii::$app->session->setFlash('danger', '设置默认地址失败。');
     }
     if (Yii::$app->request->referrer) {
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         return $this->redirect(['index']);
     }
 }
Ejemplo n.º 10
0
 /**
  * Finds the Address model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Address the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Address::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 11
0
 public function getAddress()
 {
     return $this->hasOne(Address::className(), ['university_id' => 'id']);
 }
Ejemplo n.º 12
0
 public function actionAddressLoad($id)
 {
     $model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if (!$model) {
         throw new NotFoundHttpException('未找到该地址!');
     }
     $output = ['consignee' => $model->consignee, 'gender' => $model->gender, 'cellphone' => $model->cellphone, 'building_id' => $model->building_id, 'room' => $model->room];
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $output;
 }
Ejemplo n.º 13
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.º 14
0
 public function actionAddress($id = null)
 {
     if ($id) {
         $model = Address::findOne($id);
         if ($model === null) {
             throw new NotFoundHttpException('model does not exist.');
         }
     } else {
         $model = new Address();
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['cart/checkout']);
         }
     }
     return $this->render('address', ['model' => $model]);
 }
Ejemplo n.º 15
0
use yii\helpers\Url;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use common\models\Address;
use common\models\Building;
use common\models\School;
$this->title = $model->isNewRecord ? '添加收货地址' : '更新收货地址';
$this->params['breadcrumbs'][] = ['label' => '个人中心', 'url' => ['/i']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="edit-form">
<?php 
$form = ActiveForm::begin(['enableAjaxValidation' => true, 'validateOnChange' => false, 'validateOnBlur' => false, 'layout' => 'horizontal', 'fieldConfig' => ['horizontalCssClasses' => ['label' => 'col-md-2', 'wrapper' => 'col-md-8']]]);
?>
    <?php 
echo $form->field($model, 'consignee', ['template' => "{label}\n{beginWrapper}\n{beginRow}\n{beginCol}\n{input}\n{hint}\n{error}\n{endCol}\n{beginCol}\n{gender}\n{endCol}\n{endRow}\n{endWrapper}", 'parts' => ['{gender}' => Html::activeRadioList($model, 'gender', Address::getGenderList()), '{beginRow}' => '<div class="row">', '{endRow}' => '</div>', '{beginCol}' => '<div class="col-xs-6">', '{endCol}' => '</div>']]);
?>
    <?php 
echo $form->field($model, 'cellphone');
?>
    <?php 
echo $form->field($model, 'school_id')->dropDownList(School::getKeyValuePairs());
?>
    <div class="form-group">
        <label class="col-md-2 control-label">收货地址</label>
        <div class="col-md-8">
            <div class="row">
                <div class="col-xs-6">
                    <div class="col-md-12"><?php 
echo $form->field($model, 'building_id', ['template' => "{input}\n{hint}\n{error}"])->dropDownList(Building::getKeyValuePairs($model->school_id));
?>