145 lines
4.6 KiB
C#
145 lines
4.6 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
public class SurveyService
|
|
{
|
|
//#if UNITY_EDITOR
|
|
// const string SurveyUrl = "https://open.wj.qq.com/";
|
|
// const string appid = "tpid2UhhJL1E";
|
|
// const string secret = "XZBD4NF2hxzR2SwOHEqnTgnD0tfS4bSo";
|
|
//#else
|
|
const string SurveyUrl = "https://wesurvey.com/";
|
|
// const string appid = "tpid2RhYNpeZ";
|
|
// const string secret = "fmW4oSrd31bXrcSfg1mpgBv3BScn4qvT";
|
|
//#endif
|
|
const string SurveyData = "SurveyData";
|
|
const string SurveyReadSidData = "SurveyReadSidData";
|
|
|
|
IUserService userService;
|
|
cfg.Tables tables;
|
|
List<string> receivedReward = new List<string>();
|
|
List<string> readSid = new List<string>();
|
|
string access_token;
|
|
public SurveyData tableData;
|
|
public SurveyService(IUserService userService, cfg.Tables tables)
|
|
{
|
|
this.userService = userService;
|
|
this.tables = tables;
|
|
tableData = null;
|
|
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 void GetSurveyMatchlist()
|
|
{
|
|
try
|
|
{
|
|
PlayerData playerData = GContext.container.Resolve<PlayerData>();
|
|
|
|
List<SurveyData> surveyDataTable = tables.TbSurveyData.DataList;
|
|
ulong userId = Convert.ToUInt64(userService.UserId, 16);
|
|
tableData = null;
|
|
if (surveyDataTable.Count > 0)
|
|
{
|
|
for (int i = 0; i < surveyDataTable.Count; i++)
|
|
{
|
|
if (!receivedReward.Contains(surveyDataTable[i].ID.ToString()))
|
|
{
|
|
if (surveyDataTable[i].LevelCondition >= playerData.lv)
|
|
{
|
|
continue;
|
|
}
|
|
int tailNumber = (int)(userId % 10);
|
|
if (!surveyDataTable[i].TailNumberList.Contains(tailNumber))
|
|
{
|
|
continue;
|
|
}
|
|
tableData = surveyDataTable[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
////设置红点
|
|
SetRedPoint();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError("GetSurveyMatchlist:" + e);
|
|
}
|
|
|
|
}
|
|
|
|
void SetRedPoint()
|
|
{
|
|
if (tableData == null)
|
|
{
|
|
RedPointManager.Instance.SetRedPointState("menu.survey", false);
|
|
}
|
|
else
|
|
{
|
|
RedPointManager.Instance.SetRedPointState("menu.survey", true);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 请求答题的链接
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetSurveyAnswer()
|
|
{
|
|
if (tableData == null)
|
|
{
|
|
return "";
|
|
}
|
|
string url = $"{SurveyUrl}s2/{tableData.ID}/{tableData.Hash}/?&uid={userService.CustomId}";
|
|
//标记已读
|
|
readSid.Add(tableData.ID.ToString());
|
|
PlayFabMgr.Instance.UpdateUserDataValue(SurveyReadSidData, Newtonsoft.Json.JsonConvert.SerializeObject(readSid));
|
|
GetSurveyMatchlist();
|
|
return url;
|
|
}
|
|
/// <summary>
|
|
/// 检查是否能领奖
|
|
/// </summary>
|
|
public void GetSurveyCheckAnswer()
|
|
{
|
|
try
|
|
{
|
|
if (tableData == null)
|
|
{
|
|
return;
|
|
}
|
|
string sid = tableData.ID.ToString();
|
|
if (receivedReward.Contains(sid))
|
|
{
|
|
//Debug.Log("已经领过奖:" + json);
|
|
return;
|
|
}
|
|
GContext.container.Resolve<PlayerItemData>().AddItemByDrop(tableData.Reward, null);
|
|
GContext.Publish(new ShowData());
|
|
receivedReward.Add(sid);
|
|
PlayFabMgr.Instance.UpdateUserDataValue(SurveyData, Newtonsoft.Json.JsonConvert.SerializeObject(receivedReward));
|
|
GetSurveyMatchlist();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError("GetSurveyCheckAnswer:" + e);
|
|
}
|
|
|
|
}
|
|
} |