game2006api/webapp/services/MailApiService.php
aozhiwei 7d7df2f41d 1
2024-06-11 16:46:34 +08:00

153 lines
4.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace services;
use phpcommon\SqlHelper;
class MailApiService extends BaseService {
const SELL_UNIKEY_PRE = 'ingame.market.sell:';
const BUY_UNIKEY_PRE = 'ingame.market.buy:';
const OPEN_GOLD_BULLION_UNIKEY_PRE = 'gold_bullion:open:';
const SELL_MAIL_SUBJECT = 'Item successfully sold';
/*
orderId订单id
to邮件接受方account_id
subject: 邮件标题
content: 邮件正文
attachments: 邮件附件
[
{
"itemid": 0, //道具id
"itemnum": 0, //道具数量
}
]
*/
public function sendSellMail($orderId, $to, $subject, $content, $attachments)
{
$unikey = self::SELL_UNIKEY_PRE . $orderId;
SqlHelper::upsert
(myself()->_getMailMysql(),
't_sys_mail',
array(
'unikey' => $unikey
),
array(
),
array(
'unikey' => $unikey,
'subject' => $subject,
'content' => $content,
'recipients' => json_encode(array(
$to
)),
'attachments' => json_encode($attachments),
'tag1' => 1,
'tag2' => 1,
'sendtime' => myself()->_getNowTime(),
'expiretime' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'user_reg_start_time' => 0,
'user_reg_end_time' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
/*
orderId订单id
to邮件接受方account_id
subject: 邮件标题
content: 邮件正文
attachments: 邮件附件
[
{
"itemid": 0, //道具id
"itemnum": 0, //道具数量
}
]
*/
public function sendBuyMail($orderId, $to, $subject, $content, $attachments)
{
$unikey = self::BUY_UNIKEY_PRE . $orderId;
SqlHelper::upsert
(myself()->_getMailMysql(),
't_sys_mail',
array(
'unikey' => $unikey
),
array(
),
array(
'unikey' => $unikey,
'subject' => $subject,
'content' => $content,
'recipients' => json_encode(array(
$to
)),
'attachments' => json_encode($attachments),
'tag1' => 1,
'tag2' => 2,
'sendtime' => myself()->_getNowTime(),
'expiretime' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'user_reg_start_time' => 0,
'user_reg_end_time' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
/*
netId: netId
tokenIdtokenid
to邮件接受方account_id
subject: 邮件标题
content: 邮件正文
*/
public function sendOpenGold($netId, $tokenId, $subject, $content)
{
$unikey = self::OPEN_GOLD_BULLION_UNIKEY_PRE . $netId . '_' . $tokenId;
SqlHelper::upsert
(myself()->_getMailMysql(),
't_sys_mail',
array(
'unikey' => $unikey
),
array(
),
array(
'unikey' => $unikey,
'subject' => $subject,
'content' => $content,
'recipients' => json_encode(array(
$to
)),
'attachments' => json_encode(array()),
'tag1' => 1,
'tag2' => 3,
'sendtime' => myself()->_getNowTime(),
'expiretime' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'user_reg_start_time' => 0,
'user_reg_end_time' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
private function adjustAttachments(&$attachments)
{
if (empty($attachments)) {
$attachments = '';
return;
}
foreach ($attachments as &$val) {
$val['itemid'] = intval($val['itemid']);
$val['itemnum'] = intval($val['itemnum']);
}
}
}