Răsfoiți Sursa

feat:资源扣减

wangchuanjin 3 ani în urmă
părinte
comite
4f63dacd5c

+ 1 - 1
rpc/internal/entity/base_ent_empower.go

@@ -19,5 +19,5 @@ type base_ent_empower struct {
 //授权记录
 //授权记录
 func (b *base_ent_empower) FindMyEntId(appid, function_code string, ent_id int64) *[]*base_ent_empower {
 func (b *base_ent_empower) FindMyEntId(appid, function_code string, ent_id int64) *[]*base_ent_empower {
 	list := Mysql_BaseService.SelectBySql(`select * from base_ent_empower where appid=? and function_code=? and ent_id=?`, appid, function_code, ent_id)
 	list := Mysql_BaseService.SelectBySql(`select * from base_ent_empower where appid=? and function_code=? and ent_id=?`, appid, function_code, ent_id)
-	return JsonUnmarshal(list, &[]base_ent_empower{}).(*[]*base_ent_empower)
+	return JsonUnmarshal(list, &[]*base_ent_empower{}).(*[]*base_ent_empower)
 }
 }

+ 2 - 2
rpc/internal/entity/base_power.go

@@ -29,8 +29,8 @@ type base_power struct {
 //查找我的权益
 //查找我的权益
 func (b *base_power) FindMyPower(appid, function_code string, user_id, ent_id int64) *[]*base_power {
 func (b *base_power) FindMyPower(appid, function_code string, user_id, ent_id int64) *[]*base_power {
 	now := NowFormat(Date_Full_Layout)
 	now := NowFormat(Date_Full_Layout)
-	list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and ((power_type=1 and power_ofid=?) or (power_type=2 and power_ofid=?)) and end_time>? and status=1 order by power_type`, appid, function_code, user_id, ent_id, now)
-	return JsonUnmarshal(list, &[]base_power{}).(*[]*base_power)
+	list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and ((power_type=1 and power_ofid=?) or (power_type=2 and power_ofid=?)) and end_time<? and status=1 order by power_type`, appid, function_code, user_id, ent_id, now)
+	return JsonUnmarshal(list, &[]*base_power{}).(*[]*base_power)
 }
 }
 
 
 //开通权益
 //开通权益

+ 1 - 1
rpc/internal/entity/base_resource_use.go

@@ -37,7 +37,7 @@ func (b *base_resource_use) FindLastOne(appid, function_code string, user_id, en
 		return nil, errors.New("power_type error")
 		return nil, errors.New("power_type error")
 	}
 	}
 	query += ` order by create_time desc limit 1`
 	query += ` order by create_time desc limit 1`
-	list := Mysql_BaseService.SelectBySql(query, args)
+	list := Mysql_BaseService.SelectBySql(query, args...)
 	if list == nil {
 	if list == nil {
 		return nil, errors.New("find error")
 		return nil, errors.New("find error")
 	}
 	}

+ 1 - 1
rpc/internal/logic/checkpowerlogic.go

@@ -87,7 +87,7 @@ func (l *CheckPowerLogic) CheckPower(in *pb.CheckPowerReq) (*pb.Resp, error) {
 			} else if function.Power_rule == 3 { //周期+频率+数量校验
 			} else if function.Power_rule == 3 { //周期+频率+数量校验
 				use, err := Base_resource_use.FindLastOne(in.Appid, in.FunctionCode, in.UserId, in.EntId, v.Power_type)
 				use, err := Base_resource_use.FindLastOne(in.Appid, in.FunctionCode, in.UserId, in.EntId, v.Power_type)
 				if err != nil {
 				if err != nil {
-					l.Error(fmt.Sprintf("%+v", in), "查询资源使用记录失败")
+					l.Error(fmt.Sprintf("%+v", in), "查询资源使用记录失败", err)
 					return resp, nil
 					return resp, nil
 				} else if use == nil {
 				} else if use == nil {
 					resp.Status = 1
 					resp.Status = 1

BIN
rpc/rpc.exe


+ 8 - 2
test/resource.go

@@ -18,7 +18,8 @@ var c = resource.NewResource(zrpc.MustNewClient(zrpc.RpcClientConf{
 }))
 }))
 
 
 func main() {
 func main() {
-	PowerHandle()
+	//PowerHandle()
+	CheckPower()
 }
 }
 
 
 //开通或者取消用户/企业权益
 //开通或者取消用户/企业权益
@@ -36,7 +37,12 @@ func PowerHandle() {
 
 
 //检查用户/企业权益
 //检查用户/企业权益
 func CheckPower() {
 func CheckPower() {
-
+	r, err := c.CheckPower(context.Background(), &pb.CheckPowerReq{
+		Appid:        "10000",
+		FunctionCode: "xxfb_gyxx_add",
+		EntId:        55,
+	})
+	log.Println("----------", r.Status, err)
 }
 }
 
 
 //资源扣减
 //资源扣减

BIN
test/test.exe