<?php

    /**
     * 状态码说明
     * 200 成功
     * 201 未登录
     * 202 失败
     * 203 空值
     * 204 无结果
     */

	// 页面编码
	header("Content-type:application/json");
	
	// 判断登录状态
    session_start();
    if(isset($_SESSION["yinliubao"])){
        
        // 已登录
    	$order_num = trim($_GET['order_num']);
    	
        // 过滤参数
        if(empty($order_num) || !isset($order_num)){
            
            $result = array(
			    'code' => 203,
                'msg' => '非法请求'
		    );
        }else{
            
            // 当前登录的用户
            $LoginUser = $_SESSION["yinliubao"];
            
            // 数据库配置
        	include '../../../../Db.php';
        
        	// 实例化类
        	$db = new DB_API($config);
        	
        	// 验证操作权限
            $checkAdmin = $db->set_table('huoma_user')->find(['user_name' => $_SESSION["yinliubao"]]);
            $user_admin = $checkAdmin['user_admin'];
            
            if($user_admin == 2) {
                
                $result = array(
                    'code' => 202,
                    'msg' => '无操作权限'
                );
                echo json_encode($result,JSON_UNESCAPED_UNICODE);
                exit;
            }
        	
            // 验证当前要删除的order_num的操作者是否为当前登录的用户
            $getUser = $db->set_table('ylb_ChatroomPayOrders')->find(['order_num' => $order_num]);
            $Action_User = $getUser['Action_User'];
            
            // 判断操作结果
            if($Action_User == $LoginUser){
                
                // 用户一致：允许操作
                $delSQL = $db->set_table('ylb_ChatroomPayOrders')->delete(['order_num' => $order_num]);
                
                // 操作结果
                if($delSQL){
                    
                    // 删除成功
                    $result = array(
    			        'code' => 200,
                        'msg' => '已删除'
    		        );
                    
                }else{
                    
                    // 删除失败
                    $result = array(
        			    'code' => 202,
                        'msg' => '删除失败'
        		    );
                }
                
            }else{
                
                // 用户不一致：禁止操作
                $result = array(
        			'code' => 202,
                    'msg' => '删除失败：禁止操作'.$order_num
        		);
            }
        }
    }else{
        
        // 未登录
        $result = array(
			'code' => 201,
            'msg' => '未登录'
		);
    }

	// 输出JSON
	echo json_encode($result,JSON_UNESCAPED_UNICODE);
	
?>