WH01243 4 vuotta sitten
vanhempi
commit
8949fca566

+ 74 - 0
api/activity.api

@@ -0,0 +1,74 @@
+syntax = "v1"
+
+type Request {
+	ActivityId    int64  `form:"activityId,optional"`    //活动标识
+	UserId        string `form:"userId"`                 //用户标识
+	AppId         string `form:"appId"`                  //身份标识
+	Page          int64  `form:"page,optional"`          //
+	PageSize      int64  `form:"pageSize,optional"`      //
+	Model         int64  `form:"model,optional"`         //1查看名下所有奖券 0查看可以使用的奖券(没有过期的) 2过期的奖券
+	UserName      string `form:"userName,optional"`      //用户名称
+	UserLottertId int64  `form:"userLottertId,optional"` //用户奖券标识
+}
+
+type LotteryOperation {
+	LotteryIdArr     []int64 `form:"lotteryIdArr,optional"`     //奖券标识集合
+	UserLotteryIdArr []int64 `form:"userLotteryIdArr,optional"` //用户奖券标识集合
+	UserId           string  `form:"userId"`                    //用户标识
+	AppId            string  `form:"appId"`                     //身份标识
+	UserName         string  `form:"userName,optional"`         //用户名称
+	OrderCode        string  `form:"orderCode,optional"`        //订单编号
+}
+
+type UpdateStateReq {
+	UserId        string `form:"userId"`             //用户标识
+	AppId         string `form:"appId"`              //身份标识
+	OrderCode     string `form:"orderCode,optional"` //订单编号
+	UserLotteryId int64  `form:"userLotteryId"`      //用户奖券标识
+	UserName      string `form:"userName,optional"`  //用户名称
+	Model         bool   `form:"model"`              //true待用false取消
+}
+type Response {
+	Code    int64  `form:"code"`    //响应代码
+	Message string `form:"message"` //响应消息
+}
+type ActivityLotteryResp {
+	Code    int64          `form:"code"`    //响应代码
+	Message string         `form:"message"` //响应消息
+	Data    []*LotteryJson `form:"data"`    //奖券信息
+	Count   int64          `form:"count"`   //数据条数
+}
+type LotteryJson {
+	LotteryId         int64  `form:"lotteryId"`         //奖券Id
+	LotteryName       string `form:"lotteryName"`       //奖券名字
+	ActivityName      string `form:"activityName"`      //活动名字
+	ActivityBeginDate string `form:"activityBeginDate"` //活动时间起
+	ActivityendDate   string `form:"activityendDate"`   //活动时间止
+	IsReceive         bool   `form:"isReceive"`         //是否领取
+	UseProductList    string `form:"useProductList"`    //使用商品列表
+	Full              int64  `form:"full"`              //满多少
+	Reduce            int64  `form:"reduce"`            //减多少
+	Instructions      string `form:"instructions"`      //使用说明
+	Remark            string `form:"remark"`            //备注
+	UserLotteryId     int64  `form:"userLotteryId"`     //用户奖券标识
+	UseDate           string `form:"useDate"`           //使用时间
+	CreateTime        string `form:"createTime"`        //创建时间
+}
+
+service activity-api {
+	//查询活动下的奖券
+	@handler activityLotteryCheckHandler // TODO: set handler name and delete this comment
+	get /activityLottery (Request) returns(ActivityLotteryResp)
+	//用户下的奖券
+	@handler userLotteryCheckHandler // TODO: set handler name and delete this comment
+	get /userLottery (Request) returns(ActivityLotteryResp)
+	//奖券领取
+	@handler lotteryReceiveCheckHandler // TODO: set handler name and delete this comment
+	post /lotteryReceive (LotteryOperation) returns(Response)
+	//修改奖券状态
+	@handler lotteryStateChangeCheckHandler // TODO: set handler name and delete this comment
+	post /lotteryStateChange (UpdateStateReq) returns(Response)
+	//奖券使用
+	@handler activityUseCheckHandler // TODO: set handler name and delete this comment
+	post /activityUse (LotteryOperation) returns(Response)
+}

+ 31 - 0
api/activity.go

