Jelajahi Sumber

医疗领域化

wangchuanjin 2 tahun lalu
induk
melakukan
e72e50029f

+ 9 - 10
public/entity/base_function.go

@@ -9,16 +9,15 @@ var Base_function = base_function{}
 
 //功能原始表
 type base_function struct {
-	Id            int64
-	Appid         string
-	Name          string //功能名称
-	Code          string //功能代码
-	Status        int64  //0:不可用 1:可用
-	Haspower      int64  //能否生成用户权益;0:否 1:是
-	Version       string //版本号
-	Function_type int64  //1:消耗型(比如:信息发布,需要扣减) 2:固额型(比如:关注条数,不需要扣减) 3:配额型(比如:搜索结果条数)
-	Power_rule    int64  //校验权限规则;1:仅周期 2:周期+数量 3:周期+频率+数量
-	Power_type    int64  //权限类型;1:互斥 2:兼容
+	Id         int64
+	Appid      string
+	Name       string //功能名称
+	Code       string //功能代码
+	Status     int64  //0:不可用 1:可用
+	Haspower   int64  //能否生成用户权益;0:否 1:是
+	Version    string //版本号
+	Power_rule int64  //校验权限规则;1:仅周期 2:周期+数量 3:周期+频率+数量
+	Power_type int64  //权限类型;1:互斥 2:兼容
 }
 
 //根据代码查找功能详情

+ 15 - 6
public/entity/base_power.go

@@ -42,6 +42,15 @@ func (b *base_power) FindMyPower(appid, function_code string, user_id, ent_id in
 	return JsonUnmarshal(list, &[]*base_power{}).(*[]*base_power)
 }
 
+//查找我的权益,加锁
+func (b *base_power) FindMyPowerForUpdate(id int64) *base_power {
+	list := Mysql_BaseService.SelectBySql(`select * from base_power where id=? for update wait 5`, id)
+	if list == nil || len(*list) == 0 {
+		return nil
+	}
+	return JsonUnmarshal((*list)[0], &base_power{}).(*base_power)
+}
+
 //开通权益
 func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, user_id, ent_id int64, buy_num int64, bgss *[]*base_goods_spec) bool {
 	return Mysql_BaseService.ExecTx("开通权益", func(tx *sql.Tx) bool {
@@ -49,14 +58,14 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 		//企业互斥的功能失效掉
 		if ent_id > 0 {
 			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
-				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code) 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? 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, goods_spec_id, appid) > -1
 		}
 		//用户互斥的功能失效掉
 		if user_id > 0 {
 			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
-				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code) 
+				on (a.appid=? and a.power_type=1 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? 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, goods_spec_id, appid) > -1
 		}
@@ -101,7 +110,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 				if bgs.Calculation_type == 2 {
 					use_count = buy_num * v.Use_count
 				}
-				power_values = append(power_values, use_count, v.Limit_strategy, v.Strategy_count, 1, NowFormat(Date_Full_Layout))
+				power_values = append(power_values, use_count, use_count, v.Limit_strategy, v.Strategy_count, 1, NowFormat(Date_Full_Layout))
 				//
 				if v.Power_type == 2 && v.Power_count == -1 && Base_ent_empower.Count(appid, v.Function_code, ent_id) == 0 {
 					empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, NowFormat(Date_Full_Layout))
@@ -114,7 +123,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 			logx.Error(appid, goods_code, goods_spec_id, user_id, ent_id, "没有找到需要开通的权益")
 			return false
 		}
-		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "goods_spec_power_id", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_count", "limit_strategy", "strategy_count", "status", "create_time"}, power_values)
+		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "goods_spec_power_id", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_count", "surplus_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)
@@ -135,12 +144,12 @@ func (b *base_power) CancelPower(appid, goods_code string, spec_id, user_id, ent
 		ok1, ok2 := false, false
 		if user_id > 0 {
 			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
-				on (a.appid=? and a.power_type=1 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=1 and a.function_code=b.function_code) 
+				on (a.appid=? and a.power_type=1 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=1 and a.function_code=b.function_code) 
 				set a.status=-1`, appid, user_id, appid, goods_code, spec_id) > 0
 		}
 		if ent_id > 0 {
 			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
-				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=2 and a.function_code=b.function_code) 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=2 and a.function_code=b.function_code) 
 				set a.status=-1`, appid, ent_id, appid, goods_code, spec_id) > 0
 		}
 		return ok1 || ok2

+ 29 - 0
public/entity/base_resource_use.go

@@ -3,8 +3,10 @@ package entity
 import (
 	"database/sql"
 	"errors"
+	"strings"
 
 	. "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/date"
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
 )
 
