/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Customer(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['viewafterupdate', 'id' => $model->customer_user_name, 'checkIfUpdate' => 'created']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Customer(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * 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; }
public function addCus($name, $sort, $level, $parentId, $blogo, $clogo, $img1 = '', $img2 = '', $img3 = '', $img4 = '', $img5 = '') { $model = new Customer(); $model->name = $name; $model->sort = $sort; $model->level = $level; $model->parentId = $parentId; $model->blogo = $blogo; $model->clogo = $clogo; $model->img1 = $img1; $model->img2 = $img2; $model->img3 = $img3; $model->img4 = $img4; $model->img5 = $img5; $model->count = 0; $model->addTime = date('Y-m-d H:i:s', time()); $model->addUser = Yii::$app->session->get(Variable::$session_userId_str); if ($model->save()) { return true; } return false; }
/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $xmodel = []; $db = Yii::$app->db; // $query = $db->createCommand('EXEC mytest @xid=27'); $query = $db->createCommand('EXEC sp_company'); $xec = $query->queryAll(); foreach ($xec as $x) { // $xmodel['recid']=$x['recid']; $xmodel[$x['company_id']] = $x['company_name']; } $prov = new ArrayDataProvider(['allModels' => $xec]); $modelx = $prov->getModels(); // print_r($xmodel); // echo('<pre>'); // var_dump($modelx); // echo('</pre>'); // for($i=0;$i<count($modelx);$i++){ // echo $modelx[$i]['recid']; // echo $modelx[$i]['saleno']; // echo $modelx[$i]['saledate']; // } // for ($i=0;$i <= $model->lenght;$i++){ // echo $model[0]->recid; // } // return ; $model = new Customer(); $sale = new \backend\models\Saledata(); $country = new \backend\models\Country(); $province = new \backend\Models\Province(); $updatecom = []; $updatesec = []; $updatedep = []; $updatesale = []; $n = 0; $m = 0; if ($model->Cus_Customeras != '') { $dbcon = Yii::$app->db3; $res = $dbcon->createCommand('SELECT * FROM Sale_SaleData WHERE Sal_id=' . $model->Cus_Customeras)->queryAll(); foreach ($res as $res2) { $updatesale[$n]['recid'] = $res2['Sal_id']; $updatesale[$n]['salename'] = $res2['Sal_name']; // $updatesale[$res2['Sal_id']]= $res2['Sal_name']; $com = Yii::$app->db->createCommand('EXEC sp_company2 @param=' . $res2['bch_id'])->queryAll(); foreach ($com as $comres) { $updatecom[$m]['recid'] = $res2['bch_id']; // $updatecom[$m]['comname']=$comres['company_name']; // $updatecom[$comres['company'_id']]=$comres['company_name']; } $updatesec[$n]['recid'] = $res2['div_id']; $updatedep[$n]['recid'] = $res2['Sal_department']; // echo $updatesec[$n]['recid'];return; // $sec = Yii::$app->db->createCommand('EXEC sp_section2 @param='.$res2['div_id'])->queryAll(); // foreach ($sec as $secres){ // $updatesec[$m]['recid']=$secres['section_id']; // $updatecom[$m]['secname']=$secres['section_name']; // echo $secres['section_name'];return; // } } } $secmodel = []; $secdb = Yii::$app->db->createCommand('EXEC sp_section2')->queryAll(); foreach ($secdb as $secdbres) { $secmodel[$secdbres['section_id']] = $secdbres['section_name']; } $depmodel = []; $depdb = Yii::$app->db->createCommand('EXEC sp_department2')->queryAll(); foreach ($depdb as $depres) { $depmodel[$depres['department_id']] = $depres['department_name']; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->Cus_id]); } else { return $this->render('create', ['model' => $model, 'sale' => $sale, 'country' => $country, 'province' => $province, 'xmodel' => $xmodel, 'updatecom' => $updatecom, 'updatesec' => $updatesec, 'updatedep' => $updatedep, 'secmodel' => $secmodel, 'depmodel' => $depmodel]); } }