game2006api/webapp/controller/MailController.class.php
aozhiwei adffee41da 1
2024-07-04 16:46:05 +08:00

109 lines
3.5 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 getAttachmentCb()
{
$timestamp = getReqVal('timestamp', '');
$signStr = getReqVal('sign', '');
$data = file_get_contents('php://input');
$dataJson = json_decode($data, true);
$localSignStr = md5($data . MAIL_KEY . $timestamp);
if ($localSignStr != $signStr) {
myself()->_rspErr(500, 'server internal error 3, url:');
return;
}
if (empty($dataJson)) {
myself()->_rspErr(500, 'server internal error 4, url:');
return;
}
error_log(json_encode($dataJson));
if ($dataJson['account_id'] != myself()->_getAccountId()) {
myself()->_rspErr(500, 'server internal error 2, url:');
return;
}
if (abs($timestamp - myself()->_getNowTime()) > 60) {
myself()->_rspErr(500, 'server internal error 5, url:');
return;
}
$this->procAttachments($dataJson);
myself()->_rspData(array(
'award' => $this->awardService->toDto(),
'property_chg' => $this->propertyChgService->toDto()
));
}
private function procAttachments($dataJson)
{
$mailHash = $dataJson['mails'];
foreach ($mailHash as $val) {
$mailId = $val['mailid'];
$items = array();
foreach ($val['attachments'] 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
)
);
}
}
}
}