diff --git a/application/admin/controller/Appversion.php b/application/admin/controller/Appversion.php index 65bd6f6..adbf5c6 100644 --- a/application/admin/controller/Appversion.php +++ b/application/admin/controller/Appversion.php @@ -42,9 +42,9 @@ class Appversion extends Base{ $num = Db::table('app_version_log')->where($parameter)->count(); $result = Db::table('app_version_log')->where($parameter)->order('is_del,id desc')->page($page,$this->page_num)->select(); if(!$pd){ - $result['num'] = $num; - $result['data'] = $result; - return $this->msg(0,'success',$result); + $return_data['num'] = $num; + $return_data['data'] = $result; + return $this->msg($return_data); } $this->assign([ 'result' => $result, @@ -58,6 +58,17 @@ class Appversion extends Base{ return $this->fetch(); } + public function app_edit(){ + $data = input(); + $result = Db::table('app_version_log')->where(['id'=>$data['id']])->find(); + $this->assign([ + 'result' => $result, + ]); + return $this->fetch(); + } + + + public function app_add_action(){ $file = request()->file('apk'); $name = request()->param(); @@ -68,6 +79,22 @@ class Appversion extends Base{ } if($file){ // 移动到框架应用根目录/public/uploads/ 目录下 + + // 设置文件路径 + $filePath = ROOT_PATH . 'public' . DS . 'appupdatefile' . DS . $name['file_name'].'_'.$name['version_num'].'.apk'; + // 检查文件是否存在 + if (file_exists($filePath)) { + // 尝试删除文件 + if (unlink($filePath)) { + // 删除成功 + // echo "文件删除成功。"; + } else { + // 删除失败 + // echo "文件删除失败,请检查权限设置。"; + return $this->msg(10001,'更新文件失败'); + } + } + $file_name_new = $name['file_name'].'_'.$name['version_num'].'.apk'; $info = $file->validate(['size'=>$this->file_max,'ext'=>'apk'])->move(ROOT_PATH . 'public' . DS . 'appupdatefile',$file_name_new); if($info){ @@ -102,6 +129,61 @@ class Appversion extends Base{ } + + public function app_edit_action(){ + $file = request()->file('apk'); + $name = request()->param(); + + if($file){ + // 移动到框架应用根目录/public/uploads/ 目录下 + $app_yz = Db::table('app_version_log')->where(['id'=>$name['id']])->find(); + if($app_yz){ + $file_name_new = $name['file_name'].'_'.$name['version_num'].'.apk'; + if($app_yz['name'] == $name['file_name'] && $app_yz['version_num'] == $name['version_num'] && $app_yz['version_num_original'] == $name['version_num_original'] && $app_yz['content'] == $name['content']){ + $update_data = [ + 'update_time'=>date('Y-m-d H:i:s'), + ]; + }else{ + $update_data = [ + 'name'=>$name['file_name'], + 'version_num'=>$name['version_num'], + 'version_num_original'=>$name['version_num_original'], + 'content'=>$name['content'], + 'download_url'=>'http://tc.pcxbc.com/appupdatefile/'.$file_name_new, + 'update_time'=>date('Y-m-d H:i:s'), + ]; + } + // 如果修改信息不变,直接更新文件即可 + // 设置文件路径 + $filePath = ROOT_PATH . 'public' . DS . 'appupdatefile' . DS . $name['file_name'].'_'.$name['version_num'].'.apk'; + // 检查文件是否存在 + if (file_exists($filePath)) { + // 尝试删除文件 + if (unlink($filePath)) { + // 删除成功 + } else { + return $this->msg(10001,'删除原始文件失败'); + } + } + $info = $file->validate(['size'=>$this->file_max,'ext'=>'apk'])->move(ROOT_PATH . 'public' . DS . 'appupdatefile',$file_name_new); + if($info){ + $result = Db::table('app_version_log')->where(['id'=>$name['id']])->update($update_data); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + }else{ + return $this->msg(10001, $file->getError()); + } + }else{ + return $this->msg(10001,'未找到需要更新的数据'); + } + }else{ + return $this->msg(10001, '文件缺失'); + } + } + public function app_del(){ $data = input(); if(is_array($data['id'])){ diff --git a/application/admin/view/appversion/index.html b/application/admin/view/appversion/index.html index 6b30950..d86290e 100644 --- a/application/admin/view/appversion/index.html +++ b/application/admin/view/appversion/index.html @@ -31,35 +31,8 @@