|
@@ -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
|