/** * 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)); }
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')); }
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)); } }
function file_remote_delete($file) { global $_W; if (empty($file)) { return true; } if ($_W['setting']['remote']['type'] == '1') { require IA_ROOT . '/framework/library/ftp/ftp.php'; $ftp_config = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout'], 'rootdir' => $_W['setting']['remote']['ftp']['dir']); $ftp = new Ftp($ftp_config); if (true === $ftp->connect()) { if ($ftp->delete_file($file)) { return true; } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } elseif ($_W['setting']['remote']['type'] == '2') { require IA_ROOT . '/framework/library/alioss/sdk.class.php'; $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['ossurl']); $response = $oss->delete_object($_W['setting']['remote']['alioss']['bucket'], $file); if ($response->status == 204) { return true; } else { return error(1, '删除oss远程文件失败'); } } return true; }
/** * 公司信息保存 */ 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 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 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(); }
function file_remote_delete($file) { global $_W; if (empty($file)) { return true; } if ($_W['setting']['remote']['type'] == '1') { require_once IA_ROOT . '/framework/library/ftp/ftp.php'; $ftp_config = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout'], 'rootdir' => $_W['setting']['remote']['ftp']['dir']); $ftp = new Ftp($ftp_config); if (true === $ftp->connect()) { if ($ftp->delete_file($file)) { return true; } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } elseif ($_W['setting']['remote']['type'] == '2') { require_once IA_ROOT . '/framework/library/alioss/sdk.class.php'; $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['ossurl']); $response = $oss->delete_object($_W['setting']['remote']['alioss']['bucket'], $file); if ($response->status == 204) { return true; } else { return error(1, '删除oss远程文件失败'); } } elseif ($_W['setting']['remote']['type'] == '3') { require_once IA_ROOT . '/framework/library/qiniu/autoload.php'; $auth = new Qiniu\Auth($_W['setting']['remote']['qiniu']['accesskey'], $_W['setting']['remote']['qiniu']['secretkey']); $bucketMgr = new Qiniu\Storage\BucketManager($auth); $error = $bucketMgr->delete($_W['setting']['remote']['qiniu']['bucket'], $file); if ($error instanceof Qiniu\Http\Error) { if ($error->code() == 612) { return true; } return error(1, '删除七牛远程文件失败'); } else { return true; } } return true; }
public function actionDelPto() { $imageid = Yii::app()->request->getParam("imageid"); $ftp = new Ftp(); $res = $ftp->delete_file($imageid); $ftp->close(); echo json_encode($res); }
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)); } } }