public static function createBusinessBranch($business_id, $business_name) { $branch = new Branch(); $branch->name = $business_name . " Branch"; $branch->business_id = $business_id; $branch->save(); return $branch->branch_id; }
/** * Creates a new Branch model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Branch(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->branch_id]); } else { return $this->render('create', ['model' => $model]); } }
public function createItem($item) { $branch = new Branch(); if (isset($item['image']) && $item['image'] !== 'undefined') { $image = $item['image']; $original_name = explode(".", $image->getClientOriginalName()); $original_name = $original_name[0]; $new_name = str_slug($original_name, "-") . '-' . time() . '.' . $image->getClientOriginalExtension(); $path = public_path(BRANCH_IMAGE . date('Y-m-d')); if (!file_exists($path)) { mkdir($path, 0777, true); } else { chmod($path, 0777); } Image::make($image->getRealPath())->resize(200, 200)->save($path . '/' . $new_name); $branch->image = $new_name; } $branch->name = $item['name']; $branch->created = date('Y-m-d H:i:s'); $branch->updated = date('Y-m-d H:i:s'); $branch->save(); }
public function actionLoadBranches() { $key = 'rusazx2220'; $raw = file_get_contents('http://catalog.api.2gis.ru/2.0/catalog/marker/search?page=1&page_size=10000&q=%D0%B1%D0%B0%D0%BD%D0%BA%D0%B8&hash=m0qkmb8zr3yvstts&stat%5Bts%5D=1452016254482&stat%5Buser%5D=d241f017-2569-4e2d-8e15-3a6b4ed85efb&stat%5Bsid%5D=02a4e3d3-d6de-4162-8a22-59080e2e6507®ion_id=1&key=rusazx2220'); $json = json_decode($raw); $banks = []; if ($json->meta->code == '200') { //$json->result->total - 1 for ($i = 0; $i < 50; $i++) { $bankID = $json->result->items[$i]->id; $bankInfo = json_decode(file_get_contents("http://catalog.api.2gis.ru/2.0/catalog/branch/get?id={$bankID}&key={$key}")); if ($bankInfo->meta->code == '200') { $phone = ''; if ($bankInfo->result->items[0]->contact_groups) { foreach ($bankInfo->result->items[0]->contact_groups as $cg) { foreach ($cg->contacts as $c) { if ($c->type == 'phone') { $phone .= $c->text . '; '; } } } } if (!$banks[$bankInfo->result->items[0]->name]) { $banks[$bankInfo->result->items[0]->name] = [['lon' => $json->result->items[$i]->lon, 'lat' => $json->result->items[$i]->lat, 'address' => $bankInfo->result->items[0]->address_name, 'phone' => $phone, 'monWH' => $bankInfo->result->items[0]->schedule->Mon->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Mon->working_hours[0]->to, 'tueWH' => $bankInfo->result->items[0]->schedule->Tue->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Tue->working_hours[0]->to, 'wedWH' => $bankInfo->result->items[0]->schedule->Wed->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Wed->working_hours[0]->to, 'thuWH' => $bankInfo->result->items[0]->schedule->Thu->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Thu->working_hours[0]->to, 'friWH' => $bankInfo->result->items[0]->schedule->Fri->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Fri->working_hours[0]->to, 'satWH' => $bankInfo->result->items[0]->schedule->Sat->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Sat->working_hours[0]->to, 'sunWH' => $bankInfo->result->items[0]->schedule->Sun->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Sun->working_hours[0]->to]]; } else { array_push($banks[$bankInfo->result->items[0]->name], ['lon' => $json->result->items[$i]->lon, 'lat' => $json->result->items[$i]->lat, 'address' => $bankInfo->result->items[0]->address_name, 'phone' => $phone, 'monWH' => $bankInfo->result->items[0]->schedule->Mon->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Mon->working_hours[0]->to, 'tueWH' => $bankInfo->result->items[0]->schedule->Tue->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Tue->working_hours[0]->to, 'wedWH' => $bankInfo->result->items[0]->schedule->Wed->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Wed->working_hours[0]->to, 'thuWH' => $bankInfo->result->items[0]->schedule->Thu->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Thu->working_hours[0]->to, 'friWH' => $bankInfo->result->items[0]->schedule->Fri->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Fri->working_hours[0]->to, 'satWH' => $bankInfo->result->items[0]->schedule->Sat->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Sat->working_hours[0]->to, 'sunWH' => $bankInfo->result->items[0]->schedule->Sun->working_hours[0]->from . ' - ' . $bankInfo->result->items[0]->schedule->Sun->working_hours[0]->to]); } } else { echo 'Server: ' . $bankInfo->meta->code; } } foreach ($banks as $key => $value) { $bank = Bank::findOne(['name' => $key]); foreach ($value as $branchInfo) { $branch = new Branch(); $branch->bankID = $bank->id; $branch->lon = strval($branchInfo['lon']); $branch->lat = strval($branchInfo['lat']); $branch->address = $branchInfo['address']; $branch->phone = $branchInfo['phone']; $branch->monWH = $branchInfo['monWH']; $branch->tueWH = $branchInfo['tueWH']; $branch->wedWH = $branchInfo['wedWH']; $branch->thuWH = $branchInfo['thuWH']; $branch->friWH = $branchInfo['friWH']; $branch->satWH = $branchInfo['satWH']; $branch->sunWH = $branchInfo['sunWH']; $branch->isActive = true; $branch->save(); } } } else { echo 'Server: ' . $json->meta->code; } $this->redirect(['bank/index']); }