public function do_exchange() { global_run(); if (check_save_login() != LOGIN_STATUS_LOGINED) { $result['status'] = 2; ajax_return($result); } $id = intval($_REQUEST['id']); $ecv_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "ecv_type where id = " . $id); if (!$ecv_type) { showErr($GLOBALS['lang']['INVALID_VOUCHER'], 1); } else { $exchange_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "ecv where ecv_type_id = " . $id . " and user_id = " . intval($GLOBALS['user_info']['id'])); if ($ecv_type['exchange_limit'] > 0 && $exchange_count >= $ecv_type['exchange_limit']) { $msg = sprintf($GLOBALS['lang']['EXCHANGE_VOUCHER_LIMIT'], $ecv_type['exchange_limit']); showErr($msg, 1); } elseif ($ecv_type['exchange_score'] > intval($GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . intval($GLOBALS['user_info']['id'])))) { showErr($GLOBALS['lang']['INSUFFCIENT_SCORE'], 1); } else { require_once APP_ROOT_PATH . "system/libs/voucher.php"; $rs = send_voucher($ecv_type['id'], $GLOBALS['user_info']['id'], 1); if ($rs) { require_once APP_ROOT_PATH . "system/model/user.php"; $msg = sprintf($GLOBALS['lang']['EXCHANGE_VOUCHER_USE_SCORE'], $ecv_type['name'], $ecv_type['exchange_score']); modify_account(array('money' => 0, 'score' => "-" . $ecv_type['exchange_score']), $GLOBALS['user_info']['id'], $msg); showSuccess($GLOBALS['lang']['EXCHANGE_SUCCESS'], 1); } else { showSuccess($GLOBALS['lang']['EXCHANGE_FAILED'], 1, url('index', 'uc_voucher')); } } } }
public function doSend() { require_once APP_ROOT_PATH . "system/libs/voucher.php"; $ecv_type_id = intval($_REQUEST['ecv_type_id']); $need_password = intval($_REQUEST['need_password']); $send_type = intval($_REQUEST['send_type']); $user_group = intval($_REQUEST['user_group']); $user_ids = trim($_REQUEST['user_id']); $gen_count = intval($_REQUEST['gen_count']); $page = intval($_REQUEST['page']) == 0 ? 1 : intval($_REQUEST['page']); //大数据量时的载入的页数 $page_size = app_conf("BATCH_PAGE_SIZE"); //每次运行的次数, 开发时可根据实际环境改变此大小 $page_limit = ($page - 1) * $page_size . "," . $page_size; switch ($send_type) { case 0: //按会员组 $user_list = M("User")->where("group_id=" . $user_group)->order("id asc")->limit($page_limit)->findAll(); if ($user_list) { foreach ($user_list as $v) { send_voucher($ecv_type_id, $v['id'], $need_password); } $this->assign("jumpUrl", u("EcvType/doSend", array("ecv_type_id" => $ecv_type_id, 'need_password' => $need_password, 'send_type' => $send_type, 'user_group' => $user_group, 'user_id' => $user_ids, 'gen_count' => $gen_count, 'page' => $page + 1))); $msg = sprintf(l("SEND_VOUCHER_PAGE_SUCCESS"), ($page - 1) * $page_size, $page * $page_size); $this->success($msg); } else { save_log("ID" . $ecv_type_id . l("VOUCHER_SEND_SUCCESS"), 1); $this->assign("jumpUrl", u("EcvType/index")); $this->success(l("VOUCHER_SEND_SUCCESS")); } break; case 1: //按会员ID $user_list = M("User")->where("id in(" . $user_ids . ")")->order("id asc")->limit($page_limit)->findAll(); if ($user_list) { foreach ($user_list as $v) { send_voucher($ecv_type_id, $v['id'], $need_password); } $this->assign("jumpUrl", u("EcvType/doSend", array("ecv_type_id" => $ecv_type_id, 'need_password' => $need_password, 'send_type' => $send_type, 'user_group' => $user_group, 'user_id' => $user_ids, 'gen_count' => $gen_count, 'page' => $page + 1))); $msg = sprintf(l("SEND_VOUCHER_PAGE_SUCCESS"), ($page - 1) * $page_size, $page * $page_size); $this->success($msg); } else { save_log("ID" . $ecv_type_id . l("VOUCHER_SEND_SUCCESS"), 1); $this->assign("jumpUrl", u("EcvType/index")); $this->success(l("VOUCHER_SEND_SUCCESS")); } break; case 2: //线下 for ($i = 0; $i < $page_size; $i++) { if (($page - 1) * $page_size + $i == $gen_count) { save_log("ID" . $ecv_type_id . l("VOUCHER_SEND_SUCCESS"), 1); $this->assign("jumpUrl", u("EcvType/index")); $this->success(l("VOUCHER_SEND_SUCCESS")); break; } send_voucher($ecv_type_id, 0, $need_password); } $this->assign("jumpUrl", u("EcvType/doSend", array("ecv_type_id" => $ecv_type_id, 'need_password' => $need_password, 'send_type' => $send_type, 'user_group' => $user_group, 'user_id' => $user_ids, 'gen_count' => $gen_count, 'page' => $page + 1))); $msg = sprintf(l("SEND_VOUCHER_PAGE_SUCCESS"), ($page - 1) * $page_size, $page * $page_size); $this->success($msg); break; } }