@@ -0,0 +1,31 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/config"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/handler"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+
+	"github.com/tal-tech/go-zero/core/conf"
+	"github.com/tal-tech/go-zero/rest"
+)
+
+var configFile = flag.String("f", "etc/activity-api.yaml", "the config file")
+
+func main() {
+	flag.Parse()
+
+	var c config.Config
+	conf.MustLoad(*configFile, &c)
+
+	ctx := svc.NewServiceContext(c)
+	server := rest.MustNewServer(c.RestConf)
+	defer server.Stop()
+
+	handler.RegisterHandlers(server, ctx)
+
+	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
+	server.Start()
+}

+ 8 - 0
api/etc/activity-api.yaml

@@ -0,0 +1,8 @@
+Name: activity-api
+Host: 0.0.0.0
+Port: 8888
+Activity:
+  Etcd:
+    Hosts:
+      - 127.0.0.1:2379
+    Key: activity.rpc

+ 11 - 0
api/internal/config/config.go

@@ -0,0 +1,11 @@
+package config
+
+import (
+	"github.com/tal-tech/go-zero/rest"
+	"github.com/tal-tech/go-zero/zrpc"
+)
+
+type Config struct {
+	rest.RestConf
+	Activity zrpc.RpcClientConf
+}

+ 28 - 0
api/internal/handler/activitylotterycheckhandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/logic"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func activityLotteryCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.Request
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+		l := logic.NewActivityLotteryCheckLogic(r.Context(), ctx)
+		resp, err := l.ActivityLotteryCheck(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/activityusecheckhandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/logic"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func activityUseCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.LotteryOperation
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewActivityUseCheckLogic(r.Context(), ctx)
+		resp, err := l.ActivityUseCheck(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/lotteryreceivecheckhandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/logic"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func lotteryReceiveCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.LotteryOperation
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewLotteryReceiveCheckLogic(r.Context(), ctx)
+		resp, err := l.LotteryReceiveCheck(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/lotterystatechangecheckhandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/logic"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func lotteryStateChangeCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.UpdateStateReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewLotteryStateChangeCheckLogic(r.Context(), ctx)
+		resp, err := l.LotteryStateChangeCheck(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 42 - 0
api/internal/handler/routes.go

@@ -0,0 +1,42 @@
+// Code generated by goctl. DO NOT EDIT.
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+
+	"github.com/tal-tech/go-zero/rest"
+)
+
+func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
+	engine.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodGet,
+				Path:    "/activityLottery",
+				Handler: activityLotteryCheckHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodGet,
+				Path:    "/userLottery",
+				Handler: userLotteryCheckHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/lotteryReceive",
+				Handler: lotteryReceiveCheckHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/lotteryStateChange",
+				Handler: lotteryStateChangeCheckHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/activityUse",
+				Handler: activityUseCheckHandler(serverCtx),
+			},
+		},
+	)
+}

