zhaojs
2023-09-27 74098f1401afe40f961d1d167bb18dd0a71c4d59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
    {
        /// <summary>
        /// 授权送积分
        /// </summary>
        /// <param name="request"></param>
        public static void AuthPointTask(AuthPointTaskRequest request)
        {
            try
            {
                //获取设置信息
                var pointSet = CommonHandle.GetAuthPointSet();
                if (pointSet.IsNull())
                {
                    return;
                }
                //获取用户信息
                var token = CommonHandle.GetSetInfo();
                AuthSendPointDto rule = JSONUtil.JsonToObject<AuthSendPointDto>(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");
            }
        }
    }
}