need_auth('market'); if (is_post()) { $card = $_POST; $card['quantity'] = abs(intval($card['quantity'])); $card['money'] = abs(intval($card['money'])); $card['partner_id'] = abs(intval($card['partner_id'])); $card['begin_time'] = strtotime($card['begin_time']); $card['end_time'] = strtotime($card['end_time']); $error = array(); if ($card['money'] < 1) { $error[] = "代金券面额不能小于1元"; } if ($card['quantity'] < 1 || $card['quantity'] > 1000) { $error[] = "代金券每次只能生产1-1000枚"; } $today = strtotime(date('Y-m-d')); if ($card['begin_time'] < $today) { $error[] = "开始时间不能小于当天"; } elseif ($card['end_time'] < $card['begin_time']) { $error[] = "结束时间不能小于开始时间"; } if (!$error && ZCard::CardCreate($card)) { Session::Set('notice', "{$card['quantity']}张代金券生成成功"); redirect(WEB_ROOT . '/manage/coupon/cardcreate.php'); } $error = join("<br />", $error); Session::Set('error', $error); } else { $card = array('begin_time' => time(), 'end_time' => strtotime('+3 months'), 'quantity' => 10, 'money' => 10, 'code' => date('Ymd') . '_ZT'); } include template('manage_coupon_cardcreate');
<?php require_once dirname(dirname(__FILE__)) . '/app.php'; need_login(); $action = strval($_GET['action']); $id = $order_id = abs(intval($_GET['id'])); $charge = strval($_GET['id']) == 'charge'; $id = $order_id = $charge ? 'charge' : $id; if (!$order_id && !$charge) { json('订单记录不存在', 'alert'); } if ($action == 'dialog') { $html = render('ajax_dialog_order'); json($html, 'dialog'); } elseif ($action == 'cardcode') { $cid = strval($_GET['cid']); $order = Table::Fetch('order', $order_id); if (!$order) { json('订单记录不存在', 'alert'); } $ret = ZCard::UseCard($order, $cid); if (true === $ret) { json(array(array('data' => "代金券使用成功", 'type' => 'alert'), array('data' => null, 'type' => 'refresh')), 'mix'); } $error = ZCard::Explain($ret); json($error, 'alert'); }