/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Dealer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Dealer'])) { $model->attributes = $_POST['Dealer']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * 公司信息保存 */ public function actionSavedealerorgan() { $OrganID = Yii::app()->user->getOrganID(); $Organ = Yii::app()->request->getParam("Organ"); $arr = Yii::app()->request->getParam("telPhone"); $TelPhone = ""; foreach ($arr as $key => $val) { if (empty($val)) { continue; } $TelPhone .= $val . ","; } $model = Organ::model()->findByPK($OrganID); if (empty($model)) { $model = new Organ(); } //保存organ数据 $model->attributes = $Organ; $model->TelPhone = trim($TelPhone, ','); //判断基本信息是否为空,为空则不提交 if ($Organ) { //接收删除图片的地址 $photoId = Yii::app()->request->getParam("photoId"); //判断是否删除图片 if (!empty($photoId)) { $imageids = explode(',', $photoId); foreach ($imageids as $imageid) { $picture = OrganPhoto::model()->find('Path=:img AND OrganID=:OrganID', array(':img' => $imageid, ':OrganID' => $OrganID)); //判断该图片路径是否存在数据库中 if (empty($picture)) { $ftp = new Ftp(); $res = $ftp->delete_file($imageid); $ftp->close(); } else { OrganPhoto::model()->deleteAll('Path=:img AND OrganID=:OrganID', array(':img' => $imageid, ':OrganID' => $OrganID)); $ftp = new Ftp(); $res = $ftp->delete_file($picture->Path); $ftp->close(); } } } //接收上传图片地址 $goodsImages = Yii::app()->request->getParam("goodsImages"); //判断是否有上传图片 if (!empty($goodsImages)) { $imglegth = count($goodsImages); for ($i = 0; $i < $imglegth; $i++) { $goodsImg = new OrganPhoto(); $goodsImg->OrganID = $OrganID; $goodsImg->Path = $goodsImages[$i]; $goodsImg->save(); } } //判断是否上传营业执照 $BLPoto = Yii::app()->request->getParam("BLPoto"); if ($model->BLPoto != $BLPoto) { if (!empty($model->BLPoto)) { $ftp = new Ftp(); $res = $ftp->delete_file($model->BLPoto); $ftp->close(); } $model->BLPoto = $BLPoto; } //接收dealer数据 $dealer = Yii::app()->request->getParam("Dealer"); //保存dealer数据 $dealermodel = Dealer::model()->find("OrganID=:organid", array(":organid" => $OrganID)); if (empty($dealermodel)) { //判断是否第一次添加 $dealermodel = new Dealer(); $dealermodel->OrganID = $OrganID; } $dealermodel->SaleMoney = $dealer['SaleMoney']; $dealermodel->SaleDomain = $dealer['SaleDomain']; $dealermodel->ShopArea = $dealer['ShopArea']; if ($dealermodel->save() && $model->save()) { //保存成功 $this->redirect(array('index')); } else { var_dump($dealermodel->errors); var_dump($model->errors); die; } } }
public function savedealerdata() { $OrganID = Yii::app()->user->getOrganID(); //接收dealer数据 $dealer = Yii::app()->request->getParam("Dealer"); //保存dealer数据 $dealermodel = Dealer::model()->find("OrganID=:organid", array(":organid" => $OrganID)); if (empty($dealermodel)) { //判断是否第一次添加 $dealermodel = new Dealer(); $dealermodel->OrganID = $OrganID; } $dealermodel->SaleMoney = $dealer['SaleMoney']; $dealermodel->SaleDomain = $dealer['SaleDomain']; $dealermodel->ShopArea = $dealer['ShopArea']; if (!$dealermodel->save()) { //var_dump($dealermodel->errors);die; throw new CHttpException(400, '保存机构信息失败!'); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aDealer !== null) { if ($this->aDealer->isModified() || $this->aDealer->isNew()) { $affectedRows += $this->aDealer->save($con); } $this->setDealer($this->aDealer); } if ($this->aTeam !== null) { if ($this->aTeam->isModified() || $this->aTeam->isNew()) { $affectedRows += $this->aTeam->save($con); } $this->setTeam($this->aTeam); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->dealerTeamVersionsScheduledForDeletion !== null) { if (!$this->dealerTeamVersionsScheduledForDeletion->isEmpty()) { \DealerTeam\Model\DealerTeamVersionQuery::create()->filterByPrimaryKeys($this->dealerTeamVersionsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->dealerTeamVersionsScheduledForDeletion = null; } } if ($this->collDealerTeamVersions !== null) { foreach ($this->collDealerTeamVersions as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * 保存机构信息 */ public function actionSavedealerorgan() { $userID = Commonmodel::getOrganID(); $model = Dealer::model()->findByAttributes(array('userID' => $userID)); if (empty($model)) { $model = new Dealer(); // $display = 'none'; } if (isset($_POST['Dealer'])) { $model->attributes = $_POST['Dealer']; $model->Pinyin = F::Pinyin1($_POST['Dealer']['organName']); $model->CreateTime = time(); $model->userID = $userID; $model->jiapartsId = $model->attributes['Phone']; // 上传图片 $goodsImages = $_POST['goodsImages']; $imglegth = count($goodsImages); for ($i = 0; $i < $imglegth; $i++) { $goodsImg = new DealerOrganphoto(); $goodsImg->addtime = time(); $goodsImg->dealerID = $userID; $goodsImg->photoName = $goodsImages[$i]; $goodsImg->save(); } $usercheckmodel = Dealer::model()->findByAttributes(array('userID' => $userID)); if ($model->save()) { if (empty($usercheckmodel)) { $user = User::model()->findByPk($userID); $user->OrganID = $userID; $user->save(); $dealmenu = Menu::model()->find("root=1 and level=2 and name='经销商菜单' and if_show=1"); $threeM = Menu::model()->findAll("lft>:lft and rgt<:rgt and root=1 and level=3 and if_show=1", array(':lft' => $dealmenu->lft, ':rgt' => $dealmenu->rgt)); $jurF = ''; $jurS = ''; $jurT = ''; foreach ($threeM as $key => $val) { if ($val->name == '销售管理' || $val->name == '营销管理' || $val->name == '数据查询' || $val->name == '用户中心' || $val->name == '采购管理') { $jusM = Menu::model()->findAll("lft>:lft and rgt<:rgt and root=1 and level>3 and if_show=1", array(':lft' => $val->lft, ':rgt' => $val->rgt)); if ($val->name == '销售管理') { foreach ($jusM as $keyj => $valj) { if ($valj->name == '统计分析') { $jurT .= $valj->id . ','; } else { $jurF .= $valj->id . ','; } } } elseif ($val->name == '营销管理') { foreach ($jusM as $keyj => $valj) { if ($valj->name != '业务联系人管理') { $jurF .= $valj->id . ','; } } } elseif ($val->name == '数据查询') { $jurF .= $val->id . ','; foreach ($jusM as $keyj => $valj) { $jurF .= $valj->id . ','; } } elseif ($val->name == '用户中心') { foreach ($jusM as $keyj => $valj) { if ($valj->name == '物流配送管理') { $jurF .= $valj->id . ','; } elseif ($valj->name == '金融账户管理') { $jurT .= $valj->id . ','; } } } elseif ($val->name == '采购管理') { foreach ($jusM as $keyj => $valj) { if ($valj->name == '统计分析') { $jurT .= $valj->id . ','; } else { $jurS .= $valj->id . ','; } } } } } for ($i = 0; $i < 3; $i++) { $jur = ''; $role = new Role(); if ($i == 0) { $role->RoleName = "销售专员"; $role->Jurisdiction = $jurF; } elseif ($i == 1) { $role->RoleName = "采购专员"; $role->Jurisdiction = $jurS; } elseif ($i == 2) { $role->RoleName = "财务专员"; $role->Jurisdiction = $jurT; } $role->OrganID = $userID; $role->UserID = Yii::app()->user->id; $role->CreateTime = time(); $role->save(); } } echo json_encode('OK'); // $this->redirect('Index'); } else { echo json_encode('NoOk'); } } }