@@ -68,3 +70,30 @@ func (b *base_resource_use) Deduction(use_values []interface{}, detail_values []
 		return v1 > 0 && v2 > 0 && v3 > 0 && v4 > 0 && ok
 	})
 }
+
+//新增充值记录
+func (b *base_resource_use) Recharge(appid, function_code string, power_id, user_id, ent_id int64, count int64, ids []string) int {
+	status := 0
+	Mysql_BaseService.ExecTx("新增充值记录", func(tx *sql.Tx) bool {
+		power := Base_power.FindMyPowerForUpdate(power_id)
+		if power == nil {
+			return true
+		}
+		if power.Surplus_count+count > power.Use_count {
+			status = -1
+			return true
+		}
+		nowFormat := NowFormat(Date_Full_Layout)
+		use_values := []interface{}{appid, ent_id, user_id, function_code, count, power.Surplus_count + count, 0, strings.Join(ids, ","), nowFormat}
+		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_resource_use", []string{"appid", "ent_id", "user_id", "function_code", "add_count", "surplus_count", "deduct_count", "business_id", "create_time"}, use_values)
+		use_detail_values := []interface{}{appid, v2, power_id, 0, 0, nowFormat}
+		v4, v5 := Mysql_BaseService.InsertBatchByTx(tx, "base_resource_use_detail", []string{"appid", "use_id", "power_id", "surplus_count", "deduct_count", "create_time"}, use_detail_values)
+		v3 := Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power set surplus_count=surplus_count+?,update_time=? where id=?`, count, nowFormat, power_id)
+		if v1 > 0 && v2 > 0 && v3 > 0 && v4 > 0 && v5 > 0 {
+			status = 1
+			return true
+		}
+		return false
+	})
+	return status
+}

+ 8 - 3
public/service/deduction_test.go

@@ -3,12 +3,17 @@ package service
 import (
 	"testing"
 
-	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
 	"github.com/stretchr/testify/assert"
 )
 
 func TestDeduction(t *testing.T) {
-	status, err := Deduction("10000", "xxfb_gyxx", 0, 14184, 1, []string{"test"})
+	// 医疗标讯搜索	lyh_yl_ylbxss
+	// 医疗机构搜索	lyh_yl_yljgss
+	// 经销商搜索		lyh_yl_jxsss
+	// 医疗机构画像	lyh_yl_yljghx
+	// 医疗机构认领	lyh_yl_yljgrl
+	// 经销商认领		lyh_yl_jxsrl
+	status, err := Deduction("10000", "lyh_yl_yljgrl", 68773, 0, 1, []string{"test"})
 	assert.Nil(t, err)
-	assert.Equal(t, 1, status)
+	assert.Equal(t, int64(1), status)
 }

+ 36 - 0
public/service/power.go

@@ -1,10 +1,46 @@
 package service
 
 import (
+	"errors"
+
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 )
 
+/*
+ * 开通权益
+ * @param appid
+ * @param goods_code 商品代码
+ * @param goods_spec_id 商品规格id
+ * @param user_id 用户id
+ * @param ent_id 企业id
+ * @param buy_num 购买数量
+ * @return error
+ */
+func OpenPower(appid, goods_code string, goods_spec_id, user_id, ent_id int64, buy_num int64) error {
+	list := Base_goods_spec.FindById(goods_spec_id, appid, goods_code)
+	if list == nil {
+		return errors.New("没有找到该商品规格")
+	} else if Base_power.OpenPower(goods_spec_id, appid, goods_code, user_id, ent_id, buy_num, list) {
+		return nil
+	} else {
+		return errors.New("开通失败")
+	}
+}
+
+/*
+ * 取消权益
+ * @param appid
+ * @param goods_code 商品代码
+ * @param goods_spec_id 商品规格id
+ * @param user_id 用户id
+ * @param ent_id 企业id
+ * @return 是否成功
+ */
+func CancelPower(appid, goods_code string, goods_spec_id, user_id, ent_id int64) bool {
+	return Base_power.CancelPower(appid, goods_code, goods_spec_id, user_id, ent_id)
+}
+
 /*
  * 获取待授权详情
  * @param appid

+ 16 - 5
public/service/power_test.go

@@ -3,17 +3,28 @@ package service
 import (
 	"testing"
 
-	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
 	"github.com/stretchr/testify/assert"
 )
 
-func TestOpenPowers(t *testing.T) {
-	list := Base_goods_spec.FindById(4, "10000", "xxfb_gyxx")
-	Base_power.OpenPower(4, "10000", "xxfb_gyxx", 0, 14184, 1, list)
+func TestOpenPower(t *testing.T) {
+	//站内社交
+	//OpenPower("10000", "xxfb_gyxx", 4, 0, 14184, 1)
+	//医疗领域化
+	err := OpenPower("10000", "lyh", 13, 68773, 0, 1)
+	assert.Nil(t, err)
+}
+
+func TestCancelPower(t *testing.T) {
+	//医疗领域化
+	b := CancelPower("10000", "lyh", 13, 68773, 0)
+	assert.True(t, b)
 }
 
 func TestHasPowers(t *testing.T) {
-	t.Log(HasPowers("10000", 0, 14184, 4271))
+	//企业
+	//t.Log(HasPowers("10000", 0, 14184, 4271))
+	//个人
+	t.Log(HasPowers("10000", 68773, 0, 0))
 }
 
 func TestReEmpower(t *testing.T) {

+ 6 - 0
public/service/recharge.go

@@ -25,5 +25,11 @@ func Recharge(appid, function_code string, user_id, ent_id int64, count int64, i
 	if myPowers == nil || len(*myPowers) == 0 {
 		return -1, errors.New("功能权益表中没有找到权益记录")
 	}
+	status := Base_resource_use.Recharge(appid, function_code, (*myPowers)[0].Id, user_id, ent_id, count, ids)
+	if status == 1 {
+		return 1, nil
+	} else if status == -1 {
+		return -4, nil
+	}
 	return 0, nil
 }

+ 5 - 3
public/service/recharge_test.go

@@ -3,12 +3,14 @@ package service
 import (
 	"testing"
 
-	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
 	"github.com/stretchr/testify/assert"
 )
 
 func TestRecharge(t *testing.T) {
-	status, err := Recharge("10000", "xxfb_gyxx", 0, 0, 1, []string{"test"})
+	// 医疗机构认领	lyh_yl_yljgrl
+	// 经销商认领		lyh_yl_jxsrl
+	status, err := Recharge("10000", "lyh_yl_yljgrl", 68773, 0, 1, []string{"test"})
+	t.Log(status, err)
 	assert.Nil(t, err)
-	assert.Equal(t, 1, status)
+	assert.Equal(t, int64(1), status)
 }

+ 9 - 1
public/service/surplus_test.go

@@ -5,5 +5,13 @@ import (
 )
 
 func TestSurplus(t *testing.T) {
-	t.Log(Surplus("10000", "xxfb_gyxx_add", 0, 14184, 0))
+	//供应信息发布
+	//t.Log(Surplus("10000", "xxfb_gyxx_add", 0, 14184, 0))
+	// 医疗标讯搜索	lyh_yl_ylbxss
+	// 医疗机构搜索	lyh_yl_yljgss
+	// 经销商搜索		lyh_yl_jxsss
+	// 医疗机构画像	lyh_yl_yljghx
+	// 医疗机构认领	lyh_yl_yljgrl
+	// 经销商认领		lyh_yl_jxsrl
+	t.Log(Surplus("10000", "lyh_yl_yljgrl", 68773, 0, 0))
 }

+ 5 - 9
rpc/internal/logic/powerhandlelogic.go

@@ -4,7 +4,7 @@ import (
 	"context"
 	"fmt"
 
-	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -38,17 +38,13 @@ func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
 		return resp, nil
 	}
 	if in.Type == 1 { //开通
-		list := Base_goods_spec.FindById(in.GoodsSpecId, in.Appid, in.GoodsCode)
-		if list != nil {
-			if Base_power.OpenPower(in.GoodsSpecId, in.Appid, in.GoodsCode, in.UserId, in.EntId, in.BuyNum, list) {
-				return &pb.Resp{Status: 1}, nil
-			}
+		if err := OpenPower(in.Appid, in.GoodsCode, in.GoodsSpecId, in.UserId, in.EntId, in.BuyNum); err != nil {
+			l.Error(fmt.Sprintf("%+v", in), err)
 		} else {
-			l.Error(fmt.Sprintf("%+v", in), "没有找到该商品规格")
-			return resp, nil
+			return &pb.Resp{Status: 1}, nil
 		}
 	} else if in.Type == -1 { //取消
-		if Base_power.CancelPower(in.Appid, in.GoodsCode, in.GoodsSpecId, in.UserId, in.EntId) {
+		if CancelPower(in.Appid, in.GoodsCode, in.GoodsSpecId, in.UserId, in.EntId) {
 			return &pb.Resp{Status: 1}, nil
 		}
 	} else {

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

@@ -40,7 +40,7 @@ func (l *RechargeLogic) Recharge(in *pb.RechargeReq) (*pb.Resp, error) {
 		l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id")
 		return resp, nil
 	}
-	status, err := Deduction(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.Count, in.Ids)
+	status, err := Recharge(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.Count, in.Ids)
 	if err != nil {
 		l.Error(fmt.Sprintf("%+v", in), err)
 	}