Merge branch 'main' of http://8.134.184.104:10801/r/came
New file |
| | |
| | | |
| | | <% |
| | | '-------------------------------------------------------------发票申请 |
| | | ServiceOrdID= SafeRequest(request("ServiceOrdID")) |
| | | DispatchOrdID=SafeRequest(request("DispatchOrdID")) |
| | | InvoiceID=SafeRequest(request("InvoiceID")) |
| | | ReturnID = SafeRequest(request("ReturnID")) |
| | | |
| | | InvoiceType = SafeRequest(request("InvoiceType")) '发票类型 |
| | | InvoiceName = SafeRequest(request("InvoiceName")) '发票抬头 |
| | | InvoiceMakeout = SafeRequest(request("InvoiceMakeout")) '发票备注 |
| | | |
| | | InvoiceCompanyPhone= SafeRequest(request("InvoiceCompanyPhone")) '企业电话 |
| | | InvoiceCompanyID = SafeRequest(request("InvoiceCompanyID")) '纳税识别号 |
| | | InvoiceCompanyAdd = SafeRequest(request("InvoiceCompanyAdd")) '企业注册地址 |
| | | InvoiceCompanyBank = SafeRequest(request("InvoiceCompanyBank")) '企业开户银行 |
| | | InvoiceCompanyBankNo= SafeRequest(request("InvoiceCompanyBankNo")) '企业银行账号 |
| | | InvoiceZipCode = SafeRequest(request("InvoiceZipCode")) '邮编 |
| | | Invoice_strAdd = SafeRequest(request("Invoice_strAdd")) '邮寄地址 |
| | | Invoice_strName = SafeRequest(request("Invoice_strName")) '联系人 |
| | | Invoice_strPhone = SafeRequest(request("Invoice_strPhone")) '联系电话 |
| | | Invoice_strEmail = SafeRequest(request("Invoice_strEmail")) '电子邮箱 |
| | | |
| | | InvoiceMoney = SafeRequest(request("InvoiceMoney")) '发票金额 |
| | | |
| | | If InvoiceMoney="" Or InvoiceMoney="0" Then%> |
| | | Response.Write "开票金额不可为0!!" |
| | | Response.End |
| | | End If |
| | | If InvoiceMoney="" Or InvoiceMoney="0" Or InvoiceType="" Or ServiceOrdID="" Then |
| | | Response.Write "参数错误!!" |
| | | Response.End |
| | | End If |
| | | |
| | | If InvoiceID="0" Or InvoiceID="" Then |
| | | sql="insert into InvoiceData (ServiceOrderIDPK, InvoiceType, InvoiceName, InvoiceMakeout, InvoiceCompanyPhone, InvoiceCompanyID, InvoiceCompanyAdd, InvoiceCompanyBank, InvoiceCompanyBankNo, InvoiceZipCode, Invoice_strAdd, Invoice_strName, Invoice_strPhone,Invoice_strEmail,InvoiceMoney,ApplyOAID) values ("&ServiceOrdID&","&InvoiceType&",'"&InvoiceName&"','"&InvoiceMakeout&"','"&InvoiceCompanyPhone&"','"&InvoiceCompanyID&"','"&InvoiceCompanyAdd&"','"&InvoiceCompanyBank&"','"&InvoiceCompanyBankNo&"','"&InvoiceZipCode&"','"&Invoice_strAdd&"','"&Invoice_strName&"','"&Invoice_strPhone&"','"&Invoice_strEmail&"',"&InvoiceMoney&","&session("adminID")&")" |
| | | objConn.Execute sql |
| | | Else |
| | | sql="update InvoiceData set InvoiceType="&InvoiceType&",InvoiceName='"&InvoiceName&"',InvoiceMakeout='"&InvoiceMakeout&"',InvoiceCompanyPhone='"&InvoiceCompanyPhone&"',InvoiceCompanyID='"&InvoiceCompanyID&"',InvoiceCompanyAdd='"&InvoiceCompanyAdd&"',InvoiceCompanyBank='"&InvoiceCompanyBank&"',InvoiceCompanyBankNo='"&InvoiceCompanyBankNo&"',InvoiceZipCode='"&InvoiceZipCode&"',Invoice_strAdd='"&Invoice_strAdd&"',Invoice_strEmail='"&Invoice_strEmail&"',Invoice_strName='"&Invoice_strName&"',Invoice_strPhone='"&Invoice_strPhone&"',AuditStatus=0,AuditMakeout='"&AuditMakeout&"',InvoiceNo='"&InvoiceNo&"',InvoiceMoney="&InvoiceMoney&",AuditOAID="&session("adminID")&",AuditTime=getdate() where InvoiceID="&InvoiceID |
| | | objConn.Execute sql |
| | | End If |
| | | |
| | | Call OA_Running("申请发票:"&ServiceOrdID) |
| | | rsRollbackTrans(objConn.Errors.count) |
| | | |
| | | '企微通知%> |
| | | <!--#include virtual="/weixin/JsonPost_1000006.gds"--> |
| | | <% |
| | | Set rs = Server.CreateObject("ADODB.Recordset") |
| | | sql="select InvoiceID from InvoiceData where AuditStatus not in (3,4) and ServiceOrderIDPK="&ServiceOrdID |
| | | rs.open sql,objConn,1,1 |
| | | If not rs.Eof then |
| | | InvoiceID = rs("InvoiceID") |
| | | end if |
| | | rs.close() |
| | | title="新的发票申请(PC后台)" |
| | | description=InvoiceName&",有一个新的发票申请,请即时处理" |
| | | sql="SELECT OA_weixinID=STUFF((SELECT '|' + OA_weixinUserID from OA_User where OA_Power like '%030205%' and OA_execLevel>=1 FOR XML PATH('')), 1, 1, '')" |
| | | rs.open sql,objConn,1,1 |
| | | If not rs.Eof then |
| | | touser = rs("OA_weixinID") |
| | | end if |
| | | rs.close() |
| | | 'touser="liaojunliang|ylkx_vicgame" '测试 |
| | | If touser<>"" And title<>"" Then |
| | | '微信OA信息下发接口 |
| | | appUrl="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="&access_token |
| | | args1="{" |
| | | args1=args1&"""touser"": """&touser&"""," '成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送 |liaojunliang |
| | | args1=args1&"""toparty"": """"," '部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 |
| | | args1=args1&"""totag"": """"," '标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数 |
| | | args1=args1&"""agentid"": 1000006," '企业应用的id,整型。可在应用的设置页面查看 |
| | | args1=args1&"""msgtype"": ""news""," |
| | | args1=args1&"""news"": {" |
| | | args1=args1&"""articles"":[" |
| | | args1=args1&"{" |
| | | args1=args1&"""title"": ""【"&title&"】""," |
| | | args1=args1&"""description"": """&description&"""," |
| | | args1=args1&"""url"": ""https://sys.966120.com.cn/m_Invoice.gds?InvoiceID="&InvoiceID&"&ServiceOrdID="&ServiceOrdID&"&order_type=11""" |
| | | args1=args1&"}" |
| | | args1=args1&"]" |
| | | args1=args1&"}" |
| | | args1=args1&"}" |
| | | call PostBody(appUrl,args1) |
| | | End If |
| | | Response.Write "success" |
| | | Response.End |
| | | %> |
New file |
| | |
| | | <% |
| | | |
| | | |
| | | '出车物品单号生成 |
| | | Function NewDispatchMRPOrderID(OrderType,DispatchOrdID,Type1) |
| | | NewDispatchMRPOrderID="MRP-"&OrderType&"-"&DispatchOrdID&Type1 |
| | | End Function |
| | | '出车物品单返回 |
| | | Function DispatchMRPOrderReturn(OrderType,DispatchOrdID) |
| | | MRP_OrderID_Out=NewDispatchMRPOrderID(OrderType,DispatchOrdID,"Out") |
| | | MRP_OrderID=NewDispatchMRPOrderID(OrderType,DispatchOrdID,"In") |
| | | OutWarehouseID=5 '转出仓(出车任务) |
| | | InWarehouseID=2 '转入仓(集盛总部正常仓一) |
| | | Set adminrs = Server.CreateObject("ADODB.Recordset") |
| | | sql="select MRP_OrderID from MRP_OrderManoeuvre where MRP_OrderID='"&MRP_OrderID&"' and OrderState=3" |
| | | adminrs.open sql,objConn,1,1 |
| | | if adminrs.Eof Then |
| | | adminrs.close() |
| | | sql="select MRP_OrderID from MRP_OrderManoeuvre where MRP_OrderID='"&MRP_OrderID_Out&"' and OrderState=3" |
| | | adminrs.open sql,objConn,1,1 |
| | | if not adminrs.Eof then |
| | | '新建转仓单 |
| | | sql="insert into MRP_OrderManoeuvre (MRP_OrderID,OutWarehouseID,InWarehouseID,OrderState,OrderTime_OAid,TotalQty,OrderRemarks,AuditTime,AuditTime_OAid,OutTime,OutTime_OAid,InTime,InTime_OAid) select '"&MRP_OrderID&"',"&OutWarehouseID&","&InWarehouseID&",3,"&session("adminID")&",TotalQty,OrderRemarks,getdate(),"&session("adminID")&",getdate(),"&session("adminID")&",getdate(),"&session("adminID")&" from MRP_OrderManoeuvre where MRP_OrderID='"&MRP_OrderID_Out&"' and OrderState=3" |
| | | objConn.Execute sql |
| | | sql="insert into MRP_OrderDetail (MRP_OrderIDPK,StItmIDPK,OD_Qty,OD_QtyA,OD_Price,OD_Remarks) select '"&MRP_OrderID&"',StItmIDPK,OD_Qty,OD_QtyA,OD_Price,OD_Remarks from MRP_OrderDetail where MRP_OrderIDPK='"&MRP_OrderID_Out&"'" |
| | | objConn.Execute sql |
| | | sql="insert into MRP_Stock (StItmIDPK,StockQty,StockWarehouseID,MRP_OrderIDPK,StockTime_OAid) select StItmIDPK,-StockQty,"&OutWarehouseID&",'"&MRP_OrderID&"',"&session("adminID")&" from MRP_Stock where MRP_OrderIDPK='"&MRP_OrderID_Out&"' and StockWarehouseID="&OutWarehouseID |
| | | objConn.Execute sql |
| | | sql="insert into MRP_Stock (StItmIDPK,StockQty,StockWarehouseID,MRP_OrderIDPK,StockTime_OAid) select StItmIDPK,StockQty,"&InWarehouseID&",'"&MRP_OrderID&"',"&session("adminID")&" from MRP_Stock where MRP_OrderIDPK='"&MRP_OrderID_Out&"' and StockWarehouseID="&OutWarehouseID |
| | | objConn.Execute sql |
| | | end If |
| | | End If |
| | | adminrs.close() |
| | | End Function |
| | | |
| | | Function Get_TritonshAPI(UserUUID,orderStatus,ServiceOrdID,iuid,CoName,CoPhone,orderPrice,orderSource) |
| | | 'url="https://api.966120.com.cn/v1/cuituAPI.php" |
| | | 'Origin="OrdID="&ServiceOrdID&"&method="&method&"&iuid="&iuid&"&uuid="&uuid |
| | | 'HTMLCODE= GetBody(url,Origin) |
| | | appUrl="https://market.tritonsh.com/order/orderDeal" |
| | | args1="{" |
| | | 'args1=args1&"""id"": """&uuid&"""," '对方订单ID |
| | | args1=args1&"""userId"": """&iuid&"""," '对方用户ID(介绍人ID) |
| | | args1=args1&"""orderStatus"": """&orderStatus&"""," '订单状态 0:初始订单 , 1:最终订单状态 |
| | | args1=args1&"""orderType"":0," '下单类型 0:本人下单,1:代人下单 |
| | | If orderSource="1" Then |
| | | args1=args1&"""orderSource"":""代客下单""," |
| | | ElseIf orderSource="2" Then |
| | | args1=args1&"""orderSource"":""面对面二维码""," |
| | | ElseIf orderSource="3" Then |
| | | args1=args1&"""orderSource"":""推广海报""," |
| | | End If |
| | | args1=args1&"""orderUserPhone"": """&CoPhone&"""," '客户手机号 |
| | | args1=args1&"""userName"": """&CoName&"""," '客户姓名 |
| | | args1=args1&"""orderPrice"": """&orderPrice&"""," '订单金额 |
| | | args1=args1&"""orderServiceNo"": """&ServiceOrdID&"""" '订单服务单号 |
| | | args1=args1&"}" |
| | | 'call PostBody(appUrl,args1) |
| | | 'Response.Write args1&"<br>" |
| | | HTMLCODE= PostBody1(appUrl,args1) |
| | | sql="update ServiceOrder set ToUserUUID="&UserUUID&" where ServiceOrdID="&ServiceOrdID |
| | | objConn.Execute sql |
| | | sql="update UserUUID set ToServiceOrdID="&ServiceOrdID&",TritonshJson='"&HTMLCODE&"',TritonshTime=getdate() where id="&UserUUID |
| | | objConn.Execute sql |
| | | 'Response.Write HTMLCODE&"<br>" |
| | | 'Response.end |
| | | 'HTMLCODE= GetBody(url,Origin) |
| | | End Function |
| | | |
| | | DispatchOrdID = SafeRequest(Request("DispatchOrdID"))'调度单号 |
| | | ServiceOrdID = SafeRequest(Request("ServiceOrdID")) '对应服务单号 |
| | | ServiceOrdDel = SafeRequest(Request("ServiceOrdDel"))'是否同时取消服务号(1是,0否) |
| | | Del = SafeRequest(Request("Del")) '强制取消(YES/NO) |
| | | CancelReason = SafeRequest(Request("CancelReason"))'取消原因 |
| | | CancelReasonTXT = SafeRequest(Request("CancelReasonTXT"))'取消原因备注 |
| | | CancelReasonTXT = CancelReasonTXT&"[取消操作:"&OAUser(session("adminID"),"UserName")&"]" |
| | | Source = SafeRequest(Request("Source")) '取消来源(PC/Phone) |
| | | If CancelReason="" Then CancelReason=0 |
| | | If ServiceOrdDel="" Then ServiceOrdDel=0 |
| | | If Source="Phone" Then SourceURL="m_" |
| | | Set rs = Server.CreateObject("ADODB.Recordset") |
| | | '验证调度单是否可取消 |
| | | If DispatchOrdID<>"" Then |
| | | If Del<>"YES" then |
| | | sql="select DispatchOrdState,DispatchOrd_AP_Check from DispatchOrd where DispatchOrdID="&DispatchOrdID |
| | | rs.open sql,objConn,1,1 |
| | | If rs.eof Then |
| | | Response.Redirect "/DispatchOrder.gds?SystemMessageType=4&SMT=1" |
| | | Else |
| | | DispatchOrdState = rs("DispatchOrdState") |
| | | DispatchOrd_AP_Check= rs("DispatchOrd_AP_Check") |
| | | If CInt(DispatchOrdState)>=4 Then |
| | | Response.Redirect "/"&SourceURL&"DispatchOrder.gds?DispatchOrdID="&DispatchOrdID&"&SystemMessageType=4&SMT=10" |
| | | ElseIf DispatchOrd_AP_Check=1 Then |
| | | Response.Redirect "/"&SourceURL&"DispatchOrder.gds?DispatchOrdID="&DispatchOrdID&"&SystemMessageType=4&SMT=11" |
| | | End if |
| | | End If |
| | | rs.close() |
| | | End if |
| | | sql="update DispatchOrd set DispatchOrdState=10,DispatchOrdStartDate=getdate(),DispatchOrdCancelReason="&CancelReason&",DispatchOrdCancelReasonTXT='"&CancelReasonTXT&"',DispatchOrd_OAName=(SELECT STUFF(( select ',' + OA_Name from DispatchOrd_Entourage,OA_User where OA_User_ID=EntourageOAid and DispatchOrdIDDt=DispatchOrdID and EntourageState<>4 order by EntourageLead desc FOR XML PATH('')), 1, 1, '') AS EntourageName),DispatchOrd_OAEntourage=(SELECT STUFF(( select ',' + vtext from DispatchOrd_Entourage,OA_User,dictionary where OA_User_ID=EntourageOAid and DispatchOrdIDDt=DispatchOrdID and EntourageState<>4 and vtitle='DispatchOrdEntourage' and vID=EntourageID order by EntourageLead desc FOR XML PATH('')), 1, 1, '') AS EntouragePost),DispatchOrdUpdateOAid="&session("adminID")&",DispatchOrdUpdateTime=getdate() where DispatchOrdID="&DispatchOrdID |
| | | objConn.Execute sql |
| | | '修改相关服务单状态 |
| | | If ServiceOrdID<>"" then |
| | | sql="select DispatchOrdID from DispatchOrd where ServiceOrdIDDt="&ServiceOrdID&" and DispatchOrdState<>10" |
| | | rs.open sql,objConn,1,1 |
| | | If rs.eof Then |
| | | If ServiceOrdDel="1" Then |
| | | sql="update ServiceOrder set ServiceOrdState=4,ServiceOrd_AP_ID="&session("adminID")&",ServiceOrd_AP_Time=getdate(),ServiceOrdCancelReason="&CancelReason&",ServiceOrdCancelReasonTXT='"&CancelReasonTXT&"' where ServiceOrdID="&ServiceOrdID |
| | | else |
| | | sql="update ServiceOrder set ServiceOrdState=2,ServiceOrdStartDate=getdate(),ServiceOrdCancelReason="&CancelReason&",ServiceOrdCancelReasonTXT='"&CancelReasonTXT&"' where ServiceOrdID="&ServiceOrdID |
| | | End If |
| | | objConn.Execute sql |
| | | End If |
| | | rs.close() |
| | | End If |
| | | '重点议器归还 |
| | | Call DispatchMRPOrderReturn(14,DispatchOrdID) |
| | | ReturnURL="/"&SourceURL&"DispatchOrder.gds?DispatchOrdID="&DispatchOrdID |
| | | Call OA_Running("取消调度单:"&DispatchOrdID) |
| | | ElseIf ServiceOrdID<>"" Then |
| | | If Del<>"YES" then |
| | | sql="select ServiceOrdState,ServiceOrd_AP_Check,ServiceOrdCoName,ServiceOrdCoPhone,ToUserUUID from ServiceOrder where ServiceOrdID="&ServiceOrdID |
| | | rs.open sql,objConn,1,1 |
| | | If rs.eof Then |
| | | Response.Redirect "/"&SourceURL&"ServiceOrder_List.gds?SystemMessageType=4&SMT=1" |
| | | Else |
| | | ServiceOrdState = rs("ServiceOrdState") |
| | | ServiceOrdCoName= rs("ServiceOrdCoName") |
| | | ServiceOrdCoPhone= rs("ServiceOrdCoPhone") |
| | | ToUserUUID = rs("ToUserUUID") |
| | | If CInt(ServiceOrdState)=3 Then |
| | | Response.Redirect "/"&SourceURL&"ServiceOrder.gds?ServiceOrdID="&ServiceOrdID&"&SystemMessageType=4&SMT=10" |
| | | ElseIf ServiceOrd_AP_Check=1 Then |
| | | Response.Redirect "/"&SourceURL&"ServiceOrder.gds?ServiceOrdID="&ServiceOrdID&"&SystemMessageType=4&SMT=11" |
| | | End if |
| | | End If |
| | | rs.close() |
| | | End if |
| | | sql="update ServiceOrder set ServiceOrdState=4,ServiceOrd_AP_ID="&session("adminID")&",ServiceOrd_AP_Time=getdate(),ServiceOrdCancelReason="&CancelReason&",ServiceOrdCancelReasonTXT='"&CancelReasonTXT&"' where ServiceOrdState<>4 and ServiceOrdID="&ServiceOrdID |
| | | objConn.Execute sql |
| | | '营销小程序数据更新 |
| | | If ToUserUUID<>"0" And ToUserUUID<>"" Then |
| | | sql="select top 1 id,iuid from UserUUID where id="&ToUserUUID |
| | | rs.open sql,objConn,1,1 |
| | | if not rs.eof Then |
| | | iuid=rs("iuid") |
| | | Call Get_TritonshAPI(ToUserUUID,1,ServiceOrdID,iuid,ServiceOrdCoName,ServiceOrdCoPhone,0) |
| | | End If |
| | | rs.close() |
| | | End If |
| | | ReturnURL="/"&SourceURL&"ServiceOrder_List.gds?OrdState=0" |
| | | Call OA_Running("取消调度单:"&ServiceOrdID) |
| | | End If |
| | | |
| | | objConn.Execute "exec OrdDataUP "&ServiceOrdID |
| | | rsRollbackTrans(objConn.Errors.count) |
| | | Response.Redirect ReturnURL&"&SystemMessageType=3&SMT=8&h_menu1_1="&session("h_menu1_1") |
| | | Response.End |
New file |
| | |
| | | <?php |
| | | header('Content-Type: application/json; charset=utf-8'); |
| | | |
| | | // 设置错误报告 |
| | | error_reporting(E_ALL); |
| | | ini_set('display_errors', 1); |
| | | |
| | | // 允许跨域请求(如果需要) |
| | | header('Access-Control-Allow-Origin: *'); |
| | | header('Access-Control-Allow-Methods: POST'); |
| | | header('Access-Control-Allow-Headers: Content-Type'); |
| | | |
| | | // 检查请求方法 |
| | | if ($_SERVER['REQUEST_METHOD'] !== 'POST') { |
| | | echo json_encode([ |
| | | 'success' => false, |
| | | 'message' => '只支持POST请求' |
| | | ]); |
| | | exit; |
| | | } |
| | | |
| | | // 获取参数 |
| | | $uploadFileName = isset($_POST['uploadFileName']) ? $_POST['uploadFileName'] : ''; |
| | | $file = isset($_FILES['file']) ? $_FILES['file'] : null; |
| | | |
| | | // 验证参数 |
| | | if (empty($uploadFileName)) { |
| | | echo json_encode([ |
| | | 'success' => false, |
| | | 'message' => 'uploadFileName参数不能为空' |
| | | ]); |
| | | exit; |
| | | } |
| | | |
| | | if (!$file || $file['error'] !== UPLOAD_ERR_OK) { |
| | | $errorMessage = '文件上传失败'; |
| | | if ($file) { |
| | | switch ($file['error']) { |
| | | case UPLOAD_ERR_INI_SIZE: |
| | | $errorMessage = '文件大小超过php.ini限制'; |
| | | break; |
| | | case UPLOAD_ERR_FORM_SIZE: |
| | | $errorMessage = '文件大小超过表单限制'; |
| | | break; |
| | | case UPLOAD_ERR_PARTIAL: |
| | | $errorMessage = '文件只有部分被上传'; |
| | | break; |
| | | case UPLOAD_ERR_NO_FILE: |
| | | $errorMessage = '没有文件被上传'; |
| | | break; |
| | | case UPLOAD_ERR_NO_TMP_DIR: |
| | | $errorMessage = '找不到临时文件夹'; |
| | | break; |
| | | case UPLOAD_ERR_CANT_WRITE: |
| | | $errorMessage = '文件写入失败'; |
| | | break; |
| | | } |
| | | } |
| | | echo json_encode([ |
| | | 'success' => false, |
| | | 'message' => $errorMessage |
| | | ]); |
| | | exit; |
| | | } |
| | | |
| | | // 验证文件类型(可选) |
| | | $allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']; |
| | | if (!in_array($file['type'], $allowedTypes)) { |
| | | echo json_encode([ |
| | | 'success' => false, |
| | | 'message' => '不支持的文件类型:' . $file['type'] |
| | | ]); |
| | | exit; |
| | | } |
| | | |
| | | // 验证文件大小(限制为10MB) |
| | | $maxFileSize = 10 * 1024 * 1024; // 10MB |
| | | if ($file['size'] > $maxFileSize) { |
| | | echo json_encode([ |
| | | 'success' => false, |
| | | 'message' => '文件大小超过限制(最大10MB)' |
| | | ]); |
| | | exit; |
| | | } |
| | | |
| | | try { |
| | | // 创建年月目录 |
| | | $yearMonth = date('Ym'); |
| | | $uploadDir = "../upload/{$yearMonth}/"; |
| | | |
| | | // 如果目录不存在则创建 |
| | | if (!is_dir($uploadDir)) { |
| | | if (!mkdir($uploadDir, 0755, true)) { |
| | | throw new Exception('无法创建目录:' . $uploadDir); |
| | | } |
| | | } |
| | | |
| | | // 生成唯一文件名 |
| | | $fileExtension = pathinfo($file['name'], PATHINFO_EXTENSION); |
| | | $uniqueFileName = $uploadFileName . '_' . time() . '_' . uniqid() . '.' . $fileExtension; |
| | | $filePath = $uploadDir . $uniqueFileName; |
| | | |
| | | // 移动上传的文件 |
| | | if (!move_uploaded_file($file['tmp_name'], $filePath)) { |
| | | throw new Exception('文件保存失败'); |
| | | } |
| | | |
| | | // 如果是图片,生成缩略图 |
| | | $thumbnailPath = ''; |
| | | if (in_array($file['type'], ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) { |
| | | $thumbnailPath = $uploadDir . 's_' . $uniqueFileName; |
| | | createThumbnail($filePath, $thumbnailPath, 100, 0); |
| | | } |
| | | |
| | | // 返回成功信息 |
| | | $response = [ |
| | | 'success' => true, |
| | | 'message' => '文件上传成功', |
| | | 'data' => [ |
| | | 'originalName' => $file['name'], |
| | | 'fileName' => $uniqueFileName, |
| | | 'filePath' => str_replace('../', 'https://sys.966120.com.cn/', $filePath), |
| | | 'thumbnailPath' => $thumbnailPath ? str_replace('../', 'https://sys.966120.com.cn/', $thumbnailPath) : '', |
| | | 'fileSize' => $file['size'], |
| | | 'fileType' => $file['type'], |
| | | 'uploadTime' => date('Y-m-d H:i:s') |
| | | ] |
| | | ]; |
| | | |
| | | echo json_encode($response); |
| | | |
| | | } catch (Exception $e) { |
| | | echo json_encode([ |
| | | 'success' => false, |
| | | 'message' => '上传失败:' . $e->getMessage() |
| | | ]); |
| | | } |
| | | |
| | | /** |
| | | * 创建缩略图 |
| | | * @param string $sourcePath 源图片路径 |
| | | * @param string $targetPath 目标缩略图路径 |
| | | * @param int $width 宽度 |
| | | * @param int $height 高度(0表示按比例缩放) |
| | | */ |
| | | function createThumbnail($sourcePath, $targetPath, $width, $height) { |
| | | $imageInfo = getimagesize($sourcePath); |
| | | if (!$imageInfo) { |
| | | return false; |
| | | } |
| | | |
| | | $sourceWidth = $imageInfo[0]; |
| | | $sourceHeight = $imageInfo[1]; |
| | | $imageType = $imageInfo[2]; |
| | | |
| | | // 计算缩略图尺寸 |
| | | if ($height == 0) { |
| | | $height = floor($width / $sourceWidth * $sourceHeight); |
| | | } elseif ($width == 0) { |
| | | $width = floor($height / $sourceHeight * $sourceWidth); |
| | | } |
| | | |
| | | // 创建源图像 |
| | | switch ($imageType) { |
| | | case IMAGETYPE_GIF: |
| | | $sourceImage = imagecreatefromgif($sourcePath); |
| | | break; |
| | | case IMAGETYPE_JPEG: |
| | | $sourceImage = imagecreatefromjpeg($sourcePath); |
| | | break; |
| | | case IMAGETYPE_PNG: |
| | | $sourceImage = imagecreatefrompng($sourcePath); |
| | | break; |
| | | default: |
| | | return false; |
| | | } |
| | | |
| | | if (!$sourceImage) { |
| | | return false; |
| | | } |
| | | |
| | | // 创建缩略图 |
| | | $thumbnailImage = imagecreatetruecolor($width, $height); |
| | | |
| | | // 保持PNG透明度 |
| | | if ($imageType == IMAGETYPE_PNG) { |
| | | imagealphablending($thumbnailImage, false); |
| | | imagesavealpha($thumbnailImage, true); |
| | | $transparent = imagecolorallocatealpha($thumbnailImage, 255, 255, 255, 127); |
| | | imagefilledrectangle($thumbnailImage, 0, 0, $width, $height, $transparent); |
| | | } |
| | | |
| | | // 调整图像大小 |
| | | imagecopyresampled($thumbnailImage, $sourceImage, 0, 0, 0, 0, $width, $height, $sourceWidth, $sourceHeight); |
| | | |
| | | // 保存缩略图 |
| | | $result = false; |
| | | switch ($imageType) { |
| | | case IMAGETYPE_GIF: |
| | | $result = imagegif($thumbnailImage, $targetPath); |
| | | break; |
| | | case IMAGETYPE_JPEG: |
| | | $result = imagejpeg($thumbnailImage, $targetPath, 90); |
| | | break; |
| | | case IMAGETYPE_PNG: |
| | | $result = imagepng($thumbnailImage, $targetPath, 9); |
| | | break; |
| | | } |
| | | |
| | | // 释放内存 |
| | | imagedestroy($sourceImage); |
| | | imagedestroy($thumbnailImage); |
| | | |
| | | return $result; |
| | | } |
| | | ?> |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html lang="zh-CN"> |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| | | <title>文件上传测试</title> |
| | | <style> |
| | | body { |
| | | font-family: Arial, sans-serif; |
| | | max-width: 800px; |
| | | margin: 0 auto; |
| | | padding: 20px; |
| | | } |
| | | .upload-form { |
| | | border: 2px dashed #ccc; |
| | | padding: 20px; |
| | | text-align: center; |
| | | margin-bottom: 20px; |
| | | } |
| | | .upload-form:hover { |
| | | border-color: #999; |
| | | } |
| | | .form-group { |
| | | margin-bottom: 15px; |
| | | } |
| | | label { |
| | | display: block; |
| | | margin-bottom: 5px; |
| | | font-weight: bold; |
| | | } |
| | | input[type="text"], input[type="file"] { |
| | | width: 100%; |
| | | padding: 8px; |
| | | border: 1px solid #ddd; |
| | | border-radius: 4px; |
| | | box-sizing: border-box; |
| | | } |
| | | button { |
| | | background-color: #4CAF50; |
| | | color: white; |
| | | padding: 10px 20px; |
| | | border: none; |
| | | border-radius: 4px; |
| | | cursor: pointer; |
| | | font-size: 16px; |
| | | } |
| | | button:hover { |
| | | background-color: #45a049; |
| | | } |
| | | button:disabled { |
| | | background-color: #cccccc; |
| | | cursor: not-allowed; |
| | | } |
| | | .result { |
| | | margin-top: 20px; |
| | | padding: 15px; |
| | | border-radius: 4px; |
| | | } |
| | | .success { |
| | | background-color: #d4edda; |
| | | border: 1px solid #c3e6cb; |
| | | color: #155724; |
| | | } |
| | | .error { |
| | | background-color: #f8d7da; |
| | | border: 1px solid #f5c6cb; |
| | | color: #721c24; |
| | | } |
| | | .progress { |
| | | width: 100%; |
| | | height: 20px; |
| | | background-color: #f0f0f0; |
| | | border-radius: 10px; |
| | | overflow: hidden; |
| | | margin-top: 10px; |
| | | } |
| | | .progress-bar { |
| | | height: 100%; |
| | | background-color: #4CAF50; |
| | | width: 0%; |
| | | transition: width 0.3s ease; |
| | | } |
| | | .file-info { |
| | | margin-top: 10px; |
| | | font-size: 14px; |
| | | color: #666; |
| | | } |
| | | </style> |
| | | </head> |
| | | <body> |
| | | <h1>文件上传测试</h1> |
| | | |
| | | <div class="upload-form"> |
| | | <form id="uploadForm" enctype="multipart/form-data"> |
| | | <div class="form-group"> |
| | | <label for="uploadFileName">文件名前缀:</label> |
| | | <input type="text" id="uploadFileName" name="uploadFileName" placeholder="例如:test123" required> |
| | | </div> |
| | | |
| | | <div class="form-group"> |
| | | <label for="file">选择文件:</label> |
| | | <input type="file" id="file" name="file" required> |
| | | <div class="file-info"> |
| | | 支持的文件类型:JPG, PNG, GIF, PDF, DOC, DOCX<br> |
| | | 最大文件大小:10MB |
| | | </div> |
| | | </div> |
| | | |
| | | <button type="submit" id="submitBtn">上传文件</button> |
| | | </form> |
| | | |
| | | <div class="progress" id="progress" style="display: none;"> |
| | | <div class="progress-bar" id="progressBar"></div> |
| | | </div> |
| | | </div> |
| | | |
| | | <div id="result"></div> |
| | | |
| | | <script> |
| | | document.getElementById('uploadForm').addEventListener('submit', function(e) { |
| | | e.preventDefault(); |
| | | |
| | | const formData = new FormData(); |
| | | const uploadFileName = document.getElementById('uploadFileName').value; |
| | | const file = document.getElementById('file').files[0]; |
| | | |
| | | if (!uploadFileName || !file) { |
| | | showResult('请填写文件名前缀并选择文件', false); |
| | | return; |
| | | } |
| | | |
| | | formData.append('uploadFileName', uploadFileName); |
| | | formData.append('file', file); |
| | | |
| | | // 显示进度条 |
| | | document.getElementById('progress').style.display = 'block'; |
| | | document.getElementById('submitBtn').disabled = true; |
| | | |
| | | // 模拟进度 |
| | | let progress = 0; |
| | | const progressInterval = setInterval(() => { |
| | | progress += Math.random() * 10; |
| | | if (progress > 90) progress = 90; |
| | | document.getElementById('progressBar').style.width = progress + '%'; |
| | | }, 100); |
| | | |
| | | fetch('upload_file.php', { |
| | | method: 'POST', |
| | | body: formData |
| | | }) |
| | | .then(response => response.json()) |
| | | .then(data => { |
| | | clearInterval(progressInterval); |
| | | document.getElementById('progressBar').style.width = '100%'; |
| | | |
| | | setTimeout(() => { |
| | | document.getElementById('progress').style.display = 'none'; |
| | | document.getElementById('submitBtn').disabled = false; |
| | | |
| | | if (data.success) { |
| | | showResult(` |
| | | <h3>上传成功!</h3> |
| | | <p><strong>原始文件名:</strong>${data.data.originalName}</p> |
| | | <p><strong>保存文件名:</strong>${data.data.fileName}</p> |
| | | <p><strong>文件大小:</strong>${formatFileSize(data.data.fileSize)}</p> |
| | | <p><strong>文件类型:</strong>${data.data.fileType}</p> |
| | | <p><strong>上传时间:</strong>${data.data.uploadTime}</p> |
| | | <p><strong>文件路径:</strong><a href="${data.data.filePath}" target="_blank">${data.data.filePath}</a></p> |
| | | ${data.data.thumbnailPath ? `<p><strong>缩略图:</strong><a href="${data.data.thumbnailPath}" target="_blank">${data.data.thumbnailPath}</a></p>` : ''} |
| | | `, true); |
| | | } else { |
| | | showResult('上传失败:' + data.message, false); |
| | | } |
| | | }, 500); |
| | | }) |
| | | .catch(error => { |
| | | clearInterval(progressInterval); |
| | | document.getElementById('progress').style.display = 'none'; |
| | | document.getElementById('submitBtn').disabled = false; |
| | | showResult('网络错误:' + error.message, false); |
| | | }); |
| | | }); |
| | | |
| | | function showResult(message, isSuccess) { |
| | | const resultDiv = document.getElementById('result'); |
| | | resultDiv.innerHTML = message; |
| | | resultDiv.className = 'result ' + (isSuccess ? 'success' : 'error'); |
| | | } |
| | | |
| | | function formatFileSize(bytes) { |
| | | if (bytes === 0) return '0 Bytes'; |
| | | const k = 1024; |
| | | const sizes = ['Bytes', 'KB', 'MB', 'GB']; |
| | | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| | | return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; |
| | | } |
| | | |
| | | // 文件选择时显示文件信息 |
| | | document.getElementById('file').addEventListener('change', function(e) { |
| | | const file = e.target.files[0]; |
| | | if (file) { |
| | | const fileInfo = document.querySelector('.file-info'); |
| | | fileInfo.innerHTML = ` |
| | | 已选择文件:${file.name}<br> |
| | | 文件大小:${formatFileSize(file.size)}<br> |
| | | 文件类型:${file.type}<br> |
| | | 支持的文件类型:JPG, PNG, GIF, PDF, DOC, DOCX<br> |
| | | 最大文件大小:10MB |
| | | `; |
| | | } |
| | | }); |
| | | </script> |
| | | </body> |
| | | </html> |