/** * @param DatabaseBackupFile $file * @return ResultObject[] */ public function process(DatabaseBackupFile $file) { $d = $file->getBackupDate(); $results = []; foreach ($this->uploadsCredentials as $credentials) { $result = new ResultObject(); // empty ResultObject means all is OK $backupPath = $credentials['path'] . '/' . $d->format('Y') . '/' . $d->format('F'); $entireFilePath = $backupPath . '/' . $file->getFileName(); try { $ftp = new \Ftp(); $ftp->connect($credentials['host']); $ftp->login($credentials['username'], $credentials['password']); if (!$ftp->fileExists($backupPath)) { $ftp->mkDirRecursive($backupPath); } $ftp->put($entireFilePath, $file->getFilePath(), FTP_BINARY); $ftp->close(); } catch (\FtpException $e) { $this->logger->addCritical(sprintf('Uploading backup file\'s failed. %s', $e)); $result->addError('Zálohu se nepodařilo nahrát na: ' . $credentials['host'], 'error'); } $results[] = $result; } return $results; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $menu = $model->attributes; if (isset($_POST['FrontMenu'])) { $model->attributes = $_POST['FrontMenu']; foreach ($this->uploadArr as $column) { $file = CUploadedFile::getInstance($model, $column); //获取表单名为filename的上传信息 if ($file) { $model->{$column} = $this->uploadIcon($file); if ($menu[$column]) { $ftp = new Ftp(); $res = $ftp->delete_file('common/frontmenu/' . $menu[$column]); $ftp->close(); } } else { unset($model->{$column}); } } if (!$model->ParentID) { $model->ParentID = 0; } if ($model->save()) { $this->freshMenuCache(); $this->redirect(array('admin')); } } $this->render('update', array('model' => $model)); }
/** * Ist für den Abgleich der Bestellungen im Cronjob. */ public function update() { global $selectline, $oxid, $ftp; $this->set_log('Cronjob: ' . date('d.m.Y H:i:s') . "\r\n"); try { $ftp = new Ftp(); $ftp->connect($oxid['ftp_host']); $ftp->login($oxid['ftp_user'], $oxid['ftp_password']); $ftp->close(); } catch (Exception $e) { $this->set_log('SelectConnect konnte keine Verbindung zum FTP-Server herstellen!'); exit; } if (!oxid_userlogin()) { $this->set_log('SelectConnect konnte sich nicht bei Oxid einloggen!'); exit; } if (!$this->is_current_update_process()) { $this->set_log("Cronjob wurde gestartet \r\n"); $this->set_lock_file(); $last_update = $this->get_last_update(); $this->set_log("Bestellungen werden in Selectline importiert \r\n"); $orders = $oxid['db']->get_results("SELECT * FROM " . $oxid['table_order'] . " WHERE OXFOLDER = '" . $oxid['get_order_status'] . "' ORDER BY OXORDERNR"); if ($orders) { foreach ($orders as $order) { $order_products = $oxid['db']->get_results("SELECT * FROM " . $oxid['table_orderarticles'] . " WHERE OXORDERID = '" . $order->OXID . "' "); $order->products = $order_products; $order_payment = $oxid['db']->get_row("SELECT * FROM " . $oxid['table_payments'] . " WHERE ('" . $order->OXPAYMENTTYPE . "' = OXID)"); $order->payment = $order_payment; $this->set_order_to_selectline($order, true); $oxid['db']->query("UPDATE " . $oxid['table_order'] . " SET OXFOLDER = '" . $oxid['set_order_status'] . "', OXEXPORT = 1 WHERE `OXID` = '" . $order->OXID . "' "); } } $this->set_log("Bestellungstatus wird abgeglichen \r\n"); $orders = $selectline['db']->get_results("SELECT * FROM " . $selectline['table_orders'] . " WHERE [Belegtyp] = '" . $selectline['filter_order_invoice'] . "' AND [BearbeitetAm] >= CONVERT(datetime, '" . $last_update->format('d.m.Y H:i:s') . "',104)"); if ($orders) { foreach ($orders as $order) { $tracking_id = $this->get_tracking_id_from_selectline($order); $updateArray = array('OXBILLNR' => $order->Belegnummer, 'OXBILLDATE' => $order->Datum->format('Y-m-d'), 'OXSENDDATE' => $order->Datum->format('Y-m-d H:i:s'), 'OXFOLDER' => $oxid['order_status_finish']); if ($tracking_id !== NULL) { $updateArray['OXTRACKCODE'] = $tracking_id; } //print_r($this->format_update_query($oxid['table_order'], $updateArray, array('OXORDERNR' => str_replace('OX', '', $order->IhrAuftrag)))); $oxid['db']->query($this->format_update_query($oxid['table_order'], $updateArray, array('OXORDERNR' => str_replace('OX', '', $order->IhrAuftrag)))); $this->set_log("Bestellung " . $order->IhrAuftrag . "/" . $order->Belegnummer . " - Status: FINISHED - Tracking: " . $tracking_id . " \r\n"); } } $this->set_last_update(); $this->remove_lock_file(); $this->set_log("Cron wurde beendet \r\n"); $this->set_log("\r\n##################################\r\n\r\n"); } else { print_r('Error: Es läuft bereits Update-Prozess.'); } }
function get_ftp_content($source, $target) { $result = false; $config = array('hostname' => FTP_HOST, 'username' => FTP_USER, 'password' => FTP_PASSWORD, 'port' => FTP_PORT, 'timeout' => FTP_TIMEOUT); $ftp = new Ftp(); $ftp->connect($config); if ($ftp->existsFile($source)) { $result = $ftp->download($source, $target); } else { access_log('log', 'No documents.'); //clear_file(); } $ftp->close(); return $result; }
/** * [set_product_images_oxid description] * @param [type] $product [description] */ private function set_product_images_oxid($product) { global $oxid, $selectline; $product->images = $selectline['db']->get_results("SELECT * FROM " . $selectline['table_product_img'] . " WHERE [Blobkey] = 'AR" . $product->Artikelnummer . "'"); if ($product->images) { $i = 1; $ftp = new Ftp(); $ftp->connect($oxid['ftp_host']); $ftp->login($oxid['ftp_user'], $oxid['ftp_password']); foreach ($product->images as $image) { $img = WideImage::load($image->Bild); if ($i > 1) { $filename = $product->ART_ID . '_' . $i . '.jpg'; } else { $filename = $product->ART_ID . '.jpg'; } $img->saveToFile(ABSPATH . '/images/' . $filename); $ftp->put($oxid['img_path'] . '/master/product/' . $i . '/' . $filename, ABSPATH . '/images/' . $filename, FTP_BINARY); @unlink(ABSPATH . '/images/' . $filename); $oxid['db']->query($this->format_update_query($oxid['table_products'], array('OXPIC1' => $filename), array('OXID' => $product->ART_ID))); $i++; } $ftp->close(); } }
<script src="js/jquery-2.1.3.min.js"></script> <script src="js/jQuery.ajaxQueue.js"></script> <script src="bootstrap/js/bootstrap.min.js"></script> <script src="bootstrap/js/bootstrap-select.min.js"></script> </head> <body class="<?php echo $action; ?> "> <?php try { $ftp = new Ftp(); $ftp->connect($oxid['ftp_host']); $ftp->login($oxid['ftp_user'], $oxid['ftp_password']); $ftp->close(); } catch (Exception $e) { print_r('<p class="alert alert-danger">SelectConnect konnte keine Verbindung zum FTP-Server herstellen!</p>'); $action = 'error'; } if (!oxid_userlogin()) { print_r('<p class="alert alert-danger">SelectConnect konnte sich nicht bei Oxid einloggen!</p>'); $action = 'error'; } switch ($action) { case 'orders': $orders = new Orders(); $items = $orders->import(); ?> <h1>SelectConnect | Bestellungen</h1> <p>Es wurden <?php
public function forward_suobei($id) { //获取视频id $sql = 'SELECT content_id,vodid FROM ' . DB_PREFIX . 'materials WHERE content_id IN (' . $id . ') AND vodid !=""'; $query = $this->db->query($sql); $k = array(); while ($row = $this->db->fetch_array($query)) { $k[$row['content_id']] = $row['vodid']; } $ids = ''; $ret = array(); if (!empty($k)) { //获取视频信息 $ids = implode(',', $k); $keys = array_keys($k); $vodpath = array(); //获取报料标题 $sql = 'SELECT id,title FROM ' . DB_PREFIX . 'content WHERE id IN (' . implode(',', $keys) . ')'; $query = $this->db->query($sql); $title = array(); while ($row = $this->db->fetch_array($query)) { $title[$row['id']] = $row['title']; } $title = array_combine($k, $title); $ftp = $this->settings['App_suobei']['ftp']; $ids = implode(',', $k); $ret = $this->get_vodinfo($ids, $ftp['host'], $ftp['username'], $ftp['password']); $vodpath = array(); if (!empty($ret) && is_array($ret)) { foreach ($ret as $key => $val) { $vodpath[$val['id']] = $ret[$key]; } } else { $this->errorOutput('ftp上传失败'); } } if (!empty($vodpath) && !empty($title)) { //获取报料标题 //写xml文件 $this->vod_xml($vodpath, $title); //ftp上传 //实例化ftp,并连接 $ftp_config = array('hostname' => $ftp['host'], 'username' => $ftp['username'], 'password' => $ftp['password']); $ftp_up = new Ftp(); if (!$ftp_up->connect($ftp_config)) { $this->errorOutput('CAN NOT CONNECT FTP SERVER'); } foreach ($vodpath as $k => $v) { $target_dir = $v['dir'] . '/'; $target_path = $target_dir . $v['filename'] . '.xml'; $xml_filepath = $this->settings['App_suobei']['xmldir'] . $v['filename'] . '.xml'; if (!file_exists($xml_filepath)) { $this->errorOutput('CAN NOT FIND XML'); } if (!$ftp_up->mkdir($target_dir)) { $this->errorOutput('CAN NOT MAKE DIR'); } if (!$ftp_up->upload($xml_filepath, $target_path)) { $this->errorOutput('CAN NOT UPLOAD FILE'); } } $ftp_up->close(); //更新状态位 $sql = 'UPDATE ' . DB_PREFIX . 'content SET suobei=1 WHERE id IN (' . implode(',', $keys) . ')'; $this->db->query($sql); } return $id; }
public function upload2ftp() { $config = json_decode($this->input['config'], 1); $files = json_decode($this->input['files'], 1); include_once ROOT_PATH . 'lib/class/ftp.class.php'; $ftp = new Ftp(); $server_dir = trim($config['server_dir'], '/'); $app_dir = $config['app_dir']; $message = array('error' => 0); if (!$ftp->connect($config)) { $message['error'] = 1; $message['message'] = '连接服务器失败[' . $config['hostname'] . ']'; } if ($server_dir && !$message['error']) { if (!$ftp->mkdir($server_dir)) { $message['error'] = 2; $message['message'] = '目标目录不存在且创建失败[' . $server_dir . ']'; } } if (!$files && !$message['error']) { $message['error'] = 3; $message['message'] = '文件列表不存在[' . $files . ']'; } if (!$message['error']) { foreach ($files as $file) { if (!file_exists($file)) { //continue; } //返回上传错误的文件 $dfile = str_replace($app_dir, '', $file); //如果设定了ftp目标目录 $dfile = $server_dir ? $server_dir . $dfile : $dfile; $upload_dir = trim(str_replace('/' . basename($file), '', $dfile), '/'); if ($upload_dir) { $ftp->mkdir($upload_dir); } if (!$ftp->upload($file, $dfile)) { $message['error'] = 4; $message['message'][$file] = $dfile; } } } //file_put_contents(CACHE_DIR . 'debug.txt', var_export($config,1)); $ftp->close(); $this->addItem($message); $this->output(); }
/** * 公司信息保存 */ public function actionSaveserviceorgan() { $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; } //接收service数据 $service = Yii::app()->request->getParam("Service"); $opentime = Yii::app()->request->getParam("OpenTime"); //保存service数据 $servicemodel = Service::model()->find("OrganID=:organid", array(":organid" => $OrganID)); if (empty($servicemodel)) { //判断是否第一次添加 $servicemodel = new Service(); $servicemodel->OrganID = $OrganID; } $servicemodel->PositionCount = $service['PositionCount']; $servicemodel->TechnicianCount = $service['TechnicianCount']; $servicemodel->ParkingDigits = $service['ParkingDigits']; $servicemodel->ReservationMode = $service['ReservationMode']; $servicemodel->ShopArea = $service['ShopArea']; $servicemodel->OpenTime = $opentime[0] . ',' . $opentime[1] . ',' . $opentime[2] . ',' . $opentime[3]; //$model->attributes = $Organ; if ($servicemodel->save() && $model->save()) { //保存成功 //$file->saveAs(Yii::app()->params['uploadPath'].$model->Logo, true); $this->redirect(array('index')); } else { var_dump($goodsImg->errors); die; } } }
public function actionEditlogo() { $organID = Yii::app()->user->OrganID; //organ表单验证 $model = Organ::model()->findByPK($organID); if ($model->Logo) { //删除 $ftp = new Ftp(); $res = $ftp->delete_file($model->Logo); $ftp->close(); } //获得一个CUploadedFile的实例 $file = CUploadedFile::getInstanceByName('Logo'); $rs = array('code' => 100, 'msg' => '上传失败!' . $ImgName . '已经上传'); $upload = Yii::app()->params['uploadPath'] . 'tmp/logo/' . $organID . '/'; $path = Yii::app()->params['uploadPath'] . 'tmp/'; if (!is_dir($upload)) { mkdir($upload, 0777, true) or die('创建失败'); chmod($upload, 0777); } // 判断实例化是否成功 if (is_object($file) && get_class($file) === 'CUploadedFile') { $model->Logo = 'logo/' . $organID . '/' . 'file_' . date("YmdHis") . '_' . rand(1000, 9999) . '.' . $file->extensionName; //定义文件保存的名称 } /* else{ // 若果失败则应该是什么图片 $model->url = './assets/upfile/noPic.jpg'; } */ if ($model->save()) { $file->saveAs($path . $model->Logo, true); $ftp = new Ftp(); $res = $ftp->uploadfile($path . $model->Logo, $model->Logo); $ftp->close(); @unlink($path . $model->Logo); } $this->redirect(array('index')); }
/** * Cambia el nombre de una imagen existente * * Actualiza el nombre nuevo en la tabla de imagenes y cambia * el nombre al archivo físico * * @param string $titulo El titulo de la imagen * @param string $slug El nombre de la imagen sin limpiar * @param booelan $mostrarPieFoto TRUE si se quiere mostrar el titulo en el pie de la imagen * @param array $documento Array con los parametros del documento * @param booelan $idThumbnail * @param integer $orden * @return boolean TRUE si se cambió con Exito */ public function actualiza() { $ok = TRUE; // Cargo los datos del objeto antes de cambiarlos $doc = new CpanDocs($this->getId()); $pathName = $doc->getPathName(); $nombreAnterior = $doc->getName(); unset($doc); // Si el nombre propuesto es distinto al que ya tiene y no es Thumbnail // recalculo el nombre amigable, cambio el path y renombro el archivo $this->actualizaNombreAmigable(); $nombreNuevo = $this->getName(); $pathInfo = pathinfo($pathName); $carpetaDestino = $this->_prePath . $pathInfo['dirname']; $ftp = new Ftp($_SESSION['project']['ftp']); $ok = $ftp->rename($carpetaDestino, $nombreAnterior, $nombreNuevo); $this->_errores = $ftp->getErrores(); $ftp->close(); unset($ftp); if ($this->_ArrayDoc['tmp_name'] != '') { $ok = $this->subeDocumento(); } // Si todo ha ido bien, actualizo el objeto if ($ok) { $this->save(); } unset($this); return $ok; }
public function actionUploadFile() { $path = $_POST['path']; if (!empty($_FILES)) { $oldfileName = $_FILES['Filedata']['name']; $ext = substr($oldfileName, strrpos($oldfileName, ".") + 1); $filesize = $_FILES['Filedata']['size']; //上传文件大小 $fileName = $this->getRandomName($oldfileName); $tmpFile = $_FILES['Filedata']['tmp_name']; //缓存文件路径 //$type = $_FILES['Filedata']['type']; //上传文件类型 $tp = array('gif', 'jpg', 'png', 'bmp', 'jpeg', 'doc', 'docx', 'xls', 'xlsx', 'txt'); //检查上传文件是否在允许上传的类型 if (!in_array($ext, $tp)) { echo json_encode(array('code' => 1, 'msg' => '只能发送图片、文档、表格等文件')); die; } if (in_array($ext, array('gif', 'jpg', 'png', 'bmp', 'jpeg'))) { $ftype = 1; } else { $ftype = 2; } //检查文件大小 $max_size = 2 * 1024 * 1024; //2M if ($filesize > $max_size) { echo json_encode(array('code' => 0, 'msg' => '上传文件大小超过限制,不允许超过2M ')); die; } //上传文件临时保存路径 $tmpsavepath = Yii::app()->params['uploadPath'] . 'tmp/'; if (!file_exists($tmpsavepath)) { if (!@mkdir($tmpsavepath, 0777, true)) { echo json_encode(array('code' => 0, 'msg' => '临时保存目录创建失败 - ' . $tmpsavepath)); die; } else { chmod($tmpsavepath, 0777); } } //检查目录写权限 if (@is_writable($tmpsavepath) === false) { echo json_encode(array('code' => 0, 'msg' => '临时保存目录没有写权限 - ' . $tmpsavepath)); die; } $tmpsavefile = $tmpsavepath . basename($tmpFile); if (@move_uploaded_file($tmpFile, $tmpsavefile) === false) { echo json_encode(array('code' => 0, 'msg' => '文件保存失败 - ' . $tmpsavefile)); die; } $fileurl = $path . $fileName; // 新文件名 $ftp = new Ftp(); $res = $ftp->uploadfile($tmpsavefile, $fileurl); $ftp->close(); if ($res['success']) { @unlink($tmpsavefile); //删除临时文件 echo json_encode(array('code' => 200, 'ftype' => $ftype, 'fileurl' => $fileurl, 'filename' => $oldfileName, 'msg' => '上传成功!')); } else { echo json_encode(array('code' => 0, 'msg' => $res['msg'])); } } else { echo json_encode(array('code' => 0, 'msg' => '请选择文件!')); } }
public function actionDelPto() { $imageid = Yii::app()->request->getParam("imageid"); $ftp = new Ftp(); $res = $ftp->delete_file($imageid); $ftp->close(); echo json_encode($res); }
/** * ftp上传 * @param $file_path:本地文件的路径 * @param $savename:文件名 * @return 1;上传成功<br> * 0;上传失败 */ private function ftp_upload($ftp_file_path, $local_file_path, $savename, $type) { import("@.ORG.Ftp"); $ftp = new Ftp(); $conn = $ftp->connect('w1.weimg.cn', 'images', 'images580230', $port = '21', $pasv = false, $ssl = false, $timeout = 30); $ftp->mkdir($ftp_file_path); $res = $ftp->put($ftp_file_path . $savename, $local_file_path . $savename); if ($type == 4) { $ftp->put($ftp_file_path . 's_' . $savename, $local_file_path . 's_' . $savename); unlink('./Public/upload/s_' . $savename); } $ftp->close(); unlink('./Public/upload/' . $savename); if (!$res) { return 0; } else { return 1; } }
/** * Sube al servidor el archivo de plantilla a la carpeta * docs/docsXXX/circulares/plantillas. * * Debe existir la carpeta docs/docsXXX/circulares. * Se sube usando ftp. * * @return type */ public function SubirPlantillaAction() { $fichero = $this->request['FILES']['filePlantilla']; if (in_array($fichero['type'], $this->tiposPermitidos)) { $carpetaPlantillas = $_SESSION['appPath'] . "/docs/docs{$_SESSION['emp']}/circulares/plantillas"; Archivo::creaCarpeta($carpetaPlantillas); if (is_uploaded_file($fichero['tmp_name'])) { $ftp = new Ftp($_SESSION['project']['ftp']); if ($ftp) { $ok = $ftp->upLoad($carpetaPlantillas, $fichero['tmp_name'], $fichero['name']); $this->_errores = $ftp->getErrores(); $ftp->close(); } else { $this->_errores[] = "Fallo al conectar vía FTP"; foreach ($_SESSION['project']['ftp'] as $item) { $this->_errores[] = $item; } } } } else { $this->_errores[] = "Tipo de archivo no permitido. Sólo se admiten archivos rtf,txt y html"; } $this->values['errores'] = $this->_errores; return $this->IndexAction(); }
/** * 公司信息保存 */ 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 delorganphoto($photoId) { $imageids = explode(',', $photoId); $OrganID = Yii::app()->user->getOrganID(); $ftp = new Ftp(); foreach ($imageids as $imageid) { $picture = OrganPhoto::model()->find('Path=:img AND OrganID=:OrganID', array(':img' => $imageid, ':OrganID' => $OrganID)); //判断该图片路径是否存在数据库中 if (empty($picture)) { $res = $ftp->delete_file($imageid); } else { OrganPhoto::model()->deleteAll('Path=:img AND OrganID=:OrganID', array(':img' => $imageid, ':OrganID' => $OrganID)); $res = $ftp->delete_file($picture->Path); } } $ftp->close(); }
public static function editscheme($params) { $organID = Yii::app()->user->getOrganID(); $time = $_SERVER['REQUEST_TIME']; //更新报价单 $quoID = self::ifsendquo(array('inqid' => $params['inqid'])); $quodatas['UpdateTime'] = $time; $quodatas['Title'] = $params['quoname']; $result = Yii::app()->papdb->createCommand()->update('pap_quotation', $quodatas, 'QuoID=' . $quoID); $SchID = $params['schid']; $datas['TotalFee'] = $params['quoprices']; $datas['GoodFee'] = $params['totalprices']; $datas['ShipFee'] = $params['shipprices']; $datas['ShipFee'] = $params['shipprices']; $datas['UpdateTime'] = $time; //保存附件 if ($params['fileurl']) { $datas['FileName'] = $params['filename']; $datas['FileUrl'] = $params['fileurl']; //删除之前附件 $quo_data = PapQuotationScheme::model()->findByPk($SchID); if (!empty($quo_data['FileName'])) { $ftp = new Ftp(); $res = $ftp->delete_file($quo_data->FileUrl); $ftp->close(); } } $result = Yii::app()->papdb->createCommand()->update('pap_quotation_scheme', $datas, 'SchID=:SchID', array(':SchID' => $SchID)); //获取商品信息 $goodsinfo = array(); $goodsids = explode(',', $params['quoids']); $goodsnum = explode(',', $params['quonum']); $goodsprice = explode(',', $params['quoprice']); //获取以前的商品信息 $oldgoodsinfo = PapQuotationGoods::model()->findAll('SchID=' . $SchID); $newgoodsinfo = array(); foreach ($goodsids as $key => $v) { if ($v) { $newgoodsinfo[$key]['GoodsID'] = $goodsids[$key]; $newgoodsinfo[$key]['Num'] = $goodsnum[$key]; $newgoodsinfo[$key]['Price'] = $goodsprice[$key]; $version = QuotationService::getgoodsversion($goodsids[$key]); $newgoodsinfo[$key]['Version'] = $version ? $version : 0; } } $insertid = array(); //将报价单商品插入报价单商品表中 if ($SchID) { foreach ($newgoodsinfo as $nkey => $new) { $newids[] = $new['GoodsID']; } if ($oldgoodsinfo) { foreach ($oldgoodsinfo as $okey => $old) { $oldids[] = $old['GoodsID']; } } else { $oldids = array(); } foreach ($oldids as $id) { if (!in_array($id, $newids)) { //删除商品 $delcount = Yii::app()->papdb->createCommand()->delete('pap_quotation_goods', 'SchID=:SchID and GoodsID=:goodsid', array(':SchID' => $SchID, ':goodsid' => $id)); } } foreach ($newids as $key => $id) { if (in_array($id, $oldids)) { //更新商品 $update['Num'] = $newgoodsinfo[$key]['Num']; $update['Price'] = $newgoodsinfo[$key]['Price']; $update['Version'] = $newgoodsinfo[$key]['Version']; $result = Yii::app()->papdb->createCommand()->update('pap_quotation_goods', $update, 'SchID=:SchID and GoodsID=:goodsid', array(':SchID' => $SchID, ':goodsid' => $id)); if ($result == 1) { $res = 1; } } else { //插入商品 $goodsdatas['SchID'] = $SchID; $goodsdatas['GoodsID'] = $newgoodsinfo[$key]['GoodsID']; $goodsdatas['Num'] = $newgoodsinfo[$key]['Num']; $goodsdatas['Price'] = $newgoodsinfo[$key]['Price']; $goodsdatas['Version'] = $newgoodsinfo[$key]['Version']; $result = Yii::app()->papdb->createCommand()->insert('pap_quotation_goods', $goodsdatas); $insertid[] = Yii::app()->papdb->getLastInsertID(); } } } if ($res = 1 || count($insertid) > 0 || $delcount > 0) { echo json_encode(array('count' => 1, 'schid' => $SchID, 'success' => true)); } else { echo json_encode(array('count' => 0)); } }
public function actionFtpDelfile() { if (Yii::app()->user->isGuest) { echo json_encode(array('res' => 0, 'msg' => '请先登录')); die; } if (Yii::app()->request->isAjaxRequest) { $path = Yii::app()->request->getParam('path'); $ftp = new Ftp(); $res = $ftp->delete_file($path); $ftp->close(); if ($res['success']) { echo json_encode(array('res' => 1)); } else { echo json_encode(array('res' => 0)); } } }