WH01243 4 years ago
parent
commit
6e10365084

+ 20 - 16
api/activity.api

@@ -41,22 +41,24 @@ type ActivityLotteryResp {
 	Activity ActivityJson   `form:"Activity"` //活动信息
 }
 type LotteryJson {
-	LotteryId        int64         `form:"lotteryId"`        //奖券Id
-	LotteryName      string        `form:"lotteryName"`      //奖券名字
-	LotteryBeginDate string        `form:"lotteryBeginDate"` //活动时间起
-	LotteryendDate   string        `form:"lotteryendDate"`   //活动时间止
-	IsReceive        bool          `form:"isReceive"`        //是否领取
-	UseProductList   []ProductJson `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"`          //使用时间
-	StockNumber      int64         `form:"stockNumber"`      //库存数
-	ReceiveNumber    int64         `form:"receiveNumber"`    //领取数
-	ValidityDates    int64         `form:"validityDates"`    //有效天数
-	ValidityTimeType int64         `form:"validityTimeType"` //有效时间类型0、有起止时间1、当天起几天可用2、次日起几天可用
+	LotteryId        int64         `form:"lotteryId"`                                         //奖券Id
+	LotteryName      string        `form:"lotteryName"`                                       //奖券名字
+	LotteryBeginDate string        `form:"lotteryBeginDate"`                                  //活动时间起
+	LotteryendDate   string        `form:"lotteryendDate"`                                    //活动时间止
+	IsReceive        bool          `form:"isReceive"`                                         //是否领取
+	UseProductList   []ProductJson `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"`                                           //使用时间
+	StockNumber      int64         `form:"stockNumber"`                                       //库存数
+	ReceiveNumber    int64         `form:"receiveNumber"`                                     //领取数
+	ValidityDates    int64         `form:"validityDates"`                                     //有效天数
+	ValidityTimeType int64         `form:"validityTimeType"`                                  //有效时间类型0、有起止时间1、当天起几天可用2、次日起几天可用
+	PrizeType        int64         `xorm:"prizeType" form:"prizeType" json:"prizeType"`       //0未使用1已使用2已过期3待使用
+	LotteryType      int64         `xorm:"lotteryType" form:"lotteryType" json:"lotteryType"` //0、满减1折扣券2、实物
 }
 type ActivityJson {
 	ActivityName      string `form:"activityName"`      //活动名字
@@ -70,6 +72,8 @@ type ProductJson {
 	WxPage      string `xorm:"wxPage" form:"wxPage" json:"wxPage"`                //wx端产品推广页地址
 	AppPage     string `xorm:"appPage" form:"appPage" json:"appPage"`             //app端产品推广页地址
 	Describe    string `xorm:"describe" form:"describe" json:"describe"`          //描述
+	ProductCode int64  `xorm:"productCode" form:"productCode" json:"productCode"` //产品编号
+	ParentCode  int64  `xorm:"parentCode" form:"parentCode" json:"parentCode"`
 }
 
 type LotteryResp {

+ 0 - 1
api/activity.go

@@ -23,7 +23,6 @@ func main() {
 	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)

+ 1 - 1
api/internal/types/types.go

@@ -74,11 +74,11 @@ type ActivityJson struct {
 
 type ProductJson struct {
 	ProductName string `xorm:"productName" form:"productName" json:"productName"` //产品名称
-	ProductCode int64  `xorm:"productCode" form:"productCode" json:"productCode"` //产品编号
 	PcPage      string `xorm:"pcPage" form:"pcPage" json:"pcPage"`                //pc端产品推广页地址
 	WxPage      string `xorm:"wxPage" form:"wxPage" json:"wxPage"`                //wx端产品推广页地址
 	AppPage     string `xorm:"appPage" form:"appPage" json:"appPage"`             //app端产品推广页地址
 	Describe    string `xorm:"describe" form:"describe" json:"describe"`          //描述
+	ProductCode int64  `xorm:"productCode" form:"productCode" json:"productCode"` //产品编号
 	ParentCode  int64  `xorm:"parentCode" form:"parentCode" json:"parentCode"`
 }
 

+ 22 - 2
entity/activity.go

@@ -13,6 +13,17 @@ const (
 	SuccessCode int64 = 1
 	ErrorCode   int64 = 0
 )
+const (
+	Error_code      = 0
+	Error_code_1001 = 1001
+	Error_msg_1001  = "需要登录"
+	Error_code_1002 = 1002
+	Error_msg_1002  = "缺失参数"
+	Error_code_1003 = 1003
+	Error_msg_1003  = "无效参数"
+	Error_code_1004 = 1004
+	Error_msg_1004  = "没有权限"
+)
 
 //奖品信息
 type PrizeJson struct {
@@ -51,7 +62,8 @@ type LotteryJson struct {
 	ValidityDates    int           `xorm:"validityDates" form:"validityDates" json:"validityDates"`          //有效天数
 	ValidityTimeType int           `xorm:"validityTimeType" form:"validityTimeType" json:"validityTimeType"` //有效时间类型0、有起止时间1、当天起几天可用2、次日起几天可用
 	Name             string        `xorm:"name" form:"name" json:"name"`                                     //奖券名字
-	Count            int64         `xorm:"count" form:"count" json:"reduce"`                                 //领取次数
+	Count            int64         `xorm:"count" form:"count" json:"count"`                                  //领取次数
+	DayCount         int64         `xorm:"dayCount" form:"dayCount" json:"dayCount"`                         //领取次数
 	UseProductList   []ProductJson `xorm:"useProductList" form:"useProductList" json:"useProductList"`       //使用商品列表
 	StockNumber      int64         `xorm:"stockNumber" form:"stockNumber" json:"stockNumber"`                //库存
 	ReceiveNumber    int64         `xorm:"receiveNumber" form:"receiveNumber" json:"receiveNumber"`          //领取数量
@@ -90,7 +102,7 @@ type UserPrizeJson struct {
 	EndDate        string        `xorm:"endDate" form:"endDate" json:"endDate"`                      //有效期止
 	UseDate        time.Time     `xorm:"useDate" form:"useDate" json:"useDate"`                      //使用时间
 	CreateTime     time.Time     `xorm:"createTime" form:"createTime" json:"createTime"`             //创建时间
-	PrizeType      int64           `xorm:"prizeType" form:"prizeType" json:"prizeType"`                //0未使用1已使用2已过期
+	PrizeType      int64         `xorm:"prizeType" form:"prizeType" json:"prizeType"`                //0未使用1已使用2已过期
 	LotteryId      int64         `xorm:"lotteryId" form:"lotteryId" json:"lotteryId"`                //奖券标识
 	Name           string        `xorm:"name" form:"name" json:"name"`                               //奖券名字
 	Full           int64         `xorm:"full" form:"full" json:"full"`                               //满多少
@@ -125,3 +137,11 @@ type ProductJson struct {
 	ProductCode int64  `xorm:"productCode" form:"productCode" json:"productCode"` //产品编号
 	ParentCode  int64  `xorm:"parentCode" form:"parentCode" json:"parentCode"`
 }
+
+//接口统一返回值
+type Result struct {
+	Error_code int         `json:"error_code"`
+	Error_msg  string      `json:"error_msg"`
+	Data       interface{} `json:"data"`
+}
+

+ 43 - 5
rpc/activity.go

@@ -12,8 +12,10 @@ import (
 	"encoding/json"
 	"flag"
 	"fmt"
+	_ "github.com/gin-contrib/sessions"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/go-xorm/xorm"
+
 	"github.com/robfig/cron"
 	"github.com/tal-tech/go-zero/core/conf"
 	"github.com/tal-tech/go-zero/zrpc"
@@ -67,17 +69,53 @@ func init() {
 func rateLimitInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
 	fmt.Println("拦截器")
 	log.Println("方法名:",info.FullMethod,"  参数:",req)
-	resp, err = handler(ctx, req)
-	fmt.Println("返回值",resp,err)
-	orm := entity.Engine.NewSession()
-	/*	reqData := req.(map[string]interface{})
-		appId:=reqData["AppId"]*/
+
 	var dat map[string]interface{}
 	jsonStr := Strval(req)
 	if err := json.Unmarshal([]byte(jsonStr), &dat); err == nil {
 		fmt.Println(dat)
 	}
 	appId:=dat["appId"]
+
+	/*session := App.SessionManager.Session(req, w)
+	session := l.App.SessionManager.Session(req, w)
+	id := string(session.Id())*/
+	//验证是否为剑鱼用户、是否登录
+	/*fool, _ := util.Exists("other", id)
+	if fool {
+		res := util.Get("other", id)
+		data := res.(map[string]interface{})
+		if _, ok := data["userId"]; ok {
+			// 存在
+			log.Println("存在")
+				}else{
+			return &entity.Result{entity.Error_code_1001, entity.Error_msg_1001, nil} ,err
+		}
+	}else{
+		return &entity.Result{entity.Error_code_1001, entity.Error_msg_1001, nil} ,err
+
+	}*/
+	/*userId:=dat["userId"]
+	fool, _ := util.Exists("other", fmt.Sprint(userId))
+	if fool {
+		res := util.Get("other", fmt.Sprint(userId))
+		data := res.(map[string]interface{})
+		if _, ok := data["userId"]; ok {
+			// 存在
+			log.Println("存在")
+
+		}else{
+			return &entity.Result{entity.Error_code_1001, entity.Error_msg_1001, nil} ,err
+		}
+	}else{
+		return &entity.Result{entity.Error_code_1001, entity.Error_msg_1001, nil} ,err
+	}*/
+	resp, err = handler(ctx, req)
+	fmt.Println("返回值",resp,err)
+	orm := entity.Engine.NewSession()
+	/*	reqData := req.(map[string]interface{})
+		appId:=reqData["AppId"]*/
+
 	eqspStr := Strval(resp)
 	if(len(eqspStr)>300){
 		eqspStr=eqspStr[0:300]

+ 7 - 3
rpc/internal/logic/activitylotterylogic.go

@@ -32,10 +32,14 @@ func (l *ActivityLotteryLogic) ActivityLottery(in *activity.Request) (*activity.
 		userLottery.LotteryId = value.LotteryId
 		userLottery.LotteryName=value.Name
 		userLottery.IsReceive=true
-		if (value.IsLimitNumber==1){
-			if value.Count>=int64(value.LimitNumber){
-				userLottery.IsReceive=false
+		if (value.DayCount==0){
+			if (value.IsLimitNumber==1){
+				if value.Count>=int64(value.LimitNumber){
+					userLottery.IsReceive=false
+				}
 			}
+		}else{
+			userLottery.IsReceive=false
 		}
 		for _, value := range value.UseProductList {
 			productJson:=activity.ProductJson{}

+ 1 - 1
service/ActivityService.go

@@ -184,7 +184,7 @@ func (service *ActivityService) ActivityLottery(in *activity.Request) (int64, st
 	//2、先查找活动下的奖品Id
 	lotteryJsonList := []entity.LotteryJson{}
 	err = orm.Table("activity").Alias("a").
-		Select("p.prizeType as lotteryType,l.full,l.reduce, p.beginDate,p.endDate,l.stockNumber,l.receiveNumber,p.limitNumber,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id AND up.userId ='"+in.UserId+"' ) AS count,p.isLimitNumber,p.validityTimeType,p.validityDates,p.instructions,p.remark,l.id as lotteryId ,l.name ").
+		Select("p.prizeType as lotteryType,l.full,l.reduce, p.beginDate,p.endDate,l.stockNumber,l.receiveNumber,p.limitNumber,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id AND up.userId ='"+in.UserId+"' ) AS count,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id AND up.userId ='"+in.UserId+"' and  to_days(createTime) = to_days(now())) AS daycount,p.isLimitNumber,p.validityTimeType,p.validityDates,p.instructions,p.remark,l.id as lotteryId ,l.name ").
 		Join("left", "prize p", " a.prizeId = p.Id").
 		Join("left", "lottery l", " l.prizeId = p.id ").
 		Where("a.id = ?  and a.appId=? ", in.ActivityId, in.AppId).Find(&lotteryJsonList)