|
@@ -28,28 +28,41 @@ class enum_Mail_Type extends Enum {
|
|
|
|
|
|
/**
|
|
|
* 邮件模块
|
|
|
- *
|
|
|
* @author gwang
|
|
|
- * @version 1.0.1 经过分析, 邮件系统有性能问题. 当邮件数量较多的时候, 如何优雅的处理,
|
|
|
+ * @version 2.0.0 言灵世界2改版邮件系统 2020.8.13
|
|
|
+ * 1.0.1 经过分析, 邮件系统有性能问题. 当邮件数量较多的时候, 如何优雅的处理,
|
|
|
* 代码中无解决方案.
|
|
|
* 1.0.0 created 邮件系统.
|
|
|
*/
|
|
|
class EmailProc {
|
|
|
|
|
|
+ /**
|
|
|
+ * 邮件最大容量100封
|
|
|
+ */
|
|
|
+ const MaxMailContent = 100;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 邮件最大过期时间7天
|
|
|
+ */
|
|
|
+ const MaxMailExpireTs = 7 * 24 * 3600;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 邮件日志表
|
|
|
+ */
|
|
|
const MailLog_TableName = 'tab_mailrecord';
|
|
|
|
|
|
public static function procMain($req) {
|
|
|
switch ($req->cmd) {
|
|
|
case CmdCode::cmd_email_questEmailList: # 6701 刷新邮件列表状态
|
|
|
return EmailProc::RefreshEmailList($req);
|
|
|
- case CmdCode::cmd_email_readAEmail: # 6702 读取邮件/领取奖励
|
|
|
+ case CmdCode::cmd_email_readAEmail: # 6702 读取一封邮件
|
|
|
return EmailProc::ReadEmail($req);
|
|
|
- case CmdCode::cmd_email_DrawReward: # 6703 删除邮件
|
|
|
- return EmailProc::deleteMail($req);
|
|
|
+ case CmdCode::cmd_email_DrawReward: # 6703 领取一封邮件附件(奖励)
|
|
|
+ return EmailProc::DrawEmailAppendix($req);
|
|
|
case CmdCode::cmd_email_DrawAllRewards: # 6704 领取所有邮件
|
|
|
- return self::test($req);
|
|
|
- case CmdCode::cmd_mail_delMailReaded: # 6705 删除邮件 没有条件限制
|
|
|
- return EmailProc::deleteMailNoCondition($req);
|
|
|
+ return EmailProc::DrawAllEmailAppendixes($req);
|
|
|
+ case CmdCode::cmd_mail_delMailReaded: # 6705 删除已读邮件
|
|
|
+ return EmailProc::DelReadedEmail($req);
|
|
|
case CmdCode::cmd_mail_notReadMailNum: # 6706 请求邮件未处理的数量
|
|
|
return EmailProc::queryNotReadEmails($req);
|
|
|
default:
|
|
@@ -57,19 +70,20 @@ class EmailProc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// <editor-fold defaultstate="collapsed" desc=" API ">
|
|
|
+
|
|
|
/**
|
|
|
- *
|
|
|
- * @param type $req
|
|
|
+ * 【6706】查询未处理邮件数量
|
|
|
+ * @param req $req
|
|
|
*/
|
|
|
static function queryNotReadEmails($req) {
|
|
|
$uid = $req->uid;
|
|
|
$zoneid = $req->zoneid;
|
|
|
- $n = 0;
|
|
|
- //删除全部标记为已读的,且没有奖励内容的邮件
|
|
|
- $mails = ArrayInit();
|
|
|
+ $n = 0; # 计数器
|
|
|
$mails = self::getMailQueue($zoneid, $uid);
|
|
|
foreach ($mails as $m) {
|
|
|
- if (!$m->isDrawed()) {
|
|
|
+// isEditor() and $m = new EmailModel();
|
|
|
+ if (!$m->readts <= 0) {
|
|
|
$n += 1;
|
|
|
}
|
|
|
}
|
|
@@ -77,149 +91,145 @@ class EmailProc {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ * 【6701】拉取最新邮件列表
|
|
|
* @param Req $req
|
|
|
*/
|
|
|
- static function test($req) {
|
|
|
- if (GAME_ONLINE) {
|
|
|
- return;
|
|
|
- }
|
|
|
- $zonid = $req->zoneid;
|
|
|
+ public static function RefreshEmailList($req) {
|
|
|
$uid = $req->uid;
|
|
|
+ $zoneid = $req->zoneid;
|
|
|
+ self::refreshSysMail($zoneid, $uid); # 更新下系统邮件
|
|
|
+ self::clearExpireMails($zoneid, $uid); # 清理过期邮件, 以及超过容量的邮件
|
|
|
+ $mails = self::getMailQueue($zoneid, $uid); # 拉取邮件列表
|
|
|
+ var_dump($mails);
|
|
|
+ return Resp::ok(array('mailQueue' => $mails)); # 返回值
|
|
|
+ }
|
|
|
|
|
|
- $itemid = 399001; # 钻石
|
|
|
- $num = 3;
|
|
|
+ /**
|
|
|
+ * 【6702】读取一封邮件, 更新readts
|
|
|
+ * @param Req $req
|
|
|
+ */
|
|
|
+ public static function ReadEmail($req) {
|
|
|
|
|
|
- $mail = new EmailModel(null, enum_Mail_Type::SysTemMail, #
|
|
|
- "测试", "测试有好礼", $itemid, $num, "系统", "系统");
|
|
|
- for ($i = 0; $i < 100; $i++) {
|
|
|
- $mailId = self::InsertMail($zonid, $uid, $mail);
|
|
|
- }
|
|
|
- $req->paras[0] = $mailId;
|
|
|
-// self:: ReadEmail($req);
|
|
|
- return Resp::ok('ok');
|
|
|
+ $uid = $req->uid;
|
|
|
+ $zoneid = $req->zoneid;
|
|
|
+ $mailId = $req->paras[0]; # 传递参数,邮件的id字符串
|
|
|
+ my_Assert($mailId, ErrCode::email_wrongid); # 普通读取一封邮件的逻辑
|
|
|
+
|
|
|
+ $mail = self::getMail($zoneid, $uid, $mailId);
|
|
|
+ $mail->readts = now();
|
|
|
+ self::updateMail($zoneid, $uid, $mail); # 更新邮件数据
|
|
|
+ self::logMailReaded(array($mailId), $uid, $zoneid); # 更新数据库中邮件的read记录
|
|
|
+ return Resp::ok(array("rewardstr" => $mail->appendix));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 刷新邮件列表状态
|
|
|
- * @param Req $req
|
|
|
+ * 【6703】 领取一封邮件的附件,更新drawedts
|
|
|
+ * @param req $req
|
|
|
+ * @return type
|
|
|
*/
|
|
|
- public static function RefreshEmailList($req) {
|
|
|
+ public static function DrawEmailAppendix($req) {
|
|
|
$uid = $req->uid;
|
|
|
$zoneid = $req->zoneid;
|
|
|
- $mailId = $req->paras[0]; # Ps. 对比mailid, 推送更新包,
|
|
|
-# # 第一次mailid传0, 以后传最新id,
|
|
|
-# # 这样服务端发送的是增量包,节约流量
|
|
|
- self::refreshSysMail($zoneid, $uid); # 更新下系统邮件
|
|
|
- self::clearExpireMails($zoneid, $uid); # 清理过期邮件, 以及超过容量的邮件
|
|
|
- $mails = self::getMailQueue($zoneid, $uid, $mailId); # 拉取邮件列表
|
|
|
- return Resp::ok(array('mailQueue' => $mails)); # 返回值
|
|
|
+ $mailId = $req->paras[0]; # 传递参数,邮件的id字符串
|
|
|
+ my_Assert($mailId, ErrCode::email_wrongid); # 邮件id
|
|
|
+
|
|
|
+ $mail = self::getMail($zoneid, $uid, $mailId); # 取出对应的邮件数据
|
|
|
+ my_Assert($mail->readts > 0, ErrCode::err_innerfault); # 未打开的不可能调用领取接口
|
|
|
+ my_Assert($mail->isExistReward(), ErrCode::email_no_appendix); # 先判断邮件,是否存在有效的奖励物品
|
|
|
+ my_Assert($mail->drawedts <= 0, ErrCode::email_appendix_drawed); # 邮件不可重复领取
|
|
|
+ $err = StoreProc::AddMultiItemInStore($req, $mail->appendix, 4); # 发放奖励
|
|
|
+
|
|
|
+ my_Assert(ErrCode::ok == $err, $err); # 发奖成功
|
|
|
+ $mail->drawedts = now(); # 更新领取时间戳
|
|
|
+ self::updateMail($zoneid, $uid, $mail); # 回写邮件数据
|
|
|
+ self::logMailDrawed(array($mailId), $uid, $zoneid); # 更新数据库中邮件的领取记录
|
|
|
+ UserProc::updateUserInfo();
|
|
|
+ return Resp::ok(array(# # 同步数据
|
|
|
+ 'gold' => $req->userInfo->game->baseInfo->gold,
|
|
|
+ 'cash' => $req->userInfo->game->baseInfo->cash,
|
|
|
+ 'store' => $req->userInfo->game->store,
|
|
|
+ 'hero' => $req->userInfo->game->heros,
|
|
|
+ 'num' => 1,
|
|
|
+ 'reward' => $mail->appendix
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 读取一封邮件, 注意: 有删除所有邮件,但是没有一件领取好吗? 要不也加上吧
|
|
|
- * @param Req $req
|
|
|
+ * 【6704】 领取所有邮件附件奖励
|
|
|
+ * @param req $req
|
|
|
+ * @return type
|
|
|
*/
|
|
|
- public static function ReadEmail($req) {
|
|
|
+ public static function DrawAllEmailAppendixes($req) {
|
|
|
$uid = $req->uid;
|
|
|
$zoneid = $req->zoneid;
|
|
|
- $mailId = $req->paras[0]; # 传递参数,邮件的id字符串
|
|
|
- $arr = ArrayInit();
|
|
|
- $rewardEmailIds = ArrayInit();
|
|
|
- $notrewardEmails = ArrayInit();
|
|
|
- $mails = ArrayInit();
|
|
|
-
|
|
|
- if ($mailId) { # 普通读取一封邮件的逻辑
|
|
|
- $mail = self::getMail($zoneid, $uid, $mailId);
|
|
|
- if (!$mail) {
|
|
|
- return Resp::ok(array('err' => -1, 'msg' => 'mail not found!'));
|
|
|
- }
|
|
|
- $mails[] = $mail;
|
|
|
- } else { # 非有效mailid,执行一键领取
|
|
|
- $mails = self::getMailQueue($zoneid, $uid);
|
|
|
- }
|
|
|
- ////如果进行的是全部领取操作
|
|
|
- ////是 1 ,有奖励的邮件,全部处理,领取奖励。无奖励的邮件,不处理。因为全部领取邮件功能只限于处理有奖励的物品,无奖励的不管
|
|
|
- /// 非 2 ,有奖励就领取。 无奖励,则要进行标记为已读。
|
|
|
- //// 综上所述: 无论是全部还是单个邮件,
|
|
|
- ////有奖励的邮件肯定要领取的,还得删掉。 无奖励的看情况, 一键领取模式则不处理,否则就标记为已读;但是不需要删掉。
|
|
|
- foreach ($mails as $m) {
|
|
|
- //先判断邮件,是否存在有效的奖励物品
|
|
|
- if ($m->isExistReward()) {
|
|
|
- $err = StoreProc::AddMultiItemInStore($req, $m->getRewardStr(), 4);
|
|
|
-
|
|
|
- if (ErrCode::ok == $err) { # 发奖成功
|
|
|
- $arr[] = $m->getRewardStr();
|
|
|
- $rewardEmailIds[] = $m->mailId;
|
|
|
- self::delMail($zoneid, $uid, $m->mailId); # 规则: 领取后就会删除邮件,需要跟策划确认
|
|
|
- } else { # 发放物品失败或部分失败
|
|
|
- // todo: how to deal this case?
|
|
|
+ $arr = ArrayInit(); # 记录奖励字符串
|
|
|
+ $rewardEmailIds = ArrayInit(); # 记录领取邮件id
|
|
|
+ $mails = self::getMailQueue($zoneid, $uid); # 提取邮件列表
|
|
|
+ // 有奖励的邮件,全部处理,领取奖励。无奖励的邮件,不处理。因为全部领取邮件功能只限于处理有奖励的物品,无奖励的不管
|
|
|
+ foreach ($mails as $m) { # 遍历所有邮件
|
|
|
+ isEditor() and $m = new EmailModel;
|
|
|
+ if ($m->isExistReward()) { # 先判断邮件,是否存在附件
|
|
|
+ if ($m->drawedts > 0) { # 已领取邮件跳过
|
|
|
+ continue;
|
|
|
}
|
|
|
- } else {
|
|
|
- if ($mailId != 0) {
|
|
|
- $notrewardEmails[] = $m;
|
|
|
+ $err = StoreProc::AddMultiItemInStore($req, $m->appendix, 4);
|
|
|
+ my_Assert(ErrCode::ok == $err, $err); # 发奖成功
|
|
|
+ $m->drawedts = now(); # 更新下领取时间戳
|
|
|
+ if ($m->readts <= 0) { # 更新下读取时间戳
|
|
|
+ $m->readts = now();
|
|
|
}
|
|
|
- }
|
|
|
+ $arr[] = $m->appendix;
|
|
|
+ $rewardEmailIds[] = $m->mailId;
|
|
|
+ } // else # 无附件的邮件不管
|
|
|
}
|
|
|
- foreach ($notrewardEmails as $t_mail) {
|
|
|
- #回写个人邮件的无奖励邮件的读取时间戳
|
|
|
- $t_mail->drawedts = now();
|
|
|
- self::updateMail($zoneid, $uid, $t_mail);
|
|
|
+ $asocMails = array();
|
|
|
+ foreach ($mails as $mm) { # 转为关联数组
|
|
|
+// isEditor() and $mm = new EmailModel;
|
|
|
+ $asocMails[$mm->mailId] = $mm;
|
|
|
}
|
|
|
+ self::updateMails($zoneid, $uid, $asocMails); # 批量更新邮件
|
|
|
self::logMailDrawed($rewardEmailIds, $uid, $zoneid); # 更新数据库中邮件的领取记录
|
|
|
+ $n = count($rewardEmailIds); # 计数,领取邮件数量
|
|
|
$reward = implode(';', $arr); # 拼接下奖励字符串
|
|
|
- return Resp::ok(array('err' => 0,
|
|
|
+ UserProc::updateUserInfo();
|
|
|
+ return Resp::ok(array(# # 同步数据
|
|
|
+ 'gold' => $req->userInfo->game->baseInfo->gold,
|
|
|
+ 'cash' => $req->userInfo->game->baseInfo->cash,
|
|
|
'store' => $req->userInfo->game->store,
|
|
|
'hero' => $req->userInfo->game->heros,
|
|
|
+ 'num' => $n,
|
|
|
'reward' => $reward));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除邮件
|
|
|
- * @param Req $req
|
|
|
+ * 【6705】 删除所有已读邮件
|
|
|
+ * @param req $req
|
|
|
+ * @return type
|
|
|
*/
|
|
|
- static function deleteMail($req) {
|
|
|
+ public static function DelReadedEmail($req) {
|
|
|
$uid = $req->uid;
|
|
|
$zoneid = $req->zoneid;
|
|
|
- $mailId = $req->paras[0]; # 邮件id, 0 or null:删除所有邮件
|
|
|
- $n = 0;
|
|
|
- if (!$mailId) { # null or 0 删除所有邮件
|
|
|
-// $n = self::clearMailQueue($zoneid, $uid);
|
|
|
- //上面操作太霸道,而且也不正确
|
|
|
- $n = 0;
|
|
|
- //删除全部标记为已读的,且没有奖励内容的邮件
|
|
|
- $mails = ArrayInit();
|
|
|
- $mails = self::getMailQueue($zoneid, $uid);
|
|
|
- foreach ($mails as $m) {
|
|
|
- if ($m->isDrawed() && !$m->isExistReward()) {
|
|
|
- self::delMail($zoneid, $uid, $m->mailId);
|
|
|
- $n += 1;
|
|
|
+ $mails = self::getMailQueue($zoneid, $uid); # 取邮件队列
|
|
|
+ $n = 0; # 记个数,看一共删除几封邮件
|
|
|
+ foreach ($mails as $m) {
|
|
|
+ isEditor() and $m = new EmailModel;
|
|
|
+ if ($m->readts <= 0) { # 未读邮件跳过
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($m->isExistReward()) { # 包含附件,
|
|
|
+ if (!$m->isDrawed()) { # 且附件尚未领取的,不能删除,跳过
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
- } else { # 传过来的是一个mailid
|
|
|
- $n = self::delMail($zoneid, $uid, $mailId);
|
|
|
- }
|
|
|
- return Resp::ok(array('del' => $n)); # 返回删除的邮件数量
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除邮件 没有条件限制
|
|
|
- * @param type $req
|
|
|
- */
|
|
|
- static function deleteMailNoCondition($req) {
|
|
|
- $uid = $req->uid;
|
|
|
- $zoneid = $req->zoneid;
|
|
|
- $mailIdStr = $req->paras[0];
|
|
|
- $mids = explode(',', $req->paras[0]); // 逗号分割uid字符串
|
|
|
- $n = 0;
|
|
|
- foreach ($mids as $mailId) {
|
|
|
- self::delMail($zoneid, $uid, $mailId);
|
|
|
- $n += 1;
|
|
|
+ self::delMail($zoneid, $uid, $m->mailId); # 规则: 附件领取后就可以删除邮件
|
|
|
+ $n++;
|
|
|
}
|
|
|
- return Resp::ok(array('del' => $n)); # 返回删除的邮件数量
|
|
|
+ return Resp::ok(array('num' => $n)); # 返回删除数量
|
|
|
}
|
|
|
|
|
|
- // <editor-fold defaultstate="collapsed" desc=" 插入邮件">
|
|
|
+// </editor-fold>
|
|
|
+//
|
|
|
+// <editor-fold defaultstate="collapsed" desc=" 插入邮件">
|
|
|
|
|
|
/**
|
|
|
* 系统邮件 - 发送竞技场赛季排行榜奖励
|
|
@@ -236,7 +246,7 @@ class EmailProc {
|
|
|
$num = $arr[1];
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::SysTemMail, "竞技场赛季上榜奖励", #
|
|
|
"恭喜您在上赛季的竞技场战斗中获得总榜" . $rkrwd->rankName . "的奖励", #
|
|
|
- $itemid, $num);
|
|
|
+ "$itemid,$num");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
break;
|
|
|
}
|
|
@@ -258,7 +268,7 @@ class EmailProc {
|
|
|
$num = $arr[1];
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::SysTemMail, "竞技场每日上榜奖励", #
|
|
|
"恭喜您在昨天的竞技场战斗中获得总榜" . $rkrwd->rankName . "的奖励", #
|
|
|
- $itemid, $num);
|
|
|
+ "$itemid,$num");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
break;
|
|
|
}
|
|
@@ -275,10 +285,9 @@ class EmailProc {
|
|
|
public static function SendDelTestMail($zoneid, $uid, $name, $content) {
|
|
|
$arr = explode(',', $content);
|
|
|
$itemid = $arr[0];
|
|
|
- $num = intval($arr[1]);
|
|
|
+ $num = intval($arr[1]) * 2; # 2倍返还
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::SysTemMail, "删档内侧补偿", #
|
|
|
- "感谢您在之前的删档内侧活动中充值购买$name.", #
|
|
|
- $itemid, $num * 2); # 2倍返还
|
|
|
+ "感谢您在之前的删档内侧活动中充值购买$name.", "$itemid, $num");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
}
|
|
|
|
|
@@ -294,8 +303,7 @@ class EmailProc {
|
|
|
*/
|
|
|
public static function SendGuildApplyRefusedMail($zoneid, $uid, $guildName) {
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::GuildApplyRefuseMail, "公会申请结果", #
|
|
|
- "很遗憾" . $guildName . "公会拒绝了您的加入申请", #
|
|
|
- 0, 0, "公会");
|
|
|
+ "很遗憾" . $guildName . "公会拒绝了您的加入申请", "", "公会");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
}
|
|
|
|
|
@@ -310,8 +318,7 @@ class EmailProc {
|
|
|
$itemNum = $chipArr[1];
|
|
|
$content = $itemNum == null ? "请求捐献结算时间截止,没有得到捐献碎片" : "请求捐献结算时间截止,领取已获得碎片";
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::GuildDonateSettle, "公会捐献碎片结算", #
|
|
|
- $content, #
|
|
|
- $itemId, $itemNum, "公会");
|
|
|
+ $content, "$itemId, $itemNum", "公会");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
}
|
|
|
|
|
@@ -323,8 +330,7 @@ class EmailProc {
|
|
|
*/
|
|
|
public static function SendGuildCashGiftReward($zoneid, $uid, $itemId, $num) {
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::GuildCashGiftReward, "公会礼包回赠", #
|
|
|
- "系统回赠礼品", #
|
|
|
- $itemId, $num, "公会");
|
|
|
+ "系统回赠礼品", "$itemId, $num", "公会");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
}
|
|
|
|
|
@@ -336,8 +342,7 @@ class EmailProc {
|
|
|
*/
|
|
|
public static function SendGuildNoticeMail($zoneid, $uid, $title, $content) {
|
|
|
$mail = new EmailModel(null, enum_Mail_Type::GuildNoticeMail, $title, #
|
|
|
- $content, #
|
|
|
- 0, 0, "公会");
|
|
|
+ $content, "", "公会");
|
|
|
self::InsertMail($zoneid, $uid, $mail);
|
|
|
}
|
|
|
|
|
@@ -360,7 +365,7 @@ class EmailProc {
|
|
|
if (!$mem->hsetnx($key_queue, $mail->mailId, $mail)) { # 重试下
|
|
|
$mail->mailId = $mem->increment($key_id);
|
|
|
if (!$mem->hsetnx($key_queue, $mail->mailId, $mail)) {
|
|
|
-//todo: 重试都没能成功的话, 记录下日志, log err;
|
|
|
+ // todo: 重试都没能成功的话, 记录下日志, log err;
|
|
|
CLog::err('create sysmail failed! id:' . JsonUtil::encode($mail), "EmailProc");
|
|
|
}
|
|
|
}
|
|
@@ -369,7 +374,7 @@ class EmailProc {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ * 回写mail数据
|
|
|
* @param type $zoneid
|
|
|
* @param type $uid
|
|
|
* @param EmailModel $mail
|
|
@@ -378,36 +383,65 @@ class EmailProc {
|
|
|
gMem()->hset(MemKey_User::Mail_Queue_hash($zoneid, $uid), $mail->mailId, $mail);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量回写mail数据
|
|
|
+ * @param type $zoneid
|
|
|
+ * @param type $uid
|
|
|
+ * @param dic<mailId, EmailModel> $mails
|
|
|
+ */
|
|
|
+ private static function updateMails($zoneid, $uid, $mails) {
|
|
|
+ gMem()->hmset(MemKey_User::Mail_Queue_hash($zoneid, $uid), $mails);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param type $zoneid
|
|
|
+ * @param type $uid
|
|
|
+ * @param EmailModel $mail
|
|
|
+ */
|
|
|
private static function logMail($zoneid, $uid, $mail) {
|
|
|
$data = array(
|
|
|
'mailId' => $mail->mailId,
|
|
|
'zoneid' => $zoneid,
|
|
|
- 'itemid' => $mail->itemid,
|
|
|
- 'num' => $mail->num,
|
|
|
+ 'appendix' => $mail->appendix,
|
|
|
'type' => $mail->type,
|
|
|
- 'name_sender' => $mail->name_sender,
|
|
|
- 'uid_sender' => $mail->uid_sender,
|
|
|
- 'uid_to' => $uid, # # this mail is send to me 啊.
|
|
|
+ 'sender_name' => $mail->sender_name,
|
|
|
+ 'sender_uid' => $mail->sender_uid,
|
|
|
+ 'to_uid' => $uid, # # this mail is send to me 啊.
|
|
|
'title' => $mail->title,
|
|
|
'content' => $mail->content,
|
|
|
- 'tag' => $mail->tag,
|
|
|
- 'startts' => $mail->startts,
|
|
|
- 'endts' => $mail->endts
|
|
|
+ 'tag' => $mail->tag
|
|
|
);
|
|
|
daoInst()->insert('tab_mailrecord')->data($data)->exec();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新邮件的领取记录
|
|
|
+ * @version 1 这里邮件id不是唯一, 需要联合uid一起改.--晨叶反馈于2020.5.21
|
|
|
+ * 0 created at 言灵世界1.0
|
|
|
* @param type $ids
|
|
|
*/
|
|
|
static function logMailDrawed($ids, $uid, $zoneid) {
|
|
|
-// Err("这里邮件id不是唯一, 需要联合uid一起改.--晨叶反馈于2020.5.21");
|
|
|
daoInst()->update(self::MailLog_TableName)->data(array(
|
|
|
'drawedts' => now()
|
|
|
))->where('mailId')->in($ids)->
|
|
|
andWhere('zoneid')->eq($zoneid)->
|
|
|
- andWhere('uid_to')->eq($uid)->
|
|
|
+ andWhere('to_uid')->eq($uid)->
|
|
|
+ exec();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新邮件的读取/打开记录
|
|
|
+ * @version 1 这里邮件id不是唯一, 需要联合uid一起改.--晨叶反馈于2020.5.21
|
|
|
+ * 0 created at 言灵世界1.0
|
|
|
+ * @param type $ids
|
|
|
+ */
|
|
|
+ static function logMailReaded($ids, $uid, $zoneid) {
|
|
|
+ daoInst()->update(self::MailLog_TableName)->data(array(
|
|
|
+ 'readts' => now()
|
|
|
+ ))->where('mailId')->in($ids)->
|
|
|
+ andWhere('zoneid')->eq($zoneid)->
|
|
|
+ andWhere('to_uid')->eq($uid)->
|
|
|
exec();
|
|
|
}
|
|
|
|
|
@@ -419,17 +453,18 @@ class EmailProc {
|
|
|
*/
|
|
|
private static function refreshSysMail($zoneid, $uid) {
|
|
|
$mem = gMem();
|
|
|
- $sysMailQueue = GameConfig::sysmail();
|
|
|
+ $sysMailQueue = GameConfig::sysmail(); # 取系统消息列表
|
|
|
if (!$sysMailQueue) {
|
|
|
return; # 系统消息为空
|
|
|
}
|
|
|
$key = MemKey_User::Mail_SysRecord_set($zoneid, $uid); # memkey
|
|
|
- $record = $mem->smembers($key); # 系统邮件处理记录,在数据集过大以前, 个人认为全部获取比较高效 --王刚,所以系统邮件不能太多呢
|
|
|
+ $record = $mem->smembers($key); # 系统邮件处理记录,在数据集过大以前, 个人认为全部获取比较高效 --王刚,所以系统邮件不能太多呢(后面取已处理最大id,做优化吧)
|
|
|
foreach ($sysMailQueue as $sysId => $sysMail) {
|
|
|
+ isEditor() and $sysMail = new \sm_sysmail(); # 辅助方法.
|
|
|
if (!StlUtil::arrayContains($record, $sysId)) { # 判断尚未处理此邮件
|
|
|
$ts = now();
|
|
|
if ($ts > $sysMail->endts) { # 已经过期的系统邮件
|
|
|
- $mem->sadd($key, $sysId); # 记录已经领取此邮件
|
|
|
+ $mem->sadd($key, $sysId); # 记录已经领取此邮件, 但不插入玩家邮件列表了.
|
|
|
continue; # 继续处理下一封
|
|
|
}
|
|
|
if ($ts < $sysMail->startts) {
|
|
@@ -437,7 +472,7 @@ class EmailProc {
|
|
|
} # else => 有效期内,继续处理
|
|
|
$mail = new EmailModel($sysMail); # 创建邮件
|
|
|
$mail->type = enum_Mail_Type::SysTemMail; # 设置邮件类型为系统邮件
|
|
|
- $mail->uid_sender = $mail->name_sender = "系统"; # 设置发送者昵称和uid为系统
|
|
|
+ $mail->sender_uid = $mail->sender_name = "系统"; # 设置发送者昵称和uid为系统
|
|
|
self::InsertMail($zoneid, $uid, $mail); # 插入邮件
|
|
|
$mem->sadd($key, $sysId); # 记录已经领取此邮件
|
|
|
}
|
|
@@ -456,7 +491,8 @@ class EmailProc {
|
|
|
$key = MemKey_User::Mail_Queue_hash($zoneid, $uid);
|
|
|
$arr = $mem->hgetall($key); # 所有邮件
|
|
|
$del = array_filter((array) $arr, function($v) use($ts) {
|
|
|
- return $v->endts < $ts; # 选出过期邮件
|
|
|
+ $email = new EmailModel($v);
|
|
|
+ return $email->ExpireTs() < $ts; # 选出过期邮件
|
|
|
});
|
|
|
if (count($del)) { # >0
|
|
|
$mem->hdel($key, array_keys($del)); # 批量清除
|
|
@@ -464,20 +500,18 @@ class EmailProc {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取邮件序列[自动提取id>mailid的邮件]
|
|
|
+ * 获取邮件序列
|
|
|
* @param int $zoneid
|
|
|
* @param string $uid
|
|
|
- * @param int $mailId
|
|
|
* @return array
|
|
|
*/
|
|
|
- private static function getMailQueue($zoneid, $uid, $mailId = 0) {
|
|
|
- $key = MemKey_User::Mail_Queue_hash($zoneid, $uid);
|
|
|
- $keys = gMem()->hkeys($key); # 拉取所有id
|
|
|
- $fkeys = array_filter($keys, function($v)use($mailId) { # 过滤邮件
|
|
|
- return $v > $mailId; # id 大于更新id
|
|
|
- });
|
|
|
- $skeys = sort($fkeys); # 排序
|
|
|
- $mkeys = array_slice($fkeys, 0, 50); # 取固定数量
|
|
|
+ private static function getMailQueue($zoneid, $uid) {
|
|
|
+ $key = MemKey_User::Mail_Queue_hash($zoneid, $uid); # redis-key:= 玩家邮件列表
|
|
|
+ $keys = gMem()->hkeys($key); # 拉取所有id
|
|
|
+ var_dump($keys);
|
|
|
+ sort($keys); # 排序
|
|
|
+ $mkeys = array_slice($keys, 0, self::MaxMailContent); # 取固定数量100
|
|
|
+ var_dump($mkeys);
|
|
|
$mails = (array) gMem()->hmget($key, $mkeys); # mget
|
|
|
$ret = array_map(function($v) {
|
|
|
return new EmailModel($v); # 装箱
|
|
@@ -494,10 +528,8 @@ class EmailProc {
|
|
|
*/
|
|
|
private static function getMail($zoneid, $uid, $mailId) {
|
|
|
$m = gMem()->hget(MemKey_User::Mail_Queue_hash($zoneid, $uid), $mailId);
|
|
|
- if ($m) {
|
|
|
- $m = new EmailModel($m);
|
|
|
- }
|
|
|
- return $m;
|
|
|
+ my_Assert($m, ErrCode::email_not_found);
|
|
|
+ return new EmailModel($m);
|
|
|
}
|
|
|
|
|
|
/**
|