/** * function ::create ($data) */ public static function create($data) { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = new Customer(); if ($model->load($data)) { if ($log = new UserLog()) { $log->username = $username; $log->action = "Create"; $log->object_class = "Customer"; $log->created_at = $now; $log->is_success = 0; $log->save(); } $model->created_at = $now; do { $path = FileUtils::generatePath($now); } while (file_exists(Yii::$app->params['images_folder'] . $path)); $model->image_path = $path; $targetFolder = Yii::$app->params['images_folder'] . $model->image_path; $targetUrl = Yii::$app->params['images_url'] . $model->image_path; if (!empty($data['customer-image'])) { $copyResult = FileUtils::copyImage(['imageName' => $model->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => [[120, 120], [200, 200]], 'removeInputImage' => true]); if ($copyResult['success']) { $model->image = $copyResult['imageName']; } } if ($model->save()) { if ($log) { $log->object_pk = $model->id; $log->is_success = 1; $log->save(); } return $model; } $model->getErrors(); return $model; } return false; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['customer_birthdate' => $this->customer_birthdate]); $query->andFilterWhere(['like', 'customer_user_name', $this->customer_user_name])->andFilterWhere(['like', 'customer_first_name', $this->customer_first_name])->andFilterWhere(['like', 'customer_last_name', $this->customer_last_name])->andFilterWhere(['like', 'customer_address1', $this->customer_address1])->andFilterWhere(['like', 'customer_address2', $this->customer_address2])->andFilterWhere(['like', 'customer_email', $this->customer_email])->andFilterWhere(['like', 'customer_gender', $this->customer_gender])->andFilterWhere(['like', 'customer_from', $this->customer_from])->andFilterWhere(['like', 'customer_favcolor', $this->customer_favcolor]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customer::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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, 'phone_number' => $this->phone_number, 'dob' => $this->dob, 'gender' => $this->gender, 'language_id' => $this->language_id, 'is_active' => $this->is_active, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'total_purchase_orders' => $this->total_purchase_orders, 'total_purchase_products' => $this->total_purchase_products, 'total_purchase_value' => $this->total_purchase_value]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'zip_postal_code', $this->zip_postal_code]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $pagination = 10) { $query = Customer::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => $pagination]]); $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'tel', $this->tel])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'postal', $this->postal])->andFilterWhere(['like', 'city', $this->city]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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([ // 'ts_create' => $this->ts_create, // 'ts_update' => $this->ts_update, // 'IsDelete' => $this->IsDelete, // ]); $query->orFilterWhere(['like', 'Cus_id', $this->globalSearch])->orFilterWhere(['like', 'Cus_Name', $this->globalSearch])->orFilterWhere(['like', 'Cus_Nickname', $this->globalSearch])->orFilterWhere(['like', 'Cus_Phone', $this->globalSearch])->orFilterWhere(['like', 'Cus_Email', $this->globalSearch])->orFilterWhere(['like', 'Cus_Website', $this->globalSearch])->orFilterWhere(['like', 'Cus_Address', $this->globalSearch])->orFilterWhere(['like', 'Cus_Contactname', $this->globalSearch])->orFilterWhere(['like', 'Cus_Customeras', $this->globalSearch])->orFilterWhere(['like', 'Cus_Country', $this->globalSearch])->orFilterWhere(['like', 'ts_name', $this->globalSearch]); return $dataProvider; }
/** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Customer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDetails() { $session = new Sitesession(); $user_id = $session->getUserId(); $goods = $session->getGoods($user_id); $order_id = $session->getOrderId(); $order = null; if (!empty($order_id)) { $order = Orders::findOne($order_id); } $user = null; if ($user_id) { //获取user_id用户信息 /*$connection = \Yii::$app->db; $command = $connection->createCommand('SELECT * FROM customer WHERE id='.$user_id); $user = $command->queryOne();*/ $user = Customer::findOne($user_id); } $count = 0; if (is_array($goods) && !empty($goods)) { /*$str = ''; foreach ($goods as $key => $value) { if(empty($str)) { $str = $str." ".$value; } else { $str = $str.", ".$value; } } */ $count = count($goods); //获取goods $connection = \Yii::$app->db; $transaction = $connection->beginTransaction(); try { // 所有的查询都在主服务器上执行 //$goods = $connection->createCommand('SELECT * FROM goods WHERE goods_id in ('.$str.')')->queryAll(); $goods = Goods::findAll($goods); $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); throw $e; } } else { $goods = false; } return $this->render('details', ['user' => $user, 'goods' => $goods, 'count' => $count, 'order' => $order]); }
public function actionShowlist2($id) { $count = Customer::find()->where(['Cus_id' => $id])->count(); $model = Customer::find()->where(['Cus_id' => $id])->all(); if ($count > 0) { foreach ($model as $value) { $contry = \backend\models\Country::find()->where(['Cry_id' => $value->Cus_Country])->all(); $fullname2 = ''; foreach ($contry as $data2) { $fullname2 = $data2->Cry_nameEN . " [" . $data2->Cry_nameTH . "]"; } $session = new Session(); $session->open(); $session['shipto'] = $value->Cus_Country; echo "<option value='" . $value->Cus_Country . "'>{$fullname2}</option>"; } } else { echo "<option>-</option>"; } }
/** * @return \yii\db\ActiveQuery */ public function getCustomer() { return $this->hasOne(Customer::className(), ['customer_user_name' => 'user_name']); }
public function getCustomer() { return $this->hasOne(Customer::className(), ['id' => 'action_user']); }
echo Yii::$app->urlManager->createUrl('noreply-email/create'); ?> "><i class="fa fa-circle-o"></i> Thêm mới</a></li> </ul> </li> <!-- Khách hàng --> <li class="treeview <?php echo in_array(Yii::$app->controller->id, ['customer', 'customer-log']) ? 'active' : ''; ?> "> <a href="<?php echo Yii::$app->urlManager->createUrl('customer/index'); ?> "> <i class="fa fa-user"></i> <span>Khách hàng</span> <span class="label label-danger pull-right"><?php echo Customer::find()->where(['status' => Customer::STATUS_ACTIVE])->count(); ?> </span> </a> <!-- <ul class="treeview-menu"> <li class="<?php echo Yii::$app->controller->id == 'customer' && Yii::$app->controller->action->id == 'index' ? 'active' : ''; ?> "><a href="<?php echo Yii::$app->urlManager->createUrl('customer/index'); ?> "><i class="fa fa-circle-o"></i> Danh sách</a></li> <li class="<?php echo Yii::$app->controller->id == 'customer-log' && Yii::$app->controller->action->id == 'index' ? 'active' : ''; ?> "><a href="<?php
public function deleteCus($id) { $model = Customer::findOne($id); if (!$model) { return false; } if ($model->delete()) { Customer::deleteAll(['parentId' => $id]); return true; } return false; }
public function actionEditpointimg() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } $req = Yii::$app->request; //创建一个请求对象 $form = new CustomerForm(); $form->level = Variable::$customer_type_w; $form->setScenario('img'); $id = trim($req->get('id')); if (!is_numeric($id) || $id == 0) { $this->redirect(Variable::$customerBrand_url); return; } //修改 if ($form->load($req->post()) && $form->validate()) { $isSuccess = (new Customer())->updateCus($id, $form->name, $form->sort, $form->level, $form->blogo, $form->clogo, $form->img1, $form->img2, $form->img3, $form->img4, $form->img5); if ($isSuccess) { Yii::$app->session->setFlash(Variable::$flash_success, '设置成功'); } else { // $form->addError('','更新失败'); Yii::$app->session->setFlash(Variable::$flash_error, '设置失败,请重试'); } } $customerModel = Customer::findOne($id); $form->img1 = $customerModel->img1; $form->img2 = $customerModel->img2; $form->img3 = $customerModel->img3; $form->img4 = $customerModel->img4; $form->img5 = $customerModel->img5; $form->name = $customerModel->name; $form->id = $customerModel->id; $list = []; if (!empty($form->img1)) { array_push($list, $form->img1); } if (!empty($form->img2)) { array_push($list, $form->img2); } if (!empty($form->img3)) { array_push($list, $form->img3); } if (!empty($form->img4)) { array_push($list, $form->img4); } if (!empty($form->img5)) { array_push($list, $form->img5); } return $this->render(Variable::$editPointImg_view, ['model' => $form, 'customerModel' => $customerModel, 'list' => $list]); }