备份CatanBuilding瘦身独立工程
This commit is contained in:
232
Assets/Scripts/Services/SurveyService.cs
Normal file
232
Assets/Scripts/Services/SurveyService.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using asap.core;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
public class SurveyService
|
||||
{
|
||||
const string SurveyUrl = "https://pt93-tyqnr.qijihdhk.com/";
|
||||
const string SurveyData = "SurveyData";
|
||||
const string SurveyReadSidData = "SurveyReadSidData";
|
||||
|
||||
ICustomServerMgr customServerMgr;
|
||||
IUserService userService;
|
||||
cfg.Tables tables;
|
||||
MatchlistData matchlistData { get; set; }
|
||||
List<string> receivedReward = new List<string>();
|
||||
List<string> readSid = new List<string>();
|
||||
public SurveyService(ICustomServerMgr customServerMgr, IUserService userService, cfg.Tables tables)
|
||||
{
|
||||
this.customServerMgr = customServerMgr;
|
||||
this.userService = userService;
|
||||
this.tables = tables;
|
||||
string surveyData = PlayFabMgr.Instance.GetLocalData(SurveyData);
|
||||
if (!string.IsNullOrEmpty(surveyData))
|
||||
{
|
||||
receivedReward = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(surveyData);
|
||||
}
|
||||
string surveyReadSidData = PlayFabMgr.Instance.GetLocalData(SurveyReadSidData);
|
||||
if (!string.IsNullOrEmpty(surveyReadSidData))
|
||||
{
|
||||
readSid = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(surveyReadSidData);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 拉取问卷
|
||||
/// </summary>
|
||||
public async void PostSurveyMatchlist()
|
||||
{
|
||||
try
|
||||
{
|
||||
PlayerData playerData = GContext.container.Resolve<PlayerData>();
|
||||
if (playerData.lv < tables.TbGlobalConfig.SurveyLevelRequire)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int register_days = (ZZTimeHelper.UtcNow() - userService.CreateTime).Days;
|
||||
float totalPay = GContext.container.Resolve<PlayerShopData>().GetBuyPaymentAmount();
|
||||
|
||||
PostMatchlist post = new PostMatchlist
|
||||
{
|
||||
uid = userService.CustomId,//"318904",//
|
||||
register_days = register_days,
|
||||
language = userService.Language,
|
||||
totalPay = totalPay,
|
||||
level = playerData.lv,
|
||||
vip = playerData.vip
|
||||
};
|
||||
matchlistData = null;
|
||||
string boby = Newtonsoft.Json.JsonConvert.SerializeObject(post);
|
||||
string url = $"{SurveyUrl}api/dwsurvey/anon/response/matchList.do?appId=17&platformName=ft";
|
||||
string json = await customServerMgr.CustomServerPost(url, boby);
|
||||
if (!string.IsNullOrEmpty(json) && json != "[]")
|
||||
{
|
||||
matchlistData = Newtonsoft.Json.JsonConvert.DeserializeObject<MatchlistData>(json);
|
||||
}
|
||||
//设置红点
|
||||
SetRedPoint();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("PostSurveyMatchlist:" + e);
|
||||
}
|
||||
|
||||
}
|
||||
public string Sid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (matchlistData != null && matchlistData.resultCode == 200 && matchlistData.data.Length > 0)
|
||||
{
|
||||
return matchlistData.data[0].sid;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public int Award
|
||||
{
|
||||
get
|
||||
{
|
||||
if (matchlistData != null && matchlistData.resultCode == 200 && matchlistData.data.Length > 0)
|
||||
{
|
||||
string award = matchlistData.data[0].award;
|
||||
if (int.TryParse(award, out int result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
void SetRedPoint()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Sid) || readSid.Contains(Sid))
|
||||
{
|
||||
RedPointManager.Instance.SetRedPointState("menu.survey", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
RedPointManager.Instance.SetRedPointState("menu.survey", true);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 请求答题的链接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetSurveyAnswer()
|
||||
{
|
||||
string url = $"{SurveyUrl}static/diaowen/answer-p.html?";
|
||||
string register_days = (ZZTimeHelper.UtcNow() - userService.CreateTime).Days.ToString();
|
||||
string totalPay = GContext.container.Resolve<PlayerShopData>().GetBuyPaymentAmount().ToString();
|
||||
PlayerData playerData = GContext.container.Resolve<PlayerData>();
|
||||
url += $"sid={Sid}" +
|
||||
"&platform=ft" +
|
||||
$"&uid={userService.CustomId}" +
|
||||
$"&language={userService.Language}" +
|
||||
$"®ister_days={register_days}" +
|
||||
$"&extraInfo={playerData.lv}" +
|
||||
$"&totalPay={totalPay}";
|
||||
//标记已读
|
||||
readSid.Add(Sid);
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(SurveyReadSidData, Newtonsoft.Json.JsonConvert.SerializeObject(readSid));
|
||||
//设置红点
|
||||
SetRedPoint();
|
||||
return url;
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查是否能领奖
|
||||
/// </summary>
|
||||
public async void GetSurveyCheckAnswer()
|
||||
{
|
||||
try
|
||||
{
|
||||
string sid = Sid;
|
||||
string url = $"{SurveyUrl}api/dwsurvey/anon/response/checkAnswer.do?";
|
||||
url += $"uid={userService.CustomId}&surveySid={sid}&appId=17&platformName=ft";
|
||||
|
||||
//#if UNITY_EDITOR
|
||||
// //测试
|
||||
// url = "https://pt93-tyqnr.qijihdhk.com/api/dwsurvey/anon/response/checkAnswer.do?surveySid=8zij9i5&uid=1&platformName=ft&appId=17";
|
||||
//#endif
|
||||
matchlistData = null;
|
||||
|
||||
string json = await customServerMgr.GetStringAsync(url);
|
||||
if (receivedReward.Contains(sid))
|
||||
{
|
||||
//Debug.Log("已经领过奖:" + json);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(json) && json != "[]")
|
||||
{
|
||||
SurveyCheckAnswerResult data = Newtonsoft.Json.JsonConvert.DeserializeObject<SurveyCheckAnswerResult>(json);
|
||||
if (data.resultCode == 200 && data.data != null)
|
||||
{
|
||||
SurveyCheckAnswerData surveyCheckAnswerData = Newtonsoft.Json.JsonConvert.DeserializeObject<SurveyCheckAnswerData>(data.data);
|
||||
var SurveyReward = tables.TbGlobalConfig.SurveyReward;
|
||||
string awardStr = surveyCheckAnswerData.award;
|
||||
if (int.TryParse(awardStr, out int award))
|
||||
{
|
||||
if (!SurveyReward.Contains(award))
|
||||
{
|
||||
Debug.LogError("问卷奖励错误: " + awardStr);
|
||||
award = SurveyReward[0];
|
||||
}
|
||||
GContext.container.Resolve<PlayerItemData>().AddItemByDrop(award);
|
||||
GContext.Publish(new ShowData());
|
||||
receivedReward.Add(sid);
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(SurveyData, Newtonsoft.Json.JsonConvert.SerializeObject(receivedReward));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("问卷奖励错误: " + awardStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("GetSurveyCheckAnswer:" + e);
|
||||
}
|
||||
|
||||
}
|
||||
class PostMatchlist
|
||||
{
|
||||
public string uid { get; set; }
|
||||
public int register_days { get; set; }
|
||||
public string language { get; set; }
|
||||
public float totalPay { get; set; }
|
||||
public int level { get; set; }
|
||||
public int vip { get; set; }
|
||||
}
|
||||
}
|
||||
public class MatchlistData
|
||||
{
|
||||
public int resultCode { get; set; }
|
||||
public string resultMsg { get; set; }
|
||||
public MatchlistDataInfo[] data { get; set; }
|
||||
}
|
||||
public class MatchlistDataInfo
|
||||
{
|
||||
public string award { get; set; }
|
||||
public string defaultLanguage { get; set; }
|
||||
public string[] languages { get; set; }
|
||||
public string surveyNameText { get; set; }
|
||||
public string id { get; set; }
|
||||
public string creatDate { get; set; }
|
||||
public string sid { get; set; }
|
||||
public string title { get; set; }
|
||||
public string introduce { get; set; }
|
||||
}
|
||||
|
||||
public class SurveyCheckAnswerResult
|
||||
{
|
||||
public int resultCode { get; set; }
|
||||
public string resultMsg { get; set; }
|
||||
public string data { get; set; }
|
||||
}
|
||||
public class SurveyCheckAnswerData
|
||||
{
|
||||
public string award { get; set; }
|
||||
public string extraInfo { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user