public function actionCreate() { $mod = new Customers(); if ($mod->load(Yii::$app->request->post()) && $mod->create()) { // VarDumper::dump($_POST["Cancel"]); // return $this->goBack(); $this->redirect(array('/table/index')); } else { return $this->render('create', ['model' => $mod]); } }
public function delete() { $idd = $_POST['id']; Customers::deleteAll('id = :id', [':id' => $idd]); // $cst = Customers()->findOne($idd); // VarDumper::dump($cst); // VarDumper::dump($idd); // $cst->delete(); // $cst->name = $this->name; // $cst->email = $this->email; // $cst->mobile = $this->mobile; // // return $cst->save(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customers::find(); if (!empty($params)) { $query->select("*, CONCAT(`firstname`, `lastname`) as `fullName`")->andFilterWhere(['or', ['like', '`firstname`', $params], ['like', '`lastname`', $params]]); } else { $query->select("*, CONCAT(`firstname`, `lastname`) as `fullName`"); } $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'email', 'phone', 'image', 'birthdate', 'street', 'city', 'suburb', 'zipcode', 'firstname', 'lastname', 'fax', 'mobile', 'refferedby', 'username', 'fullName' => ['asc' => ['fullName' => SORT_ASC], 'desc' => ['fullName' => SORT_DESC], 'label' => 'fullName', 'default' => SORT_ASC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'birthdate' => $this->birthdate, 'city' => $this->city, 'suburb' => $this->suburb, 'refferedby' => $this->refferedby]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['like', 'fax', $this->fax])->andFilterWhere(['like', 'street', $this->street])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'zipcode', $this->zipcode])->andFilterWhere(['likr', 'CONCAT(firstname, " ", lastname)', $this->fullName]); return $dataProvider; }
/** * Finds the Customers model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Customers the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customers::findOne($id)) !== null) { $model->scenario = 'customerEdit'; return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndex() { $customers = Customers::find()->all(); return $this->render('index', array('customers' => $customers)); }
private function getCustomers() { $customers = Customers::find()->select(['id', 'firstname', 'lastname'])->orderBy(['firstname' => SORT_ASC, 'lastname' => SORT_ASC])->all(); $cs = []; for ($i = 0; $i < sizeof($customers); $i++) { $cs[$customers[$i]['id']] = $customers[$i]['firstname'] . " " . $customers[$i]['lastname']; } return $cs; }
/** * @return \yii\db\ActiveQuery */ public function getCustomer() { return $this->hasOne(Customers::className(), ['userID' => 'customerID']); }
public function addReward($data) { /* ** Cancel process if data invalid */ if (!isset($data['reward_key']) || !isset($data['customer_id']) || !isset($data['reference_id'])) { return false; } $customer_id = $data['customer_id']; $reward_key = $data['reward_key']; $reference_id = $data['reference_id']; /* ** Create log */ $reward_type = RewardType::where('key', $reward_key)->first(); $reward_type_id = $reward_type->id; $point_rewards = $reward_type->point; if ($reward_key == 'order') { $point_rewards = isset($data['reward_point']) ? $data['reward_point'] : $point_rewards; } $reward_log = new RewardLog(); $reward_log->reward_type_id = $reward_type_id; $reward_log->customer_id = $customer_id; $reward_log->reference_id = is_array($reference_id) ? json_encode($reference_id) : $reference_id; $reward_log->point = $point_rewards; $reward_log->message = $this->__rewardMessage($reward_key, $point_rewards); /* ** Update customer point */ $customer = Customers::find($customer_id); $customer->point_rewards += $point_rewards; if ($reward_key == 'referal' && isset($reference_id['customer_id'])) { $referal = Customers::find($reference_id['customer_id']); $referal->flag_referal_get_reward = true; } try { $reward_log->save(); $customer->save(); if (isset($referal)) { $referal->save(); } return true; } catch (Exception $e) { return false; } return false; }
public function actionTable() { $customers = Customers::find()->All(); return $this->render('table', ['rows' => $customers]); }