|
|
@@ -1,9 +1,11 @@
|
|
|
package task
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
"go.uber.org/zap"
|
|
|
"gorm.io/gorm"
|
|
|
"log-server/global"
|
|
|
@@ -11,6 +13,7 @@ import (
|
|
|
"log-server/model/task/control"
|
|
|
"log-server/model/task/request"
|
|
|
"log-server/model/task/response"
|
|
|
+ "log-server/service/cache"
|
|
|
"log-server/utils"
|
|
|
"math"
|
|
|
"math/rand"
|
|
|
@@ -52,6 +55,8 @@ var (
|
|
|
)
|
|
|
|
|
|
type GameTask struct {
|
|
|
+ cache cache.Cache
|
|
|
+ common Common
|
|
|
}
|
|
|
|
|
|
// 创建游戏任务
|
|
|
@@ -341,6 +346,8 @@ func (c *GameTask) GetGameTaskById(id int) (gameTask request.GameTaskRequest, er
|
|
|
gameTask.PayTarget = requestData.PayTarget
|
|
|
gameTask.RetainedTarget = requestData.RetainedTarget
|
|
|
gameTask.PayPrice = requestData.PayPrice
|
|
|
+ gameTask.RetainedTargetH = requestData.RetainedTargetH
|
|
|
+ gameTask.NewTargetH = requestData.NewTargetH
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -504,19 +511,23 @@ func (s *GameTask) DeleteGameTask(api request.GameTaskRequest) (err error) {
|
|
|
//@description: 分页获取数据,
|
|
|
//@param: card card.Card, info request.PageInfo, order string, desc bool
|
|
|
//@return: list interface{}, total int64, err error
|
|
|
-func (apiService *GameTask) GetGameTaskTargetInfoList(api request.GameTargetCompleteRequest, info request.PageInfo, order string, desc bool, isTx bool) (list interface{}, total int64, err error) {
|
|
|
+func (apiService *GameTask) GetGameTaskTargetInfoList(api request.GameTargetCompleteRequest, info request.PageInfo, order string, desc bool, isTx bool) (apiList []response.GetGameTargetComplete, total int64, err error) {
|
|
|
limit := info.PageSize
|
|
|
offset := info.PageSize * (info.Page - 1)
|
|
|
- if api.CreateDate == "" {
|
|
|
- api.CreateDate = time.Now().Format("2006-01-02")
|
|
|
+ startDate := time.Now().Format("2006-01-02")
|
|
|
+ endDate := time.Now().Format("2006-01-02")
|
|
|
+ if len(api.Date) == 2 {
|
|
|
+ startDate = api.Date[0]
|
|
|
+ endDate = api.Date[1]
|
|
|
}
|
|
|
db := global.GVA_DB.Table("game_target_complete gtc")
|
|
|
- db = db.Select("gtc.id,gtc.task_id,gt.task_name,gtc.new_target,gt.login_method,gt.user,gtc.pay_target,gtc.retained_target," +
|
|
|
+ db = db.Select("gtc.id,gtc.task_id,gt.task_name,gt.game_id_xmy,gtc.new_target,gt.login_method,gt.user,gtc.pay_target,gtc.retained_target," +
|
|
|
"gtc.new_complete,gtc.pay_complete,gtc.retained_complete,gtc.create_date,gtc.amount,gtc.game_rate,gtc.is_complete,gtc.hand_new_complete," +
|
|
|
"gtc.hand_retained_complete,gtc.hand_pay_complete,gtc.hand_amount_total")
|
|
|
db = db.Joins("left join game_task gt on gt.task_id = gtc.task_id")
|
|
|
- db = db.Where("gtc.create_date = ?", api.CreateDate)
|
|
|
- var apiList []response.GetGameTargetComplete
|
|
|
+ //db = db.Where("gtc.create_date = ?", api.CreateDate)
|
|
|
+ db = db.Where("create_date >= ? and create_date <= ?", startDate, endDate)
|
|
|
+
|
|
|
if api.TaskName != "" {
|
|
|
db = db.Where("gt.task_name LIKE ?", "%"+api.TaskName+"%")
|
|
|
}
|
|
|
@@ -526,6 +537,9 @@ func (apiService *GameTask) GetGameTaskTargetInfoList(api request.GameTargetComp
|
|
|
if isTx {
|
|
|
db = db.Where("gt.game_port_id = ?", 1)
|
|
|
}
|
|
|
+ if api.GamePortId != 0 {
|
|
|
+ db = db.Where("gt.game_port_id = ?", api.GamePortId)
|
|
|
+ }
|
|
|
if api.TaskId != 0 {
|
|
|
db = db.Where("gtc.task_id = ?", api.TaskId)
|
|
|
}
|
|
|
@@ -567,10 +581,8 @@ func (apiService *GameTask) GetGameTaskTargetInfoList(api request.GameTargetComp
|
|
|
loginMethod, _ := strconv.Atoi(api.LoginMethod)
|
|
|
apiList[i].LoginMethod = LoginMethod[loginMethod]
|
|
|
apiList[i].CreateDate = date[0]
|
|
|
- apiList[i].RetainedComplete = api.RetainedComplete + api.HandRetainedComplete + api.HandNewComplete
|
|
|
- apiList[i].PayComplete = api.PayComplete + api.HandPayComplete
|
|
|
apiList[i].NewComplete = api.NewComplete + api.HandNewComplete
|
|
|
- apiList[i].Amount = api.Amount + api.HandAmountTotal
|
|
|
+ apiList[i].RetainedComplete = api.RetainedComplete + api.HandRetainedComplete
|
|
|
}
|
|
|
}
|
|
|
return apiList, total, err
|
|
|
@@ -672,6 +684,7 @@ func (s *GameTask) UpdateGameTaskTarget(requestData request.UpdateGameTaskTarget
|
|
|
"hand_pay_complete": requestData.HandPayComplete + gameTask.HandPayComplete,
|
|
|
"hand_amount_total": requestData.HandAmountTotal + gameTask.HandAmountTotal,
|
|
|
}
|
|
|
+ date := time.Now().Format("2006-01-02")
|
|
|
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
|
|
if requestData.IsFree == 1 {
|
|
|
handComplete := new(task.GameHandComplete)
|
|
|
@@ -727,7 +740,7 @@ func (s *GameTask) UpdateGameTaskTarget(requestData request.UpdateGameTaskTarget
|
|
|
}
|
|
|
if requestData.IsUploadXjf == 1 {
|
|
|
for i := 0; i < requestData.HandPayComplete; i++ {
|
|
|
- account := "hand_" + strconv.Itoa(i) + "_" + createDate
|
|
|
+ account := "hand_" + strconv.Itoa(i) + "_" + strconv.Itoa(int(time.Now().Unix()))
|
|
|
err = s.FreeUploadXjf(strconv.Itoa(taskData.TaskId), "付费充值", account, "付费成功", "")
|
|
|
if err != nil {
|
|
|
global.GVA_LOG.Error("上传xjf数据失败taskId = "+strconv.Itoa(taskData.TaskId)+"date = "+createDate, zap.Error(err))
|
|
|
@@ -745,6 +758,23 @@ func (s *GameTask) UpdateGameTaskTarget(requestData request.UpdateGameTaskTarget
|
|
|
}
|
|
|
return err
|
|
|
})
|
|
|
+ if gameTask.CreateDate.Format("2006-01-02") == date {
|
|
|
+ if gameTask.PayTarget < requestData.PayTarget {
|
|
|
+ global.GVA_LOG.Warn("进入修改add update")
|
|
|
+ lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, gameTask.TaskId)
|
|
|
+ _ = s.cache.SetCacheStr(context.Background(), lastPayAddUpdateTimeKey, time.Now().Unix())
|
|
|
+ msg := "# 测试监控报警 " + time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ msg += "\n"
|
|
|
+ msg += "**" + taskData.User + "**"
|
|
|
+ msg += "\n"
|
|
|
+ msg += taskData.TaskName + ", 付费目标改为" + strconv.Itoa(requestData.PayTarget)
|
|
|
+ url := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5ccfb180-c062-48b5-ae18-0c96f7c19f0b"
|
|
|
+ var sendData SendMsg
|
|
|
+ sendData.MsgType = "markdown"
|
|
|
+ sendData.Markdown.Content = msg
|
|
|
+ s.common.SendMsgData(url, sendData)
|
|
|
+ }
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -771,7 +801,7 @@ func (s *GameTask) TargetStatistics(date string) (apiList []control.TargetStatis
|
|
|
targetStatistics.TargetNew = target.NewTarget
|
|
|
targetStatistics.CompleteNew = target.NewComplete + target.HandNewComplete
|
|
|
targetStatistics.CompleteActive = target.RetainedComplete + target.HandRetainedComplete
|
|
|
- targetStatistics.CompletePay = target.PayComplete + target.HandPayComplete
|
|
|
+ targetStatistics.CompletePay = target.PayComplete
|
|
|
targetStatistics.XmyId = target.GameIdXmy
|
|
|
targetStatistics.QqId = target.TxGameId
|
|
|
targetStatistics.QqChannel = target.TxChannel
|
|
|
@@ -801,10 +831,10 @@ func (s *GameTask) DayStatisticsData(request request.GameTaskStatisticsRequest)
|
|
|
gameTargetDate.PayTarget = gameTarget.PayTarget
|
|
|
gameTargetDate.NewTarget = gameTarget.NewTarget
|
|
|
gameTargetDate.RetainedTarget = gameTarget.RetainedTarget
|
|
|
- gameTargetDate.PayComplete = gameTarget.PayComplete + gameTarget.HandPayComplete
|
|
|
- gameTargetDate.NewComplete = gameTarget.NewComplete + gameTarget.HandNewComplete
|
|
|
- gameTargetDate.RetainedComplete = gameTarget.RetainedComplete + gameTarget.HandRetainedComplete
|
|
|
- gameTargetDate.Amount = gameTarget.Amount + gameTarget.HandAmountTotal
|
|
|
+ gameTargetDate.PayComplete = gameTarget.PayComplete
|
|
|
+ gameTargetDate.NewComplete = gameTarget.NewComplete
|
|
|
+ gameTargetDate.RetainedComplete = gameTarget.RetainedComplete
|
|
|
+ gameTargetDate.Amount = gameTarget.Amount
|
|
|
gameTargetDate.GamePort = GamePort[gameTarget.GamePortId]
|
|
|
gameTargetDate.User = gameTarget.User
|
|
|
gameTargetDate.TaskDate = gameTarget.CreateDate.Format("2006-01-02")
|
|
|
@@ -910,3 +940,136 @@ func (s *GameTask) GameStatisticsList(rq request.GameListRequest) (gameTarget []
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//
|
|
|
+func (s *GameTask) ResetFeeUploadXjf(gameId int) (err error) {
|
|
|
+ url := global.GVA_CONFIG.ExtranetDomain.Control + "/v1/task_statistics/rerun_retained"
|
|
|
+ requestData := map[string]string{
|
|
|
+ "game_id": strconv.Itoa(gameId),
|
|
|
+ }
|
|
|
+ data, code, err := utils.HttpGetReplyCode(url, requestData)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Println(code)
|
|
|
+ if code != 200 {
|
|
|
+ return errors.New(string(data))
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//@function: TaskResetFee
|
|
|
+//@description: 重置付费
|
|
|
+//@param: api task.GameTask
|
|
|
+//@return: err error
|
|
|
+func (s *GameTask) TaskResetFee(api request.GameTaskRequest) (err error) {
|
|
|
+ var entity task.GameTask
|
|
|
+ err = global.GVA_DB.Where("task_id = ?", api.TaskId).First(&entity).Error
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = s.ResetFeeUploadXjf(api.TaskId)
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("请求群控数据报错: ", zap.Error(err))
|
|
|
+ return errors.New("请求群控数据报错")
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// http请求群控付费账号
|
|
|
+func (s *GameTask) GetFeeAccountControl(taskId int) (d []byte, err error) {
|
|
|
+ url := global.GVA_CONFIG.ExtranetDomain.Control + "/v1/device/get_log_by_game"
|
|
|
+ //url := "http://xjf.lianyou.fun:8099/v1/device/get_log_by_game"
|
|
|
+ params := map[string]string{
|
|
|
+ "date": time.Now().Format("2006-01-02"),
|
|
|
+ "action": "付费账号",
|
|
|
+ "action_result": "占位",
|
|
|
+ "game_id": strconv.Itoa(taskId),
|
|
|
+ }
|
|
|
+ d, code, err := utils.HttpGetReplyCode(url, params)
|
|
|
+ fmt.Println(code)
|
|
|
+ if code != 200 {
|
|
|
+ return nil, errors.New(string(d))
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type FeeAccount struct {
|
|
|
+ Account string `json:"account"`
|
|
|
+ Password string `json:"password"`
|
|
|
+}
|
|
|
+
|
|
|
+func (s *GameTask) GetFeeAccountList(taskId int) (fa []FeeAccount, err error) {
|
|
|
+ b, err := s.GetFeeAccountControl(taskId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal(b, &fa)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (exa *GameTask) TaskStatisticsList2Excel(infoList []response.GetGameTargetComplete, filePath string) error {
|
|
|
+ excel := excelize.NewFile()
|
|
|
+ excel.SetSheetRow("Sheet1", "A1", &[]string{
|
|
|
+ "日期",
|
|
|
+ "任务id",
|
|
|
+ "任务名称",
|
|
|
+ "登录方式",
|
|
|
+ "目标新增",
|
|
|
+ "目标付费",
|
|
|
+ "目标活跃",
|
|
|
+ "完成新增",
|
|
|
+ "完成付费",
|
|
|
+ "完成活跃",
|
|
|
+ "未完新增",
|
|
|
+ "未完付费",
|
|
|
+ "未完活跃",
|
|
|
+ "负责人",
|
|
|
+ "完成",
|
|
|
+ "手动付费",
|
|
|
+ "手动付费金额",
|
|
|
+ "付费流水"})
|
|
|
+ for i, statisticsLog := range infoList {
|
|
|
+ axis := fmt.Sprintf("A%d", i+2)
|
|
|
+ newNo := 0
|
|
|
+ retainedNo := 0
|
|
|
+ payNo := 0
|
|
|
+ isComplete := "是"
|
|
|
+ if statisticsLog.IsComplete == -1 {
|
|
|
+ isComplete = "否"
|
|
|
+ }
|
|
|
+ if statisticsLog.PayComplete < statisticsLog.PayTarget {
|
|
|
+ payNo = statisticsLog.PayTarget - statisticsLog.PayComplete
|
|
|
+ }
|
|
|
+ if statisticsLog.RetainedComplete+statisticsLog.HandRetainedComplete < statisticsLog.RetainedTarget {
|
|
|
+ retainedNo = statisticsLog.RetainedTarget - statisticsLog.RetainedComplete - statisticsLog.HandRetainedComplete
|
|
|
+ }
|
|
|
+ if statisticsLog.NewComplete+statisticsLog.HandNewComplete < statisticsLog.NewTarget {
|
|
|
+ newNo = statisticsLog.NewTarget - statisticsLog.NewComplete - statisticsLog.HandNewComplete
|
|
|
+ }
|
|
|
+ excel.SetSheetRow("Sheet1", axis, &[]interface{}{
|
|
|
+ statisticsLog.CreateDate[:10],
|
|
|
+ statisticsLog.TaskId,
|
|
|
+ statisticsLog.TaskName,
|
|
|
+ statisticsLog.LoginMethod,
|
|
|
+ statisticsLog.NewTarget,
|
|
|
+ statisticsLog.PayTarget,
|
|
|
+ statisticsLog.RetainedTarget,
|
|
|
+ statisticsLog.NewComplete + statisticsLog.NewComplete,
|
|
|
+ statisticsLog.PayComplete,
|
|
|
+ statisticsLog.RetainedComplete + statisticsLog.HandRetainedComplete,
|
|
|
+ newNo,
|
|
|
+ payNo,
|
|
|
+ retainedNo,
|
|
|
+ statisticsLog.User,
|
|
|
+ isComplete,
|
|
|
+ statisticsLog.HandPayComplete,
|
|
|
+ statisticsLog.HandAmountTotal,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ err := excel.SaveAs(filePath)
|
|
|
+ return err
|
|
|
+}
|