示例#1
0
 /**
  * Creates a new Customers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Customers();
     $model->setScenario("create");
     $last = Customers::find()->orderBy(['id' => SORT_DESC])->one();
     $last_customer = empty($last) ? $last = 1 : $last->id + 1;
     if (isset($_POST['Customers'])) {
         $model->attributes = $_POST['Customers'];
         $main_image = UploadedFile::getInstance($model, 'img');
         $pathimage = null;
         if (!empty($main_image)) {
             $model->img = $main_image;
             $model->image = Yii::$app->security->generateRandomString() . $main_image->name . "." . $main_image->extension;
             $pathimage = getcwd() . '/images/customers/' . $model->image;
         }
         if ($model->save()) {
             if (isset($pathimage)) {
                 $main_image->saveAs($pathimage);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'last_customer' => $last_customer]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'last_customer' => $last_customer]);
     }
 }
 /**
  * Creates a new Cliche model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Cliche();
     $customers_base = array();
     $customers_model = new Customers();
     $customers_model->scenario = 'clisheEdit';
     $good_base = $customers_model->find()->where(['isWork' => 1])->orderBy('id')->asArray()->all();
     foreach ($good_base as $key => $value) {
         $customers_base = array_combine(array($value["id"]), array($value["customerName"]));
     }
     //if (Model::loadMultiple([$model, $customers_model], Yii::$app->request->post())) {
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'customers_model' => $customers_model, 'customers_base' => $customers_base]);
     }
 }
示例#3
0
 /**
  * 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;
 }
 /**
  * Lists all Customers models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Customers::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
 public function actionIndex()
 {
     $customers = Customers::find()->all();
     return $this->render('index', array('customers' => $customers));
 }
示例#6
0
 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;
 }
示例#7
0
 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;
 }
示例#8
0
 public function actionTable()
 {
     $customers = Customers::find()->All();
     return $this->render('table', ['rows' => $customers]);
 }
 /**
  * Updates an existing Order model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $modelOrder = $this->findModel($id);
     $modelsItems = $this->getModelItems($modelOrder->orderId);
     $modelOrder->scenario = 'managerAdd';
     //$modelsItems = $modelOrder->items;
     $customers_model = new Customers();
     $customers_base = $arr_keys = $arr_vals = array();
     $good_base = $customers_model->find()->where(['isWork' => 1])->orderBy('id')->asArray()->all();
     foreach ($good_base as $key => $value) {
         array_push($arr_keys, $value["id"]);
         array_push($arr_vals, $value["customerName"]);
     }
     $customers_base = array_combine(array($arr_keys), array($arr_vals));
     if ($modelOrder->load(Yii::$app->request->post())) {
         echo "== post request<br/>";
         $oldIDs = ArrayHelper::map($modelsItems, 'id', 'orderId');
         echo "== oldIDs are=<br/>";
         print_r($oldIDs);
         $modelsItems = OrderDetail::createMultiple(OrderDetail::classname(), $modelsItems);
         Model::loadMultiple($modelsItems, Yii::$app->request->post());
         echo "== deletedIDs are=<br/>";
         print_r($deletedIDs);
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsItems, 'id', 'orderId')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsItems), ActiveForm::validate($modelOrder));
         }
         // validate all models
         $valid = $modelOrder->validate();
         $valid = print_r(Model::validateMultiple($modelsItems)) && $valid;
         echo "== valid is=  " . $valid . "<br/>";
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             echo "==(trasaction) start<br/>";
             try {
                 if ($flag = $modelOrder->save(false)) {
                     if (!empty($deletedIDs)) {
                         echo "==(trasaction) delete oldIDs<br/>";
                         OrderDetail::deleteAll(['orderId' => $deletedIDs]);
                     }
                     echo "==(trasaction) modelItems post data are=<br/>";
                     foreach ($modelsItems as $modelItems) {
                         echo "==(trasaction) save model item<br/>";
                         $modelItems->orderId = $modelOrder->orderId;
                         if (!($flag = $modelItems->save(false))) {
                             echo "======(trasaction) rollback<br/>";
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     echo "==(trasaction) all ok. start redirect<br/>";
                     return $this->redirect(['view', 'orderId' => $modelOrder->orderId]);
                 }
             } catch (Exception $e) {
                 echo "======(trasaction) rollback catch way<br/>";
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['modelOrder' => $modelOrder, 'modelsItems' => empty($modelsItems) ? [new OrderDetail()] : $modelsItems, 'customers_base' => $customers_base]);
 }