+ 29 - 0
api/internal/handler/userlotterycheckhandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/logic"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func userLotteryCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.Request
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewUserLotteryCheckLogic(r.Context(), ctx)
+		resp, err := l.UserLotteryCheck(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 52 - 0
api/internal/logic/activitylotterychecklogic.go

@@ -0,0 +1,52 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"context"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type ActivityLotteryCheckLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewActivityLotteryCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) ActivityLotteryCheckLogic {
+	return ActivityLotteryCheckLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *ActivityLotteryCheckLogic) ActivityLotteryCheck(req types.Request) (*types.ActivityLotteryResp, error) {
+	// todo: add your logic here and delete this line
+	result := &types.ActivityLotteryResp{}
+	lsi := l.svcCtx.Activity
+	resp,err := lsi.ActivityLottery(l.ctx,&activity.Request{
+		ActivityId:    req.ActivityId,
+		UserId:        req.UserId,
+		AppId:         req.AppId,
+	})
+	if err != nil {
+		return nil, err
+	}
+	var userLotteryList []*types.LotteryJson
+	for _, value := range resp.Data {
+		userLottery := types.LotteryJson{}
+		userLottery.LotteryId = value.LotteryId
+		userLottery.LotteryName=value.LotteryName
+		userLottery.IsReceive=value.IsReceive
+		userLottery.UseProductList = value.UseProductList
+		userLotteryList = append(userLotteryList, &userLottery)
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	result.Data=userLotteryList
+	return result, nil
+}

+ 43 - 0
api/internal/logic/activityusechecklogic.go

@@ -0,0 +1,43 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"context"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type ActivityUseCheckLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewActivityUseCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) ActivityUseCheckLogic {
+	return ActivityUseCheckLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *ActivityUseCheckLogic) ActivityUseCheck(req types.LotteryOperation) (*types.Response, error) {
+	result := &types.Response{}
+	lsi := l.svcCtx.Activity
+	resp,err := lsi.ActivityUse(l.ctx,&activity.LotteryOperation{
+		UserId:req.UserId,
+		AppId: req.AppId,
+		LotteryIdArr: req.UserLotteryIdArr,
+		UserName:req.UserName,
+		OrderCode:req.OrderCode,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 41 - 0
api/internal/logic/lotteryreceivechecklogic.go

@@ -0,0 +1,41 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"context"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type LotteryReceiveCheckLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewLotteryReceiveCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) LotteryReceiveCheckLogic {
+	return LotteryReceiveCheckLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *LotteryReceiveCheckLogic) LotteryReceiveCheck(req types.LotteryOperation) (*types.Response, error) {
+	result := &types.Response{}
+	lsi := l.svcCtx.Activity
+	resp,err := lsi.LotteryReceive(l.ctx,&activity.LotteryOperation{
+		UserId:req.UserId,
+		AppId: req.AppId,
+		LotteryIdArr: req.LotteryIdArr,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 44 - 0
api/internal/logic/lotterystatechangechecklogic.go

@@ -0,0 +1,44 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"context"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type LotteryStateChangeCheckLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewLotteryStateChangeCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) LotteryStateChangeCheckLogic {
+	return LotteryStateChangeCheckLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *LotteryStateChangeCheckLogic) LotteryStateChangeCheck(req types.UpdateStateReq) (*types.Response, error) {
+	result := &types.Response{}
+	lsi := l.svcCtx.Activity
+	resp,err := lsi.LotteryStateChange(l.ctx,&activity.UpdateStateReq{
+		UserId:req.UserId,
+		AppId: req.AppId,
+		UserLotteryId: req.UserLotteryId,
+		Model:req.Model,
+		OrderCode:req.OrderCode,
+		userName:req.UserName,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 60 - 0
api/internal/logic/userlotterychecklogic.go

@@ -0,0 +1,60 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"context"
+
+	"app.yhyue.com/moapp/jyMarketing/api/internal/svc"
+	"app.yhyue.com/moapp/jyMarketing/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type UserLotteryCheckLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUserLotteryCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) UserLotteryCheckLogic {
+	return UserLotteryCheckLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *UserLotteryCheckLogic) UserLotteryCheck(req types.Request) (*types.ActivityLotteryResp, error) {
+	// todo: add your logic here and delete this line
+	result := &types.ActivityLotteryResp{}
+	lsi := l.svcCtx.Activity
+	resp, err := lsi.UserLottery(l.ctx, &activity.Request{
+		UserId:        req.UserId,
+		AppId:         req.AppId,
+		Model:         req.Model,
+		UserLottertId: req.UserLottertId,
+	})
+	if err != nil {
+		return nil, err
+	}
+	var userLotteryList []*types.LotteryJson
+	for _, value := range resp.Data {
+		userLottery := types.LotteryJson{}
+		userLottery.Reduce = value.Reduce
+		userLottery.Full = value.Full
+		userLottery.LotteryId = value.LotteryId
+		userLottery.ActivityBeginDate = value.ActivityBeginDate
+		userLottery.ActivityendDate = value.ActivityendDate
+		userLottery.LotteryName = value.LotteryName
+		userLottery.UseProductList = value.UseProductList
+		userLottery.UserLotteryId = value.UserLotteryId
+		userLottery.UseDate = value.UseDate
+		userLottery.CreateTime = value.CreateTime
+		userLotteryList = append(userLotteryList, &userLottery)
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	result.Data = userLotteryList
+	result.Count=resp.Count
+	return result, nil
+}

+ 19 - 0
api/internal/svc/servicecontext.go

@@ -0,0 +1,19 @@
+package svc
+
+import (
+	"app.yhyue.com/moapp/jyMarketing/api/internal/config"
+	"app.yhyue.com/moapp/jyMarketing/rpc/activityclient"
+	"github.com/tal-tech/go-zero/zrpc"
+)
+
+type ServiceContext struct {
+	Config config.Config
+	Activity activityclient.Activity
+}
+
+func NewServiceContext(c config.Config) *ServiceContext {
+	return &ServiceContext{
+		Config: c,
+		Activity:activityclient.NewActivity(zrpc.MustNewClient(c.Activity)),
+	}
+}

+ 60 - 0
api/internal/types/types.go

@@ -0,0 +1,60 @@
+// Code generated by goctl. DO NOT EDIT.
+package types
+
+type Request struct {
+	ActivityId    int64  `form:"activityId,optional"`    //活动标识
+	UserId        string `form:"userId"`                 //用户标识
+	AppId         string `form:"appId"`                  //身份标识
+	Page          int64  `form:"page,optional"`          //
+	PageSize      int64  `form:"pageSize,optional"`      //
+	Model         int64  `form:"model,optional"`         //1查看名下所有奖券 0查看可以使用的奖券(没有过期的) 2过期的奖券
+	UserName      string `form:"userName,optional"`      //用户名称
+	UserLottertId int64  `form:"userLottertId,optional"` //用户奖券标识
+}
+
+type LotteryOperation struct {
+	LotteryIdArr     []int64 `form:"lotteryIdArr,optional"`     //奖券标识集合
+	UserLotteryIdArr []int64 `form:"userLotteryIdArr,optional"` //用户奖券标识集合
+	UserId           string  `form:"userId"`                    //用户标识
+	AppId            string  `form:"appId"`                     //身份标识
+	UserName         string  `form:"userName,optional"`         //用户名称
+	OrderCode        string  `form:"orderCode,optional"`        //订单编号
+}
+
+type UpdateStateReq struct {
+	UserId        string `form:"userId"`             //用户标识
+	AppId         string `form:"appId"`              //身份标识
+	OrderCode     string `form:"orderCode,optional"` //订单编号
+	UserLotteryId int64  `form:"userLotteryId"`      //用户奖券标识
+	UserName      string `form:"userName,optional"`  //用户名称
+	Model         bool   `form:"model"`              //true待用false取消
+}
+
+type Response struct {
+	Code    int64  `form:"code"`    //响应代码
+	Message string `form:"message"` //响应消息
+}
+
+type ActivityLotteryResp struct {
+	Code    int64          `form:"code"`    //响应代码
+	Message string         `form:"message"` //响应消息
+	Data    []*LotteryJson `form:"data"`    //奖券信息
+	Count   int64          `form:"count"`   //数据条数
+}
+
+type LotteryJson struct {
+	LotteryId         int64  `form:"lotteryId"`         //奖券Id
+	LotteryName       string `form:"lotteryName"`       //奖券名字
+	ActivityName      string `form:"activityName"`      //活动名字
+	ActivityBeginDate string `form:"activityBeginDate"` //活动时间起
+	ActivityendDate   string `form:"activityendDate"`   //活动时间止
+	IsReceive         bool   `form:"isReceive"`         //是否领取
+	UseProductList    string `form:"useProductList"`    //使用商品列表
+	Full              int64  `form:"full"`              //满多少
+	Reduce            int64  `form:"reduce"`            //减多少
+	Instructions      string `form:"instructions"`      //使用说明
+	Remark            string `form:"remark"`            //备注
+	UserLotteryId     int64  `form:"userLotteryId"`     //用户奖券标识
+	UseDate           string `form:"useDate"`           //使用时间
+	CreateTime        string `form:"createTime"`        //创建时间
+}

+ 1 - 0
rpc/activity.proto

@@ -25,6 +25,7 @@ message UpdateStateReq{
    string orderCode=3;//订单编号
    int64  userLotteryId=4;//用户奖券标识
    bool   model=5;//true待用false取消
+   string userName=6;//用户名称
 }
 
 message Response {

+ 0 - 1
rpc/etc/activity.yaml

@@ -20,7 +20,6 @@ FileSystemConf:
     Hosts:
       - 127.0.0.1:2379
     Key: activity.rpc
-
 CalleeId: activity.rpc
 Node: 1
 TimeSource: 0 1 0 * * ? *

+ 1 - 3
rpc/internal/logic/userlotterylogic.go

@@ -32,12 +32,10 @@ func (l *UserLotteryLogic) UserLottery(in *activity.Request) (*activity.Activity
 	var userLotteryList []*activity.LotteryJson
 	for _, value := range data {
 		userLottery := activity.LotteryJson{}
-		userLottery.Reduce = value.Reduce
 		userLottery.Full = value.Full
-		userLottery.LotteryId = value.LotteryId
 		userLottery.ActivityBeginDate = value.BeginDate
 		userLottery.ActivityendDate = value.EndDate
-		userLottery.ActivityName = value.Name
+		userLottery.LotteryName = value.Name
 		userLottery.UseProductList = value.UseProductList
 		userLottery.UserLotteryId=value.Id
 		userLottery.UseDate=value.UseDate.Format("2006-01-02 15:04:05")

+ 21 - 14
service/ActivityService.go

@@ -163,22 +163,12 @@ func (service *ActivityService) ActivityUse(data *activity.LotteryOperation) (in
 		//3、奖券状态改为已使用
 		userLottery.UseDate = time.Now().Local()
 		userLottery.PrizeType = 1
-		userLottery.OrderCode = data.OrderCode
-		numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "useDate", "orderCode").Update(userLottery)
+		numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "useDate").Update(userLottery)
 		if err != nil || numb == 0 {
 			log.Println("修改用户奖券失败:", err)
 			orm.Rollback()
 			return entity.ErrorCode, "修改用户奖券失败"
 		}
-		//4、修改卷的使用量
-		lottery := entity.Lottery{}
-		lottery.Id = lotteryId
-		_, err = orm.Exec("UPDATE lottery SET `useNumber` = useNumber+1 WHERE `id` = ?", lotteryId)
-		if err != nil || numb == 0 {
-			log.Println("修改奖券使用数量失败:", err)
-			orm.Rollback()
-			return entity.ErrorCode, "修改奖券使用数量失败"
-		}
 	}
 	orm.Commit()
 	return entity.SuccessCode, "使用奖券成功"
@@ -342,12 +332,21 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
 			//奖券状态改为待使用
 			userLottery.PrizeType = 3
 			userLottery.OrderCode = data.OrderCode
-			numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "OrderCode").Update(userLottery)
+			//userLottery.UserName=data.UserName
+			userLottery.UseDate=time.Now().Local()
+			numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "orderCode","userName","useDate").Update(userLottery)
 			if err != nil || numb == 0 {
 				log.Println("修改用户奖券失败:", err)
 				orm.Rollback()
 				return entity.ErrorCode, "修改用户奖券失败"
 			}
+			//修改卷的使用量
+			_, err = orm.Exec("UPDATE lottery SET `useNumber` = useNumber+1 WHERE `id` = ?", userLottery.LotteryId)
+			if err != nil || numb == 0 {
+				log.Println("修改奖券使用数量失败:", err)
+				orm.Rollback()
+				return entity.ErrorCode, "修改奖券使用数量失败"
+			}
 			orm.Commit()
 			return entity.SuccessCode, "修改用户奖券成功"
 		} else if userLottery.PrizeType == 3 {
@@ -356,15 +355,23 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
 		return entity.ErrorCode, "该奖券状态不可修改"
 	} else {
 		if (userLottery.PrizeType == 3) {
-			//奖券状态改为使用
+			//奖券状态改为使用
 			userLottery.PrizeType = 0
 			userLottery.OrderCode = ""
-			numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "orderCode").Update(userLottery)
+			userLottery.UserName=""
+			numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "orderCode","userName").Update(userLottery)
 			if err != nil || numb == 0 {
 				log.Println("修改用户奖券失败:", err)
 				orm.Rollback()
 				return entity.ErrorCode, "修改用户奖券失败"
 			}
+			//修改卷的使用量
+			_, err = orm.Exec("UPDATE lottery SET `useNumber` = useNumber-1 WHERE `id` = ?", userLottery.LotteryId)
+			if err != nil || numb == 0 {
+				log.Println("修改奖券使用数量失败:", err)
+				orm.Rollback()
+				return entity.ErrorCode, "修改奖券使用数量失败"
+			}
 			orm.Commit()
 			return entity.SuccessCode, "修改用户奖券成功"
 		} else if (userLottery.PrizeType == 2) {