فهرست منبع

feat:资源扣减

wangchuanjin 3 سال پیش
والد
کامیت
3e4447270f

+ 2 - 2
rpc/etc/resource.yaml

@@ -2,11 +2,11 @@ Name: resource.rpc
 ListenOn: 0.0.0.0:1005
 Etcd:
   Hosts:
-  - 192.168.3.240:2379
+  - 127.0.0.1:2379
   Key: resource.rpc
 Mysql:
   BaseService:
-    DbName: jianyu
+    DbName: base_service
     Address: 192.168.3.11:3366
     UserName: root
     PassWord: Topnet123

+ 8 - 6
rpc/internal/entity/base_goods_function.go

@@ -25,20 +25,22 @@ type base_goods_function struct {
 
 //根据商品代码查找商品的功能明细
 func (b *base_goods_function) FindByGoodsCode(appid, goods_code string) *[]*base_goods_function {
-	list := Mysql_BaseService.SelectBySql(`select a.*,b.* from base_goods_function a inner join base_function b on (a.appid=? and a.goods_code=? and b.appid=? and a.function_code=b.code)`, appid, goods_code, appid)
+	list := Mysql_BaseService.SelectBySql(`select a.id as a_id,a.appid as a_appid,a.goods_code as a_goods_code,a.function_code as a_function_code,a.limit_strategy as a_limit_strategy,a.strategy_count as a_strategy_count,a.power_type as a_power_type,a.use_count as a_use_count,a.power_count as a_power_count,
+		b.id as b_id,b.appid as b_appid,b.name as b_name,b.code as b_code,b.status as b_status,b.haspower as b_haspower,b.version as b_version,b.power_rule as b_power_rule,b.power_type as b_power_type  
+		from base_goods_function a inner join base_function b on (a.appid=? and a.goods_code=? and b.appid=? and a.function_code=b.code)`, appid, goods_code, appid)
 	l := []*base_goods_function{}
 	if list != nil {
 		for _, v := range *list {
 			a, b := map[string]interface{}{}, map[string]interface{}{}
 			for kk, vv := range v {
-				if strings.HasPrefix(kk, "a.") {
-					a[strings.TrimPrefix(kk, "a.")] = vv
-				} else if strings.HasPrefix(kk, "b.") {
-					b[strings.TrimPrefix(kk, "b.")] = vv
+				if strings.HasPrefix(kk, "a_") {
+					a[strings.TrimPrefix(kk, "a_")] = vv
+				} else if strings.HasPrefix(kk, "b_") {
+					b[strings.TrimPrefix(kk, "b_")] = vv
 				}
 			}
 			aa := JsonUnmarshal(a, &base_goods_function{}).(*base_goods_function)
-			bb := JsonUnmarshal(list, &base_function{}).(*base_function)
+			bb := JsonUnmarshal(b, &base_function{}).(*base_function)
 			aa.Base_function = bb
 			l = append(l, aa)
 		}

+ 10 - 8
rpc/internal/entity/base_power.go

@@ -40,20 +40,22 @@ func (b *base_power) OpenPower(appid, goods_code string, user_id, ent_id int64,
 		//企业互斥的功能失效掉
 		if ent_id > 0 {
 			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_function b 
-				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and a.goods_code=? and a.function_code=b.function_code) 
-				inner join base_function c on (c.appid=? and c.status=1 and power_type=1 and code=a.function_code) 
-				set a.status=0`, appid, ent_id, appid, goods_code) > -1
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and a.function_code=b.function_code) 
+				inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code) 
+				set a.status=0`, appid, ent_id, appid, goods_code, appid) > -1
 		}
 		//用户互斥的功能失效掉
 		if user_id > 0 {
 			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_function b 
-				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and a.goods_code=? and a.function_code=b.function_code) 
-				inner join base_function c on (c.appid=? and c.status=1 and power_type=1 and code=a.function_code) 
-				set a.status=0`, appid, user_id, appid, goods_code) > -1
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and a.function_code=b.function_code) 
+				inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code) 
+				set a.status=0`, appid, user_id, appid, goods_code, appid) > -1
 		}
 		power_values, empower_values := []interface{}{}, []interface{}{}
 		for _, v := range *bgfs {
-			if v.Base_function.Haspower == 0 {
+			if v.Base_function == nil {
+				continue
+			} else if v.Base_function.Haspower == 0 {
 				continue
 			}
 			power_values = append(power_values, appid, v.Function_code, v.Power_type)
@@ -81,7 +83,7 @@ func (b *base_power) OpenPower(appid, goods_code string, user_id, ent_id int64,
 			logx.Error(appid, goods_code, user_id, ent_id, "没有找到需要开通的权益")
 			return false
 		}
-		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "function_code", "power_type", "power_ofid", "start_time", "end_time", "count", "limit_strategy", "strategy_count", "status", "create_time"}, power_values)
+		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_count", "limit_strategy", "strategy_count", "status", "create_time"}, power_values)
 		ok3 := true
 		if len(empower_values) > 0 {
 			v3, v4 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_empower", []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}, empower_values)

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

@@ -29,7 +29,6 @@ func NewCheckPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckP
 
 //检查用户权益
 func (l *CheckPowerLogic) CheckPower(in *pb.CheckPowerReq) (*pb.Resp, error) {
-	l.Info("检查用户权益请求参数", fmt.Sprintf("%+v", in))
 	resp := &pb.Resp{}
 	if in.Appid == "" {
 		l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")

+ 0 - 1
rpc/internal/logic/deductionlogic.go

@@ -29,7 +29,6 @@ func NewDeductionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Deducti
 
 //资源扣减
 func (l *DeductionLogic) Deduction(in *pb.DeductionReq) (*pb.Resp, error) {
-	l.Info("资源扣减请求参数", fmt.Sprintf("%+v", in))
 	resp := &pb.Resp{}
 	if in.Appid == "" {
 		l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")

+ 0 - 1
rpc/internal/logic/powerhandlelogic.go

@@ -26,7 +26,6 @@ func NewPowerHandleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Power
 
 //开通或者取消权益
 func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
-	l.Info("开通或者取消权益请求参数", fmt.Sprintf("%+v", in))
 	resp := &pb.Resp{}
 	if in.Appid == "" {
 		l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")

+ 0 - 1
rpc/resource.go

@@ -8,7 +8,6 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/config"
-	_ "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/db"
 	"github.com/zeromicro/go-zero/core/service"
 	"github.com/zeromicro/go-zero/zrpc"
 	"google.golang.org/grpc"

BIN
rpc/rpc.exe


+ 45 - 0
test/resource.go

@@ -0,0 +1,45 @@
+package main
+
+import (
+	"context"
+	"log"
+
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+var c = resource.NewResource(zrpc.MustNewClient(zrpc.RpcClientConf{
+	Etcd: discov.EtcdConf{
+		Hosts: []string{"127.0.0.1:2379"},
+		Key:   "resource.rpc",
+	},
+}))
+
+func main() {
+	PowerHandle()
+}
+
+//开通或者取消用户/企业权益
+func PowerHandle() {
+	r, err := c.PowerHandle(context.Background(), &pb.PowerReq{
+		Appid:     "10000",
+		GoodsCode: "xxfb_gyxx",
+		EntId:     55,
+		StartTime: "2022-04-19 00:00:00",
+		EndTime:   "2021-04-19 23:59:59",
+		Type:      1,
+	})
+	log.Println("----------", r.Status, err)
+}
+
+//检查用户/企业权益
+func CheckPower() {
+
+}
+
+//资源扣减
+func Deduction() {
+
+}

BIN
test/test.exe