public function actionGetCard($cid)
 {
     $company = Company::find()->where(['id' => $cid])->asArray()->one();
     $address = Address::find()->where(['id' => $company['address_id']])->asArray()->one();
     $shedule = Shedule::find()->where(['company_id' => $cid])->asArray()->all();
     $brand = Company::find()->where(['id' => $cid])->one()->brand;
     $service = Company::find()->where(['id' => $cid])->one()->service;
     $srv = ArrayHelper::getColumn($service, 'category_id');
     $category = Category::find()->where(['id' => $srv])->asArray()->indexBy('id')->all();
     $srv = ArrayHelper::map($service, 'id', 'name', 'category_id');
     $spoffer = SpecialOffer::find()->where(['company_id' => $cid])->asArray()->one();
     $file = Files::find()->where(['id' => $spoffer['file_id']])->asArray()->one();
     Yii::$app->response->format = Response::FORMAT_JSON;
     $response = ['company' => $company, 'address' => $address, 'shedule' => $shedule, 'brand' => $brand, 'category' => $category, 'service' => $srv, 'spoffer' => $spoffer, 'file' => $file];
     return $response;
 }
 public function actionIndex($id)
 {
     if (Yii::$app->user->isGuest) {
         return $this->redirect(Url::home());
     }
     $user = User::findOne(Yii::$app->user->id);
     if ($user->company->id != $id) {
         return $this->redirect(Url::home());
     }
     $company = Company::findOne($id);
     $shedule = Shedule::getSheduleString($company->id, $company->twenty_four_hours);
     $categories = Category::find()->all();
     $countries = Country::find()->all();
     $cInfFrm = new CompanyInfoForm();
     $cInfFrm->loadInfo($id);
     $cPasFrm = new ChangePasswordForm();
     $cEmailFrm = new ChangeEmailForm();
     $cEmailFrm->loadEmail();
     $cOptFrm = new OptionsForm();
     $cOptFrm->loadData($id);
     $cities = City::find()->asArray()->all();
     $cities = ArrayHelper::map($cities, 'name', 'name');
     return $this->render('/private-room/private-room', ['company' => $company, 'shedule' => $shedule, 'categories' => $categories, 'countries' => $countries, 'cInfFrm' => $cInfFrm, 'cPasFrm' => $cPasFrm, 'cEmailFrm' => $cEmailFrm, 'cOptFrm' => $cOptFrm, 'cities' => $cities]);
 }
示例#3
0
 public function getSrchRes($city = null, $brand = null, $service = null, $district = null, $name = null, $address = null, $twfhr = null)
 {
     $cityObj = City::findOne($city);
     if ($address) {
         $a1 = str_replace(' ', ',', trim($address));
         $a2 = explode(',', $a1);
         if ($a2) {
             $a4 = [];
             foreach ($a2 as $a3) {
                 if (mb_strlen($a3, 'UTF-8') > 4) {
                     $a4[] = $a3;
                 }
             }
             if (count($a4) > 0) {
                 $a5 = implode('%', $a4);
                 $address = $a5;
             }
         }
     }
     $srchres = $this->find()->select(['company.id', 'company.name', 'company.phone', 'company.twenty_four_hours', 'address.city', 'address.district', 'address.street', 'address.home', 'address.housing', 'address.building', 'address.latitude', 'address.longitude', 'special_offer.id AS special_offer_id', 'company_brands.id AS company_brands_id', 'company_services.id AS company_services_id'])->leftJoin('address', '`address`.`id` = `company`.`address_id`')->leftJoin('special_offer', '`special_offer`.`company_id` = `company`.`id`')->leftJoin('company_brands', '`company_brands`.`company_id` = `company`.`id`')->leftJoin('company_services', '`company_services`.`company_id` = `company`.`id`')->filterWhere(['company_brands.brand_id' => $brand, 'company_services.service_id' => $service, 'address.city' => $cityObj['name'], 'address.district' => $district, 'company.name' => $name, 'company.twenty_four_hours' => $twfhr])->andFilterWhere(['like', 'address.street', $address])->asArray()->all();
     $id = ArrayHelper::getColumn($srchres, 'id');
     $shedule = Shedule::find()->where(['company_id' => $id])->asArray()->all();
     $shedule2 = [];
     foreach ($shedule as $sh) {
         $companyID = $sh['company_id'];
         $shedule2[$companyID][] = $sh;
     }
     for ($i = 0; $i < count($srchres); $i++) {
         $companyID = $srchres[$i]['id'];
         $srchres[$i]['shedule'] = $shedule2[$companyID];
     }
     return $srchres;
 }
示例#4
0
 public function saveOptions()
 {
     $db = Yii::$app->db;
     $transaction = $db->beginTransaction();
     try {
         $company = Company::findOne($this->id);
         $company->name = $this->company_name;
         $company->phone = $this->company_phone;
         $company->twenty_four_hours = $this->shedule_twfhr;
         $company->save();
         $address = $company->address;
         $address->region = $this->address_region;
         $address->city = $this->address_city;
         $address->district = $this->address_district;
         $address->street = $this->address_street;
         $address->home = $this->address_home;
         $address->housing = $this->address_housing;
         $address->building = $this->address_building;
         $address->metro = $this->address_metro;
         $address->save();
         Shedule::deleteAll(['company_id' => $company->id]);
         $days = array(1 => 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
         for ($i = 1; $i <= 7; $i++) {
             $day = 'shedule_' . $days[$i];
             if ($this[$day] == 1) {
                 $shedule = new Shedule();
                 $shedule->company_id = $company->id;
                 $shedule->day = $i;
                 $shedule->begin = $this->b_hour . ':' . $this->b_minute . ':00';
                 $shedule->end = $this->e_hour . ':' . $this->e_minute . ':00';
                 $shedule->save();
             }
         }
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollBack();
         return false;
     }
     return true;
 }