Exemplo n.º 1
0
 public function savemakerdata()
 {
     $OrganID = Yii::app()->user->getOrganID();
     //接收make数据
     $make = Yii::app()->request->getParam("Make");
     //保存make数据
     $makemodel = Make::model()->find("OrganID=:organid", array(":organid" => $OrganID));
     if (empty($makemodel)) {
         //判断是否第一次添加
         $makemodel = new Make();
         $makemodel->OrganID = $OrganID;
     }
     $makemodel->SaleMoney = $make['SaleMoney'];
     $makemodel->SaleDomain = $make['SaleDomain'];
     if (!$makemodel->save()) {
         //var_dump($makemodel->errors);die;
         throw new CHttpException(400, '保存机构信息失败!');
     }
 }
Exemplo n.º 2
0
 /**
  * 公司信息保存
  */
 public function actionSavemakeorgan()
 {
     $OrganID = Yii::app()->user->getOrganID();
     $Organ = Yii::app()->request->getParam("Organ");
     $model = Organ::model()->findByPK($OrganID);
     if (empty($model)) {
         $model = new Organ();
     }
     //保存organ数据
     $model->attributes = $Organ;
     //判断基本信息是否为空,为空则不提交
     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)) {
                     $myfileurl = Yii::app()->params['uploadPath'] . $imageid;
                     if (file_exists($myfileurl)) {
                         $result = unlink($myfileurl);
                     }
                 } else {
                     $myfileurl = Yii::app()->params['uploadPath'] . $picture->Path;
                     OrganPhoto::model()->deleteAll('Path=:img AND OrganID=:OrganID', array(':img' => $imageid, ':OrganID' => $OrganID));
                     if (file_exists($myfileurl)) {
                         $result = unlink($myfileurl);
                     }
                 }
             }
         }
         //接收上传图片地址
         $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)) {
                 $filePath = Yii::app()->params['uploadPath'] . $model->BLPoto;
                 if (file_exists($filePath)) {
                     unlink($filePath);
                 }
             }
             $model->BLPoto = $BLPoto;
         }
         //接收make数据
         $make = Yii::app()->request->getParam("Make");
         //保存make数据
         $makemodel = Make::model()->find("OrganID=:organid", array(":organid" => $OrganID));
         if (empty($makemodel)) {
             //判断是否第一次添加
             $makemodel = new Make();
             $makemodel->OrganID = $OrganID;
         }
         $makemodel->SaleMoney = $make['SaleMoney'];
         $makemodel->SaleDomain = $make['SaleDomain'];
         if ($makemodel->save() && $model->save()) {
             //保存成功
             $this->redirect(array('index'));
         } else {
             var_dump($makemodel->errors);
             var_dump($model->errors);
             die;
         }
     }
 }