219 lines
7.8 KiB
PHP
219 lines
7.8 KiB
PHP
<?php
|
|
|
|
|
|
namespace services;
|
|
|
|
require_once('phpcommon/tglog.php');
|
|
|
|
require_once('models/User.php');
|
|
|
|
use mt;
|
|
use models\User;
|
|
use phpcommon\TGLog;
|
|
use phpcommon;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class LogService extends BaseService
|
|
{
|
|
|
|
const REFRESH_MISSION = "refresh_mission"; //刷新每日任务
|
|
const SHOP_BUY_ITEM_DAILY = "shop_buy_item_daily"; //商城每日精选购买物品
|
|
|
|
const CONSUME_TYPE = 0; //消耗 ↑
|
|
const PRODUCT_TYPE = 1; //产出 ↓
|
|
|
|
const BATTLE_AWARD_PVP = "battle_award_pvp"; //PVP战斗奖励
|
|
const STAR_MISSION_AWARD = "star_mission_award"; //星星之路奖励
|
|
const BATTLE_PASS_AWARD = "battle_pass_award"; //通行证奖励
|
|
const SIGN_AWARD = "sign_award"; //签到奖励
|
|
|
|
const MARKET_SELL_GOLD = "market_sell_gold"; //市场出售金币
|
|
const MARKET_CANCEL_SELL_GOLD = "market_cancel_sell_gold"; //市场取消出售金币
|
|
const MARKET_BUY_GOLD = "market_buy_gold"; //市场购买金币
|
|
|
|
const PRONAME = 'game_2006_api';
|
|
const GAMEID = 2006;
|
|
|
|
const GOLD_TYPE = 0;
|
|
const DIAMOND_TYPE = 1;
|
|
|
|
public static function addTgLog($eventName, $prop){
|
|
$data = [
|
|
"#account_id" => myself()->_getAccountId(),
|
|
"#event_name"=> $eventName,
|
|
"#ip"=> phpcommon\getIPv4(),
|
|
"#controller"=> getReqVal('c', ''),
|
|
"#action"=> getReqVal('a', ''),
|
|
"#time"=> myself()->_getNowTime(),
|
|
"#type"=> "track",
|
|
"properties"=> $prop
|
|
];
|
|
TGLog::writeToLog(self::PRONAME, self::GAMEID, $data);
|
|
}
|
|
|
|
public static function addGameLogEx($accountId, $type, $subtype, $params)
|
|
{
|
|
$fieldsKv = array(
|
|
'account_id' => $accountId,
|
|
'type' => $type,
|
|
'subtype' => $subtype,
|
|
'param1' => getXVal($params, 'param1', ''),
|
|
'param2' => getXVal($params, 'param2', ''),
|
|
'param3' => getXVal($params, 'param3', ''),
|
|
'param4' => getXVal($params, 'param4', ''),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
);
|
|
SqlHelper::insert(
|
|
myself()->_getLogMysql(),
|
|
't_game_log',
|
|
$fieldsKv
|
|
);
|
|
}
|
|
|
|
public static function burialPointEvent($event){
|
|
$logInfo = self::ItemRecord();
|
|
$logInfo['properties'] = $event;
|
|
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
|
|
}
|
|
|
|
public static function consumeGold($event,$param = [])
|
|
{
|
|
$logInfo = self::goldRecord($param);
|
|
$data = self::userInfo();
|
|
$data['type'] = self::CONSUME_TYPE;
|
|
$data['event_name'] = $event['name'];
|
|
$data['event_type'] = self::GOLD_TYPE;
|
|
$data['event_demand'] = 'gold';
|
|
$data['event_demand_val'] = $event['val'];
|
|
|
|
$logInfo['properties'] = array_merge($data,$param);
|
|
|
|
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
|
|
}
|
|
|
|
public static function productGold($event,$param = [])
|
|
{
|
|
$logInfo = self::goldRecord($param);
|
|
$data = self::userInfo();
|
|
$data['type'] = self::PRODUCT_TYPE;
|
|
$data['event_name'] = $event['name'];
|
|
$data['event_type'] = self::GOLD_TYPE;
|
|
$data['event_product'] = 'gold';
|
|
$data['event_product_val'] = $event['val'];
|
|
|
|
$logInfo['properties'] = array_merge($data,$param);
|
|
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
|
|
}
|
|
public static function productGoldCallback($base, $event,$param = [])
|
|
{
|
|
$logInfo = self::goldRecord($base);
|
|
$data = self::userInfoByAccountId($base['account_id']);
|
|
$data['type'] = self::PRODUCT_TYPE;
|
|
$data['event_name'] = $event['name'];
|
|
$data['event_type'] = self::GOLD_TYPE;
|
|
$data['event_product'] = 'gold';
|
|
$data['event_product_val'] = $event['val'];
|
|
|
|
$logInfo['properties'] = array_merge($data,$param);
|
|
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
|
|
}
|
|
|
|
public static function consumeItem($event,$param = [])
|
|
{
|
|
$logInfo = self::ItemRecord();
|
|
$data = self::userInfo();
|
|
$data['type'] = self::CONSUME_TYPE;
|
|
$data['item_id'] = $event['item_id'];
|
|
$data['item_num'] = $event['item_num'];
|
|
|
|
$logInfo['properties'] = array_merge($data,$param);
|
|
|
|
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
|
|
}
|
|
|
|
public static function productItem($event,$param = [])
|
|
{
|
|
$logInfo = self::ItemRecord();
|
|
$data = self::userInfo();
|
|
$data['type'] = self::PRODUCT_TYPE;
|
|
$data['item_id'] = $event['item_id'];
|
|
$data['item_num'] = $event['item_num'];
|
|
|
|
$logInfo['properties'] = array_merge($data,$param);
|
|
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
|
|
}
|
|
|
|
|
|
private static function userInfo()
|
|
{
|
|
$user = User::find(myself()->_getAccountId());
|
|
$info = array(
|
|
'account_id' => myself()->_getAccountId(), //账号id
|
|
'channel' => myself()->_getChannel(), //账号channel
|
|
'openid' => myself()->_getOpenId(), //账号openid
|
|
'adress' => myself()->_getAddress(), //账号openid
|
|
'name' => $user['name'], //用户名字
|
|
'rank' => $user['rank'], //段位
|
|
'gold' => $user['gold'], //金币
|
|
'diamond' => $user['diamond'], //钻石
|
|
'account_register_time' => myself()->_getRegisterTime(), //账号注册时间
|
|
'ip' => $_SERVER['REMOTE_ADDR'], //用户ip
|
|
'_os' => getReqVal('_os', ''),
|
|
'_net' => getReqVal('_net', ''),
|
|
);
|
|
return $info;
|
|
}
|
|
|
|
private static function userInfoByAccountId($account_id) {
|
|
$user = User::find($account_id);
|
|
$info = array(
|
|
'account_id' => $user['account_id'], //账号id
|
|
'channel' => $user['channel'], //账号channel
|
|
'openid' => 'unknown',
|
|
'adress' => $user['address'], //账号openid
|
|
'name' => $user['name'], //用户名字
|
|
'rank' => $user['rank'], //段位
|
|
'gold' => $user['gold'], //金币
|
|
'diamond' => $user['diamond'], //钻石
|
|
'account_register_time' => $user['createtime'], //账号注册时间
|
|
'ip' => $_SERVER['REMOTE_ADDR'], //用户ip
|
|
'_os' => getReqVal('_os', ''),
|
|
'_net' => getReqVal('_net', ''),
|
|
);
|
|
return $info;
|
|
}
|
|
private static function goldRecord($params = [])
|
|
{
|
|
if (isset($params['account_id']) && !empty($params['account_id'])) {
|
|
$account_id = $params['account_id'];
|
|
} else {
|
|
$account_id = myself()->_getAccountId();
|
|
}
|
|
$data = array(
|
|
"#account_id" => $account_id,
|
|
"#event_name"=> "gold_record",
|
|
"#ip"=> $_SERVER['REMOTE_ADDR'],
|
|
"#time"=> myself()->_getNowTime(),
|
|
"#type"=> "track",
|
|
"properties"=>''
|
|
);
|
|
return $data;
|
|
}
|
|
|
|
private static function ItemRecord(){
|
|
$data = [
|
|
"#account_id" => myself()->_getAccountId(),
|
|
"#event_name"=> "item_record",
|
|
"#ip"=> $_SERVER['REMOTE_ADDR'],
|
|
"#controller"=> getReqVal('c', ''),
|
|
"#artion"=> getReqVal('a', ''),
|
|
"#time"=> myself()->_getNowTime(),
|
|
"#type"=> "track",
|
|
"properties"=>''
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
}
|