game2006api/webapp/services/MailApiService.php
aozhiwei 4b6d3498e6 1
2024-06-26 14:00:57 +08:00

114 lines
3.4 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 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()
)
);
}
private function adjustAttachments(&$attachments)
{
if (empty($attachments)) {
$attachments = '';
return;
}
foreach ($attachments as &$val) {
$val['itemid'] = intval($val['itemid']);
$val['itemnum'] = intval($val['itemnum']);
}
}
}