<?php
/**
 * Author：晴天 QQ：1186258278
 * Creation：2020/3/27 18:53
 * Filename：admin.order.list_log.php
 * 批量导出订单
 */
$protect_admin = true; #勿动,否则后台瘫痪
include "../includes/fun.global.php";
switch ($_QET['sum']) {
    default:
        $sum = (empty($_QET['sum']) ? 100 : (int)$_QET['sum']);
        break;
}
switch ($_QET['page']) {
    default:
        $page = (empty($_QET['page']) ? 0 : (int)$_QET['page']);
        break;
}
switch ($_QET['gid']) {
    default:
        $gid = (empty($_QET['gid']) ? 0 : (int)$_QET['gid']);
        break;
}
if ($gid == 0) {
    $sql = '';
} else {
    $sql = ' where a.gid = ' . (int)$gid . ' ';
}
echo '当前查看数量为' . $sum . '条,订单查看范围：' . $page . ' - ' . $sum . '条，商品范围：' . $gid . '<br>
<form><input name="page" value="' . $page . '"><input name="sum" value="' . $sum . '"><input name="gid" value="' . $gid . '"><input type="submit" value="确定"></form><hr>';
echo '<table border="1">';
echo '<tr>
        <th>ID</th>
        <th>订单号</th>
        <th>状态</th>
        <th>商品ID</th>
        <th>商品名称</th>
        <th>下单信息</th>
        <th>下单份数</th>
        <th>付款方式</th>
        <th>支付金额</th>
        <th>付款时间</th>
        <th>订单备注</th>
    </tr><tbody>';
$res = $DB->query("SELECT a.*,(select b.name from sky_goods as b where b.gid = a.gid )as name,(select b.value from sky_goods as b where b.gid = a.gid )as value FROM `sky_order` as a $sql ORDER BY `id` DESC LIMIT $page, $sum");
while ($re = $DB->fetch($res)) {
    switch ($re['state']) {
        case 1:
            $state = '已完成';
            break;
        case 2:
            $state = '待处理';
            break;
        case 3:
            $state = '异常中';
            break;
        case 4:
            $state = '正在处理';
            break;
        case 5:
            $state = '已退款';
            break;
    }

    $re['inputs'] = $re['input'];
    $re['input'] = json_decode($re['input'], true);
    $input = '';
    $d = 1;

    $TID_V = explode('|', $re['value']);
    $TID_A = [];
    foreach ($TID_V as $v) {
        $v = explode(',', $v);
        $TID_A[] = $v[0];
    }
    $c = 0;
    foreach ($re['input'] as $s) {
        if ($TID_A[$c] <> '') {
            if (strpos($TID_A[$c], '{')) {
                $TID_A[$c] = substr($TID_A[$c], 0, strpos($TID_A[$c], '{'));
            }
            $input .= $TID_A[$c] . '：' . $s . ' <br> ';
        } else {
            $input .= '输入框[' . $d . ']：' . $s . '<br>';
        }
        $d++;
        $c++;
    }

    echo '<tr>
        <td>' . $re['id'] . '</td>
        <td>' . $re['order'] . '</td>
        <td>' . $state . '</td>
        <td>' . $re['gid'] . '</td>
        <td style="width: 20em">' . $re['name'] . '</td>
        <td>' . $input . '</td>
        <td>' . $re['num'] . '份</td>
        <td>' . $re['payment'] . '</td>
        <td>' . round($re['price'], 8) . '</td>
        <td>' . $re['addtitm'] . '</td>
        <td style="width: 20em">' . $re['remark'] . '</td>
    </tr>';
}
echo '</tbody></table>';
?>


