using Operater.DTO.TopMessage;
using CommonUtil;
using System;
using System.Collections.Generic;
using System.Text;
using Operater.DAL;
using Operater.DbModel;
using Operater.DTO.System;
using YouZanSDKStandard.Api.Request;
using YouZanSDKStandard.Api.Domain;
using YouZanSDKStandard.Api;
namespace TradeInterflow.Handle
{
public class PointTaskHandle
{
///
/// 授权送积分
///
///
public static void AuthPointTask(AuthPointTaskRequest request)
{
try
{
//获取设置信息
var pointSet = CommonHandle.GetAuthPointSet();
if (pointSet.IsNull())
{
return;
}
//获取用户信息
var token = CommonHandle.GetSetInfo();
AuthSendPointDto rule = JSONUtil.JsonToObject(pointSet.PointTaskSet.TaskRule);
string id = Guid.NewGuid().ToString();
PointSendHistory pointSendHistory = new PointSendHistory()
{
Id = id,
TaskType = pointSet.PointTaskSet.TaskType,
TaskId = pointSet.PointTaskSet.Id,
YzOpenId = request.YzOpenId,
Mobile = request.Mobile,
SendTime = DateTime.Now
};
//查询是否送过积分
var isExit = new PointSendHistoryDAL().IsExist(t => t.YzOpenId == request.YzOpenId && t.IsSend == 1);
if (isExit)
{//送过了
pointSendHistory.IsSend = 0;
pointSendHistory.Memo = "已经送过积分";
}
else
{//赠送积分
Random ran = new Random();
int n = ran.Next(rule.MinPoint, rule.MaxPoint);
//有赞赠送积分
YouZanPointIncreaseUser paraUser = new YouZanPointIncreaseUser()
{
account_type = 5,
account_id = request.YzOpenId
};
pointSendHistory.SendPoint = n;
YouZanPointIncreaseDomain para = new YouZanPointIncreaseDomain()
{
reason = "授权送积分",
biz_value = id,
points = n,
user = paraUser
};
YouZanPointIncreaseRequest yzReq = new YouZanPointIncreaseRequest()
{
paramsData = para
};
var yzRsp = YouZanClient.Execute(yzReq, token.yzToken);
if (yzRsp.IsNull() || !yzRsp.success || !yzRsp.data.is_success)
{//接口调用失败
pointSendHistory.IsSend = 0;
pointSendHistory.Memo = $"有赞接口调用失败:{yzRsp.message}";
LogUtil.Info($"有赞接口错误,request:{JSONUtil.ObjectToJson(yzReq)}--返回:{JSONUtil.ObjectToJson(yzRsp)}", "授权送积分error");
}
else
{
pointSendHistory.IsSend = 1;
}
}
new PointSendHistoryDAL().Insert(pointSendHistory);
}
catch (Exception e)
{
LogUtil.Info($"request:{JSONUtil.ObjectToJson(request)}--错误:" + e.ToString(), "授权送积分error");
}
}
}
}