=',$data['s_time']]; // } // if($data['e_time']){ // $parameter['create_time'] = ['<=',$data['e_time']]; // } } $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){ $return_data['num'] = $num; $return_data['data'] = $result; return $this->msg($return_data); } $this->assign([ 'result' => $result, 'num' => $num, ]); return $this->fetch(); } public function app_add(){ 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(); $num = Db::table('app_version_log')->where(['name'=>$name['file_name'],'version_num'=>$name['version_num']])->count(); // dump($num); if($num > 0){ return $this->msg(10001,'版本号已存在'); } 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){ $result = Db::table('app_version_log')->insert([ '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, 'create_time'=>date('Y-m-d H:i:s'), ]); if($result){ return $this->msg([]); }else{ return $this->msg(10002); } // 成功上传后 获取上传信息 // 输出 jpg // echo $info->getExtension(); // // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg // echo $info->getSaveName(); // // 输出 42a79759f284b767dfcb2a0197904287.jpg // echo $info->getFilename(); }else{ // 上传失败获取错误信息 return $this->msg(10001, $file->getError()); // echo $file->getError(); } }else{ return $this->msg(10001, '文件缺失'); } } 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'])){ $data['id'] = implode(',',$data['id']); $result = Db::table('app_version_log')->where("id in (".$data['id'].")")->update(['is_del'=>$data['is_del']]); }else{ $result = Db::table('app_version_log')->where(['id'=>$data['id']])->update(['is_del'=>$data['is_del']]); } if($result){ return $this->msg(0,'success'); }else{ return $this->msg(10001,'success'); } // $num = Db::table('app_version_log')->where(['id'=>$data['id']])->update(['is_del'=>1]); // if($num){ // return $this->msg([]); // }else{ // return $this->msg(10002); // } } ################################################################other################################################################ ################################################################other################################################################ ################################################################other################################################################ }