/** * Creates a new ResrveCustomer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ResrveCustomer(); $data = array(); $data['model'] = $model; $data['birthdate_d'] = array(); for ($d = 1; $d <= 31; $d++) { $data['birthdate_d'][$d] = $d; } $data['birthdate_y'] = array(); for ($y = date('Y'); $y >= date('Y') - 60; $y--) { $data['birthdate_y'][$y] = $y; } $data['birthdate_m'] = array(1 => 'มกราคม', 2 => 'กุมภาพันธ์', 3 => 'มีนาคม', 4 => 'เมษายน', 5 => 'พฤษภาคม', 6 => 'มิถุนายน', 7 => 'กรกฎาคม', 8 => 'สิงหาคม', 9 => 'กันยายน', 10 => 'ตุลาคม', 11 => 'พฤศจิกายน', 12 => 'ธันวาคม'); $data['classLevels'] = ResrveClasslevel::ddlClassLevel(); $data['majormsts'] = ResrveMajormst::ddlMajormst(); $data['schools'] = ResrveSchool::ddlSchool(); $data['statemsts'] = Statemst::ddlStatemst(); if ($model->load(Yii::$app->request->post())) { //$post = Yii::$app->request->post(); $RefNo = RefNoStat::getCustomerCode(); $customer_code = "1000" . $RefNo->SREF_CUR + 1; $ref_code = $RefNo->SREF_CUR + 1; $paswd = Convert::student_password($customer_code); $RefNoStat = RefNoStat::findOne(['SREF_TYPE1' => 'RES', 'SREF_TYPE2' => 'CUS', 'SREF_REFERER' => 'resrve_customer']); $RefNoStat->SREF_CUR = $ref_code; if ($RefNoStat->save()) { $model->customer_code = (string) $customer_code; $model->customer_id01 = (string) $customer_code; $model->customer_id02 = (string) $customer_code; $model->customer_password = $paswd; $model->customer_flag = '1'; $model->customer_status = '0'; $model->customer_dbtr_link = '83'; $model->customer_branch = '37'; $model->customer_userdefine4 = '0'; $model->customer_query_promo = '1'; $model->customer_last_name = Utf8ToHtml::encrypt($model->customer_last_name, ''); $model->customer_first_name = Utf8ToHtml::encrypt($model->customer_first_name, ''); $model->customer_nickname = Utf8ToHtml::encrypt($model->customer_nickname, ''); $model->customer_parent_name = Utf8ToHtml::encrypt($model->customer_parent_name, ''); $model->customer_parent_last_name = Utf8ToHtml::encrypt($model->customer_parent_last_name, ''); $model->customer_address1 = Utf8ToHtml::encrypt($model->customer_address1, ''); $model->customer_birthdate = $_POST['birthdate_y'] . '-' . $_POST['birthdate_m'] . '-' . $_POST['birthdate_d']; if ($model->save()) { return $this->redirect(['site/login']); } else { echo '<pre>'; print_r($model->getErrors()); echo '</pre>'; } } else { echo '<pre>'; print_r($RefNoStat->getErrors()); echo '</pre>'; } } else { return $this->render('create', $data); } }
public static function getCustomerCode() { $model = RefNoStat::find()->where(['sref_type1' => 'RES', 'sref_type2' => 'CUS', 'sref_referer' => 'resrve_customer'])->one(); return $model; }