public function store(Request $request, $user_model) { $buyer_data = $this->collectBuyerFormData($request, $user_model); $buyer = new Buyer(); $buyer_model = $buyer->create($buyer_data); return $buyer_model; }
public function validateBuyer($attribute, $params) { echo 'validateBuyer'; $buyer = Buyer::find()->where('account = :account', [':account' => $this->{$attribute}])->one(); if (is_null($buyer)) { return $this->addError($attribute, '买家不存在'); } $buyer->isBuy = 1; $buyer->buy_time = $this->order_time; $buyer->save(); $check = false; if ($this->scenario == 'create') { $check = true; } if ($this->scenario == 'update') { $order = Order::find($this->id); if (!is_null($order) && $order->buyer != $this->{$attribute}) { $check = true; } } if ($check) { $count = (new Query())->from(Order::tableName())->where('buyer = :buyer AND commodity = :commodity AND DATE(create_time) = DATE (now())', [':buyer' => $this->{$attribute}, ':commodity' => $this->commodity])->count(); if ($count > 0) { return $this->addError($attribute, '该买家今天已提交该商品订单'); } } }
public function getList() { $d = []; // GET LAST THREE YEARS OF DATA for ($i = 0; $i < 3; $i++) { $year = date("Y") - $i; $data = ['dependencia' => '901', "ejercicio" => $year]; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $this->apiContratos); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $result = curl_exec($ch); $excercise = json_decode($result); $d = array_merge($d, $excercise); } // SAVE THEM TO THE DB foreach ($d as $c) { $contract = Contract::firstOrCreate(['ocdsid' => $c->ocdsID, 'ejercicio' => $c->ejercicio, 'cvedependencia' => $c->cveDependencia, 'nomDependencia' => $c->nomDependencia]); // save extra data $meta = $this->getMetaDataX($contract); if (!empty($meta) && !property_exists($meta, 'error')) { // add extra data to contracts $contract->uri = $meta->uri; $contract->published_date = date("Y-m-d", strtotime($meta->publishedDate)); // create the publisher $contract->publisher_id = Publisher::firstOrCreate(["scheme" => $meta->publisher->scheme, "name" => $meta->publisher->name, "uri" => $meta->publisher->uri, "uid" => $meta->publisher->uid]); // update contract $contract->update(); // create releases foreach ($meta->releases as $r) { $release = Release::firstOrCreate(["local_id" => $r->id, "contract_id" => $contract->id, "ocid" => $contract->ocdsid, "date" => date("Y-m-d", strtotime($r->date)), "initiation_type" => $r->initiationType, "language" => $r->language]); if (count($r->awards)) { foreach ($r->awards as $aw) { $award = Award::firstOrCreate(["release_id" => $release->id, "local_id" => $aw->id]); $award->title = $aw->title; $award->description = $aw->description; $award->status = $aw->status; $award->date = date("Y-m-d", strtotime($aw->date)); $award->value = $aw->value->amount; $award->currency = $aw->value->currency; $award->update(); if (count($aw->items)) { foreach ($aw->items as $it) { $item = $award->items()->firstOrCreate(['local_id' => $it->id]); $item->quantity = $it->quantity; $item->description = $it->description; $item->unit = $it->unit->name; $item->update(); } } if (count($aw->suppliers)) { foreach ($aw->suppliers as $sup) { $supplier = Supplier::firstOrCreate(["award_id" => $aw->id, "rfc" => $sup->identifier->id]); $supplier->name = $sup->name; $supplier->street = $sup->address->streetAddress; $supplier->locality = $sup->address->locality; $supplier->region = $sup->address->region; $supplier->zip = $sup->address->postalCode; $supplier->country = $sup->address->countryName; $supplier->contact_name = $sup->contactPoint->name; $supplier->email = $sup->contactPoint->email; $supplier->phone = $sup->contactPoint->telephone; $supplier->fax = $sup->contactPoint->faxNumber; $supplier->url = $sup->contactPoint->url; $supplier->update(); } } } } if (count($r->contracts)) { foreach ($r->contracts as $single) { $single_contract = SingleContract::firstOrCreate(["local_id" => $single->id, "release_id" => $release->id]); $single_contract->award_id = $single->awardID; $single_contract->title = $single->title; $single_contract->description = $single->description; $single_contract->status = $single->status; $single_contract->contract_start = $single->period ? date("Y-m-d", strtotime($single->period->startDate)) : null; $single_contract->contract_end = $single->period ? date("Y-m-d", strtotime($single->period->endDate)) : null; $single_contract->amount = $single->value->amount; $single_contract->currency = $single->value->currency; $single_contract->date_signed = $single->dateSigned ? date("Y-m-d", strtotime($single->dateSigned)) : null; $single_contract->documents = count($single->documents); // ? implode(',',$r->tender->submissionMethod) : null; $single_contract->update(); if (count($single->items)) { foreach ($single->items as $it) { $item = $single_contract->items()->firstOrCreate(['local_id' => $it->id]); $item->quantity = $it->quantity; $item->description = $it->description; $item->unit = $it->unit->name; $item->update(); } } } } // create planning if ($r->planning) { $planning = Planning::firstOrCreate(["release_id" => $release->id]); $planning->amount = $r->planning->budget->amount->amount; $planning->currency = $r->planning->budget->amount->currency; $planning->project = $r->planning->budget->project; $planning->update(); //$release->planning_id = $planning->id; } // create tender if ($r->tender) { $tender = Tender::firstOrCreate(["release_id" => $release->id]); $tender->local_id = $r->tender->id; $tender->title = $r->tender->title; $tender->description = $r->tender->description; $tender->status = $r->tender->status; $tender->amount = $r->tender->value ? $r->tender->value->amount : null; $tender->currency = $r->tender->value ? $r->tender->value->currency : null; $tender->procurement_method = $r->tender->procurementMethod; $tender->award_criteria = $r->tender->awardCriteria; $tender->tender_start = $r->tender->tenderPeriod ? date("Y-m-d", strtotime($r->tender->tenderPeriod->startDate)) : null; $tender->tender_end = $r->tender->tenderPeriod ? date("Y-m-d", strtotime($r->tender->tenderPeriod->endDate)) : null; $tender->enquiry_start = $r->tender->enquiryPeriod ? date("Y-m-d", strtotime($r->tender->enquiryPeriod->startDate)) : null; $tender->enquiry_end = $r->tender->enquiryPeriod ? date("Y-m-d", strtotime($r->tender->enquiryPeriod->endDate)) : null; $tender->award_start = $r->tender->awardPeriod ? date("Y-m-d", strtotime($r->tender->awardPeriod->startDate)) : null; $tender->award_end = $r->tender->awardPeriod ? date("Y-m-d", strtotime($r->tender->awardPeriod->endDate)) : null; $tender->has_enquiries = $r->tender->hasEnquiries; $tender->eligibility_criteria = $r->tender->eligibilityCriteria; $tender->submission_method = count($r->tender->submissionMethod) ? implode(',', $r->tender->submissionMethod) : null; $tender->number_of_tenderers = $r->tender->numberOfTenderers; $tender->update(); if (count($r->tender->tenderers)) { foreach ($r->tender->tenderers as $tn) { $tenderer = Tenderer::firstOrCreate(["rfc" => $tn->identifier->id]); $tenderer->name = $tn->name; $tenderer->street = $tn->address->streetAddress; $tenderer->locality = $tn->address->locality; $tenderer->region = $tn->address->region; $tenderer->zip = $tn->address->postalCode; $tenderer->country = $tn->address->countryName; $tenderer->contact_name = $tn->contactPoint->name; $tenderer->email = $tn->contactPoint->email; $tenderer->phone = $tn->contactPoint->telephone; $tenderer->fax = $tn->contactPoint->faxNumber; $tenderer->url = $tn->contactPoint->url; $tenderer->update(); } } if (count($r->tender->items)) { foreach ($r->tender->items as $it) { $item = $tender->items()->firstOrCreate(['local_id' => $it->id]); $item->quantity = $it->quantity; $item->description = $it->description; $item->unit = $it->unit->name; $item->update(); } } } // create buyer if ($r->buyer) { $buyer = Buyer::firstOrCreate(["local_id" => $r->buyer->identifier->id, "name" => $r->buyer->name]); $buyer->uri = $r->buyer->identifier->uri; $buyer->update(); $release->buyer_id = $buyer->id; $release->update(); } } } } echo ":D"; }
public function actionView($id) { $model = Buyer::findOne($id); if (empty($model)) { throw new HttpException(404, '小号不存在!'); } if (empty($model->regarea)) { $model->regarea = ''; } if (empty($model->id_verifi)) { $model->id_verifi = ''; } if (empty($model->address)) { $model->address = ''; } return $this->render('view', array('model' => $model)); }
private function registerUser($data, $role) { if (isset($data['phone_number'])) { $data['phone_number'] = str_replace(' ', '', $data['phone_number']); } if (isset($data['work_phone'])) { $data['work_phone'] = str_replace(' ', '', $data['work_phone']); } $u = new User(); $data['role_id'] = $role; switch (strtolower($role)) { case Config::get('constants.ROLE_SELLER'): $a = new Seller(); break; case Config::get('constants.ROLE_BROKER'): $a = new Broker(); break; default: $a = new Buyer(); $u->status = 2; $data['skip_verification'] = true; break; } if (!isset($data['password']) || $data['password'] == "") { $pwd = Str::random(10); $data['password'] = $data['password_confirmation'] = $pwd; } if ($u->validate($data)) { if ($a->validate($data)) { if (isset($pwd)) { Session::set('validate_password', true); } $data['password'] = Hash::make($data['password']); $u->fill($data); $code = Str::random(10); $u->verification_code = $code; $data['verification_code'] = $code; $u->save(); $data['user_id'] = $u->id; $a->fill($data); $a->save(); $email = $u->email; if (isset($data['skip_verification'])) { $data['url']['link'] = url('/'); $data['url']['name'] = 'Go to CompanyExchange'; Mail::queue('emails.templates.welcome', $data, function ($message) use($email) { $message->from('*****@*****.**', 'CompanyExchange'); $message->to($email); $message->subject('Welcome to CompanyExchange'); }); } else { Mail::queue('emails.templates.progress', $data, function ($message) use($email) { $message->from('*****@*****.**', 'CompanyExchange'); $message->to($email); $message->subject('Welcome to CompanyExchange'); }); } Auth::loginUsingId($u->id); return true; } Input::flash(); return $a->getValidator(); } Input::flash(); return $u->getValidator(); }
private function saveBuyer($data) { if ($data->buyer) { $buyer = Buyer::firstOrCreate(["local_id" => $data->buyer->identifier->id, "name" => $data->buyer->name]); $buyer->uri = $data->buyer->identifier->uri; $buyer->update(); $this->info("buyer: {$buyer->id}"); return $buyer; } else { $this->error('no hay buyer!'); return null; } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { /* $brand_name_array = $request->get('brand_name'); Models used fo registering a merchant User, Bank, Buyer, Address, Merchant, Brand, Website and Director */ $user = new User(); $user_model = $user->store($request); //return new user record in db $bank = new Bank(); $bank_model = $bank->store($request); if ($request['indication'] == 'buyer') { return "no functionality implemented"; $buyer = new Buyer(); $buyer_model = $buyer->store($request, $user_model); } if ($request['indication'] == 'merchant') { //TODO: for adding address first create address then add address id to merchant table //country_id => working $address = new Address(); $address_model = $address->store($request); // user_id, country_id, address_id, bank_id => working $user_as_merchant = new Merchant(); $user_as_merchant_model = $user_as_merchant->store($request, $user_model, $bank_model, $address_model); /* * Document table */ $documents = new Document(); $documents_model = $documents->store($request, $user_as_merchant_model); //todo: add brand //1)create merchant and get model //2)create all brand and get all models //3)sync merchant model with brand models in merchantbrand table $brand = new Brand(); $brand_models = $brand->store($request, $user_as_merchant_model, $address_model); //now syncing $user_as_merchant_model->attachBrands($user_as_merchant_model, $brand_models); //http://laravel.com/docs/5.1/eloquent-relationships#inserting-many-to-many-relationships //for storing web sites in "merchantwebsite" table //first create merchant and get id //then create websites and get website model array like director //then attach merchant with each website id $website = new Website(); $website_models = $website->store($request); //attachment with merchant in "merchantwebsite" table $user_as_merchant->attachWebsites($website_models, $user_as_merchant_model); $director = new Director(); $director_model = $director->store($request, $user_as_merchant_model); /*save all FKs of directors & merchants to merchantdirectos tables */ $user_as_merchant_model->attachDirectors($director_model, $user_as_merchant_model); \Session::flash(Config::get('messages.key.name'), $this->messageHandler->success('merchantRegistered', null, null, true, true, true)); } return redirect()->back(); }
return $data['keyword']; }], ['attribute' => '浏览入口', 'value' => function ($data) { return $data['entrance']; }], ['attribute' => '卡位条件', 'value' => function ($data) { if (empty($data['condition'])) { $data['condition'] = ''; } return $data['condition']; }], ['attribute' => '笔数', 'value' => function ($data) { return $data['num']; }], ['attribute' => '单价', 'value' => function ($data) { return $data['price']; }], ['class' => 'yii\\grid\\Column', 'header' => '推荐', 'content' => function ($data) { $result = ''; if (!empty($data['recommends'])) { $buyers = Buyer::find()->where('id in (:id)', [':id' => $data['recommends']])->all(); foreach ($buyers as $buyer) { $result .= '[' . $buyer->account . ',' . $buyer->pass . ']<br/>'; } } return $result; }], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'template' => '{view}', 'buttons' => ['view' => function ($url, $data, $key) { $icon = '<span class="glyphicon glyphicon-eye-open"></span>'; $html = '<a href="view?id=' . $data['id'] . '" title="查看">' . $icon . '</a>'; return $html; }]]]]); echo LinkPager::widget(['pagination' => $pages]); echo Html::endForm(); Yii::$app->view->registerJs(' $("ul.pagination li a").click(function () { var page = $(this).attr(\'href\');