123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- namespace loyalsoft;
- /**
- * 用户交互信息数据模型
- * 注:mem中是独立于userInfo的存在, 以减少交互操作的时候出现写入冲突产生覆盖的情况。
- * attention: 读写数据的时候,利用redis的watch机制实现事务写入,加上自动重试机制. (Ps.这是目标,gwang.20170426153414)
- *
- * @version
- * 1.0.0 Created at 2017-3-25. by --gwang
- * @author gwang (mail@wanggangzero.cn)
- * @copyright ? 2017-3-25, SJZ LoyalSoft Corporation & gwang. All rights reserved.
- */
- class UserInteractModel extends Object_ext
- {
- public $uid;
- public $zoneid;
- // ------------字段声明-------------
- /**
- * 邮件列表
- * @var object
- */
- public $mailQueue;
- /**
- * 邮件序列id
- * @var int
- */
- public $mailMaxId = 0;
- /**
- * 系统邮件记录[存在于系统公共缓冲区的邮件仅能接收一次]
- * @var array
- */
- public $sysMailRecord;
- // ------------ 初始化 ------------------
- /**
- * 创建账号的时候执行初始化.
- */
- public function initialize()
- {
- $this->mailQueue = ObjectInit();
- $this->mailMaxId = 10000;
- $this->sysMailRecord = ArrayInit();
- }
- // ----------- 方法 ---------------------
- // <editor-fold defaultstate="collapsed" desc=" 公开方法 ">
- /**
- * 新增系统邮件
- * @param int $sysId 邮件的id
- * @param string $title 邮件标题
- * @param type $content 邮件正文
- * @param type $itemid 道具id (附加于tag字段)
- * @param type $startts 生效时间
- * @param type $endts 过期时间
- * @param type $interact 目标交互体
- */
- static function insertSysMail($sysId, $title, $content, $itemid, $startts, $endts, &$interact)
- {
- self::insertMail("0", "系统邮件", "", "", 1, $title, $content, $itemid, $startts, $endts, $interact);
- if ($sysId != 0) {
- $sysMailRecord = $interact->sysMailRecord;
- $sysMailRecord[] = $sysId;
- $interact->sysMailRecord = $sysMailRecord;
- }
- }
- /**
- * 新增邮件
- * @param string $fromoid 发送人的oid
- * @param type $name 发送人的呢称
- * @param type $pf pf
- * @param type $img 图像
- * @param type $type 邮件类型
- * @param string $title 邮件标题
- * @param string $content 邮件正文
- * @param type $tag 额外标签可以传递数据
- * @param ts $startts 生效时间
- * @param ts $endts 过期时间
- * @param UserInteractModel $interact 目标交互体
- * @return void
- */
- static function insertMail($fromoid, $name, $pf, $img, $type, $title, $content, $tag, $startts, $endts, &$interact)
- {
- if (CommUtil::tsCurrent() > $endts) {
- return;
- }
- $interact->mailMaxId++;
- $mailMaxId = $interact->mailMaxId;
- $mail = new EmailModel;
- $mail->fromoid = $fromoid;
- $mail->name = $name;
- $mail->pf = $pf;
- $mail->img = $img;
- $mail->type = $type;
- $mail->title = $title;
- $mail->content = $content;
- $mail->tag = $tag;
- $mail->startts = $startts;
- $mail->endts = $endts;
- $mail->ts = CommUtil::tsCurrent();
- $interact->mailQueue->$mailMaxId = $mail;
- # 记录日志
- self::_insertMailRecord($interact->oid, $interact->zoneid, $mail, $mailMaxId);
- }
- /**
- * 插入发送邮件的日志
- * @param string uid
- * @param int $zoneid
- * @param EmailModel $mail
- * @param int $mailId
- */
- static function _insertMailRecord($uid, $zoneid, $mail, $mailId)
- {
- $sql = <<<ins
- INSERT INTO `tab_mailrecord` (oid,`zoneid`,mailId, fromoid,`name`, pf,img,type,title,content,tag,startts,endts,insertts)
- VALUES ('%s',%d,%d,'%s','%s','%s','%s',%d,'%s','%s','%s',%d,%d,now());
- ins;
- $insertstr = sprintf($sql, $uid, $zoneid, $mailId, $mail->fromoid, $mail->name, #
- $mail->pf, $mail->img, $mail->type, $mail->title, $mail->content, #
- $mail->tag, $mail->startts, $mail->endts);
- daoInst()->query($insertstr);
- }
- /**
- * 获取邮件序列[自动过滤尚未到(生效)期的邮件,自动删除已过期的邮件]
- * @param UserInteractModel $interact Description
- */
- static function getMailQueue($interact)
- {
- $mailList = ObjectInit();
- $mailQueue = $interact->mailQueue;
- foreach ($mailQueue as $mailId => $mail) {
- $ts = CommUtil::tsCurrent();
- if ($ts >= $mail->startts) {
- if ($ts > $mail->endts) {
- self::deleteMail($mailId, $interact);
- } else {
- $mailList->$mailId = $mail;
- }
- }
- }
- return $mailList;
- }
- /**
- * 删除邮件[附件接收完毕之后]
- * @param type $mailId
- * @param UserInteractModel $interact Description
- */
- static function deleteMail($mailId, &$interact)
- {
- self::_drawMailRecord($mailId, $interact); # 领取记录
- StlUtil::dictRemove($interact->mailQueue, $mailId);
- }
- /**
- * 更新领取记录
- * @param type $mailId
- * @param UserInteractModel $interact
- */
- static function _drawMailRecord($mailId, $interact)
- {
- $sql = "update tab_mailrecord set drawedts=now() where mailId=%d and zoneid=%s and uid=%s;";
- $updatestr = sprintf($sql, $mailId, $interact->zoneid, $interact->uid);
- daoInst()->query($updatestr);
- }
- // </editor-fold>
- }
|