game2006api/webapp/controller/MailController.class.php
aozhiwei 2123964dc7 1
2023-09-14 14:06:13 +08:00

129 lines
4.0 KiB
PHP

<?php
use phpcommon\SqlHelper;
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
class MailController extends BaseAuthedController {
private $propertyChgService = null;
private $awardService = null;
public function _handlePre()
{
parent::_handlePre();
$this->propertyChgService = new services\PropertyChgService();
$this->awardService = new services\AwardService();
}
public function getAttachment()
{
$mailIds = getReqVal('mail_ids', '');
$response = '';
{
$params = array(
'c' => 'Mail',
'a' => 'getAttachment',
'account_id' => myself()->_getAccountId(),
'session_id' => myself()->_getSessionId(),
'mail_ids' => $mailIds
);
$url = self::getMailServerUrl();
if (!phpcommon\HttpClient::get
($url,
$params,
$response)) {
myself()->_rspErr(500, 'server internal error 3, url:' . $url);
die();
return;
}
}
error_log($mailIds);
error_log($response);
error_log($url);
$rspObj = json_decode($response, true);
if ($rspObj && $rspObj['errcode'] == 0) {
$this->procAttachments($rspObj['attachments']);
$rspObj['award'] = $this->awardService->toDto();
$rspObj['property_chg'] = $this->propertyChgService->toDto();
}
echo json_encode($rspObj);
}
private function procAttachments($attachments)
{
$mailHash = array();
{
foreach ($attachments as $item) {
if (!array_key_exists($item['mailid'], $mailHash)) {
$mailHash[$item['mailid']] = array();
}
array_push($mailHash[$item['mailid']], $item);
}
}
foreach ($mailHash as $key => $val) {
$mailId = $key;
$items = array();
foreach ($val as $item) {
array_push($items, array(
'item_id' => $item['itemid'],
'item_num' => $item['itemnum'],
));
}
$row = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_mail',
array(
'account_id' => myself()->_getAccountId(),
'mailid' => $mailId
)
);
if (!$row) {
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_mail',
array(
'account_id' => myself()->_getAccountId(),
'mailid' => $mailId
),
array(
),
array(
'account_id' => myself()->_getAccountId(),
'mailid' => $mailId,
'attachments' => json_encode($items),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
$this->_addItems($items, $this->awardService, $this->propertyChgService);
SqlHelper::update(
myself()->_getSelfMysql(),
't_mail',
array(
'account_id' => myself()->_getAccountId(),
'mailid' => $mailId
),
array(
'confirmed' => 1
)
);
}
}
}
private static function getMailServerUrl()
{
if (SERVER_ENV != _ONLINE) {
return "https://gamemail-test.kingsome.cn/webapp/index.php";
} else {
return "https://gamemail-test.cebggame.com/webapp/index.php";
}
}
}