|
道具数量超过10以上的邮箱,自动转为一下个邮箱发送,同时发送50个道具会转为5个邮箱发送
//获取数据信息
function getInfo(mysql, sql, index){
try{
api_MySQL_exec(mysql, sql);
MySQL_fetch(mysql);
return api_MySQL_get_str(mysql, index);
}catch(ex){
console.log("数据异常:"+ex);
}
return null;
}
/**
* 判断是否是数字
* @param value 字符串
* @returns
*/
function isStringANumber(value) {
var regExp = /^[0-9]+(\.[0-9]*)?$/;
return regExp.test(value);
}
/**
* 添加数据库
* @param mysql
* @param table
* @param data
*/
function addData(mysql, table, data){
var key = "";
var value = "";
for(var k in data){
if(value == ""){
if ( !isStringANumber(data[k]) ) {
value = "'"+data[k]+"'";
}else{
value = data[k];
}
}else{
if ( !isStringANumber(data[k]) ) {
value += ",'"+data[k]+"'";
}else{
value += ","+data[k];
}
}
if(key == ""){
key = "`"+k+"`";
}else{
key += ",`"+k+"`";
}
}
api_MySQL_exec(mysql, "INSERT INTO "+table+" ("+key+") VALUES ("+value+")");
}
//数组分组
function pageToArr(arr, pageNumber) {
var itemsPerPage = 10;
var startIndex = pageNumber * itemsPerPage;
var endIndex = startIndex + itemsPerPage;
return arr.slice(startIndex, endIndex);
}
/**
* 系统发送邮件(多道具),每一个邮箱最多发送10个物品或装备,超过10,自动分配下一个邮箱发送,可无限发邮箱
* *charac_no: 角色通道号,唯一标识 必填项
* *item_list: 发送邮箱清单数组:[[3037, 10],[3038,20]],物品ID,物品数量 必填项
* title:邮箱标题,不填写默认显示“系统”
* gold:金币的数量,是否需要发送金币,不发送就不填写
* upgrade:强化等级,针对武器装备强化等级,不发送就不填写
* amplify_option:振幅,针对55级粉以上的装备、武器增幅:1、体力增幅 2、精神增幅 3、力量增幅 4、智力增幅 不发送就不填写
* 使用方法:sendEmails(1, [[3037, 10],[3038,20]]);
*/
function sendEmails(charac_no, item_list, title, gold, upgrade, amplify_option) {
//var charac_no = CUserCharacInfo_getCurCharacNo(user).toString();
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute= date.getMinutes();
var second = date.getSeconds();
if(month < 10){ month = "0"+month; }
if(day < 10){ day = "0"+day; }
if(hour < 10){ hour = "0"+hour; }
if(minute < 10){ minute = "0"+minute; }
if(second < 10){ second = "0"+second; }
if(!title){ title = "系统"; }
if(!gold){ gold = 0; }
//强化、增幅,只争对装备,增幅需要装备55级以上
if(!upgrade){ upgrade = 0; }
if(!amplify_option) {
amplify_option = 0;
}else{
if(upgrade <= 0){
upgrade = 1;
}
}
var times = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
var numbers = Math.ceil( item_list.length / 10 );
for(var pageIndex = 0; pageIndex < numbers; pageIndex ++){
//查询letter_id
var ord_letter_id = getInfo(mysql_taiwan_cain, "select letter_id from `taiwan_cain_2nd`.`postal` order by letter_id DESC limit 1", 0);
var new_letter_id = ord_letter_id + 1;
//数组分组
var list = pageToArr(item_list, pageIndex);
//发送邮箱
for(var n in list){
var item_id = list[n][0];
var add_info = list[n][1];
var data = {
"occ_time" : times,
"send_charac_no" : 0,
"send_charac_name" : title,
"receive_charac_no" : charac_no, //接受人通道号
"item_id" : item_id, //物品或者装备的code
"add_info" : add_info, //添加的数量
"upgrade" : upgrade, //强化等级
"amplify_option" : amplify_option, //增幅: 1、体力增幅 2、精神增幅 3、力量增幅 4、智力增幅
"receive_time" : times, //接收时间
"gold" : gold, //金币
"letter_id" : new_letter_id,
};
addData(mysql_taiwan_cain, "taiwan_cain_2nd.postal", data);
}
}
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|